Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef nsXBLEventHandler_h__
8 : #define nsXBLEventHandler_h__
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "nsCOMPtr.h"
12 : #include "nsIDOMEventListener.h"
13 : #include "nsTArray.h"
14 :
15 : class nsIAtom;
16 : class nsIDOMKeyEvent;
17 : class nsXBLPrototypeHandler;
18 :
19 : namespace mozilla {
20 : struct IgnoreModifierState;
21 : } // namespace mozilla
22 :
23 : class nsXBLEventHandler : public nsIDOMEventListener
24 : {
25 : public:
26 : explicit nsXBLEventHandler(nsXBLPrototypeHandler* aHandler);
27 :
28 : NS_DECL_ISUPPORTS
29 :
30 : NS_DECL_NSIDOMEVENTLISTENER
31 :
32 : protected:
33 : virtual ~nsXBLEventHandler();
34 : nsXBLPrototypeHandler* mProtoHandler;
35 :
36 : private:
37 : nsXBLEventHandler();
38 6 : virtual bool EventMatched(nsIDOMEvent* aEvent)
39 : {
40 6 : return true;
41 : }
42 : };
43 :
44 : class nsXBLMouseEventHandler : public nsXBLEventHandler
45 : {
46 : public:
47 : explicit nsXBLMouseEventHandler(nsXBLPrototypeHandler* aHandler);
48 : virtual ~nsXBLMouseEventHandler();
49 :
50 : private:
51 : bool EventMatched(nsIDOMEvent* aEvent) override;
52 : };
53 :
54 : class nsXBLKeyEventHandler : public nsIDOMEventListener
55 : {
56 : typedef mozilla::IgnoreModifierState IgnoreModifierState;
57 :
58 : public:
59 : nsXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType);
60 :
61 : NS_DECL_ISUPPORTS
62 :
63 : NS_DECL_NSIDOMEVENTLISTENER
64 :
65 36 : void AddProtoHandler(nsXBLPrototypeHandler* aProtoHandler)
66 : {
67 36 : mProtoHandlers.AppendElement(aProtoHandler);
68 36 : }
69 :
70 27 : bool Matches(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType) const
71 : {
72 27 : return (mEventType == aEventType && mPhase == aPhase && mType == aType);
73 : }
74 :
75 49 : void GetEventName(nsAString& aString) const
76 : {
77 49 : mEventType->ToString(aString);
78 49 : }
79 :
80 49 : uint8_t GetPhase() const
81 : {
82 49 : return mPhase;
83 : }
84 :
85 49 : uint8_t GetType() const
86 : {
87 49 : return mType;
88 : }
89 :
90 44 : void SetIsBoundToChrome(bool aIsBoundToChrome)
91 : {
92 44 : mIsBoundToChrome = aIsBoundToChrome;
93 44 : }
94 :
95 44 : void SetUsingContentXBLScope(bool aUsingContentXBLScope)
96 : {
97 44 : mUsingContentXBLScope = aUsingContentXBLScope;
98 44 : }
99 :
100 : private:
101 : nsXBLKeyEventHandler();
102 : virtual ~nsXBLKeyEventHandler();
103 :
104 : bool ExecuteMatchedHandlers(nsIDOMKeyEvent* aEvent, uint32_t aCharCode,
105 : const IgnoreModifierState& aIgnoreModifierState);
106 :
107 : nsTArray<nsXBLPrototypeHandler*> mProtoHandlers;
108 : nsCOMPtr<nsIAtom> mEventType;
109 : uint8_t mPhase;
110 : uint8_t mType;
111 : bool mIsBoundToChrome;
112 : bool mUsingContentXBLScope;
113 : };
114 :
115 : already_AddRefed<nsXBLEventHandler>
116 : NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler,
117 : nsIAtom* aEventType);
118 :
119 : #endif
|