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

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 meta_state plumbing. 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..58e5b98bce28e6e849ddf1cd65c2ba9f79837974 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);
@@ -966,31 +968,80 @@ jboolean ContentViewCoreImpl::OnTouchEvent(
android_meta_state,
raw_pos_x - pos_x_0,
raw_pos_y - pos_y_0,
- pointer0,
- pointer1);
+ &pointer0,
+ &pointer1);
return is_touch_handle_event ? rwhv->OnTouchHandleEvent(event)
: rwhv->OnTouchEvent(event);
}
-jboolean ContentViewCoreImpl::SendMouseMoveEvent(
+jboolean ContentViewCoreImpl::SendMouseEvent(
JNIEnv* env,
const JavaParamRef<jobject>& obj,
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_meta_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,
+ nullptr /* event */,
+ time_ms,
+ android_action,
+ 1 /* pointer_count */,
+ 0 /* history_size */,
+ 0 /* action_index */,
+ android_button_state,
+ android_meta_state,
+ 0 /* raw_offset_x_pixels */,
+ 0 /* raw_offset_y_pixels */,
+ &pointer0,
+ nullptr);
+
+ 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
aelias_OOO_until_Jul13 2016/10/20 23:26:29 If the mouse is pressed outside the ContentViewCor
mustaq 2016/10/21 19:19:08 Right. I am not sure how to find the info correctl
aelias_OOO_until_Jul13 2016/10/21 21:26:54 Well, regardless of Samsung-specific or not, given
mustaq 2016/10/26 17:45:09 Looks like we were talking about two different thi
aelias_OOO_until_Jul13 2016/10/27 03:09:37 OK, thanks for the explanation. I really would pr
aelias_OOO_until_Jul13 2016/10/27 18:27:56 finger#2, stylus#1 etc), hence less "granular" tha
aelias_OOO_until_Jul13 2016/10/27 23:36:48 events (ACTION_BUTTON_PRESS & _RELEASE), and undef
+ // 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),
+ motion_event.GetFlags(),
+ 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));
+
+ rwhv->SendMouseEvent(mouse_event);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698