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

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

Issue 342633003: [Android] Select text when stylus first button is pressed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed predefined namespace Created 6 years, 6 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 2335d0a5fb05b9ca4df9420b4bb70bf60b3a5609..9dfe2107accf83c9dd9a3eeccc9fb02ad32abcd9 100644
--- a/content/browser/android/content_view_core_impl.cc
+++ b/content/browser/android/content_view_core_impl.cc
@@ -55,6 +55,7 @@
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/base/android/view_android.h"
#include "ui/base/android/window_android.h"
+#include "ui/events/gesture_detection/motion_event.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/size_conversions.h"
@@ -222,7 +223,9 @@ ContentViewCoreImpl::ContentViewCoreImpl(
view_android_(view_android),
window_android_(window_android),
device_orientation_(0),
- accessibility_enabled_(false) {
+ accessibility_enabled_(false),
+ mouse_drag_start_x_(0),
+ mouse_drag_start_y_(0) {
CHECK(web_contents) <<
"A ContentViewCoreImpl should be created with a valid WebContents.";
@@ -929,6 +932,15 @@ void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env,
}
}
+// static
+bool ContentViewCoreImpl::ShouldConvertToMouseEvent(
+ const ui::MotionEvent& event) {
+ // Currently we aren't supporting stylus + touch case.
+ return event.GetPointerCount() > 0 &&
+ event.GetToolType(0) == ui::MotionEvent::TOOL_TYPE_STYLUS &&
+ event.GetButtonState() == ui::MotionEvent::BUTTON_SECONDARY;
+}
+
jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env,
jobject obj,
jobject motion_event,
@@ -946,7 +958,10 @@ jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env,
jfloat touch_major_0,
jfloat touch_major_1,
jfloat raw_pos_x,
- jfloat raw_pos_y) {
+ jfloat raw_pos_y,
+ jint android_tool_type_0,
+ jint android_tool_type_1,
+ jint android_button_state) {
RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
// Avoid synthesizing a touch event if it cannot be forwarded.
if (!rwhv)
@@ -969,9 +984,38 @@ jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env,
touch_major_0,
touch_major_1,
raw_pos_x,
- raw_pos_y);
-
- return rwhv->OnTouchEvent(event);
+ raw_pos_y,
+ android_tool_type_0,
+ android_tool_type_1,
+ android_button_state);
+
+ bool result = rwhv->OnTouchEvent(event);
+
+ // Select text and show handles if necessary.
+ if (result && ShouldConvertToMouseEvent(event)) {
+ Java_ContentViewCore_showSelectionHandlesAutomatically(env, obj);
+ switch (event.GetAction()) {
+ case ui::MotionEvent::ACTION_DOWN:
+ web_contents_->Unselect();
+ mouse_drag_start_x_ = pos_x_0;
+ mouse_drag_start_y_ = pos_y_0;
+ break;
+ case ui::MotionEvent::ACTION_MOVE:
+ SelectBetweenCoordinates(env, obj, mouse_drag_start_x_,
+ mouse_drag_start_y_, pos_x_0, pos_y_0);
+ break;
+ case ui::MotionEvent::ACTION_UP:
+ SelectBetweenCoordinates(env, obj, mouse_drag_start_x_,
+ mouse_drag_start_y_, pos_x_0, pos_y_0);
+ break;
+ case ui::MotionEvent::ACTION_CANCEL:
+ web_contents_->Unselect();
+ break;
+ default:
+ break;
+ }
+ }
+ return result;
}
float ContentViewCoreImpl::GetDpiScale() const {

Powered by Google App Engine
This is Rietveld 408576698