gecko-dev/dom/base/nsWindowRoot.h
Emilio Cobos Álvarez 56be5080d2 Bug 1807687 - Simplify Windows keyboard indicator setting handling. r=NeilDeakin
The only thing that can explain this is the WM_UPDATEUISTATE state
getting out of sync in a way that we think we need to unconditionally
show focus indicators for a window.

I tried to first make this less error prone (see patch above) but
digging more into these messages, I'm pretty sure we just don't need all
this code. See:

 * https://devblogs.microsoft.com/oldnewthing/20130516-00/?p=4343
 * https://devblogs.microsoft.com/oldnewthing/20130517-00/?p=4323

In particular, this is intended to be a windows feature to not show
keyboard indicators on dialogs until you use the keyboard. But that's
how Gecko dialogs behave already due to how :focus-visible behaves as
per:

  https://searchfox.org/mozilla-central/rev/43ee5e789b079e94837a21336e9ce2420658fd19/toolkit/components/prompts/src/CommonDialog.jsm#319

I haven't been able to repro this state, but sounds believable that it
could happen after opening a native dialog or so on?

The purpose of this code is to implement the 'Underline access keys' in
the Keyboard Accessibility control panel of windows.

There's an easier way of tracking this, via the SPI_GETKEYBOARDCUES SPI,
documented in:

  https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa

Hook that into LookAndFeel rather than using custom IPC and so on.

Differential Revision: https://phabricator.services.mozilla.com/D165578
2023-01-09 18:19:03 +00:00

99 lines
3.4 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsWindowRoot_h__
#define nsWindowRoot_h__
class nsIGlobalObject;
#include "mozilla/Attributes.h"
#include "mozilla/EventListenerManager.h"
#include "nsIWeakReferenceUtils.h"
#include "nsPIWindowRoot.h"
#include "nsCycleCollectionParticipant.h"
#include "nsTHashSet.h"
#include "nsHashKeys.h"
class nsWindowRoot final : public nsPIWindowRoot {
public:
explicit nsWindowRoot(nsPIDOMWindowOuter* aWindow);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
mozilla::EventListenerManager* GetExistingListenerManager() const override;
mozilla::EventListenerManager* GetOrCreateListenerManager() override;
bool ComputeDefaultWantsUntrusted(mozilla::ErrorResult& aRv) final;
// TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
MOZ_CAN_RUN_SCRIPT_BOUNDARY bool DispatchEvent(
mozilla::dom::Event& aEvent, mozilla::dom::CallerType aCallerType,
mozilla::ErrorResult& aRv) override;
void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override;
nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
// nsPIWindowRoot
nsPIDOMWindowOuter* GetWindow() override;
nsresult GetControllers(bool aForVisibleWindow,
nsIControllers** aResult) override;
nsresult GetControllerForCommand(const char* aCommand, bool aForVisibleWindow,
nsIController** _retval) override;
void GetEnabledDisabledCommands(
nsTArray<nsCString>& aEnabledCommands,
nsTArray<nsCString>& aDisabledCommands) override;
already_AddRefed<nsINode> GetPopupNode() override;
void SetPopupNode(nsINode* aNode) override;
void SetParentTarget(mozilla::dom::EventTarget* aTarget) override {
mParent = aTarget;
}
mozilla::dom::EventTarget* GetParentTarget() override { return mParent; }
nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override;
nsIGlobalObject* GetOwnerGlobal() const override;
nsIGlobalObject* GetParentObject();
JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsWindowRoot)
void AddBrowser(nsIRemoteTab* aBrowser) override;
void RemoveBrowser(nsIRemoteTab* aBrowser) override;
void EnumerateBrowsers(BrowserEnumerator aEnumFunc, void* aArg) override;
protected:
virtual ~nsWindowRoot();
void GetEnabledDisabledCommandsForControllers(
nsIControllers* aControllers, nsTHashSet<nsCString>& aCommandsHandled,
nsTArray<nsCString>& aEnabledCommands,
nsTArray<nsCString>& aDisabledCommands);
// Members
nsCOMPtr<nsPIDOMWindowOuter> mWindow;
// We own the manager, which owns event listeners attached to us.
RefPtr<mozilla::EventListenerManager> mListenerManager; // [Strong]
nsWeakPtr mPopupNode;
nsCOMPtr<mozilla::dom::EventTarget> mParent;
// The BrowserParents that are currently registered with this top-level
// window.
using WeakBrowserTable = nsTHashSet<RefPtr<nsIWeakReference>>;
WeakBrowserTable mWeakBrowsers;
};
extern already_AddRefed<mozilla::dom::EventTarget> NS_NewWindowRoot(
nsPIDOMWindowOuter* aWindow);
#endif