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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/android/content_view_core_impl.h" 5 #include "content/browser/android/content_view_core_impl.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "content/public/common/content_client.h" 48 #include "content/public/common/content_client.h"
49 #include "content/public/common/content_switches.h" 49 #include "content/public/common/content_switches.h"
50 #include "content/public/common/menu_item.h" 50 #include "content/public/common/menu_item.h"
51 #include "content/public/common/page_transition_types.h" 51 #include "content/public/common/page_transition_types.h"
52 #include "content/public/common/user_agent.h" 52 #include "content/public/common/user_agent.h"
53 #include "jni/ContentViewCore_jni.h" 53 #include "jni/ContentViewCore_jni.h"
54 #include "third_party/WebKit/public/web/WebBindings.h" 54 #include "third_party/WebKit/public/web/WebBindings.h"
55 #include "third_party/WebKit/public/web/WebInputEvent.h" 55 #include "third_party/WebKit/public/web/WebInputEvent.h"
56 #include "ui/base/android/view_android.h" 56 #include "ui/base/android/view_android.h"
57 #include "ui/base/android/window_android.h" 57 #include "ui/base/android/window_android.h"
58 #include "ui/events/gesture_detection/motion_event.h"
58 #include "ui/gfx/android/java_bitmap.h" 59 #include "ui/gfx/android/java_bitmap.h"
59 #include "ui/gfx/screen.h" 60 #include "ui/gfx/screen.h"
60 #include "ui/gfx/size_conversions.h" 61 #include "ui/gfx/size_conversions.h"
61 #include "ui/gfx/size_f.h" 62 #include "ui/gfx/size_f.h"
62 63
63 using base::android::AttachCurrentThread; 64 using base::android::AttachCurrentThread;
64 using base::android::ConvertJavaStringToUTF16; 65 using base::android::ConvertJavaStringToUTF16;
65 using base::android::ConvertJavaStringToUTF8; 66 using base::android::ConvertJavaStringToUTF8;
66 using base::android::ConvertUTF16ToJavaString; 67 using base::android::ConvertUTF16ToJavaString;
67 using base::android::ConvertUTF8ToJavaString; 68 using base::android::ConvertUTF8ToJavaString;
68 using base::android::ScopedJavaGlobalRef; 69 using base::android::ScopedJavaGlobalRef;
69 using base::android::ScopedJavaLocalRef; 70 using base::android::ScopedJavaLocalRef;
70 using blink::WebGestureEvent; 71 using blink::WebGestureEvent;
71 using blink::WebInputEvent; 72 using blink::WebInputEvent;
73 using blink::WebMouseEvent;
72 74
73 // Describes the type and enabled state of a select popup item. 75 // Describes the type and enabled state of a select popup item.
74 namespace { 76 namespace {
75 77
76 enum { 78 enum {
77 #define DEFINE_POPUP_ITEM_TYPE(name, value) POPUP_ITEM_TYPE_##name = value, 79 #define DEFINE_POPUP_ITEM_TYPE(name, value) POPUP_ITEM_TYPE_##name = value,
78 #include "content/browser/android/popup_item_type_list.h" 80 #include "content/browser/android/popup_item_type_list.h"
79 #undef DEFINE_POPUP_ITEM_TYPE 81 #undef DEFINE_POPUP_ITEM_TYPE
80 }; 82 };
81 83
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 ui::WindowAndroid* window_android, 217 ui::WindowAndroid* window_android,
216 jobject java_bridge_retained_object_set) 218 jobject java_bridge_retained_object_set)
217 : WebContentsObserver(web_contents), 219 : WebContentsObserver(web_contents),
218 java_ref_(env, obj), 220 java_ref_(env, obj),
219 web_contents_(static_cast<WebContentsImpl*>(web_contents)), 221 web_contents_(static_cast<WebContentsImpl*>(web_contents)),
220 root_layer_(cc::SolidColorLayer::Create()), 222 root_layer_(cc::SolidColorLayer::Create()),
221 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), 223 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()),
222 view_android_(view_android), 224 view_android_(view_android),
223 window_android_(window_android), 225 window_android_(window_android),
224 device_orientation_(0), 226 device_orientation_(0),
225 accessibility_enabled_(false) { 227 accessibility_enabled_(false),
228 mouse_drag_start_x_(0),
229 mouse_drag_start_y_(0) {
226 CHECK(web_contents) << 230 CHECK(web_contents) <<
227 "A ContentViewCoreImpl should be created with a valid WebContents."; 231 "A ContentViewCoreImpl should be created with a valid WebContents.";
228 232
229 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj)); 233 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj));
230 gfx::Size physical_size( 234 gfx::Size physical_size(
231 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), 235 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
232 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); 236 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
233 root_layer_->SetBounds(physical_size); 237 root_layer_->SetBounds(physical_size);
234 root_layer_->SetIsDrawable(true); 238 root_layer_->SetIsDrawable(true);
235 239
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 jint action_index, 943 jint action_index,
940 jfloat pos_x_0, 944 jfloat pos_x_0,
941 jfloat pos_y_0, 945 jfloat pos_y_0,
942 jfloat pos_x_1, 946 jfloat pos_x_1,
943 jfloat pos_y_1, 947 jfloat pos_y_1,
944 jint pointer_id_0, 948 jint pointer_id_0,
945 jint pointer_id_1, 949 jint pointer_id_1,
946 jfloat touch_major_0, 950 jfloat touch_major_0,
947 jfloat touch_major_1, 951 jfloat touch_major_1,
948 jfloat raw_pos_x, 952 jfloat raw_pos_x,
949 jfloat raw_pos_y) { 953 jfloat raw_pos_y,
954 jint android_tool_type,
955 jint android_button_state) {
950 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 956 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
951 // Avoid synthesizing a touch event if it cannot be forwarded. 957 // Avoid synthesizing a touch event if it cannot be forwarded.
952 if (!rwhv) 958 if (!rwhv)
953 return false; 959 return false;
954 960
955 MotionEventAndroid event(1.f / dpi_scale(), 961 MotionEventAndroid event(1.f / dpi_scale(),
956 env, 962 env,
957 motion_event, 963 motion_event,
958 time_ms, 964 time_ms,
959 android_action, 965 android_action,
960 pointer_count, 966 pointer_count,
961 history_size, 967 history_size,
962 action_index, 968 action_index,
963 pos_x_0, 969 pos_x_0,
964 pos_y_0, 970 pos_y_0,
965 pos_x_1, 971 pos_x_1,
966 pos_y_1, 972 pos_y_1,
967 pointer_id_0, 973 pointer_id_0,
968 pointer_id_1, 974 pointer_id_1,
969 touch_major_0, 975 touch_major_0,
970 touch_major_1, 976 touch_major_1,
971 raw_pos_x, 977 raw_pos_x,
972 raw_pos_y); 978 raw_pos_y);
973 979
980 switch (event.GetAction()) {
981 case ui::MotionEvent::ACTION_DOWN:
982 mouse_drag_start_x_ = pos_x_0;
983 mouse_drag_start_y_ = pos_y_0;
984 break;
985 case ui::MotionEvent::ACTION_MOVE:
986 case ui::MotionEvent::ACTION_UP:
987 SelectBetweenCoordinates(env, obj, mouse_drag_start_x_,
988 mouse_drag_start_y_, pos_x_0, pos_y_0);
989 break;
990 default:
991 break;
992 }
993
974 return rwhv->OnTouchEvent(event); 994 return rwhv->OnTouchEvent(event);
975 } 995 }
976 996
977 float ContentViewCoreImpl::GetDpiScale() const { 997 float ContentViewCoreImpl::GetDpiScale() const {
978 return dpi_scale_; 998 return dpi_scale_;
979 } 999 }
980 1000
981 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, 1001 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env,
982 jobject obj, 1002 jobject obj,
983 jlong time_ms, 1003 jlong time_ms,
984 jfloat x, 1004 jfloat x,
985 jfloat y) { 1005 jfloat y) {
986 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 1006 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
987 if (!rwhv) 1007 if (!rwhv)
988 return false; 1008 return false;
989 1009
990 blink::WebMouseEvent event = WebMouseEventBuilder::Build( 1010 blink::WebMouseEvent event = WebMouseEventBuilder::Build(
991 WebInputEvent::MouseMove, 1011 WebInputEvent::MouseMove,
992 blink::WebMouseEvent::ButtonNone, 1012 WebMouseEvent::ButtonNone,
993 time_ms / 1000.0, x / dpi_scale(), y / dpi_scale(), 0, 1); 1013 time_ms / 1000.0, x / dpi_scale(), y / dpi_scale(), 0, 1);
994 1014
995 rwhv->SendMouseEvent(event); 1015 rwhv->SendMouseEvent(event);
996 return true; 1016 return true;
997 } 1017 }
998 1018
999 jboolean ContentViewCoreImpl::SendMouseWheelEvent(JNIEnv* env, 1019 jboolean ContentViewCoreImpl::SendMouseWheelEvent(JNIEnv* env,
1000 jobject obj, 1020 jobject obj,
1001 jlong time_ms, 1021 jlong time_ms,
1002 jfloat x, 1022 jfloat x,
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 reinterpret_cast<ui::WindowAndroid*>(window_android), 1624 reinterpret_cast<ui::WindowAndroid*>(window_android),
1605 retained_objects_set); 1625 retained_objects_set);
1606 return reinterpret_cast<intptr_t>(view); 1626 return reinterpret_cast<intptr_t>(view);
1607 } 1627 }
1608 1628
1609 bool RegisterContentViewCore(JNIEnv* env) { 1629 bool RegisterContentViewCore(JNIEnv* env) {
1610 return RegisterNativesImpl(env); 1630 return RegisterNativesImpl(env);
1611 } 1631 }
1612 1632
1613 } // namespace content 1633 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698