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: 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 mozilla_dom_UIEvent_h_ |
michael@0 | 7 | #define mozilla_dom_UIEvent_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.h" |
michael@0 | 10 | #include "mozilla/dom/Event.h" |
michael@0 | 11 | #include "mozilla/dom/UIEventBinding.h" |
michael@0 | 12 | #include "nsDeviceContext.h" |
michael@0 | 13 | #include "nsIDOMUIEvent.h" |
michael@0 | 14 | #include "nsLayoutUtils.h" |
michael@0 | 15 | #include "nsPresContext.h" |
michael@0 | 16 | |
michael@0 | 17 | class nsINode; |
michael@0 | 18 | |
michael@0 | 19 | namespace mozilla { |
michael@0 | 20 | namespace dom { |
michael@0 | 21 | |
michael@0 | 22 | class UIEvent : public Event, |
michael@0 | 23 | public nsIDOMUIEvent |
michael@0 | 24 | { |
michael@0 | 25 | public: |
michael@0 | 26 | UIEvent(EventTarget* aOwner, |
michael@0 | 27 | nsPresContext* aPresContext, |
michael@0 | 28 | WidgetGUIEvent* aEvent); |
michael@0 | 29 | |
michael@0 | 30 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 31 | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(UIEvent, Event) |
michael@0 | 32 | |
michael@0 | 33 | // nsIDOMUIEvent Interface |
michael@0 | 34 | NS_DECL_NSIDOMUIEVENT |
michael@0 | 35 | |
michael@0 | 36 | // Forward to Event |
michael@0 | 37 | NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION |
michael@0 | 38 | NS_IMETHOD DuplicatePrivateData() MOZ_OVERRIDE; |
michael@0 | 39 | NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType) MOZ_OVERRIDE; |
michael@0 | 40 | NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, void** aIter) MOZ_OVERRIDE; |
michael@0 | 41 | |
michael@0 | 42 | static nsIntPoint CalculateScreenPoint(nsPresContext* aPresContext, |
michael@0 | 43 | WidgetEvent* aEvent) |
michael@0 | 44 | { |
michael@0 | 45 | if (!aEvent || |
michael@0 | 46 | (aEvent->eventStructType != NS_MOUSE_EVENT && |
michael@0 | 47 | aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT && |
michael@0 | 48 | aEvent->eventStructType != NS_WHEEL_EVENT && |
michael@0 | 49 | aEvent->eventStructType != NS_DRAG_EVENT && |
michael@0 | 50 | aEvent->eventStructType != NS_POINTER_EVENT && |
michael@0 | 51 | aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT)) { |
michael@0 | 52 | return nsIntPoint(0, 0); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | WidgetGUIEvent* event = aEvent->AsGUIEvent(); |
michael@0 | 56 | if (!event->widget) { |
michael@0 | 57 | return LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | LayoutDeviceIntPoint offset = aEvent->refPoint + |
michael@0 | 61 | LayoutDeviceIntPoint::FromUntyped(event->widget->WidgetToScreenOffset()); |
michael@0 | 62 | nscoord factor = |
michael@0 | 63 | aPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel(); |
michael@0 | 64 | return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor), |
michael@0 | 65 | nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor)); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | static CSSIntPoint CalculateClientPoint(nsPresContext* aPresContext, |
michael@0 | 69 | WidgetEvent* aEvent, |
michael@0 | 70 | CSSIntPoint* aDefaultClientPoint) |
michael@0 | 71 | { |
michael@0 | 72 | if (!aEvent || |
michael@0 | 73 | (aEvent->eventStructType != NS_MOUSE_EVENT && |
michael@0 | 74 | aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT && |
michael@0 | 75 | aEvent->eventStructType != NS_WHEEL_EVENT && |
michael@0 | 76 | aEvent->eventStructType != NS_DRAG_EVENT && |
michael@0 | 77 | aEvent->eventStructType != NS_POINTER_EVENT && |
michael@0 | 78 | aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT) || |
michael@0 | 79 | !aPresContext || |
michael@0 | 80 | !aEvent->AsGUIEvent()->widget) { |
michael@0 | 81 | return aDefaultClientPoint |
michael@0 | 82 | ? *aDefaultClientPoint |
michael@0 | 83 | : CSSIntPoint(0, 0); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | nsIPresShell* shell = aPresContext->GetPresShell(); |
michael@0 | 87 | if (!shell) { |
michael@0 | 88 | return CSSIntPoint(0, 0); |
michael@0 | 89 | } |
michael@0 | 90 | nsIFrame* rootFrame = shell->GetRootFrame(); |
michael@0 | 91 | if (!rootFrame) { |
michael@0 | 92 | return CSSIntPoint(0, 0); |
michael@0 | 93 | } |
michael@0 | 94 | nsPoint pt = |
michael@0 | 95 | nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, rootFrame); |
michael@0 | 96 | |
michael@0 | 97 | return CSSIntPoint::FromAppUnitsRounded(pt); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | static already_AddRefed<UIEvent> Constructor(const GlobalObject& aGlobal, |
michael@0 | 101 | const nsAString& aType, |
michael@0 | 102 | const UIEventInit& aParam, |
michael@0 | 103 | ErrorResult& aRv); |
michael@0 | 104 | |
michael@0 | 105 | virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE |
michael@0 | 106 | { |
michael@0 | 107 | return UIEventBinding::Wrap(aCx, this); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | nsIDOMWindow* GetView() const |
michael@0 | 111 | { |
michael@0 | 112 | return mView; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | int32_t Detail() const |
michael@0 | 116 | { |
michael@0 | 117 | return mDetail; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | int32_t LayerX() const |
michael@0 | 121 | { |
michael@0 | 122 | return GetLayerPoint().x; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | int32_t LayerY() const |
michael@0 | 126 | { |
michael@0 | 127 | return GetLayerPoint().y; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | int32_t PageX() const; |
michael@0 | 131 | int32_t PageY() const; |
michael@0 | 132 | |
michael@0 | 133 | virtual uint32_t Which() |
michael@0 | 134 | { |
michael@0 | 135 | MOZ_ASSERT(mEvent->eventStructType != NS_KEY_EVENT, |
michael@0 | 136 | "Key events should override Which()"); |
michael@0 | 137 | MOZ_ASSERT(mEvent->eventStructType != NS_MOUSE_EVENT, |
michael@0 | 138 | "Mouse events should override Which()"); |
michael@0 | 139 | return 0; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | already_AddRefed<nsINode> GetRangeParent(); |
michael@0 | 143 | |
michael@0 | 144 | int32_t RangeOffset() const; |
michael@0 | 145 | |
michael@0 | 146 | bool CancelBubble() const |
michael@0 | 147 | { |
michael@0 | 148 | return mEvent->mFlags.mPropagationStopped; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | bool IsChar() const; |
michael@0 | 152 | |
michael@0 | 153 | protected: |
michael@0 | 154 | // Internal helper functions |
michael@0 | 155 | nsIntPoint GetMovementPoint(); |
michael@0 | 156 | nsIntPoint GetLayerPoint() const; |
michael@0 | 157 | |
michael@0 | 158 | nsCOMPtr<nsIDOMWindow> mView; |
michael@0 | 159 | int32_t mDetail; |
michael@0 | 160 | CSSIntPoint mClientPoint; |
michael@0 | 161 | // Screenpoint is mEvent->refPoint. |
michael@0 | 162 | nsIntPoint mLayerPoint; |
michael@0 | 163 | CSSIntPoint mPagePoint; |
michael@0 | 164 | nsIntPoint mMovementPoint; |
michael@0 | 165 | bool mIsPointerLocked; |
michael@0 | 166 | CSSIntPoint mLastClientPoint; |
michael@0 | 167 | |
michael@0 | 168 | static Modifiers ComputeModifierState(const nsAString& aModifiersList); |
michael@0 | 169 | bool GetModifierStateInternal(const nsAString& aKey); |
michael@0 | 170 | }; |
michael@0 | 171 | |
michael@0 | 172 | } // namespace dom |
michael@0 | 173 | } // namespace mozilla |
michael@0 | 174 | |
michael@0 | 175 | #define NS_FORWARD_TO_UIEVENT \ |
michael@0 | 176 | NS_FORWARD_NSIDOMUIEVENT(UIEvent::) \ |
michael@0 | 177 | NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION \ |
michael@0 | 178 | NS_IMETHOD DuplicatePrivateData() \ |
michael@0 | 179 | { \ |
michael@0 | 180 | return UIEvent::DuplicatePrivateData(); \ |
michael@0 | 181 | } \ |
michael@0 | 182 | NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, \ |
michael@0 | 183 | bool aSerializeInterfaceType) \ |
michael@0 | 184 | { \ |
michael@0 | 185 | UIEvent::Serialize(aMsg, aSerializeInterfaceType); \ |
michael@0 | 186 | } \ |
michael@0 | 187 | NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, \ |
michael@0 | 188 | void** aIter) \ |
michael@0 | 189 | { \ |
michael@0 | 190 | return UIEvent::Deserialize(aMsg, aIter); \ |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | #endif // mozilla_dom_UIEvent_h_ |