michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "InputData.h" michael@0: michael@0: #include "mozilla/dom/Touch.h" michael@0: #include "nsDebug.h" michael@0: #include "nsThreadUtils.h" michael@0: #include "mozilla/MouseEvents.h" michael@0: #include "mozilla/TouchEvents.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: using namespace dom; michael@0: michael@0: MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent) michael@0: : InputData(MULTITOUCH_INPUT, aTouchEvent.time, aTouchEvent.modifiers) michael@0: { michael@0: NS_ABORT_IF_FALSE(NS_IsMainThread(), michael@0: "Can only copy from WidgetTouchEvent on main thread"); michael@0: michael@0: switch (aTouchEvent.message) { michael@0: case NS_TOUCH_START: michael@0: mType = MULTITOUCH_START; michael@0: break; michael@0: case NS_TOUCH_MOVE: michael@0: mType = MULTITOUCH_MOVE; michael@0: break; michael@0: case NS_TOUCH_END: michael@0: mType = MULTITOUCH_END; michael@0: break; michael@0: case NS_TOUCH_ENTER: michael@0: mType = MULTITOUCH_ENTER; michael@0: break; michael@0: case NS_TOUCH_LEAVE: michael@0: mType = MULTITOUCH_LEAVE; michael@0: break; michael@0: case NS_TOUCH_CANCEL: michael@0: mType = MULTITOUCH_CANCEL; michael@0: break; michael@0: default: michael@0: NS_WARNING("Did not assign a type to a MultiTouchInput"); michael@0: break; michael@0: } michael@0: michael@0: for (size_t i = 0; i < aTouchEvent.touches.Length(); i++) { michael@0: const Touch* domTouch = aTouchEvent.touches[i]; michael@0: michael@0: // Extract data from weird interfaces. michael@0: int32_t identifier = domTouch->Identifier(); michael@0: int32_t radiusX = domTouch->RadiusX(); michael@0: int32_t radiusY = domTouch->RadiusY(); michael@0: float rotationAngle = domTouch->RotationAngle(); michael@0: float force = domTouch->Force(); michael@0: michael@0: SingleTouchData data(identifier, michael@0: ScreenIntPoint::FromUnknownPoint( michael@0: gfx::IntPoint(domTouch->mRefPoint.x, michael@0: domTouch->mRefPoint.y)), michael@0: ScreenSize(radiusX, radiusY), michael@0: rotationAngle, michael@0: force); michael@0: michael@0: mTouches.AppendElement(data); michael@0: } michael@0: } michael@0: michael@0: // This conversion from WidgetMouseEvent to MultiTouchInput is needed because on michael@0: // the B2G emulator we can only receive mouse events, but we need to be able michael@0: // to pan correctly. To do this, we convert the events into a format that the michael@0: // panning code can handle. This code is very limited and only supports michael@0: // SingleTouchData. It also sends garbage for the identifier, radius, force michael@0: // and rotation angle. michael@0: MultiTouchInput::MultiTouchInput(const WidgetMouseEvent& aMouseEvent) michael@0: : InputData(MULTITOUCH_INPUT, aMouseEvent.time, aMouseEvent.modifiers) michael@0: { michael@0: NS_ABORT_IF_FALSE(NS_IsMainThread(), michael@0: "Can only copy from WidgetMouseEvent on main thread"); michael@0: switch (aMouseEvent.message) { michael@0: case NS_MOUSE_BUTTON_DOWN: michael@0: mType = MULTITOUCH_START; michael@0: break; michael@0: case NS_MOUSE_MOVE: michael@0: mType = MULTITOUCH_MOVE; michael@0: break; michael@0: case NS_MOUSE_BUTTON_UP: michael@0: mType = MULTITOUCH_END; michael@0: break; michael@0: // The mouse pointer has been interrupted in an implementation-specific michael@0: // manner, such as a synchronous event or action cancelling the touch, or a michael@0: // touch point leaving the document window and going into a non-document michael@0: // area capable of handling user interactions. michael@0: case NS_MOUSE_EXIT: michael@0: mType = MULTITOUCH_CANCEL; michael@0: break; michael@0: default: michael@0: NS_WARNING("Did not assign a type to a MultiTouchInput"); michael@0: break; michael@0: } michael@0: michael@0: mTouches.AppendElement(SingleTouchData(0, michael@0: ScreenIntPoint::FromUnknownPoint( michael@0: gfx::IntPoint(aMouseEvent.refPoint.x, michael@0: aMouseEvent.refPoint.y)), michael@0: ScreenSize(1, 1), michael@0: 180.0f, michael@0: 1.0f)); michael@0: } michael@0: }