dom/events/PointerEvent.cpp

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.

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 * Portions Copyright 2013 Microsoft Open Technologies, Inc. */
michael@0 7
michael@0 8 #include "mozilla/dom/PointerEvent.h"
michael@0 9 #include "mozilla/MouseEvents.h"
michael@0 10 #include "prtime.h"
michael@0 11
michael@0 12 namespace mozilla {
michael@0 13 namespace dom {
michael@0 14
michael@0 15 PointerEvent::PointerEvent(EventTarget* aOwner,
michael@0 16 nsPresContext* aPresContext,
michael@0 17 WidgetPointerEvent* aEvent)
michael@0 18 : MouseEvent(aOwner, aPresContext,
michael@0 19 aEvent ? aEvent : new WidgetPointerEvent(false, 0, nullptr))
michael@0 20 {
michael@0 21 NS_ASSERTION(mEvent->eventStructType == NS_POINTER_EVENT,
michael@0 22 "event type mismatch NS_POINTER_EVENT");
michael@0 23
michael@0 24 WidgetMouseEvent* mouseEvent = mEvent->AsMouseEvent();
michael@0 25 if (aEvent) {
michael@0 26 mEventIsInternal = false;
michael@0 27 } else {
michael@0 28 mEventIsInternal = true;
michael@0 29 mEvent->time = PR_Now();
michael@0 30 mEvent->refPoint.x = mEvent->refPoint.y = 0;
michael@0 31 mouseEvent->inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
michael@0 32 }
michael@0 33 }
michael@0 34
michael@0 35 static uint16_t
michael@0 36 ConvertStringToPointerType(const nsAString& aPointerTypeArg)
michael@0 37 {
michael@0 38 if (aPointerTypeArg.EqualsLiteral("mouse")) {
michael@0 39 return nsIDOMMouseEvent::MOZ_SOURCE_MOUSE;
michael@0 40 }
michael@0 41 if (aPointerTypeArg.EqualsLiteral("pen")) {
michael@0 42 return nsIDOMMouseEvent::MOZ_SOURCE_PEN;
michael@0 43 }
michael@0 44 if (aPointerTypeArg.EqualsLiteral("touch")) {
michael@0 45 return nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
michael@0 46 }
michael@0 47
michael@0 48 return nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
michael@0 49 }
michael@0 50
michael@0 51 // static
michael@0 52 already_AddRefed<PointerEvent>
michael@0 53 PointerEvent::Constructor(EventTarget* aOwner,
michael@0 54 const nsAString& aType,
michael@0 55 const PointerEventInit& aParam)
michael@0 56 {
michael@0 57 nsRefPtr<PointerEvent> e = new PointerEvent(aOwner, nullptr, nullptr);
michael@0 58 bool trusted = e->Init(aOwner);
michael@0 59
michael@0 60 e->InitMouseEvent(aType, aParam.mBubbles, aParam.mCancelable,
michael@0 61 aParam.mView, aParam.mDetail, aParam.mScreenX,
michael@0 62 aParam.mScreenY, aParam.mClientX, aParam.mClientY,
michael@0 63 aParam.mCtrlKey, aParam.mAltKey, aParam.mShiftKey,
michael@0 64 aParam.mMetaKey, aParam.mButton,
michael@0 65 aParam.mRelatedTarget);
michael@0 66
michael@0 67 WidgetPointerEvent* widgetEvent = e->mEvent->AsPointerEvent();
michael@0 68 widgetEvent->pointerId = aParam.mPointerId;
michael@0 69 widgetEvent->width = aParam.mWidth;
michael@0 70 widgetEvent->height = aParam.mHeight;
michael@0 71 widgetEvent->pressure = aParam.mPressure;
michael@0 72 widgetEvent->tiltX = aParam.mTiltX;
michael@0 73 widgetEvent->tiltY = aParam.mTiltY;
michael@0 74 widgetEvent->inputSource = ConvertStringToPointerType(aParam.mPointerType);
michael@0 75 widgetEvent->isPrimary = aParam.mIsPrimary;
michael@0 76 widgetEvent->buttons = aParam.mButtons;
michael@0 77
michael@0 78 e->SetTrusted(trusted);
michael@0 79 return e.forget();
michael@0 80 }
michael@0 81
michael@0 82 // static
michael@0 83 already_AddRefed<PointerEvent>
michael@0 84 PointerEvent::Constructor(const GlobalObject& aGlobal,
michael@0 85 const nsAString& aType,
michael@0 86 const PointerEventInit& aParam,
michael@0 87 ErrorResult& aRv)
michael@0 88 {
michael@0 89 nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
michael@0 90 return Constructor(owner, aType, aParam);
michael@0 91 }
michael@0 92
michael@0 93 void
michael@0 94 PointerEvent::GetPointerType(nsAString& aPointerType)
michael@0 95 {
michael@0 96 switch (mEvent->AsPointerEvent()->inputSource) {
michael@0 97 case nsIDOMMouseEvent::MOZ_SOURCE_MOUSE:
michael@0 98 aPointerType.AssignLiteral("mouse");
michael@0 99 break;
michael@0 100 case nsIDOMMouseEvent::MOZ_SOURCE_PEN:
michael@0 101 aPointerType.AssignLiteral("pen");
michael@0 102 break;
michael@0 103 case nsIDOMMouseEvent::MOZ_SOURCE_TOUCH:
michael@0 104 aPointerType.AssignLiteral("touch");
michael@0 105 break;
michael@0 106 case nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN:
michael@0 107 aPointerType.AssignLiteral("");
michael@0 108 break;
michael@0 109 }
michael@0 110 }
michael@0 111
michael@0 112 int32_t
michael@0 113 PointerEvent::PointerId()
michael@0 114 {
michael@0 115 return mEvent->AsPointerEvent()->pointerId;
michael@0 116 }
michael@0 117
michael@0 118 int32_t
michael@0 119 PointerEvent::Width()
michael@0 120 {
michael@0 121 return mEvent->AsPointerEvent()->width;
michael@0 122 }
michael@0 123
michael@0 124 int32_t
michael@0 125 PointerEvent::Height()
michael@0 126 {
michael@0 127 return mEvent->AsPointerEvent()->height;
michael@0 128 }
michael@0 129
michael@0 130 float
michael@0 131 PointerEvent::Pressure()
michael@0 132 {
michael@0 133 return mEvent->AsPointerEvent()->pressure;
michael@0 134 }
michael@0 135
michael@0 136 int32_t
michael@0 137 PointerEvent::TiltX()
michael@0 138 {
michael@0 139 return mEvent->AsPointerEvent()->tiltX;
michael@0 140 }
michael@0 141
michael@0 142 int32_t
michael@0 143 PointerEvent::TiltY()
michael@0 144 {
michael@0 145 return mEvent->AsPointerEvent()->tiltY;
michael@0 146 }
michael@0 147
michael@0 148 bool
michael@0 149 PointerEvent::IsPrimary()
michael@0 150 {
michael@0 151 return mEvent->AsPointerEvent()->isPrimary;
michael@0 152 }
michael@0 153
michael@0 154 } // namespace dom
michael@0 155 } // namespace mozilla
michael@0 156
michael@0 157 using namespace mozilla;
michael@0 158 using namespace mozilla::dom;
michael@0 159
michael@0 160 nsresult
michael@0 161 NS_NewDOMPointerEvent(nsIDOMEvent** aInstancePtrResult,
michael@0 162 EventTarget* aOwner,
michael@0 163 nsPresContext* aPresContext,
michael@0 164 WidgetPointerEvent *aEvent)
michael@0 165 {
michael@0 166 PointerEvent *it = new PointerEvent(aOwner, aPresContext, aEvent);
michael@0 167 NS_ADDREF(it);
michael@0 168 *aInstancePtrResult = static_cast<Event*>(it);
michael@0 169 return NS_OK;
michael@0 170 }

mercurial