зеркало из https://github.com/mozilla/gecko-dev.git
Bug 832159 - Move internal part of InputData (nsEvent conversion) out from the header. r=drs, r=smaug
This commit is contained in:
Родитель
24122dfcc5
Коммит
67f10d0c36
|
@ -6,10 +6,12 @@
|
||||||
#ifndef InputData_h__
|
#ifndef InputData_h__
|
||||||
#define InputData_h__
|
#define InputData_h__
|
||||||
|
|
||||||
#include "nsGUIEvent.h"
|
|
||||||
#include "nsDOMTouchEvent.h"
|
|
||||||
#include "nsDebug.h"
|
#include "nsDebug.h"
|
||||||
|
#include "nsPoint.h"
|
||||||
|
#include "nsTArray.h"
|
||||||
|
|
||||||
|
class nsTouchEvent;
|
||||||
|
class nsMouseEvent;
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,6 +52,10 @@ public:
|
||||||
INPUTDATA_AS_CHILD_TYPE(PinchGestureInput, PINCHGESTURE_INPUT)
|
INPUTDATA_AS_CHILD_TYPE(PinchGestureInput, PINCHGESTURE_INPUT)
|
||||||
INPUTDATA_AS_CHILD_TYPE(TapGestureInput, TAPGESTURE_INPUT)
|
INPUTDATA_AS_CHILD_TYPE(TapGestureInput, TAPGESTURE_INPUT)
|
||||||
|
|
||||||
|
InputData()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
InputData(InputType aInputType, uint32_t aTime)
|
InputData(InputType aInputType, uint32_t aTime)
|
||||||
: mInputType(aInputType),
|
: mInputType(aInputType),
|
||||||
|
@ -93,6 +99,10 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SingleTouchData()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// A unique number assigned to each SingleTouchData within a MultiTouchInput so
|
// A unique number assigned to each SingleTouchData within a MultiTouchInput so
|
||||||
// that they can be easily distinguished when handling a touch start/move/end.
|
// that they can be easily distinguished when handling a touch start/move/end.
|
||||||
int32_t mIdentifier;
|
int32_t mIdentifier;
|
||||||
|
@ -144,97 +154,19 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiTouchInput(const nsTouchEvent& aTouchEvent)
|
MultiTouchInput()
|
||||||
: InputData(MULTITOUCH_INPUT, aTouchEvent.time)
|
|
||||||
{
|
{
|
||||||
NS_ABORT_IF_FALSE(NS_IsMainThread(),
|
|
||||||
"Can only copy from nsTouchEvent on main thread");
|
|
||||||
|
|
||||||
switch (aTouchEvent.message) {
|
|
||||||
case NS_TOUCH_START:
|
|
||||||
mType = MULTITOUCH_START;
|
|
||||||
break;
|
|
||||||
case NS_TOUCH_MOVE:
|
|
||||||
mType = MULTITOUCH_MOVE;
|
|
||||||
break;
|
|
||||||
case NS_TOUCH_END:
|
|
||||||
mType = MULTITOUCH_END;
|
|
||||||
break;
|
|
||||||
case NS_TOUCH_ENTER:
|
|
||||||
mType = MULTITOUCH_ENTER;
|
|
||||||
break;
|
|
||||||
case NS_TOUCH_LEAVE:
|
|
||||||
mType = MULTITOUCH_LEAVE;
|
|
||||||
break;
|
|
||||||
case NS_TOUCH_CANCEL:
|
|
||||||
mType = MULTITOUCH_CANCEL;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
NS_WARNING("Did not assign a type to a MultiTouchInput");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < aTouchEvent.touches.Length(); i++) {
|
|
||||||
nsDOMTouch* domTouch = (nsDOMTouch*)(aTouchEvent.touches[i].get());
|
|
||||||
|
|
||||||
// Extract data from weird interfaces.
|
|
||||||
int32_t identifier, radiusX, radiusY;
|
|
||||||
float rotationAngle, force;
|
|
||||||
domTouch->GetIdentifier(&identifier);
|
|
||||||
domTouch->GetRadiusX(&radiusX);
|
|
||||||
domTouch->GetRadiusY(&radiusY);
|
|
||||||
domTouch->GetRotationAngle(&rotationAngle);
|
|
||||||
domTouch->GetForce(&force);
|
|
||||||
|
|
||||||
SingleTouchData data(identifier,
|
|
||||||
domTouch->mRefPoint,
|
|
||||||
nsIntPoint(radiusX, radiusY),
|
|
||||||
rotationAngle,
|
|
||||||
force);
|
|
||||||
|
|
||||||
mTouches.AppendElement(data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MultiTouchInput(const nsTouchEvent& aTouchEvent);
|
||||||
|
|
||||||
// This conversion from nsMouseEvent to MultiTouchInput is needed because on
|
// This conversion from nsMouseEvent to MultiTouchInput is needed because on
|
||||||
// the B2G emulator we can only receive mouse events, but we need to be able
|
// the B2G emulator we can only receive mouse events, but we need to be able
|
||||||
// to pan correctly. To do this, we convert the events into a format that the
|
// to pan correctly. To do this, we convert the events into a format that the
|
||||||
// panning code can handle. This code is very limited and only supports
|
// panning code can handle. This code is very limited and only supports
|
||||||
// SingleTouchData. It also sends garbage for the identifier, radius, force
|
// SingleTouchData. It also sends garbage for the identifier, radius, force
|
||||||
// and rotation angle.
|
// and rotation angle.
|
||||||
MultiTouchInput(const nsMouseEvent& aMouseEvent)
|
MultiTouchInput(const nsMouseEvent& aMouseEvent);
|
||||||
: InputData(MULTITOUCH_INPUT, aMouseEvent.time)
|
|
||||||
{
|
|
||||||
NS_ABORT_IF_FALSE(NS_IsMainThread(),
|
|
||||||
"Can only copy from nsMouseEvent on main thread");
|
|
||||||
switch (aMouseEvent.message) {
|
|
||||||
case NS_MOUSE_BUTTON_DOWN:
|
|
||||||
mType = MULTITOUCH_START;
|
|
||||||
break;
|
|
||||||
case NS_MOUSE_MOVE:
|
|
||||||
mType = MULTITOUCH_MOVE;
|
|
||||||
break;
|
|
||||||
case NS_MOUSE_BUTTON_UP:
|
|
||||||
mType = MULTITOUCH_END;
|
|
||||||
break;
|
|
||||||
// The mouse pointer has been interrupted in an implementation-specific
|
|
||||||
// manner, such as a synchronous event or action cancelling the touch, or a
|
|
||||||
// touch point leaving the document window and going into a non-document
|
|
||||||
// area capable of handling user interactions.
|
|
||||||
case NS_MOUSE_EXIT:
|
|
||||||
mType = MULTITOUCH_CANCEL;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
NS_WARNING("Did not assign a type to a MultiTouchInput");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
mTouches.AppendElement(SingleTouchData(0,
|
|
||||||
aMouseEvent.refPoint,
|
|
||||||
nsIntPoint(1, 1),
|
|
||||||
180.0f,
|
|
||||||
1.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
MultiTouchType mType;
|
MultiTouchType mType;
|
||||||
nsTArray<SingleTouchData> mTouches;
|
nsTArray<SingleTouchData> mTouches;
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "InputData.h"
|
||||||
|
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsDOMTouchEvent.h"
|
||||||
|
#include "nsDebug.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
MultiTouchInput::MultiTouchInput(const nsTouchEvent& aTouchEvent)
|
||||||
|
: InputData(MULTITOUCH_INPUT, aTouchEvent.time)
|
||||||
|
{
|
||||||
|
NS_ABORT_IF_FALSE(NS_IsMainThread(),
|
||||||
|
"Can only copy from nsTouchEvent on main thread");
|
||||||
|
|
||||||
|
switch (aTouchEvent.message) {
|
||||||
|
case NS_TOUCH_START:
|
||||||
|
mType = MULTITOUCH_START;
|
||||||
|
break;
|
||||||
|
case NS_TOUCH_MOVE:
|
||||||
|
mType = MULTITOUCH_MOVE;
|
||||||
|
break;
|
||||||
|
case NS_TOUCH_END:
|
||||||
|
mType = MULTITOUCH_END;
|
||||||
|
break;
|
||||||
|
case NS_TOUCH_ENTER:
|
||||||
|
mType = MULTITOUCH_ENTER;
|
||||||
|
break;
|
||||||
|
case NS_TOUCH_LEAVE:
|
||||||
|
mType = MULTITOUCH_LEAVE;
|
||||||
|
break;
|
||||||
|
case NS_TOUCH_CANCEL:
|
||||||
|
mType = MULTITOUCH_CANCEL;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
NS_WARNING("Did not assign a type to a MultiTouchInput");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < aTouchEvent.touches.Length(); i++) {
|
||||||
|
nsDOMTouch* domTouch = (nsDOMTouch*)(aTouchEvent.touches[i].get());
|
||||||
|
|
||||||
|
// Extract data from weird interfaces.
|
||||||
|
int32_t identifier, radiusX, radiusY;
|
||||||
|
float rotationAngle, force;
|
||||||
|
domTouch->GetIdentifier(&identifier);
|
||||||
|
domTouch->GetRadiusX(&radiusX);
|
||||||
|
domTouch->GetRadiusY(&radiusY);
|
||||||
|
domTouch->GetRotationAngle(&rotationAngle);
|
||||||
|
domTouch->GetForce(&force);
|
||||||
|
|
||||||
|
SingleTouchData data(identifier,
|
||||||
|
domTouch->mRefPoint,
|
||||||
|
nsIntPoint(radiusX, radiusY),
|
||||||
|
rotationAngle,
|
||||||
|
force);
|
||||||
|
|
||||||
|
mTouches.AppendElement(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This conversion from nsMouseEvent to MultiTouchInput is needed because on
|
||||||
|
// the B2G emulator we can only receive mouse events, but we need to be able
|
||||||
|
// to pan correctly. To do this, we convert the events into a format that the
|
||||||
|
// panning code can handle. This code is very limited and only supports
|
||||||
|
// SingleTouchData. It also sends garbage for the identifier, radius, force
|
||||||
|
// and rotation angle.
|
||||||
|
MultiTouchInput::MultiTouchInput(const nsMouseEvent& aMouseEvent)
|
||||||
|
: InputData(MULTITOUCH_INPUT, aMouseEvent.time)
|
||||||
|
{
|
||||||
|
NS_ABORT_IF_FALSE(NS_IsMainThread(),
|
||||||
|
"Can only copy from nsMouseEvent on main thread");
|
||||||
|
switch (aMouseEvent.message) {
|
||||||
|
case NS_MOUSE_BUTTON_DOWN:
|
||||||
|
mType = MULTITOUCH_START;
|
||||||
|
break;
|
||||||
|
case NS_MOUSE_MOVE:
|
||||||
|
mType = MULTITOUCH_MOVE;
|
||||||
|
break;
|
||||||
|
case NS_MOUSE_BUTTON_UP:
|
||||||
|
mType = MULTITOUCH_END;
|
||||||
|
break;
|
||||||
|
// The mouse pointer has been interrupted in an implementation-specific
|
||||||
|
// manner, such as a synchronous event or action cancelling the touch, or a
|
||||||
|
// touch point leaving the document window and going into a non-document
|
||||||
|
// area capable of handling user interactions.
|
||||||
|
case NS_MOUSE_EXIT:
|
||||||
|
mType = MULTITOUCH_CANCEL;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
NS_WARNING("Did not assign a type to a MultiTouchInput");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mTouches.AppendElement(SingleTouchData(0,
|
||||||
|
aMouseEvent.refPoint,
|
||||||
|
nsIntPoint(1, 1),
|
||||||
|
180.0f,
|
||||||
|
1.0f));
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,6 +43,7 @@ CPPSRCS = \
|
||||||
PuppetWidget.cpp \
|
PuppetWidget.cpp \
|
||||||
nsFilePickerProxy.cpp \
|
nsFilePickerProxy.cpp \
|
||||||
WidgetUtils.cpp \
|
WidgetUtils.cpp \
|
||||||
|
InputData.cpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
ifdef MOZ_X11
|
ifdef MOZ_X11
|
||||||
|
|
Загрузка…
Ссылка в новой задаче