Bug 575839 - Simple magnify gesture event support on Android, r=dougt

This commit is contained in:
Michael Wu 2010-07-07 14:34:12 -07:00
Родитель 1c00282e9b
Коммит 9fe0ae68d9
4 изменённых файлов: 60 добавлений и 4 удалений

Просмотреть файл

@ -111,7 +111,10 @@ public class GeckoEvent {
mType = MOTION_EVENT;
mAction = m.getAction();
mTime = m.getEventTime();
mP0 = new Point((int)m.getX(), (int)m.getY());
mP0 = new Point((int)m.getX(0), (int)m.getY(0));
mCount = m.getPointerCount();
if (mCount > 1)
mP1 = new Point((int)m.getX(1), (int)m.getY(1));
}
public GeckoEvent(SensorEvent s) {

Просмотреть файл

@ -288,7 +288,10 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
case MOTION_EVENT:
mTime = jenv->GetLongField(jobj, jTimeField);
mCount = jenv->GetIntField(jobj, jCountField);
ReadP0Field(jenv);
if (mCount > 1)
ReadP1Field(jenv);
break;
case IME_EVENT:

Просмотреть файл

@ -616,8 +616,12 @@ nsWindow::OnGlobalAndroidEvent(AndroidGeckoEvent *ae)
DumpWindows();
#endif
if (target)
target->OnMotionEvent(ae);
if (target) {
if (ae->Count() > 1)
target->OnMultitouchEvent(ae);
else
target->OnMotionEvent(ae);
}
}
break;
}
@ -907,7 +911,6 @@ nsWindow::OnMotionEvent(AndroidGeckoEvent *ae)
break;
default:
// we don't handle any other motion events yet
return;
}
@ -950,6 +953,51 @@ send_again:
}
}
static double
getDistance(int x1, int y1, int x2, int y2)
{
double deltaX = x2 - x1;
double deltaY = y2 - y1;
return sqrt(deltaX*deltaX + deltaY*deltaY);
}
void nsWindow::OnMultitouchEvent(AndroidGeckoEvent *ae)
{
double dist = getDistance(ae->P0().x, ae->P0().y, ae->P1().x, ae->P1().y);
PRUint32 msg;
switch (ae->Action() & AndroidMotionEvent::ACTION_MASK) {
case AndroidMotionEvent::ACTION_MOVE:
msg = NS_SIMPLE_GESTURE_MAGNIFY_UPDATE;
break;
case AndroidMotionEvent::ACTION_POINTER_DOWN:
msg = NS_SIMPLE_GESTURE_MAGNIFY_START;
mStartDist = dist;
break;
case AndroidMotionEvent::ACTION_POINTER_UP:
msg = NS_SIMPLE_GESTURE_MAGNIFY;
break;
default:
return;
}
nsIntPoint offset = WidgetToScreenOffset();
nsSimpleGestureEvent event(PR_TRUE, msg, this, 0, dist - mStartDist);
event.isShift = gLeftShift || gRightShift;
event.isControl = gSym;
event.isMeta = PR_FALSE;
event.isAlt = gLeftAlt || gRightAlt;
event.time = ae->Time();
event.refPoint.x = ((ae->P0().x + ae->P1().x) / 2) - offset.x;
event.refPoint.y = ((ae->P0().y + ae->P1().y) / 2) - offset.y;
DispatchEvent(&event);
mStartDist = dist;
}
void
nsWindow::InitKeyEvent(nsKeyEvent& event, AndroidGeckoEvent& key)
{

Просмотреть файл

@ -69,6 +69,7 @@ public:
void OnAndroidEvent(mozilla::AndroidGeckoEvent *ae);
void OnDraw(mozilla::AndroidGeckoEvent *ae);
void OnMotionEvent(mozilla::AndroidGeckoEvent *ae);
void OnMultitouchEvent(mozilla::AndroidGeckoEvent *ae);
void OnKeyEvent(mozilla::AndroidGeckoEvent *ae);
void OnIMEEvent(mozilla::AndroidGeckoEvent *ae);
@ -173,6 +174,7 @@ protected:
PRPackedBool mIsVisible;
nsTArray<nsWindow*> mChildren;
nsWindow* mParent;
double mStartDist;
nsCOMPtr<nsIdleService> mIdleService;
static void DumpWindows();