Bug 859951 - Refactor the code to convert MOTION_EVENT GeckoEvents to nsTouchEvent instances. r=wesj

This commit is contained in:
Kartikaya Gupta 2013-04-17 17:39:10 -04:00
parent 3919709af4
commit eaa5b3fc84
5 changed files with 76 additions and 75 deletions

View File

@ -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 {
PointF geckoPoint = new PointF(event.getX(eventIndex), event.getY(eventIndex));
geckoPoint = GeckoApp.mAppContext.getLayerView().convertViewPointToLayerPoint(geckoPoint);

View File

@ -690,6 +690,67 @@ AndroidGeckoEvent::Init(AndroidGeckoEvent *aResizeEvent)
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
AndroidPoint::Init(JNIEnv *jenv, jobject jobj)
{

View File

@ -15,6 +15,7 @@
#include "nsString.h"
#include "nsTArray.h"
#include "mozilla/gfx/Rect.h"
#include "mozilla/dom/Touch.h"
//#define FORCE_ALOG 1
@ -660,6 +661,7 @@ public:
RefCountedJavaObject* ByteBuffer() { return mByteBuffer; }
int Width() { return mWidth; }
int Height() { return mHeight; }
nsTouchEvent MakeTouchEvent(nsIWidget* widget);
protected:
int mAction;

View File

@ -28,7 +28,6 @@ using mozilla::unused;
#include "nsRenderingContext.h"
#include "nsIDOMSimpleGestureEvent.h"
#include "mozilla/dom/Touch.h"
#include "nsGkAtoms.h"
#include "nsWidgetsCID.h"
@ -1202,31 +1201,18 @@ bool nsWindow::OnMultitouchEvent(AndroidGeckoEvent *ae)
bool preventDefaultActions = false;
bool isDownEvent = false;
switch (ae->Action() & AndroidMotionEvent::ACTION_MASK) {
case AndroidMotionEvent::ACTION_DOWN:
case AndroidMotionEvent::ACTION_POINTER_DOWN: {
nsTouchEvent event(true, NS_TOUCH_START, this);
preventDefaultActions = DispatchMultitouchEvent(event, ae);
isDownEvent = true;
break;
}
case AndroidMotionEvent::ACTION_MOVE: {
nsTouchEvent event(true, NS_TOUCH_MOVE, this);
preventDefaultActions = DispatchMultitouchEvent(event, ae);
break;
}
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;
}
nsTouchEvent event = ae->MakeTouchEvent(this);
if (event.message != NS_EVENT_NULL) {
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.
preventDefaultActions = (status == nsEventStatus_eConsumeNoDefault ||
event.mFlags.mMultipleActionsPrevented);
isDownEvent = (event.message == NS_TOUCH_START);
}
// 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;
}
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
nsWindow::OnNativeGestureEvent(AndroidGeckoEvent *ae)
{

View File

@ -215,8 +215,6 @@ protected:
private:
void InitKeyEvent(nsKeyEvent& event, mozilla::AndroidGeckoEvent& key,
ANPEvent* pluginEvent);
bool DispatchMultitouchEvent(nsTouchEvent &event,
mozilla::AndroidGeckoEvent *ae);
void DispatchMotionEvent(nsInputEvent &event,
mozilla::AndroidGeckoEvent *ae,
const nsIntPoint &refPoint);