зеркало из https://github.com/mozilla/gecko-dev.git
Bug 719647 - Add Touch Event support to Gonk widget backend, r=cjones
This commit is contained in:
Родитель
3f6867a370
Коммит
05abb87c96
|
@ -4906,12 +4906,14 @@ cairo-android)
|
||||||
|
|
||||||
cairo-gonk)
|
cairo-gonk)
|
||||||
AC_DEFINE(MOZ_WIDGET_GONK)
|
AC_DEFINE(MOZ_WIDGET_GONK)
|
||||||
|
AC_DEFINE(MOZ_TOUCH)
|
||||||
MOZ_WIDGET_TOOLKIT=gonk
|
MOZ_WIDGET_TOOLKIT=gonk
|
||||||
TK_CFLAGS='$(MOZ_CAIRO_CFLAGS)'
|
TK_CFLAGS='$(MOZ_CAIRO_CFLAGS)'
|
||||||
TK_LIBS='$(MOZ_CAIRO_LIBS)'
|
TK_LIBS='$(MOZ_CAIRO_LIBS)'
|
||||||
MOZ_WEBGL=1
|
MOZ_WEBGL=1
|
||||||
MOZ_PDF_PRINTING=1
|
MOZ_PDF_PRINTING=1
|
||||||
MOZ_B2G_RIL=1
|
MOZ_B2G_RIL=1
|
||||||
|
MOZ_TOUCH=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -71,6 +71,7 @@ LOCAL_INCLUDES += \
|
||||||
-I$(topsrcdir)/widget/xpwidgets \
|
-I$(topsrcdir)/widget/xpwidgets \
|
||||||
-I$(topsrcdir)/widget/shared \
|
-I$(topsrcdir)/widget/shared \
|
||||||
-I$(topsrcdir)/dom/system/android \
|
-I$(topsrcdir)/dom/system/android \
|
||||||
|
-I$(topsrcdir)/content/events/src \
|
||||||
-I$(srcdir) \
|
-I$(srcdir) \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@
|
||||||
#include "mozilla/Mutex.h"
|
#include "mozilla/Mutex.h"
|
||||||
#include "mozilla/Services.h"
|
#include "mozilla/Services.h"
|
||||||
#include "nsAppShell.h"
|
#include "nsAppShell.h"
|
||||||
|
#include "nsDOMTouchEvent.h"
|
||||||
#include "nsGkAtoms.h"
|
#include "nsGkAtoms.h"
|
||||||
#include "nsGUIEvent.h"
|
#include "nsGUIEvent.h"
|
||||||
#include "nsIObserverService.h"
|
#include "nsIObserverService.h"
|
||||||
|
@ -107,6 +108,32 @@ pipeHandler(int fd, FdHandler *data)
|
||||||
} while (len > 0);
|
} while (len > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Touch {
|
||||||
|
int32_t id;
|
||||||
|
PointerCoords coords;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UserInputData {
|
||||||
|
uint64_t timeMs;
|
||||||
|
enum {
|
||||||
|
MOTION_DATA,
|
||||||
|
KEY_DATA
|
||||||
|
} type;
|
||||||
|
int32_t action;
|
||||||
|
int32_t flags;
|
||||||
|
int32_t metaState;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
int32_t keyCode;
|
||||||
|
int32_t scanCode;
|
||||||
|
} key;
|
||||||
|
struct {
|
||||||
|
int32_t touchCount;
|
||||||
|
Touch touches[MAX_POINTERS];
|
||||||
|
} motion;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sendMouseEvent(PRUint32 msg, uint64_t timeMs, int x, int y)
|
sendMouseEvent(PRUint32 msg, uint64_t timeMs, int x, int y)
|
||||||
{
|
{
|
||||||
|
@ -127,6 +154,62 @@ sendMouseEvent(PRUint32 msg, uint64_t timeMs, int x, int y)
|
||||||
nsWindow::DispatchInputEvent(event);
|
nsWindow::DispatchInputEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
addDOMTouch(UserInputData& data, nsTouchEvent& event, int i)
|
||||||
|
{
|
||||||
|
const Touch& touch = data.motion.touches[i];
|
||||||
|
event.touches.AppendElement(
|
||||||
|
new nsDOMTouch(touch.id,
|
||||||
|
nsIntPoint(touch.coords.x, touch.coords.y),
|
||||||
|
nsIntPoint(touch.coords.size, touch.coords.size),
|
||||||
|
0,
|
||||||
|
touch.coords.pressure));
|
||||||
|
}
|
||||||
|
|
||||||
|
static nsEventStatus
|
||||||
|
sendTouchEvent(UserInputData& data)
|
||||||
|
{
|
||||||
|
PRUint32 msg;
|
||||||
|
int32_t action = data.action & AMOTION_EVENT_ACTION_MASK;
|
||||||
|
switch (action) {
|
||||||
|
case AMOTION_EVENT_ACTION_DOWN:
|
||||||
|
case AMOTION_EVENT_ACTION_POINTER_DOWN:
|
||||||
|
msg = NS_TOUCH_START;
|
||||||
|
break;
|
||||||
|
case AMOTION_EVENT_ACTION_MOVE:
|
||||||
|
msg = NS_TOUCH_MOVE;
|
||||||
|
break;
|
||||||
|
case AMOTION_EVENT_ACTION_UP:
|
||||||
|
case AMOTION_EVENT_ACTION_POINTER_UP:
|
||||||
|
msg = NS_TOUCH_END;
|
||||||
|
break;
|
||||||
|
case AMOTION_EVENT_ACTION_OUTSIDE:
|
||||||
|
case AMOTION_EVENT_ACTION_CANCEL:
|
||||||
|
msg = NS_TOUCH_CANCEL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsTouchEvent event(true, msg, NULL);
|
||||||
|
|
||||||
|
event.time = data.timeMs;
|
||||||
|
event.isShift = false;
|
||||||
|
event.isControl = false;
|
||||||
|
event.isMeta = false;
|
||||||
|
event.isAlt = false;
|
||||||
|
|
||||||
|
int32_t i;
|
||||||
|
if (msg == NS_TOUCH_END) {
|
||||||
|
i = data.action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK;
|
||||||
|
i >>= AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
|
||||||
|
addDOMTouch(data, event, i);
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < data.motion.touchCount; ++i)
|
||||||
|
addDOMTouch(data, event, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsWindow::DispatchInputEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
static nsEventStatus
|
static nsEventStatus
|
||||||
sendKeyEventWithMsg(PRUint32 keyCode,
|
sendKeyEventWithMsg(PRUint32 keyCode,
|
||||||
PRUint32 msg,
|
PRUint32 msg,
|
||||||
|
@ -195,26 +278,6 @@ maybeSendKeyEvent(int keyCode, bool pressed, uint64_t timeMs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UserInputData {
|
|
||||||
uint64_t timeMs;
|
|
||||||
enum {
|
|
||||||
MOTION_DATA,
|
|
||||||
KEY_DATA
|
|
||||||
} type;
|
|
||||||
int32_t action;
|
|
||||||
int32_t flags;
|
|
||||||
int32_t metaState;
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
int32_t keyCode;
|
|
||||||
int32_t scanCode;
|
|
||||||
} key;
|
|
||||||
struct {
|
|
||||||
PointerCoords coords;
|
|
||||||
} motion;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
class GeckoInputReaderPolicy : public InputReaderPolicyInterface {
|
class GeckoInputReaderPolicy : public InputReaderPolicyInterface {
|
||||||
public:
|
public:
|
||||||
GeckoInputReaderPolicy() {}
|
GeckoInputReaderPolicy() {}
|
||||||
|
@ -412,7 +475,6 @@ GeckoInputDispatcher::dispatchOnce()
|
||||||
MutexAutoLock lock(mQueueLock);
|
MutexAutoLock lock(mQueueLock);
|
||||||
if (mEventQueue.empty())
|
if (mEventQueue.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
data = mEventQueue.front();
|
data = mEventQueue.front();
|
||||||
mEventQueue.pop();
|
mEventQueue.pop();
|
||||||
if (!mEventQueue.empty())
|
if (!mEventQueue.empty())
|
||||||
|
@ -421,22 +483,30 @@ GeckoInputDispatcher::dispatchOnce()
|
||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case UserInputData::MOTION_DATA: {
|
case UserInputData::MOTION_DATA: {
|
||||||
|
nsEventStatus status = sendTouchEvent(data);
|
||||||
|
if (status == nsEventStatus_eConsumeNoDefault)
|
||||||
|
break;
|
||||||
|
|
||||||
PRUint32 msg;
|
PRUint32 msg;
|
||||||
switch (data.action) {
|
switch (data.action & AMOTION_EVENT_ACTION_MASK) {
|
||||||
case AMOTION_EVENT_ACTION_DOWN:
|
case AMOTION_EVENT_ACTION_DOWN:
|
||||||
msg = NS_MOUSE_BUTTON_DOWN;
|
msg = NS_MOUSE_BUTTON_DOWN;
|
||||||
break;
|
break;
|
||||||
|
case AMOTION_EVENT_ACTION_POINTER_DOWN:
|
||||||
|
case AMOTION_EVENT_ACTION_POINTER_UP:
|
||||||
case AMOTION_EVENT_ACTION_MOVE:
|
case AMOTION_EVENT_ACTION_MOVE:
|
||||||
msg = NS_MOUSE_MOVE;
|
msg = NS_MOUSE_MOVE;
|
||||||
break;
|
break;
|
||||||
|
case AMOTION_EVENT_ACTION_OUTSIDE:
|
||||||
|
case AMOTION_EVENT_ACTION_CANCEL:
|
||||||
case AMOTION_EVENT_ACTION_UP:
|
case AMOTION_EVENT_ACTION_UP:
|
||||||
msg = NS_MOUSE_BUTTON_UP;
|
msg = NS_MOUSE_BUTTON_UP;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sendMouseEvent(msg,
|
sendMouseEvent(msg,
|
||||||
data.timeMs,
|
data.timeMs,
|
||||||
data.motion.coords.x,
|
data.motion.touches[0].coords.x,
|
||||||
data.motion.coords.y);
|
data.motion.touches[0].coords.y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UserInputData::KEY_DATA:
|
case UserInputData::KEY_DATA:
|
||||||
|
@ -508,7 +578,13 @@ GeckoInputDispatcher::notifyMotion(nsecs_t eventTime,
|
||||||
data.action = action;
|
data.action = action;
|
||||||
data.flags = flags;
|
data.flags = flags;
|
||||||
data.metaState = metaState;
|
data.metaState = metaState;
|
||||||
data.motion.coords = *pointerCoords;
|
MOZ_ASSERT(pointerCount <= MAX_POINTERS);
|
||||||
|
data.motion.touchCount = pointerCount;
|
||||||
|
for (int32_t i = 0; i < pointerCount; ++i) {
|
||||||
|
Touch& touch = data.motion.touches[i];
|
||||||
|
touch.id = pointerIds[i];
|
||||||
|
memcpy(&touch.coords, &pointerCoords[i], sizeof(*pointerCoords));
|
||||||
|
}
|
||||||
{
|
{
|
||||||
MutexAutoLock lock(mQueueLock);
|
MutexAutoLock lock(mQueueLock);
|
||||||
mEventQueue.push(data);
|
mEventQueue.push(data);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче