mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1203059 part.3 Installing and removing keyboard event listeners of nsXBLWindowKeyHandler should be done by the class itself r=smaug
This commit is contained in:
parent
12a007fd7f
commit
10086a4e8d
@ -556,32 +556,7 @@ nsXBLService::AttachGlobalKeyHandler(EventTarget* aTarget)
|
|||||||
RefPtr<nsXBLWindowKeyHandler> handler =
|
RefPtr<nsXBLWindowKeyHandler> handler =
|
||||||
NS_NewXBLWindowKeyHandler(elt, piTarget);
|
NS_NewXBLWindowKeyHandler(elt, piTarget);
|
||||||
|
|
||||||
// listen to these events
|
handler->InstallKeyboardEventListenersTo(manager);
|
||||||
manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keydown"),
|
|
||||||
TrustedEventsAtSystemGroupBubble());
|
|
||||||
manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keyup"),
|
|
||||||
TrustedEventsAtSystemGroupBubble());
|
|
||||||
manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keypress"),
|
|
||||||
TrustedEventsAtSystemGroupBubble());
|
|
||||||
|
|
||||||
// For marking each keyboard event as if it's reserved by chrome,
|
|
||||||
// nsXBLWindowKeyHandlers need to listen each keyboard events before
|
|
||||||
// web contents.
|
|
||||||
manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keydown"),
|
|
||||||
TrustedEventsAtCapture());
|
|
||||||
manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keyup"),
|
|
||||||
TrustedEventsAtCapture());
|
|
||||||
manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keypress"),
|
|
||||||
TrustedEventsAtCapture());
|
|
||||||
|
|
||||||
// The capturing listener is only used for XUL keysets to properly handle
|
|
||||||
// shortcut keys in a multi-process environment.
|
|
||||||
manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keydown"),
|
|
||||||
TrustedEventsAtSystemGroupCapture());
|
|
||||||
manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keyup"),
|
|
||||||
TrustedEventsAtSystemGroupCapture());
|
|
||||||
manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keypress"),
|
|
||||||
TrustedEventsAtSystemGroupCapture());
|
|
||||||
|
|
||||||
if (contentNode)
|
if (contentNode)
|
||||||
return contentNode->SetProperty(nsGkAtoms::listener,
|
return contentNode->SetProperty(nsGkAtoms::listener,
|
||||||
@ -621,26 +596,8 @@ nsXBLService::DetachGlobalKeyHandler(EventTarget* aTarget)
|
|||||||
if (!handler)
|
if (!handler)
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keydown"),
|
static_cast<nsXBLWindowKeyHandler*>(handler)->
|
||||||
TrustedEventsAtSystemGroupBubble());
|
RemoveKeyboardEventListenersFrom(manager);
|
||||||
manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keyup"),
|
|
||||||
TrustedEventsAtSystemGroupBubble());
|
|
||||||
manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keypress"),
|
|
||||||
TrustedEventsAtSystemGroupBubble());
|
|
||||||
|
|
||||||
manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keydown"),
|
|
||||||
TrustedEventsAtCapture());
|
|
||||||
manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keyup"),
|
|
||||||
TrustedEventsAtCapture());
|
|
||||||
manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keypress"),
|
|
||||||
TrustedEventsAtCapture());
|
|
||||||
|
|
||||||
manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keydown"),
|
|
||||||
TrustedEventsAtSystemGroupCapture());
|
|
||||||
manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keyup"),
|
|
||||||
TrustedEventsAtSystemGroupCapture());
|
|
||||||
manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keypress"),
|
|
||||||
TrustedEventsAtSystemGroupCapture());
|
|
||||||
|
|
||||||
contentNode->DeleteProperty(nsGkAtoms::listener);
|
contentNode->DeleteProperty(nsGkAtoms::listener);
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "nsPIDOMWindow.h"
|
#include "nsPIDOMWindow.h"
|
||||||
#include "nsIDocShell.h"
|
#include "nsIDocShell.h"
|
||||||
#include "nsIPresShell.h"
|
#include "nsIPresShell.h"
|
||||||
|
#include "mozilla/EventListenerManager.h"
|
||||||
#include "mozilla/EventStateManager.h"
|
#include "mozilla/EventStateManager.h"
|
||||||
#include "nsISelectionController.h"
|
#include "nsISelectionController.h"
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
@ -297,6 +298,82 @@ nsXBLWindowKeyHandler::WalkHandlers(nsIDOMKeyEvent* aKeyEvent, nsIAtom* aEventTy
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsXBLWindowKeyHandler::InstallKeyboardEventListenersTo(
|
||||||
|
EventListenerManager* aEventListenerManager)
|
||||||
|
{
|
||||||
|
// For marking each keyboard event as if it's reserved by chrome,
|
||||||
|
// nsXBLWindowKeyHandlers need to listen each keyboard events before
|
||||||
|
// web contents.
|
||||||
|
aEventListenerManager->AddEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keydown"),
|
||||||
|
TrustedEventsAtCapture());
|
||||||
|
aEventListenerManager->AddEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keyup"),
|
||||||
|
TrustedEventsAtCapture());
|
||||||
|
aEventListenerManager->AddEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keypress"),
|
||||||
|
TrustedEventsAtCapture());
|
||||||
|
|
||||||
|
// For reducing the IPC cost, preventing to dispatch reserved keyboard
|
||||||
|
// events into the content process.
|
||||||
|
aEventListenerManager->AddEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keydown"),
|
||||||
|
TrustedEventsAtSystemGroupCapture());
|
||||||
|
aEventListenerManager->AddEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keyup"),
|
||||||
|
TrustedEventsAtSystemGroupCapture());
|
||||||
|
aEventListenerManager->AddEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keypress"),
|
||||||
|
TrustedEventsAtSystemGroupCapture());
|
||||||
|
|
||||||
|
// Handle keyboard events in bubbling phase of the system event group.
|
||||||
|
aEventListenerManager->AddEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keydown"),
|
||||||
|
TrustedEventsAtSystemGroupBubble());
|
||||||
|
aEventListenerManager->AddEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keyup"),
|
||||||
|
TrustedEventsAtSystemGroupBubble());
|
||||||
|
aEventListenerManager->AddEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keypress"),
|
||||||
|
TrustedEventsAtSystemGroupBubble());
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsXBLWindowKeyHandler::RemoveKeyboardEventListenersFrom(
|
||||||
|
EventListenerManager* aEventListenerManager)
|
||||||
|
{
|
||||||
|
aEventListenerManager->RemoveEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keydown"),
|
||||||
|
TrustedEventsAtCapture());
|
||||||
|
aEventListenerManager->RemoveEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keyup"),
|
||||||
|
TrustedEventsAtCapture());
|
||||||
|
aEventListenerManager->RemoveEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keypress"),
|
||||||
|
TrustedEventsAtCapture());
|
||||||
|
|
||||||
|
aEventListenerManager->RemoveEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keydown"),
|
||||||
|
TrustedEventsAtSystemGroupCapture());
|
||||||
|
aEventListenerManager->RemoveEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keyup"),
|
||||||
|
TrustedEventsAtSystemGroupCapture());
|
||||||
|
aEventListenerManager->RemoveEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keypress"),
|
||||||
|
TrustedEventsAtSystemGroupCapture());
|
||||||
|
|
||||||
|
aEventListenerManager->RemoveEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keydown"),
|
||||||
|
TrustedEventsAtSystemGroupBubble());
|
||||||
|
aEventListenerManager->RemoveEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keyup"),
|
||||||
|
TrustedEventsAtSystemGroupBubble());
|
||||||
|
aEventListenerManager->RemoveEventListenerByType(
|
||||||
|
this, NS_LITERAL_STRING("keypress"),
|
||||||
|
TrustedEventsAtSystemGroupBubble());
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsXBLWindowKeyHandler::HandleEvent(nsIDOMEvent* aEvent)
|
nsXBLWindowKeyHandler::HandleEvent(nsIDOMEvent* aEvent)
|
||||||
{
|
{
|
||||||
|
@ -17,6 +17,7 @@ class nsXBLSpecialDocInfo;
|
|||||||
class nsXBLPrototypeHandler;
|
class nsXBLPrototypeHandler;
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
class EventListenerManager;
|
||||||
namespace dom {
|
namespace dom {
|
||||||
class Element;
|
class Element;
|
||||||
class EventTarget;
|
class EventTarget;
|
||||||
@ -27,10 +28,16 @@ struct IgnoreModifierState;
|
|||||||
class nsXBLWindowKeyHandler : public nsIDOMEventListener
|
class nsXBLWindowKeyHandler : public nsIDOMEventListener
|
||||||
{
|
{
|
||||||
typedef mozilla::dom::IgnoreModifierState IgnoreModifierState;
|
typedef mozilla::dom::IgnoreModifierState IgnoreModifierState;
|
||||||
|
typedef mozilla::EventListenerManager EventListenerManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
nsXBLWindowKeyHandler(nsIDOMElement* aElement, mozilla::dom::EventTarget* aTarget);
|
nsXBLWindowKeyHandler(nsIDOMElement* aElement, mozilla::dom::EventTarget* aTarget);
|
||||||
|
|
||||||
|
void InstallKeyboardEventListenersTo(
|
||||||
|
EventListenerManager* aEventListenerManager);
|
||||||
|
void RemoveKeyboardEventListenersFrom(
|
||||||
|
EventListenerManager* aEventListenerManager);
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
NS_DECL_NSIDOMEVENTLISTENER
|
NS_DECL_NSIDOMEVENTLISTENER
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user