Bug 859951 - Refactor the code to convert MOTION_EVENT GeckoEvents to nsTouchEvent instances. r=wesj
This commit is contained in:
@@ -374,7 +374,7 @@ public class GeckoEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMotionPoint(int index, int eventIndex, MotionEvent event) {
|
private void addMotionPoint(int index, int eventIndex, MotionEvent event) {
|
||||||
try {
|
try {
|
||||||
PointF geckoPoint = new PointF(event.getX(eventIndex), event.getY(eventIndex));
|
PointF geckoPoint = new PointF(event.getX(eventIndex), event.getY(eventIndex));
|
||||||
geckoPoint = GeckoApp.mAppContext.getLayerView().convertViewPointToLayerPoint(geckoPoint);
|
geckoPoint = GeckoApp.mAppContext.getLayerView().convertViewPointToLayerPoint(geckoPoint);
|
||||||
|
|||||||
@@ -690,6 +690,67 @@ AndroidGeckoEvent::Init(AndroidGeckoEvent *aResizeEvent)
|
|||||||
mPoints = aResizeEvent->mPoints; // x,y coordinates
|
mPoints = aResizeEvent->mPoints; // x,y coordinates
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsTouchEvent
|
||||||
|
AndroidGeckoEvent::MakeTouchEvent(nsIWidget* widget)
|
||||||
|
{
|
||||||
|
int type = NS_EVENT_NULL;
|
||||||
|
int startIndex = 0;
|
||||||
|
int endIndex = Count();
|
||||||
|
|
||||||
|
int action = Action() & AndroidMotionEvent::ACTION_MASK;
|
||||||
|
switch (action) {
|
||||||
|
case AndroidMotionEvent::ACTION_DOWN:
|
||||||
|
case AndroidMotionEvent::ACTION_POINTER_DOWN: {
|
||||||
|
type = NS_TOUCH_START;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AndroidMotionEvent::ACTION_MOVE: {
|
||||||
|
type = NS_TOUCH_MOVE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AndroidMotionEvent::ACTION_UP:
|
||||||
|
case AndroidMotionEvent::ACTION_POINTER_UP: {
|
||||||
|
type = NS_TOUCH_END;
|
||||||
|
// for pointer-up events we only want the data from
|
||||||
|
// the one pointer that went up
|
||||||
|
startIndex = PointerIndex();
|
||||||
|
endIndex = startIndex + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AndroidMotionEvent::ACTION_OUTSIDE:
|
||||||
|
case AndroidMotionEvent::ACTION_CANCEL: {
|
||||||
|
type = NS_TOUCH_CANCEL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nsTouchEvent event(true, type, widget);
|
||||||
|
if (type == NS_EVENT_NULL) {
|
||||||
|
// An event we don't know about
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.modifiers = 0;
|
||||||
|
event.time = Time();
|
||||||
|
event.InitBasicModifiers(IsCtrlPressed(),
|
||||||
|
IsAltPressed(),
|
||||||
|
IsShiftPressed(),
|
||||||
|
IsMetaPressed());
|
||||||
|
|
||||||
|
const nsIntPoint& offset = widget->WidgetToScreenOffset();
|
||||||
|
event.touches.SetCapacity(endIndex - startIndex);
|
||||||
|
for (int i = startIndex; i < endIndex; i++) {
|
||||||
|
nsCOMPtr<nsIDOMTouch> t(new dom::Touch(PointIndicies()[i],
|
||||||
|
Points()[i] - offset,
|
||||||
|
PointRadii()[i],
|
||||||
|
Orientations()[i],
|
||||||
|
Pressures()[i]));
|
||||||
|
event.touches.AppendElement(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AndroidPoint::Init(JNIEnv *jenv, jobject jobj)
|
AndroidPoint::Init(JNIEnv *jenv, jobject jobj)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsTArray.h"
|
#include "nsTArray.h"
|
||||||
#include "mozilla/gfx/Rect.h"
|
#include "mozilla/gfx/Rect.h"
|
||||||
|
#include "mozilla/dom/Touch.h"
|
||||||
|
|
||||||
//#define FORCE_ALOG 1
|
//#define FORCE_ALOG 1
|
||||||
|
|
||||||
@@ -660,6 +661,7 @@ public:
|
|||||||
RefCountedJavaObject* ByteBuffer() { return mByteBuffer; }
|
RefCountedJavaObject* ByteBuffer() { return mByteBuffer; }
|
||||||
int Width() { return mWidth; }
|
int Width() { return mWidth; }
|
||||||
int Height() { return mHeight; }
|
int Height() { return mHeight; }
|
||||||
|
nsTouchEvent MakeTouchEvent(nsIWidget* widget);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int mAction;
|
int mAction;
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ using mozilla::unused;
|
|||||||
|
|
||||||
#include "nsRenderingContext.h"
|
#include "nsRenderingContext.h"
|
||||||
#include "nsIDOMSimpleGestureEvent.h"
|
#include "nsIDOMSimpleGestureEvent.h"
|
||||||
#include "mozilla/dom/Touch.h"
|
|
||||||
|
|
||||||
#include "nsGkAtoms.h"
|
#include "nsGkAtoms.h"
|
||||||
#include "nsWidgetsCID.h"
|
#include "nsWidgetsCID.h"
|
||||||
@@ -1202,31 +1201,18 @@ bool nsWindow::OnMultitouchEvent(AndroidGeckoEvent *ae)
|
|||||||
|
|
||||||
bool preventDefaultActions = false;
|
bool preventDefaultActions = false;
|
||||||
bool isDownEvent = false;
|
bool isDownEvent = false;
|
||||||
switch (ae->Action() & AndroidMotionEvent::ACTION_MASK) {
|
|
||||||
case AndroidMotionEvent::ACTION_DOWN:
|
nsTouchEvent event = ae->MakeTouchEvent(this);
|
||||||
case AndroidMotionEvent::ACTION_POINTER_DOWN: {
|
if (event.message != NS_EVENT_NULL) {
|
||||||
nsTouchEvent event(true, NS_TOUCH_START, this);
|
nsEventStatus status;
|
||||||
preventDefaultActions = DispatchMultitouchEvent(event, ae);
|
DispatchEvent(&event, status);
|
||||||
isDownEvent = true;
|
// We check mMultipleActionsPrevented because that's what <input type=range>
|
||||||
break;
|
// sets when someone starts dragging the thumb. It doesn't set the status
|
||||||
}
|
// because it doesn't want to prevent the code that gives the input focus
|
||||||
case AndroidMotionEvent::ACTION_MOVE: {
|
// from running.
|
||||||
nsTouchEvent event(true, NS_TOUCH_MOVE, this);
|
preventDefaultActions = (status == nsEventStatus_eConsumeNoDefault ||
|
||||||
preventDefaultActions = DispatchMultitouchEvent(event, ae);
|
event.mFlags.mMultipleActionsPrevented);
|
||||||
break;
|
isDownEvent = (event.message == NS_TOUCH_START);
|
||||||
}
|
|
||||||
case AndroidMotionEvent::ACTION_UP:
|
|
||||||
case AndroidMotionEvent::ACTION_POINTER_UP: {
|
|
||||||
nsTouchEvent event(true, NS_TOUCH_END, this);
|
|
||||||
preventDefaultActions = DispatchMultitouchEvent(event, ae);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AndroidMotionEvent::ACTION_OUTSIDE:
|
|
||||||
case AndroidMotionEvent::ACTION_CANCEL: {
|
|
||||||
nsTouchEvent event(true, NS_TOUCH_CANCEL, this);
|
|
||||||
preventDefaultActions = DispatchMultitouchEvent(event, ae);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the last event we got was a down event, then by now we know for sure whether
|
// if the last event we got was a down event, then by now we know for sure whether
|
||||||
@@ -1256,52 +1242,6 @@ bool nsWindow::OnMultitouchEvent(AndroidGeckoEvent *ae)
|
|||||||
return preventDefaultActions;
|
return preventDefaultActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
nsWindow::DispatchMultitouchEvent(nsTouchEvent &event, AndroidGeckoEvent *ae)
|
|
||||||
{
|
|
||||||
nsIntPoint offset = WidgetToScreenOffset();
|
|
||||||
|
|
||||||
event.modifiers = 0;
|
|
||||||
event.time = ae->Time();
|
|
||||||
event.InitBasicModifiers(ae->IsCtrlPressed(),
|
|
||||||
ae->IsAltPressed(),
|
|
||||||
ae->IsShiftPressed(),
|
|
||||||
ae->IsMetaPressed());
|
|
||||||
|
|
||||||
int action = ae->Action() & AndroidMotionEvent::ACTION_MASK;
|
|
||||||
if (action == AndroidMotionEvent::ACTION_UP ||
|
|
||||||
action == AndroidMotionEvent::ACTION_POINTER_UP) {
|
|
||||||
event.touches.SetCapacity(1);
|
|
||||||
int pointerIndex = ae->PointerIndex();
|
|
||||||
nsCOMPtr<nsIDOMTouch> t(new Touch(ae->PointIndicies()[pointerIndex],
|
|
||||||
ae->Points()[pointerIndex] - offset,
|
|
||||||
ae->PointRadii()[pointerIndex],
|
|
||||||
ae->Orientations()[pointerIndex],
|
|
||||||
ae->Pressures()[pointerIndex]));
|
|
||||||
event.touches.AppendElement(t);
|
|
||||||
} else {
|
|
||||||
int count = ae->Count();
|
|
||||||
event.touches.SetCapacity(count);
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
nsCOMPtr<nsIDOMTouch> t(new Touch(ae->PointIndicies()[i],
|
|
||||||
ae->Points()[i] - offset,
|
|
||||||
ae->PointRadii()[i],
|
|
||||||
ae->Orientations()[i],
|
|
||||||
ae->Pressures()[i]));
|
|
||||||
event.touches.AppendElement(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nsEventStatus status;
|
|
||||||
DispatchEvent(&event, status);
|
|
||||||
// We check mMultipleActionsPrevented because that's what <input type=range>
|
|
||||||
// sets when someone starts dragging the thumb. It doesn't set the status
|
|
||||||
// because it doesn't want to prevent the code that gives the input focus
|
|
||||||
// from running.
|
|
||||||
return (status == nsEventStatus_eConsumeNoDefault ||
|
|
||||||
event.mFlags.mMultipleActionsPrevented);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
nsWindow::OnNativeGestureEvent(AndroidGeckoEvent *ae)
|
nsWindow::OnNativeGestureEvent(AndroidGeckoEvent *ae)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -215,8 +215,6 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void InitKeyEvent(nsKeyEvent& event, mozilla::AndroidGeckoEvent& key,
|
void InitKeyEvent(nsKeyEvent& event, mozilla::AndroidGeckoEvent& key,
|
||||||
ANPEvent* pluginEvent);
|
ANPEvent* pluginEvent);
|
||||||
bool DispatchMultitouchEvent(nsTouchEvent &event,
|
|
||||||
mozilla::AndroidGeckoEvent *ae);
|
|
||||||
void DispatchMotionEvent(nsInputEvent &event,
|
void DispatchMotionEvent(nsInputEvent &event,
|
||||||
mozilla::AndroidGeckoEvent *ae,
|
mozilla::AndroidGeckoEvent *ae,
|
||||||
const nsIntPoint &refPoint);
|
const nsIntPoint &refPoint);
|
||||||
|
|||||||
Reference in New Issue
Block a user