dom/xbl/nsXBLWindowKeyHandler.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:f5b597acc84d
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef nsXBLWindowKeyHandler_h__
7 #define nsXBLWindowKeyHandler_h__
8
9 #include "nsWeakPtr.h"
10 #include "nsIDOMEventListener.h"
11
12 class nsIAtom;
13 class nsIDOMElement;
14 class nsIDOMKeyEvent;
15 class nsXBLSpecialDocInfo;
16 class nsXBLPrototypeHandler;
17
18 namespace mozilla {
19 namespace dom {
20 class Element;
21 class EventTarget;
22 }
23 }
24
25 class nsXBLWindowKeyHandler : public nsIDOMEventListener
26 {
27 public:
28 nsXBLWindowKeyHandler(nsIDOMElement* aElement, mozilla::dom::EventTarget* aTarget);
29 virtual ~nsXBLWindowKeyHandler();
30
31 NS_DECL_ISUPPORTS
32 NS_DECL_NSIDOMEVENTLISTENER
33
34 protected:
35 nsresult WalkHandlers(nsIDOMKeyEvent* aKeyEvent, nsIAtom* aEventType);
36
37 // walk the handlers, looking for one to handle the event
38 bool WalkHandlersInternal(nsIDOMKeyEvent* aKeyEvent,
39 nsIAtom* aEventType,
40 nsXBLPrototypeHandler* aHandler,
41 bool aExecute);
42
43 // walk the handlers for aEvent, aCharCode and aIgnoreShiftKey. Execute it
44 // if aExecute = true.
45 bool WalkHandlersAndExecute(nsIDOMKeyEvent* aKeyEvent, nsIAtom* aEventType,
46 nsXBLPrototypeHandler* aHandler,
47 uint32_t aCharCode, bool aIgnoreShiftKey,
48 bool aExecute);
49
50 // HandleEvent function for the capturing phase.
51 void HandleEventOnCapture(nsIDOMKeyEvent* aEvent);
52
53 // Check if any handler would handle the given event.
54 bool HasHandlerForEvent(nsIDOMKeyEvent* aEvent);
55
56 // lazily load the handlers. Overridden to handle being attached
57 // to a particular element rather than the document
58 nsresult EnsureHandlers();
59
60 // check if the given handler cares about the given key event
61 bool EventMatched(nsXBLPrototypeHandler* inHandler, nsIAtom* inEventType,
62 nsIDOMKeyEvent* inEvent, uint32_t aCharCode,
63 bool aIgnoreShiftKey);
64
65 // Is an HTML editable element focused
66 bool IsHTMLEditableFieldFocused();
67
68 // Returns the element which was passed as a parameter to the constructor,
69 // unless the element has been removed from the document. Optionally returns
70 // whether the disabled attribute is set on the element (assuming the element
71 // is non-null).
72 already_AddRefed<mozilla::dom::Element> GetElement(bool* aIsDisabled = nullptr);
73 // Using weak pointer to the DOM Element.
74 nsWeakPtr mWeakPtrForElement;
75 mozilla::dom::EventTarget* mTarget; // weak ref
76
77 // these are not owning references; the prototype handlers are owned
78 // by the prototype bindings which are owned by the docinfo.
79 nsXBLPrototypeHandler* mHandler; // platform bindings
80 nsXBLPrototypeHandler* mUserHandler; // user-specific bindings
81
82 // holds document info about bindings
83 static nsXBLSpecialDocInfo* sXBLSpecialDocInfo;
84 static uint32_t sRefCnt;
85 };
86
87 already_AddRefed<nsXBLWindowKeyHandler>
88 NS_NewXBLWindowKeyHandler(nsIDOMElement* aElement,
89 mozilla::dom::EventTarget* aTarget);
90
91 #endif

mercurial