Bug 859951 - Refactor the code to convert MOTION_EVENT GeckoEvents to nsTouchEvent instances. r=wesj
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user