Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: content/browser/android/content_view_core_impl.cc

Issue 2054193002: Android mouse events shouldn't appear as TouchEvents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added working mouse buttons. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/android/content_view_core_impl.cc
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc
index a7f92639fa22c313db88252bc64615f8ebf06c4a..745f2a203b5ade878a8274e09c991c6e3a4ecb2c 100644
--- a/content/browser/android/content_view_core_impl.cc
+++ b/content/browser/android/content_view_core_impl.cc
@@ -61,6 +61,7 @@
#include "ui/events/blink/blink_event_util.h"
#include "ui/events/blink/web_input_event_traits.h"
#include "ui/events/event_utils.h"
+#include "ui/events/gesture_detection/motion_event.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
@@ -217,7 +218,8 @@ ContentViewCoreImpl::ContentViewCoreImpl(
page_scale_(1),
dpi_scale_(ui::GetScaleFactorForNativeView(&view_)),
device_orientation_(0),
- accessibility_enabled_(false) {
+ accessibility_enabled_(false),
+ button_state_(0) {
CHECK(web_contents) <<
"A ContentViewCoreImpl should be created with a valid WebContents.";
DCHECK(window_android);
@@ -973,24 +975,74 @@ jboolean ContentViewCoreImpl::OnTouchEvent(
: rwhv->OnTouchEvent(event);
}
-jboolean ContentViewCoreImpl::SendMouseMoveEvent(
+jboolean ContentViewCoreImpl::SendMouseEvent(
JNIEnv* env,
const JavaParamRef<jobject>& obj,
dtapuska 2016/09/20 20:56:16 Can we pass const JavaParamRef<jobject>& motion_ev
mustaq 2016/09/21 19:31:29 - Done adding meta state. - Skipped passing motio
jlong time_ms,
+ jint android_action,
jfloat x,
jfloat y,
- jint tool_type) {
+ jint pointer_id,
+ jfloat pressure,
+ jfloat orientation,
+ jfloat tilt,
+ jint android_button_state,
+ jint android_tool_type) {
+
RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
if (!rwhv)
return false;
- blink::WebMouseEvent event = WebMouseEventBuilder::Build(
- WebInputEvent::MouseMove,
- blink::WebMouseEvent::Button::NoButton,
- time_ms / 1000.0, x / dpi_scale(), y / dpi_scale(), 0, 1,
- ui::ToWebPointerType(static_cast<ui::MotionEvent::ToolType>(tool_type)));
-
- rwhv->SendMouseEvent(event);
+ // Construct a motion_event object minimally, only to convert the raw
+ // parameters to ui::MotionEvent values. Since we used only the cached values
+ // at index=0, it is okay to even pass a null event to the constructor.
+ ui::MotionEventAndroid::Pointer pointer0(
+ pointer_id, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */,
+ orientation, tilt, android_tool_type);
+
+ ui::MotionEventAndroid motion_event(1.f / dpi_scale(),
+ env,
+ 0 /* event */,
+ time_ms,
+ android_action,
+ 1 /* pointer_count */,
+ 0 /* history_size */,
+ 0 /* action_index */,
+ android_button_state,
+ 0 /* meta_state */,
+ 0 /* raw_offset_x_pixels */,
+ 0 /* raw_offset_y_pixels */,
+ pointer0,
+ pointer0 /* pointer1 */);
+
+ blink::WebInputEvent::Type webMouseEventType =
+ ui::ToWebMouseEventType(motion_event.GetAction());
+
+ int old_button_state = button_state_;
+
+ // Ignore button state in MouseMove events: we have seen cases that a
+ // MouseMove with updated button state often precedes a MouseDown/MouseUp.
+ if (webMouseEventType != blink::WebInputEvent::MouseMove)
+ button_state_ = motion_event.GetButtonState();
+
+ blink::WebMouseEvent mouse_event = WebMouseEventBuilder::Build(
+ webMouseEventType,
+ time_ms / 1000.0,
+ motion_event.GetX(0),
+ motion_event.GetY(0),
+ button_state_ /* modifiers */,
+ button_state_ ? 1 : 0 /* click count */,
+ motion_event.GetPointerId(0),
+ motion_event.GetPressure(0),
+ motion_event.GetOrientation(0),
+ motion_event.GetTilt(0),
+ old_button_state,
+ button_state_,
+ motion_event.GetToolType(0));
+ // TODO(mustaq): mouse_event.modifiers should include fields from
+ // MotionEvent.getMetaState().
+
+ rwhv->SendMouseEvent(mouse_event);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698