dom/xbl/nsXBLEventHandler.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:bd00f863f00e
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 nsXBLEventHandler_h__
7 #define nsXBLEventHandler_h__
8
9 #include "mozilla/Attributes.h"
10 #include "nsCOMPtr.h"
11 #include "nsIDOMEventListener.h"
12 #include "nsTArray.h"
13
14 class nsIAtom;
15 class nsIDOMKeyEvent;
16 class nsXBLPrototypeHandler;
17
18 class nsXBLEventHandler : public nsIDOMEventListener
19 {
20 public:
21 nsXBLEventHandler(nsXBLPrototypeHandler* aHandler);
22 virtual ~nsXBLEventHandler();
23
24 NS_DECL_ISUPPORTS
25
26 NS_DECL_NSIDOMEVENTLISTENER
27
28 protected:
29 nsXBLPrototypeHandler* mProtoHandler;
30
31 private:
32 nsXBLEventHandler();
33 virtual bool EventMatched(nsIDOMEvent* aEvent)
34 {
35 return true;
36 }
37 };
38
39 class nsXBLMouseEventHandler : public nsXBLEventHandler
40 {
41 public:
42 nsXBLMouseEventHandler(nsXBLPrototypeHandler* aHandler);
43 virtual ~nsXBLMouseEventHandler();
44
45 private:
46 bool EventMatched(nsIDOMEvent* aEvent) MOZ_OVERRIDE;
47 };
48
49 class nsXBLKeyEventHandler : public nsIDOMEventListener
50 {
51 public:
52 nsXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType);
53 virtual ~nsXBLKeyEventHandler();
54
55 NS_DECL_ISUPPORTS
56
57 NS_DECL_NSIDOMEVENTLISTENER
58
59 void AddProtoHandler(nsXBLPrototypeHandler* aProtoHandler)
60 {
61 mProtoHandlers.AppendElement(aProtoHandler);
62 }
63
64 bool Matches(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType) const
65 {
66 return (mEventType == aEventType && mPhase == aPhase && mType == aType);
67 }
68
69 void GetEventName(nsAString& aString) const
70 {
71 mEventType->ToString(aString);
72 }
73
74 uint8_t GetPhase() const
75 {
76 return mPhase;
77 }
78
79 uint8_t GetType() const
80 {
81 return mType;
82 }
83
84 void SetIsBoundToChrome(bool aIsBoundToChrome)
85 {
86 mIsBoundToChrome = aIsBoundToChrome;
87 }
88
89 void SetUsingXBLScope(bool aUsingXBLScope)
90 {
91 mUsingXBLScope = aUsingXBLScope;
92 }
93
94 private:
95 nsXBLKeyEventHandler();
96 bool ExecuteMatchedHandlers(nsIDOMKeyEvent* aEvent, uint32_t aCharCode,
97 bool aIgnoreShiftKey);
98
99 nsTArray<nsXBLPrototypeHandler*> mProtoHandlers;
100 nsCOMPtr<nsIAtom> mEventType;
101 uint8_t mPhase;
102 uint8_t mType;
103 bool mIsBoundToChrome;
104 bool mUsingXBLScope;
105 };
106
107 nsresult
108 NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler,
109 nsIAtom* aEventType,
110 nsXBLEventHandler** aResult);
111
112 nsresult
113 NS_NewXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase,
114 uint8_t aType, nsXBLKeyEventHandler** aResult);
115
116 #endif

mercurial