Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 "InputData.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/dom/Touch.h" |
michael@0 | 9 | #include "nsDebug.h" |
michael@0 | 10 | #include "nsThreadUtils.h" |
michael@0 | 11 | #include "mozilla/MouseEvents.h" |
michael@0 | 12 | #include "mozilla/TouchEvents.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | |
michael@0 | 16 | using namespace dom; |
michael@0 | 17 | |
michael@0 | 18 | MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent) |
michael@0 | 19 | : InputData(MULTITOUCH_INPUT, aTouchEvent.time, aTouchEvent.modifiers) |
michael@0 | 20 | { |
michael@0 | 21 | NS_ABORT_IF_FALSE(NS_IsMainThread(), |
michael@0 | 22 | "Can only copy from WidgetTouchEvent on main thread"); |
michael@0 | 23 | |
michael@0 | 24 | switch (aTouchEvent.message) { |
michael@0 | 25 | case NS_TOUCH_START: |
michael@0 | 26 | mType = MULTITOUCH_START; |
michael@0 | 27 | break; |
michael@0 | 28 | case NS_TOUCH_MOVE: |
michael@0 | 29 | mType = MULTITOUCH_MOVE; |
michael@0 | 30 | break; |
michael@0 | 31 | case NS_TOUCH_END: |
michael@0 | 32 | mType = MULTITOUCH_END; |
michael@0 | 33 | break; |
michael@0 | 34 | case NS_TOUCH_ENTER: |
michael@0 | 35 | mType = MULTITOUCH_ENTER; |
michael@0 | 36 | break; |
michael@0 | 37 | case NS_TOUCH_LEAVE: |
michael@0 | 38 | mType = MULTITOUCH_LEAVE; |
michael@0 | 39 | break; |
michael@0 | 40 | case NS_TOUCH_CANCEL: |
michael@0 | 41 | mType = MULTITOUCH_CANCEL; |
michael@0 | 42 | break; |
michael@0 | 43 | default: |
michael@0 | 44 | NS_WARNING("Did not assign a type to a MultiTouchInput"); |
michael@0 | 45 | break; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | for (size_t i = 0; i < aTouchEvent.touches.Length(); i++) { |
michael@0 | 49 | const Touch* domTouch = aTouchEvent.touches[i]; |
michael@0 | 50 | |
michael@0 | 51 | // Extract data from weird interfaces. |
michael@0 | 52 | int32_t identifier = domTouch->Identifier(); |
michael@0 | 53 | int32_t radiusX = domTouch->RadiusX(); |
michael@0 | 54 | int32_t radiusY = domTouch->RadiusY(); |
michael@0 | 55 | float rotationAngle = domTouch->RotationAngle(); |
michael@0 | 56 | float force = domTouch->Force(); |
michael@0 | 57 | |
michael@0 | 58 | SingleTouchData data(identifier, |
michael@0 | 59 | ScreenIntPoint::FromUnknownPoint( |
michael@0 | 60 | gfx::IntPoint(domTouch->mRefPoint.x, |
michael@0 | 61 | domTouch->mRefPoint.y)), |
michael@0 | 62 | ScreenSize(radiusX, radiusY), |
michael@0 | 63 | rotationAngle, |
michael@0 | 64 | force); |
michael@0 | 65 | |
michael@0 | 66 | mTouches.AppendElement(data); |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | // This conversion from WidgetMouseEvent to MultiTouchInput is needed because on |
michael@0 | 71 | // the B2G emulator we can only receive mouse events, but we need to be able |
michael@0 | 72 | // to pan correctly. To do this, we convert the events into a format that the |
michael@0 | 73 | // panning code can handle. This code is very limited and only supports |
michael@0 | 74 | // SingleTouchData. It also sends garbage for the identifier, radius, force |
michael@0 | 75 | // and rotation angle. |
michael@0 | 76 | MultiTouchInput::MultiTouchInput(const WidgetMouseEvent& aMouseEvent) |
michael@0 | 77 | : InputData(MULTITOUCH_INPUT, aMouseEvent.time, aMouseEvent.modifiers) |
michael@0 | 78 | { |
michael@0 | 79 | NS_ABORT_IF_FALSE(NS_IsMainThread(), |
michael@0 | 80 | "Can only copy from WidgetMouseEvent on main thread"); |
michael@0 | 81 | switch (aMouseEvent.message) { |
michael@0 | 82 | case NS_MOUSE_BUTTON_DOWN: |
michael@0 | 83 | mType = MULTITOUCH_START; |
michael@0 | 84 | break; |
michael@0 | 85 | case NS_MOUSE_MOVE: |
michael@0 | 86 | mType = MULTITOUCH_MOVE; |
michael@0 | 87 | break; |
michael@0 | 88 | case NS_MOUSE_BUTTON_UP: |
michael@0 | 89 | mType = MULTITOUCH_END; |
michael@0 | 90 | break; |
michael@0 | 91 | // The mouse pointer has been interrupted in an implementation-specific |
michael@0 | 92 | // manner, such as a synchronous event or action cancelling the touch, or a |
michael@0 | 93 | // touch point leaving the document window and going into a non-document |
michael@0 | 94 | // area capable of handling user interactions. |
michael@0 | 95 | case NS_MOUSE_EXIT: |
michael@0 | 96 | mType = MULTITOUCH_CANCEL; |
michael@0 | 97 | break; |
michael@0 | 98 | default: |
michael@0 | 99 | NS_WARNING("Did not assign a type to a MultiTouchInput"); |
michael@0 | 100 | break; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | mTouches.AppendElement(SingleTouchData(0, |
michael@0 | 104 | ScreenIntPoint::FromUnknownPoint( |
michael@0 | 105 | gfx::IntPoint(aMouseEvent.refPoint.x, |
michael@0 | 106 | aMouseEvent.refPoint.y)), |
michael@0 | 107 | ScreenSize(1, 1), |
michael@0 | 108 | 180.0f, |
michael@0 | 109 | 1.0f)); |
michael@0 | 110 | } |
michael@0 | 111 | } |