dom/events/UIEvent.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

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

mercurial