Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "mozilla/dom/WheelEvent.h" |
michael@0 | 8 | #include "mozilla/MouseEvents.h" |
michael@0 | 9 | #include "prtime.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | namespace dom { |
michael@0 | 13 | |
michael@0 | 14 | WheelEvent::WheelEvent(EventTarget* aOwner, |
michael@0 | 15 | nsPresContext* aPresContext, |
michael@0 | 16 | WidgetWheelEvent* aWheelEvent) |
michael@0 | 17 | : MouseEvent(aOwner, aPresContext, |
michael@0 | 18 | aWheelEvent ? aWheelEvent : |
michael@0 | 19 | new WidgetWheelEvent(false, 0, nullptr)) |
michael@0 | 20 | , mAppUnitsPerDevPixel(0) |
michael@0 | 21 | { |
michael@0 | 22 | if (aWheelEvent) { |
michael@0 | 23 | mEventIsInternal = false; |
michael@0 | 24 | // If the delta mode is pixel, the WidgetWheelEvent's delta values are in |
michael@0 | 25 | // device pixels. However, JS contents need the delta values in CSS pixels. |
michael@0 | 26 | // We should store the value of mAppUnitsPerDevPixel here because |
michael@0 | 27 | // it might be changed by changing zoom or something. |
michael@0 | 28 | if (aWheelEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_PIXEL) { |
michael@0 | 29 | mAppUnitsPerDevPixel = aPresContext->AppUnitsPerDevPixel(); |
michael@0 | 30 | } |
michael@0 | 31 | } else { |
michael@0 | 32 | mEventIsInternal = true; |
michael@0 | 33 | mEvent->time = PR_Now(); |
michael@0 | 34 | mEvent->refPoint.x = mEvent->refPoint.y = 0; |
michael@0 | 35 | mEvent->AsWheelEvent()->inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN; |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | NS_IMPL_ADDREF_INHERITED(WheelEvent, MouseEvent) |
michael@0 | 40 | NS_IMPL_RELEASE_INHERITED(WheelEvent, MouseEvent) |
michael@0 | 41 | |
michael@0 | 42 | NS_INTERFACE_MAP_BEGIN(WheelEvent) |
michael@0 | 43 | NS_INTERFACE_MAP_ENTRY(nsIDOMWheelEvent) |
michael@0 | 44 | NS_INTERFACE_MAP_END_INHERITING(MouseEvent) |
michael@0 | 45 | |
michael@0 | 46 | NS_IMETHODIMP |
michael@0 | 47 | WheelEvent::InitWheelEvent(const nsAString& aType, |
michael@0 | 48 | bool aCanBubble, |
michael@0 | 49 | bool aCancelable, |
michael@0 | 50 | nsIDOMWindow* aView, |
michael@0 | 51 | int32_t aDetail, |
michael@0 | 52 | int32_t aScreenX, |
michael@0 | 53 | int32_t aScreenY, |
michael@0 | 54 | int32_t aClientX, |
michael@0 | 55 | int32_t aClientY, |
michael@0 | 56 | uint16_t aButton, |
michael@0 | 57 | nsIDOMEventTarget* aRelatedTarget, |
michael@0 | 58 | const nsAString& aModifiersList, |
michael@0 | 59 | double aDeltaX, |
michael@0 | 60 | double aDeltaY, |
michael@0 | 61 | double aDeltaZ, |
michael@0 | 62 | uint32_t aDeltaMode) |
michael@0 | 63 | { |
michael@0 | 64 | nsresult rv = |
michael@0 | 65 | MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable, aView, aDetail, |
michael@0 | 66 | aScreenX, aScreenY, aClientX, aClientY, aButton, |
michael@0 | 67 | aRelatedTarget, aModifiersList); |
michael@0 | 68 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 69 | |
michael@0 | 70 | WidgetWheelEvent* wheelEvent = mEvent->AsWheelEvent(); |
michael@0 | 71 | wheelEvent->deltaX = aDeltaX; |
michael@0 | 72 | wheelEvent->deltaY = aDeltaY; |
michael@0 | 73 | wheelEvent->deltaZ = aDeltaZ; |
michael@0 | 74 | wheelEvent->deltaMode = aDeltaMode; |
michael@0 | 75 | |
michael@0 | 76 | return NS_OK; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | double |
michael@0 | 80 | WheelEvent::DeltaX() |
michael@0 | 81 | { |
michael@0 | 82 | if (!mAppUnitsPerDevPixel) { |
michael@0 | 83 | return mEvent->AsWheelEvent()->deltaX; |
michael@0 | 84 | } |
michael@0 | 85 | return mEvent->AsWheelEvent()->deltaX * |
michael@0 | 86 | mAppUnitsPerDevPixel / nsPresContext::AppUnitsPerCSSPixel(); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | NS_IMETHODIMP |
michael@0 | 90 | WheelEvent::GetDeltaX(double* aDeltaX) |
michael@0 | 91 | { |
michael@0 | 92 | NS_ENSURE_ARG_POINTER(aDeltaX); |
michael@0 | 93 | |
michael@0 | 94 | *aDeltaX = DeltaX(); |
michael@0 | 95 | return NS_OK; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | double |
michael@0 | 99 | WheelEvent::DeltaY() |
michael@0 | 100 | { |
michael@0 | 101 | if (!mAppUnitsPerDevPixel) { |
michael@0 | 102 | return mEvent->AsWheelEvent()->deltaY; |
michael@0 | 103 | } |
michael@0 | 104 | return mEvent->AsWheelEvent()->deltaY * |
michael@0 | 105 | mAppUnitsPerDevPixel / nsPresContext::AppUnitsPerCSSPixel(); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | NS_IMETHODIMP |
michael@0 | 109 | WheelEvent::GetDeltaY(double* aDeltaY) |
michael@0 | 110 | { |
michael@0 | 111 | NS_ENSURE_ARG_POINTER(aDeltaY); |
michael@0 | 112 | |
michael@0 | 113 | *aDeltaY = DeltaY(); |
michael@0 | 114 | return NS_OK; |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | double |
michael@0 | 118 | WheelEvent::DeltaZ() |
michael@0 | 119 | { |
michael@0 | 120 | if (!mAppUnitsPerDevPixel) { |
michael@0 | 121 | return mEvent->AsWheelEvent()->deltaZ; |
michael@0 | 122 | } |
michael@0 | 123 | return mEvent->AsWheelEvent()->deltaZ * |
michael@0 | 124 | mAppUnitsPerDevPixel / nsPresContext::AppUnitsPerCSSPixel(); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | NS_IMETHODIMP |
michael@0 | 128 | WheelEvent::GetDeltaZ(double* aDeltaZ) |
michael@0 | 129 | { |
michael@0 | 130 | NS_ENSURE_ARG_POINTER(aDeltaZ); |
michael@0 | 131 | |
michael@0 | 132 | *aDeltaZ = DeltaZ(); |
michael@0 | 133 | return NS_OK; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | uint32_t |
michael@0 | 137 | WheelEvent::DeltaMode() |
michael@0 | 138 | { |
michael@0 | 139 | return mEvent->AsWheelEvent()->deltaMode; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | NS_IMETHODIMP |
michael@0 | 143 | WheelEvent::GetDeltaMode(uint32_t* aDeltaMode) |
michael@0 | 144 | { |
michael@0 | 145 | NS_ENSURE_ARG_POINTER(aDeltaMode); |
michael@0 | 146 | |
michael@0 | 147 | *aDeltaMode = DeltaMode(); |
michael@0 | 148 | return NS_OK; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | static void |
michael@0 | 152 | GetModifierList(bool aCtrl, bool aShift, bool aAlt, bool aMeta, |
michael@0 | 153 | nsAString& aModifierList) |
michael@0 | 154 | { |
michael@0 | 155 | if (aCtrl) { |
michael@0 | 156 | aModifierList.AppendLiteral(NS_DOM_KEYNAME_CONTROL); |
michael@0 | 157 | } |
michael@0 | 158 | if (aShift) { |
michael@0 | 159 | if (!aModifierList.IsEmpty()) { |
michael@0 | 160 | aModifierList.AppendLiteral(" "); |
michael@0 | 161 | } |
michael@0 | 162 | aModifierList.AppendLiteral(NS_DOM_KEYNAME_SHIFT); |
michael@0 | 163 | } |
michael@0 | 164 | if (aAlt) { |
michael@0 | 165 | if (!aModifierList.IsEmpty()) { |
michael@0 | 166 | aModifierList.AppendLiteral(" "); |
michael@0 | 167 | } |
michael@0 | 168 | aModifierList.AppendLiteral(NS_DOM_KEYNAME_ALT); |
michael@0 | 169 | } |
michael@0 | 170 | if (aMeta) { |
michael@0 | 171 | if (!aModifierList.IsEmpty()) { |
michael@0 | 172 | aModifierList.AppendLiteral(" "); |
michael@0 | 173 | } |
michael@0 | 174 | aModifierList.AppendLiteral(NS_DOM_KEYNAME_META); |
michael@0 | 175 | } |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | already_AddRefed<WheelEvent> |
michael@0 | 179 | WheelEvent::Constructor(const GlobalObject& aGlobal, |
michael@0 | 180 | const nsAString& aType, |
michael@0 | 181 | const WheelEventInit& aParam, |
michael@0 | 182 | ErrorResult& aRv) |
michael@0 | 183 | { |
michael@0 | 184 | nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports()); |
michael@0 | 185 | nsRefPtr<WheelEvent> e = new WheelEvent(t, nullptr, nullptr); |
michael@0 | 186 | bool trusted = e->Init(t); |
michael@0 | 187 | nsAutoString modifierList; |
michael@0 | 188 | GetModifierList(aParam.mCtrlKey, aParam.mShiftKey, |
michael@0 | 189 | aParam.mAltKey, aParam.mMetaKey, |
michael@0 | 190 | modifierList); |
michael@0 | 191 | aRv = e->InitWheelEvent(aType, aParam.mBubbles, aParam.mCancelable, |
michael@0 | 192 | aParam.mView, aParam.mDetail, |
michael@0 | 193 | aParam.mScreenX, aParam.mScreenY, |
michael@0 | 194 | aParam.mClientX, aParam.mClientY, |
michael@0 | 195 | aParam.mButton, aParam.mRelatedTarget, |
michael@0 | 196 | modifierList, aParam.mDeltaX, |
michael@0 | 197 | aParam.mDeltaY, aParam.mDeltaZ, aParam.mDeltaMode); |
michael@0 | 198 | e->mEvent->AsWheelEvent()->buttons = aParam.mButtons; |
michael@0 | 199 | e->SetTrusted(trusted); |
michael@0 | 200 | return e.forget(); |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | } // namespace dom |
michael@0 | 204 | } // namespace mozilla |
michael@0 | 205 | |
michael@0 | 206 | using namespace mozilla; |
michael@0 | 207 | using namespace mozilla::dom; |
michael@0 | 208 | |
michael@0 | 209 | nsresult |
michael@0 | 210 | NS_NewDOMWheelEvent(nsIDOMEvent** aInstancePtrResult, |
michael@0 | 211 | EventTarget* aOwner, |
michael@0 | 212 | nsPresContext* aPresContext, |
michael@0 | 213 | WidgetWheelEvent* aEvent) |
michael@0 | 214 | { |
michael@0 | 215 | WheelEvent* it = new WheelEvent(aOwner, aPresContext, aEvent); |
michael@0 | 216 | NS_ADDREF(it); |
michael@0 | 217 | *aInstancePtrResult = static_cast<Event*>(it); |
michael@0 | 218 | return NS_OK; |
michael@0 | 219 | } |