dom/xbl/nsXBLPrototypeHandler.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsXBLPrototypeHandler_h__
michael@0 7 #define nsXBLPrototypeHandler_h__
michael@0 8
michael@0 9 #include "nsIAtom.h"
michael@0 10 #include "nsString.h"
michael@0 11 #include "nsCOMPtr.h"
michael@0 12 #include "nsIController.h"
michael@0 13 #include "nsAutoPtr.h"
michael@0 14 #include "nsXBLEventHandler.h"
michael@0 15 #include "nsIWeakReference.h"
michael@0 16 #include "nsIScriptGlobalObject.h"
michael@0 17 #include "nsCycleCollectionParticipant.h"
michael@0 18 #include "js/TypeDecls.h"
michael@0 19
michael@0 20 class nsIDOMEvent;
michael@0 21 class nsIContent;
michael@0 22 class nsIDOMUIEvent;
michael@0 23 class nsIDOMKeyEvent;
michael@0 24 class nsIDOMMouseEvent;
michael@0 25 class nsIObjectInputStream;
michael@0 26 class nsIObjectOutputStream;
michael@0 27 class nsXBLPrototypeBinding;
michael@0 28
michael@0 29 namespace mozilla {
michael@0 30 namespace dom {
michael@0 31 class EventTarget;
michael@0 32 }
michael@0 33 }
michael@0 34
michael@0 35 #define NS_HANDLER_TYPE_XBL_JS (1 << 0)
michael@0 36 #define NS_HANDLER_TYPE_XBL_COMMAND (1 << 1)
michael@0 37 #define NS_HANDLER_TYPE_XUL (1 << 2)
michael@0 38 #define NS_HANDLER_HAS_ALLOW_UNTRUSTED_ATTR (1 << 4)
michael@0 39 #define NS_HANDLER_ALLOW_UNTRUSTED (1 << 5)
michael@0 40 #define NS_HANDLER_TYPE_SYSTEM (1 << 6)
michael@0 41 #define NS_HANDLER_TYPE_PREVENTDEFAULT (1 << 7)
michael@0 42
michael@0 43 // XXX Use nsIDOMEvent:: codes?
michael@0 44 #define NS_PHASE_CAPTURING 1
michael@0 45 #define NS_PHASE_TARGET 2
michael@0 46 #define NS_PHASE_BUBBLING 3
michael@0 47
michael@0 48 class nsXBLPrototypeHandler
michael@0 49 {
michael@0 50 public:
michael@0 51 // This constructor is used by XBL handlers (both the JS and command shorthand variety)
michael@0 52 nsXBLPrototypeHandler(const char16_t* aEvent, const char16_t* aPhase,
michael@0 53 const char16_t* aAction, const char16_t* aCommand,
michael@0 54 const char16_t* aKeyCode, const char16_t* aCharCode,
michael@0 55 const char16_t* aModifiers, const char16_t* aButton,
michael@0 56 const char16_t* aClickCount, const char16_t* aGroup,
michael@0 57 const char16_t* aPreventDefault,
michael@0 58 const char16_t* aAllowUntrusted,
michael@0 59 nsXBLPrototypeBinding* aBinding,
michael@0 60 uint32_t aLineNumber);
michael@0 61
michael@0 62 // This constructor is used only by XUL key handlers (e.g., <key>)
michael@0 63 nsXBLPrototypeHandler(nsIContent* aKeyElement);
michael@0 64
michael@0 65 // This constructor is used for handlers loaded from the cache
michael@0 66 nsXBLPrototypeHandler(nsXBLPrototypeBinding* aBinding);
michael@0 67
michael@0 68 ~nsXBLPrototypeHandler();
michael@0 69
michael@0 70 // if aCharCode is not zero, it is used instead of the charCode of aKeyEvent.
michael@0 71 bool KeyEventMatched(nsIDOMKeyEvent* aKeyEvent,
michael@0 72 uint32_t aCharCode = 0,
michael@0 73 bool aIgnoreShiftKey = false);
michael@0 74 inline bool KeyEventMatched(nsIAtom* aEventType,
michael@0 75 nsIDOMKeyEvent* aEvent,
michael@0 76 uint32_t aCharCode = 0,
michael@0 77 bool aIgnoreShiftKey = false)
michael@0 78 {
michael@0 79 if (aEventType != mEventName)
michael@0 80 return false;
michael@0 81
michael@0 82 return KeyEventMatched(aEvent, aCharCode, aIgnoreShiftKey);
michael@0 83 }
michael@0 84
michael@0 85 bool MouseEventMatched(nsIDOMMouseEvent* aMouseEvent);
michael@0 86 inline bool MouseEventMatched(nsIAtom* aEventType,
michael@0 87 nsIDOMMouseEvent* aEvent)
michael@0 88 {
michael@0 89 if (aEventType != mEventName)
michael@0 90 return false;
michael@0 91
michael@0 92 return MouseEventMatched(aEvent);
michael@0 93 }
michael@0 94
michael@0 95 already_AddRefed<nsIContent> GetHandlerElement();
michael@0 96
michael@0 97 void AppendHandlerText(const nsAString& aText);
michael@0 98
michael@0 99 uint8_t GetPhase() { return mPhase; }
michael@0 100 uint8_t GetType() { return mType; }
michael@0 101
michael@0 102 nsXBLPrototypeHandler* GetNextHandler() { return mNextHandler; }
michael@0 103 void SetNextHandler(nsXBLPrototypeHandler* aHandler) { mNextHandler = aHandler; }
michael@0 104
michael@0 105 nsresult ExecuteHandler(mozilla::dom::EventTarget* aTarget, nsIDOMEvent* aEvent);
michael@0 106
michael@0 107 already_AddRefed<nsIAtom> GetEventName();
michael@0 108 void SetEventName(nsIAtom* aName) { mEventName = aName; }
michael@0 109
michael@0 110 nsXBLEventHandler* GetEventHandler()
michael@0 111 {
michael@0 112 if (!mHandler) {
michael@0 113 NS_NewXBLEventHandler(this, mEventName, getter_AddRefs(mHandler));
michael@0 114 // XXX Need to signal out of memory?
michael@0 115 }
michael@0 116
michael@0 117 return mHandler;
michael@0 118 }
michael@0 119
michael@0 120 nsXBLEventHandler* GetCachedEventHandler()
michael@0 121 {
michael@0 122 return mHandler;
michael@0 123 }
michael@0 124
michael@0 125 bool HasAllowUntrustedAttr()
michael@0 126 {
michael@0 127 return (mType & NS_HANDLER_HAS_ALLOW_UNTRUSTED_ATTR) != 0;
michael@0 128 }
michael@0 129
michael@0 130 // This returns a valid value only if HasAllowUntrustedEventsAttr returns
michael@0 131 // true.
michael@0 132 bool AllowUntrustedEvents()
michael@0 133 {
michael@0 134 return (mType & NS_HANDLER_ALLOW_UNTRUSTED) != 0;
michael@0 135 }
michael@0 136
michael@0 137 nsresult Read(nsIObjectInputStream* aStream);
michael@0 138 nsresult Write(nsIObjectOutputStream* aStream);
michael@0 139
michael@0 140 public:
michael@0 141 static uint32_t gRefCnt;
michael@0 142
michael@0 143 protected:
michael@0 144 void Init() {
michael@0 145 ++gRefCnt;
michael@0 146 if (gRefCnt == 1)
michael@0 147 // Get the primary accelerator key.
michael@0 148 InitAccessKeys();
michael@0 149 }
michael@0 150
michael@0 151 already_AddRefed<nsIController> GetController(mozilla::dom::EventTarget* aTarget);
michael@0 152
michael@0 153 inline int32_t GetMatchingKeyCode(const nsAString& aKeyName);
michael@0 154 void ConstructPrototype(nsIContent* aKeyElement,
michael@0 155 const char16_t* aEvent=nullptr, const char16_t* aPhase=nullptr,
michael@0 156 const char16_t* aAction=nullptr, const char16_t* aCommand=nullptr,
michael@0 157 const char16_t* aKeyCode=nullptr, const char16_t* aCharCode=nullptr,
michael@0 158 const char16_t* aModifiers=nullptr, const char16_t* aButton=nullptr,
michael@0 159 const char16_t* aClickCount=nullptr, const char16_t* aGroup=nullptr,
michael@0 160 const char16_t* aPreventDefault=nullptr,
michael@0 161 const char16_t* aAllowUntrusted=nullptr);
michael@0 162
michael@0 163 void ReportKeyConflict(const char16_t* aKey, const char16_t* aModifiers, nsIContent* aElement, const char *aMessageName);
michael@0 164 void GetEventType(nsAString& type);
michael@0 165 bool ModifiersMatchMask(nsIDOMUIEvent* aEvent,
michael@0 166 bool aIgnoreShiftKey = false);
michael@0 167 nsresult DispatchXBLCommand(mozilla::dom::EventTarget* aTarget, nsIDOMEvent* aEvent);
michael@0 168 nsresult DispatchXULKeyCommand(nsIDOMEvent* aEvent);
michael@0 169 nsresult EnsureEventHandler(nsIScriptGlobalObject* aGlobal,
michael@0 170 nsIScriptContext *aBoundContext, nsIAtom *aName,
michael@0 171 JS::MutableHandle<JSObject*> aHandler);
michael@0 172 static int32_t KeyToMask(int32_t key);
michael@0 173
michael@0 174 static int32_t kAccelKey;
michael@0 175 static int32_t kMenuAccessKey;
michael@0 176 static void InitAccessKeys();
michael@0 177
michael@0 178 static const int32_t cShift;
michael@0 179 static const int32_t cAlt;
michael@0 180 static const int32_t cControl;
michael@0 181 static const int32_t cMeta;
michael@0 182 static const int32_t cOS;
michael@0 183
michael@0 184 static const int32_t cShiftMask;
michael@0 185 static const int32_t cAltMask;
michael@0 186 static const int32_t cControlMask;
michael@0 187 static const int32_t cMetaMask;
michael@0 188 static const int32_t cOSMask;
michael@0 189
michael@0 190 static const int32_t cAllModifiers;
michael@0 191
michael@0 192 protected:
michael@0 193 union {
michael@0 194 nsIWeakReference* mHandlerElement; // For XUL <key> element handlers. [STRONG]
michael@0 195 char16_t* mHandlerText; // For XBL handlers (we don't build an
michael@0 196 // element for the <handler>, and instead
michael@0 197 // we cache the JS text or command name
michael@0 198 // that we should use.
michael@0 199 };
michael@0 200
michael@0 201 uint32_t mLineNumber; // The line number we started at in the XBL file
michael@0 202
michael@0 203 // The following four values make up 32 bits.
michael@0 204 uint8_t mPhase; // The phase (capturing, bubbling)
michael@0 205 uint8_t mType; // The type of the handler. The handler is either a XUL key
michael@0 206 // handler, an XBL "command" event, or a normal XBL event with
michael@0 207 // accompanying JavaScript. The high bit is used to indicate
michael@0 208 // whether this handler should prevent the default action.
michael@0 209 uint8_t mMisc; // Miscellaneous extra information. For key events,
michael@0 210 // stores whether or not we're a key code or char code.
michael@0 211 // For mouse events, stores the clickCount.
michael@0 212
michael@0 213 int32_t mKeyMask; // Which modifier keys this event handler expects to have down
michael@0 214 // in order to be matched.
michael@0 215
michael@0 216 // The primary filter information for mouse/key events.
michael@0 217 int32_t mDetail; // For key events, contains a charcode or keycode. For
michael@0 218 // mouse events, stores the button info.
michael@0 219
michael@0 220 // Prototype handlers are chained. We own the next handler in the chain.
michael@0 221 nsXBLPrototypeHandler* mNextHandler;
michael@0 222 nsCOMPtr<nsIAtom> mEventName; // The type of the event, e.g., "keypress"
michael@0 223 nsRefPtr<nsXBLEventHandler> mHandler;
michael@0 224 nsXBLPrototypeBinding* mPrototypeBinding; // the binding owns us
michael@0 225 };
michael@0 226
michael@0 227 #endif

mercurial