Bug 839641 - Send touch events and prevent-default notifications to APZC. r=Cwiiis

This commit is contained in:
Kartikaya Gupta 2013-04-26 13:24:28 -04:00
parent 909ef092fe
commit 64acbc32d5
6 changed files with 86 additions and 10 deletions

View File

@ -2440,7 +2440,7 @@ abstract public class GeckoApp
}
}
GeckoAppShell.sendEventToGecko(GeckoEvent.createMotionEvent(event));
GeckoAppShell.sendEventToGecko(GeckoEvent.createMotionEvent(event, false));
return true;
}

View File

@ -329,13 +329,19 @@ public class GeckoEvent {
}
}
public static GeckoEvent createMotionEvent(MotionEvent m) {
/**
* Creates a GeckoEvent that contains the data from the MotionEvent.
* The keepInViewCoordinates parameter can be set to false to convert from the Java
* coordinate system (device pixels relative to the LayerView) to a coordinate system
* relative to gecko's coordinate system (CSS pixels relative to gecko scroll position).
*/
public static GeckoEvent createMotionEvent(MotionEvent m, boolean keepInViewCoordinates) {
GeckoEvent event = new GeckoEvent(NativeGeckoEvent.MOTION_EVENT);
event.initMotionEvent(m);
event.initMotionEvent(m, keepInViewCoordinates);
return event;
}
private void initMotionEvent(MotionEvent m) {
private void initMotionEvent(MotionEvent m, boolean keepInViewCoordinates) {
mAction = m.getActionMasked();
mTime = (System.currentTimeMillis() - SystemClock.elapsedRealtime()) + m.getEventTime();
mMetaState = m.getMetaState();
@ -358,7 +364,7 @@ public class GeckoEvent {
mPointRadii = new Point[mCount];
mPointerIndex = m.getActionIndex();
for (int i = 0; i < mCount; i++) {
addMotionPoint(i, i, m);
addMotionPoint(i, i, m, keepInViewCoordinates);
}
break;
}
@ -374,10 +380,12 @@ public class GeckoEvent {
}
}
private void addMotionPoint(int index, int eventIndex, MotionEvent event) {
private void addMotionPoint(int index, int eventIndex, MotionEvent event, boolean keepInViewCoordinates) {
try {
PointF geckoPoint = new PointF(event.getX(eventIndex), event.getY(eventIndex));
geckoPoint = GeckoApp.mAppContext.getLayerView().convertViewPointToLayerPoint(geckoPoint);
if (!keepInViewCoordinates) {
geckoPoint = GeckoApp.mAppContext.getLayerView().convertViewPointToLayerPoint(geckoPoint);
}
mPoints[index] = new Point(Math.round(geckoPoint.x), Math.round(geckoPoint.y));
mPointIndicies[index] = event.getPointerId(eventIndex);

View File

@ -37,7 +37,8 @@ class NativePanZoomController implements PanZoomController, GeckoEventListener {
}
public boolean onTouchEvent(MotionEvent event) {
// FIXME implement this
GeckoEvent wrapped = GeckoEvent.createMotionEvent(event, true);
handleTouchEvent(wrapped);
return false;
}

View File

@ -903,7 +903,15 @@ Java_org_mozilla_gecko_gfx_NativePanZoomController_init(JNIEnv* env, jobject ins
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent(JNIEnv* env, jobject instance, jobject event)
{
// FIXME implement this
AsyncPanZoomController *controller = nsWindow::GetPanZoomController();
if (controller) {
AndroidGeckoEvent* wrapper = AndroidGeckoEvent::MakeFromJavaObject(env, event);
const MultiTouchInput& input = wrapper->MakeMultiTouchInput(nsWindow::TopWindow());
delete wrapper;
if (input.mType >= 0) {
controller->ReceiveInputEvent(input);
}
}
}
NS_EXPORT void JNICALL
@ -931,7 +939,10 @@ Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy(JNIEnv* env, jobject
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented(JNIEnv* env, jobject instance, jboolean prevented)
{
// FIXME implement this
AsyncPanZoomController *controller = nsWindow::GetPanZoomController();
if (controller) {
controller->ContentReceivedTouch(prevented);
}
}
NS_EXPORT jboolean JNICALL

View File

@ -744,6 +744,60 @@ AndroidGeckoEvent::MakeTouchEvent(nsIWidget* widget)
return event;
}
MultiTouchInput
AndroidGeckoEvent::MakeMultiTouchInput(nsIWidget* widget)
{
MultiTouchInput::MultiTouchType type = (MultiTouchInput::MultiTouchType)-1;
int startIndex = 0;
int endIndex = Count();
switch (Action()) {
case AndroidMotionEvent::ACTION_DOWN:
case AndroidMotionEvent::ACTION_POINTER_DOWN: {
type = MultiTouchInput::MULTITOUCH_START;
break;
}
case AndroidMotionEvent::ACTION_MOVE: {
type = MultiTouchInput::MULTITOUCH_MOVE;
break;
}
case AndroidMotionEvent::ACTION_UP:
case AndroidMotionEvent::ACTION_POINTER_UP: {
// for pointer-up events we only want the data from
// the one pointer that went up
startIndex = PointerIndex();
endIndex = startIndex + 1;
type = MultiTouchInput::MULTITOUCH_END;
break;
}
case AndroidMotionEvent::ACTION_OUTSIDE:
case AndroidMotionEvent::ACTION_CANCEL: {
type = MultiTouchInput::MULTITOUCH_CANCEL;
break;
}
}
MultiTouchInput event(type, Time());
if (type < 0) {
// An event we don't know about
return event;
}
const nsIntPoint& offset = widget->WidgetToScreenOffset();
event.mTouches.SetCapacity(endIndex - startIndex);
for (int i = startIndex; i < endIndex; i++) {
SingleTouchData data(PointIndicies()[i],
Points()[i] - offset,
PointRadii()[i],
Orientations()[i],
Pressures()[i]);
event.mTouches.AppendElement(data);
}
return event;
}
void
AndroidPoint::Init(JNIEnv *jenv, jobject jobj)
{

View File

@ -17,6 +17,7 @@
#include "nsTArray.h"
#include "mozilla/gfx/Rect.h"
#include "mozilla/dom/Touch.h"
#include "InputData.h"
//#define FORCE_ALOG 1
@ -556,6 +557,7 @@ public:
int Width() { return mWidth; }
int Height() { return mHeight; }
nsTouchEvent MakeTouchEvent(nsIWidget* widget);
MultiTouchInput MakeMultiTouchInput(nsIWidget* widget);
void UnionRect(nsIntRect const& aRect);
protected: