widget/xpwidgets/InputData.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/xpwidgets/InputData.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "InputData.h"
    1.10 +
    1.11 +#include "mozilla/dom/Touch.h"
    1.12 +#include "nsDebug.h"
    1.13 +#include "nsThreadUtils.h"
    1.14 +#include "mozilla/MouseEvents.h"
    1.15 +#include "mozilla/TouchEvents.h"
    1.16 +
    1.17 +namespace mozilla {
    1.18 +
    1.19 +using namespace dom;
    1.20 +
    1.21 +MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
    1.22 +  : InputData(MULTITOUCH_INPUT, aTouchEvent.time, aTouchEvent.modifiers)
    1.23 +{
    1.24 +  NS_ABORT_IF_FALSE(NS_IsMainThread(),
    1.25 +                    "Can only copy from WidgetTouchEvent on main thread");
    1.26 +
    1.27 +  switch (aTouchEvent.message) {
    1.28 +    case NS_TOUCH_START:
    1.29 +      mType = MULTITOUCH_START;
    1.30 +      break;
    1.31 +    case NS_TOUCH_MOVE:
    1.32 +      mType = MULTITOUCH_MOVE;
    1.33 +      break;
    1.34 +    case NS_TOUCH_END:
    1.35 +      mType = MULTITOUCH_END;
    1.36 +      break;
    1.37 +    case NS_TOUCH_ENTER:
    1.38 +      mType = MULTITOUCH_ENTER;
    1.39 +      break;
    1.40 +    case NS_TOUCH_LEAVE:
    1.41 +      mType = MULTITOUCH_LEAVE;
    1.42 +      break;
    1.43 +    case NS_TOUCH_CANCEL:
    1.44 +      mType = MULTITOUCH_CANCEL;
    1.45 +      break;
    1.46 +    default:
    1.47 +      NS_WARNING("Did not assign a type to a MultiTouchInput");
    1.48 +      break;
    1.49 +  }
    1.50 +
    1.51 +  for (size_t i = 0; i < aTouchEvent.touches.Length(); i++) {
    1.52 +    const Touch* domTouch = aTouchEvent.touches[i];
    1.53 +
    1.54 +    // Extract data from weird interfaces.
    1.55 +    int32_t identifier = domTouch->Identifier();
    1.56 +    int32_t radiusX = domTouch->RadiusX();
    1.57 +    int32_t radiusY = domTouch->RadiusY();
    1.58 +    float rotationAngle = domTouch->RotationAngle();
    1.59 +    float force = domTouch->Force();
    1.60 +
    1.61 +    SingleTouchData data(identifier,
    1.62 +                         ScreenIntPoint::FromUnknownPoint(
    1.63 +                           gfx::IntPoint(domTouch->mRefPoint.x,
    1.64 +                                         domTouch->mRefPoint.y)),
    1.65 +                         ScreenSize(radiusX, radiusY),
    1.66 +                         rotationAngle,
    1.67 +                         force);
    1.68 +
    1.69 +    mTouches.AppendElement(data);
    1.70 +  }
    1.71 +}
    1.72 +
    1.73 +// This conversion from WidgetMouseEvent to MultiTouchInput is needed because on
    1.74 +// the B2G emulator we can only receive mouse events, but we need to be able
    1.75 +// to pan correctly. To do this, we convert the events into a format that the
    1.76 +// panning code can handle. This code is very limited and only supports
    1.77 +// SingleTouchData. It also sends garbage for the identifier, radius, force
    1.78 +// and rotation angle.
    1.79 +MultiTouchInput::MultiTouchInput(const WidgetMouseEvent& aMouseEvent)
    1.80 +  : InputData(MULTITOUCH_INPUT, aMouseEvent.time, aMouseEvent.modifiers)
    1.81 +{
    1.82 +  NS_ABORT_IF_FALSE(NS_IsMainThread(),
    1.83 +                    "Can only copy from WidgetMouseEvent on main thread");
    1.84 +  switch (aMouseEvent.message) {
    1.85 +  case NS_MOUSE_BUTTON_DOWN:
    1.86 +    mType = MULTITOUCH_START;
    1.87 +    break;
    1.88 +  case NS_MOUSE_MOVE:
    1.89 +    mType = MULTITOUCH_MOVE;
    1.90 +    break;
    1.91 +  case NS_MOUSE_BUTTON_UP:
    1.92 +    mType = MULTITOUCH_END;
    1.93 +    break;
    1.94 +  // The mouse pointer has been interrupted in an implementation-specific
    1.95 +  // manner, such as a synchronous event or action cancelling the touch, or a
    1.96 +  // touch point leaving the document window and going into a non-document
    1.97 +  // area capable of handling user interactions.
    1.98 +  case NS_MOUSE_EXIT:
    1.99 +    mType = MULTITOUCH_CANCEL;
   1.100 +    break;
   1.101 +  default:
   1.102 +    NS_WARNING("Did not assign a type to a MultiTouchInput");
   1.103 +    break;
   1.104 +  }
   1.105 +
   1.106 +  mTouches.AppendElement(SingleTouchData(0,
   1.107 +                                         ScreenIntPoint::FromUnknownPoint(
   1.108 +                                           gfx::IntPoint(aMouseEvent.refPoint.x,
   1.109 +                                                         aMouseEvent.refPoint.y)),
   1.110 +                                         ScreenSize(1, 1),
   1.111 +                                         180.0f,
   1.112 +                                         1.0f));
   1.113 +}
   1.114 +}

mercurial