Wed, 31 Dec 2014 06:09:35 +0100
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 | #include "nsCOMPtr.h" |
michael@0 | 7 | #include "nsIAtom.h" |
michael@0 | 8 | #include "nsIDOMEventListener.h" |
michael@0 | 9 | #include "nsIDOMKeyEvent.h" |
michael@0 | 10 | #include "nsIDOMMouseEvent.h" |
michael@0 | 11 | #include "nsXBLPrototypeHandler.h" |
michael@0 | 12 | #include "nsContentUtils.h" |
michael@0 | 13 | #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent() |
michael@0 | 14 | #include "mozilla/dom/EventTarget.h" |
michael@0 | 15 | |
michael@0 | 16 | using namespace mozilla::dom; |
michael@0 | 17 | |
michael@0 | 18 | nsXBLEventHandler::nsXBLEventHandler(nsXBLPrototypeHandler* aHandler) |
michael@0 | 19 | : mProtoHandler(aHandler) |
michael@0 | 20 | { |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | nsXBLEventHandler::~nsXBLEventHandler() |
michael@0 | 24 | { |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | NS_IMPL_ISUPPORTS(nsXBLEventHandler, nsIDOMEventListener) |
michael@0 | 28 | |
michael@0 | 29 | NS_IMETHODIMP |
michael@0 | 30 | nsXBLEventHandler::HandleEvent(nsIDOMEvent* aEvent) |
michael@0 | 31 | { |
michael@0 | 32 | if (!mProtoHandler) |
michael@0 | 33 | return NS_ERROR_FAILURE; |
michael@0 | 34 | |
michael@0 | 35 | uint8_t phase = mProtoHandler->GetPhase(); |
michael@0 | 36 | if (phase == NS_PHASE_TARGET) { |
michael@0 | 37 | uint16_t eventPhase; |
michael@0 | 38 | aEvent->GetEventPhase(&eventPhase); |
michael@0 | 39 | if (eventPhase != nsIDOMEvent::AT_TARGET) |
michael@0 | 40 | return NS_OK; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | if (!EventMatched(aEvent)) |
michael@0 | 44 | return NS_OK; |
michael@0 | 45 | |
michael@0 | 46 | mProtoHandler->ExecuteHandler(aEvent->InternalDOMEvent()->GetCurrentTarget(), |
michael@0 | 47 | aEvent); |
michael@0 | 48 | |
michael@0 | 49 | return NS_OK; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | nsXBLMouseEventHandler::nsXBLMouseEventHandler(nsXBLPrototypeHandler* aHandler) |
michael@0 | 53 | : nsXBLEventHandler(aHandler) |
michael@0 | 54 | { |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | nsXBLMouseEventHandler::~nsXBLMouseEventHandler() |
michael@0 | 58 | { |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | bool |
michael@0 | 62 | nsXBLMouseEventHandler::EventMatched(nsIDOMEvent* aEvent) |
michael@0 | 63 | { |
michael@0 | 64 | nsCOMPtr<nsIDOMMouseEvent> mouse(do_QueryInterface(aEvent)); |
michael@0 | 65 | return mouse && mProtoHandler->MouseEventMatched(mouse); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | nsXBLKeyEventHandler::nsXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase, |
michael@0 | 69 | uint8_t aType) |
michael@0 | 70 | : mEventType(aEventType), |
michael@0 | 71 | mPhase(aPhase), |
michael@0 | 72 | mType(aType), |
michael@0 | 73 | mIsBoundToChrome(false), |
michael@0 | 74 | mUsingXBLScope(false) |
michael@0 | 75 | { |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | nsXBLKeyEventHandler::~nsXBLKeyEventHandler() |
michael@0 | 79 | { |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | NS_IMPL_ISUPPORTS(nsXBLKeyEventHandler, nsIDOMEventListener) |
michael@0 | 83 | |
michael@0 | 84 | bool |
michael@0 | 85 | nsXBLKeyEventHandler::ExecuteMatchedHandlers(nsIDOMKeyEvent* aKeyEvent, |
michael@0 | 86 | uint32_t aCharCode, |
michael@0 | 87 | bool aIgnoreShiftKey) |
michael@0 | 88 | { |
michael@0 | 89 | bool trustedEvent = false; |
michael@0 | 90 | aKeyEvent->GetIsTrusted(&trustedEvent); |
michael@0 | 91 | |
michael@0 | 92 | nsCOMPtr<EventTarget> target = aKeyEvent->InternalDOMEvent()->GetCurrentTarget(); |
michael@0 | 93 | |
michael@0 | 94 | bool executed = false; |
michael@0 | 95 | for (uint32_t i = 0; i < mProtoHandlers.Length(); ++i) { |
michael@0 | 96 | nsXBLPrototypeHandler* handler = mProtoHandlers[i]; |
michael@0 | 97 | bool hasAllowUntrustedAttr = handler->HasAllowUntrustedAttr(); |
michael@0 | 98 | if ((trustedEvent || |
michael@0 | 99 | (hasAllowUntrustedAttr && handler->AllowUntrustedEvents()) || |
michael@0 | 100 | (!hasAllowUntrustedAttr && !mIsBoundToChrome && !mUsingXBLScope)) && |
michael@0 | 101 | handler->KeyEventMatched(aKeyEvent, aCharCode, aIgnoreShiftKey)) { |
michael@0 | 102 | handler->ExecuteHandler(target, aKeyEvent); |
michael@0 | 103 | executed = true; |
michael@0 | 104 | } |
michael@0 | 105 | } |
michael@0 | 106 | return executed; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | NS_IMETHODIMP |
michael@0 | 110 | nsXBLKeyEventHandler::HandleEvent(nsIDOMEvent* aEvent) |
michael@0 | 111 | { |
michael@0 | 112 | uint32_t count = mProtoHandlers.Length(); |
michael@0 | 113 | if (count == 0) |
michael@0 | 114 | return NS_ERROR_FAILURE; |
michael@0 | 115 | |
michael@0 | 116 | if (mPhase == NS_PHASE_TARGET) { |
michael@0 | 117 | uint16_t eventPhase; |
michael@0 | 118 | aEvent->GetEventPhase(&eventPhase); |
michael@0 | 119 | if (eventPhase != nsIDOMEvent::AT_TARGET) |
michael@0 | 120 | return NS_OK; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | nsCOMPtr<nsIDOMKeyEvent> key(do_QueryInterface(aEvent)); |
michael@0 | 124 | if (!key) |
michael@0 | 125 | return NS_OK; |
michael@0 | 126 | |
michael@0 | 127 | nsAutoTArray<nsShortcutCandidate, 10> accessKeys; |
michael@0 | 128 | nsContentUtils::GetAccelKeyCandidates(key, accessKeys); |
michael@0 | 129 | |
michael@0 | 130 | if (accessKeys.IsEmpty()) { |
michael@0 | 131 | ExecuteMatchedHandlers(key, 0, false); |
michael@0 | 132 | return NS_OK; |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | for (uint32_t i = 0; i < accessKeys.Length(); ++i) { |
michael@0 | 136 | if (ExecuteMatchedHandlers(key, accessKeys[i].mCharCode, |
michael@0 | 137 | accessKeys[i].mIgnoreShift)) |
michael@0 | 138 | return NS_OK; |
michael@0 | 139 | } |
michael@0 | 140 | return NS_OK; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | /////////////////////////////////////////////////////////////////////////////////// |
michael@0 | 144 | |
michael@0 | 145 | nsresult |
michael@0 | 146 | NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler, |
michael@0 | 147 | nsIAtom* aEventType, |
michael@0 | 148 | nsXBLEventHandler** aResult) |
michael@0 | 149 | { |
michael@0 | 150 | switch (nsContentUtils::GetEventCategory(nsDependentAtomString(aEventType))) { |
michael@0 | 151 | case NS_DRAG_EVENT: |
michael@0 | 152 | case NS_MOUSE_EVENT: |
michael@0 | 153 | case NS_MOUSE_SCROLL_EVENT: |
michael@0 | 154 | case NS_WHEEL_EVENT: |
michael@0 | 155 | case NS_SIMPLE_GESTURE_EVENT: |
michael@0 | 156 | *aResult = new nsXBLMouseEventHandler(aHandler); |
michael@0 | 157 | break; |
michael@0 | 158 | default: |
michael@0 | 159 | *aResult = new nsXBLEventHandler(aHandler); |
michael@0 | 160 | break; |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | if (!*aResult) |
michael@0 | 164 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 165 | |
michael@0 | 166 | NS_ADDREF(*aResult); |
michael@0 | 167 | |
michael@0 | 168 | return NS_OK; |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | nsresult |
michael@0 | 172 | NS_NewXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType, |
michael@0 | 173 | nsXBLKeyEventHandler** aResult) |
michael@0 | 174 | { |
michael@0 | 175 | *aResult = new nsXBLKeyEventHandler(aEventType, aPhase, aType); |
michael@0 | 176 | |
michael@0 | 177 | if (!*aResult) |
michael@0 | 178 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 179 | |
michael@0 | 180 | NS_ADDREF(*aResult); |
michael@0 | 181 | |
michael@0 | 182 | return NS_OK; |
michael@0 | 183 | } |