From df87dea38c1dbb8fdaf2a8c9ffbb8a32ab02976f Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Tue, 15 Oct 2013 17:11:39 -0400 Subject: [PATCH] Bug 924791 - Ensure hover event refpoints are converted from CSSPixels to LayoutDevicePixels. r=wesj --- widget/android/AndroidJavaWrappers.cpp | 47 ++++++++++++++++++++++++++ widget/android/AndroidJavaWrappers.h | 1 + widget/android/nsWindow.cpp | 42 ++++------------------- 3 files changed, 54 insertions(+), 36 deletions(-) diff --git a/widget/android/AndroidJavaWrappers.cpp b/widget/android/AndroidJavaWrappers.cpp index c503a2e661f..3a25845750f 100644 --- a/widget/android/AndroidJavaWrappers.cpp +++ b/widget/android/AndroidJavaWrappers.cpp @@ -833,6 +833,53 @@ AndroidGeckoEvent::MakeMultiTouchInput(nsIWidget* widget) return event; } +WidgetMouseEvent +AndroidGeckoEvent::MakeMouseEvent(nsIWidget* widget) +{ + uint32_t msg = NS_EVENT_NULL; + if (Points().Length() > 0) { + switch (Action()) { + case AndroidMotionEvent::ACTION_HOVER_MOVE: + msg = NS_MOUSE_MOVE; + break; + case AndroidMotionEvent::ACTION_HOVER_ENTER: + msg = NS_MOUSEENTER; + break; + case AndroidMotionEvent::ACTION_HOVER_EXIT: + msg = NS_MOUSELEAVE; + break; + default: + break; + } + } + + WidgetMouseEvent event(true, msg, widget, + WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal); + + if (msg == NS_EVENT_NULL) { + // unknown type, or no point data. abort + return event; + } + + // XXX can we synthesize different buttons? + event.button = WidgetMouseEvent::eLeftButton; + if (msg != NS_MOUSE_MOVE) { + event.clickCount = 1; + } + event.modifiers = 0; + event.time = Time(); + + // We are dispatching this event directly into Gecko (as opposed to going + // through the AsyncPanZoomController), and the Points() array has points + // in CSS pixels, which we need to convert to LayoutDevice pixels. + const nsIntPoint& offset = widget->WidgetToScreenOffset(); + CSSToLayoutDeviceScale scale = widget->GetDefaultScale(); + event.refPoint = LayoutDeviceIntPoint((Points()[0].x * scale.scale) - offset.x, + (Points()[0].y * scale.scale) - offset.y); + + return event; +} + void AndroidPoint::Init(JNIEnv *jenv, jobject jobj) { diff --git a/widget/android/AndroidJavaWrappers.h b/widget/android/AndroidJavaWrappers.h index ae5f3514d08..12d1754e820 100644 --- a/widget/android/AndroidJavaWrappers.h +++ b/widget/android/AndroidJavaWrappers.h @@ -590,6 +590,7 @@ public: int RequestId() { return mCount; } // for convenience WidgetTouchEvent MakeTouchEvent(nsIWidget* widget); MultiTouchInput MakeMultiTouchInput(nsIWidget* widget); + WidgetMouseEvent MakeMouseEvent(nsIWidget* widget); void UnionRect(nsIntRect const& aRect); nsIObserver *Observer() { return mObserver; } diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index e8f8c5027c7..af9fc24403f 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -1168,46 +1168,16 @@ nsWindow::GetNativeData(uint32_t aDataType) void nsWindow::OnMouseEvent(AndroidGeckoEvent *ae) { - uint32_t msg; - switch (ae->Action()) { - case AndroidMotionEvent::ACTION_HOVER_MOVE: - msg = NS_MOUSE_MOVE; - break; - - case AndroidMotionEvent::ACTION_HOVER_ENTER: - msg = NS_MOUSEENTER; - break; - - case AndroidMotionEvent::ACTION_HOVER_EXIT: - msg = NS_MOUSELEAVE; - break; - - default: - return; - } - nsRefPtr kungFuDeathGrip(this); -send_again: - - WidgetMouseEvent event(true, msg, this, - WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal); - // XXX can we synthesize different buttons? - event.button = WidgetMouseEvent::eLeftButton; - - if (msg != NS_MOUSE_MOVE) - event.clickCount = 1; + WidgetMouseEvent event = ae->MakeMouseEvent(this); + if (event.message == NS_EVENT_NULL) { + // invalid event type, abort + return; + } // XXX add the double-click handling logic here - if (ae->Points().Length() > 0) - DispatchMotionEvent(event, ae, ae->Points()[0]); - if (Destroyed()) - return; - - if (msg == NS_MOUSE_BUTTON_DOWN) { - msg = NS_MOUSE_MOVE; - goto send_again; - } + DispatchEvent(&event); } bool nsWindow::OnMultitouchEvent(AndroidGeckoEvent *ae)