gecko-dev/dom/base/nsWindowRoot.h
Masayuki Nakano 4ce89d8f61 Bug 1369072 - part3: nsXBLPrototypeHandler::DispatchXBLCommand() should use controller of visible window r=smaug
With previous change, KeyboardEvent is dispatched even when invisible window
has focus.  However, nsRootWindow::GetControllerForCommand() returns controller
for focused window even when the window is invisible because it uses
nsFocusManager::GetFocusedDescendant() to retrieve focused window.

Perhaps, we can assume that users won't expect to do something with invisible
window when they type some keys.  Then, nsRootWindow::GetControllerForCommand()
should return controller for visible ancestor window if focused window is
invisible.

This patch makes nsFocusManager::GetFocusedDescendant() can return only visible
descendants.  However, it already has a bool argument.  Therefore, it should
have a flag instead of adding new flag.  Most changes of this patch is replacing
its callers.

Then, nsRootWindow::GetControllerForCommand() and nsRootWindow::GetControllers()
should have a bool flag if it should return controller(s) for visible window.
This patch adds a bool flag for it.  Fortunately, the interface isn't scriptable.

Finally, this patch makes nsXBLPrototypeHandler::DispatchXBLCommand() and
EventStateManager::DoContentCommandEvent() retrieve controller for visible
window since they are always handles user input.

MozReview-Commit-ID: GygttTHuKRm

--HG--
extra : rebase_source : 1341273c4606298cb9b890b9312d9f5c8a75d144
2017-09-07 22:54:49 +09:00

127 lines
4.3 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 nsIDOMEvent;
class nsIGlobalObject;
#include "mozilla/Attributes.h"
#include "mozilla/EventListenerManager.h"
#include "nsIDOMEventTarget.h"
#include "nsIWeakReferenceUtils.h"
#include "nsPIWindowRoot.h"
#include "nsCycleCollectionParticipant.h"
#include "nsTHashtable.h"
#include "nsHashKeys.h"
class nsWindowRoot final : public nsPIWindowRoot
{
public:
explicit nsWindowRoot(nsPIDOMWindowOuter* aWindow);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIDOMEVENTTARGET
virtual mozilla::EventListenerManager*
GetExistingListenerManager() const override;
virtual mozilla::EventListenerManager*
GetOrCreateListenerManager() override;
using mozilla::dom::EventTarget::RemoveEventListener;
virtual void AddEventListener(const nsAString& aType,
mozilla::dom::EventListener* aListener,
const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
const mozilla::dom::Nullable<bool>& aWantsUntrusted,
mozilla::ErrorResult& aRv) override;
// nsPIWindowRoot
virtual nsPIDOMWindowOuter* GetWindow() override;
virtual nsresult GetControllers(bool aForVisibleWindow,
nsIControllers** aResult) override;
virtual nsresult GetControllerForCommand(const char * aCommand,
bool aForVisibleWindow,
nsIController** _retval) override;
virtual void GetEnabledDisabledCommands(nsTArray<nsCString>& aEnabledCommands,
nsTArray<nsCString>& aDisabledCommands) override;
virtual nsIDOMNode* GetPopupNode() override;
virtual void SetPopupNode(nsIDOMNode* aNode) override;
virtual void SetParentTarget(mozilla::dom::EventTarget* aTarget) override
{
mParent = aTarget;
}
virtual mozilla::dom::EventTarget* GetParentTarget() override { return mParent; }
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
virtual nsIGlobalObject* GetOwnerGlobal() const override;
nsIGlobalObject* GetParentObject();
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsWindowRoot,
nsIDOMEventTarget)
virtual void AddBrowser(mozilla::dom::TabParent* aBrowser) override;
virtual void RemoveBrowser(mozilla::dom::TabParent* aBrowser) override;
virtual void EnumerateBrowsers(BrowserEnumerator aEnumFunc, void *aArg) override;
virtual bool ShowAccelerators() override
{
return mShowAccelerators;
}
virtual bool ShowFocusRings() override
{
return mShowFocusRings;
}
virtual void SetShowAccelerators(bool aEnable) override
{
mShowAccelerators = aEnable;
}
virtual void SetShowFocusRings(bool aEnable) override
{
mShowFocusRings = aEnable;
}
protected:
virtual ~nsWindowRoot();
void GetEnabledDisabledCommandsForControllers(nsIControllers* aControllers,
nsTHashtable<nsCharPtrHashKey>& 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;
// True if focus rings and accelerators are enabled for this
// window hierarchy.
bool mShowAccelerators;
bool mShowFocusRings;
nsCOMPtr<mozilla::dom::EventTarget> mParent;
// The TabParents that are currently registered with this top-level window.
typedef nsTHashtable<nsRefPtrHashKey<nsIWeakReference>> WeakBrowserTable;
WeakBrowserTable mWeakBrowsers;
};
extern already_AddRefed<mozilla::dom::EventTarget>
NS_NewWindowRoot(nsPIDOMWindowOuter* aWindow);
#endif