| OLD | NEW |
| 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 Loading... |
| 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; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 ui::WindowAndroid* window_android, | 216 ui::WindowAndroid* window_android, |
| 216 jobject java_bridge_retained_object_set) | 217 jobject java_bridge_retained_object_set) |
| 217 : WebContentsObserver(web_contents), | 218 : WebContentsObserver(web_contents), |
| 218 java_ref_(env, obj), | 219 java_ref_(env, obj), |
| 219 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 220 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 220 root_layer_(cc::SolidColorLayer::Create()), | 221 root_layer_(cc::SolidColorLayer::Create()), |
| 221 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), | 222 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), |
| 222 view_android_(view_android), | 223 view_android_(view_android), |
| 223 window_android_(window_android), | 224 window_android_(window_android), |
| 224 device_orientation_(0), | 225 device_orientation_(0), |
| 225 accessibility_enabled_(false) { | 226 accessibility_enabled_(false), |
| 227 mouse_drag_start_x_(0), |
| 228 mouse_drag_start_y_(0) { |
| 226 CHECK(web_contents) << | 229 CHECK(web_contents) << |
| 227 "A ContentViewCoreImpl should be created with a valid WebContents."; | 230 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 228 | 231 |
| 229 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj)); | 232 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj)); |
| 230 gfx::Size physical_size( | 233 gfx::Size physical_size( |
| 231 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 234 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 232 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 235 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 233 root_layer_->SetBounds(physical_size); | 236 root_layer_->SetBounds(physical_size); |
| 234 root_layer_->SetIsDrawable(true); | 237 root_layer_->SetIsDrawable(true); |
| 235 | 238 |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 | 925 |
| 923 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, | 926 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, |
| 924 jobject obj, | 927 jobject obj, |
| 925 jint orientation) { | 928 jint orientation) { |
| 926 if (device_orientation_ != orientation) { | 929 if (device_orientation_ != orientation) { |
| 927 device_orientation_ = orientation; | 930 device_orientation_ = orientation; |
| 928 SendOrientationChangeEventInternal(); | 931 SendOrientationChangeEventInternal(); |
| 929 } | 932 } |
| 930 } | 933 } |
| 931 | 934 |
| 935 // static |
| 936 bool ContentViewCoreImpl::ShouldConvertToMouseEvent( |
| 937 const ui::MotionEvent& event) { |
| 938 // Currently we aren't supporting stylus + touch case. |
| 939 return event.GetPointerCount() > 0 && |
| 940 event.GetToolType(0) == ui::MotionEvent::TOOL_TYPE_STYLUS && |
| 941 event.GetButtonState() == ui::MotionEvent::BUTTON_SECONDARY; |
| 942 } |
| 943 |
| 932 jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env, | 944 jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env, |
| 933 jobject obj, | 945 jobject obj, |
| 934 jobject motion_event, | 946 jobject motion_event, |
| 935 jlong time_ms, | 947 jlong time_ms, |
| 936 jint android_action, | 948 jint android_action, |
| 937 jint pointer_count, | 949 jint pointer_count, |
| 938 jint history_size, | 950 jint history_size, |
| 939 jint action_index, | 951 jint action_index, |
| 940 jfloat pos_x_0, | 952 jfloat pos_x_0, |
| 941 jfloat pos_y_0, | 953 jfloat pos_y_0, |
| 942 jfloat pos_x_1, | 954 jfloat pos_x_1, |
| 943 jfloat pos_y_1, | 955 jfloat pos_y_1, |
| 944 jint pointer_id_0, | 956 jint pointer_id_0, |
| 945 jint pointer_id_1, | 957 jint pointer_id_1, |
| 946 jfloat touch_major_0, | 958 jfloat touch_major_0, |
| 947 jfloat touch_major_1, | 959 jfloat touch_major_1, |
| 948 jfloat raw_pos_x, | 960 jfloat raw_pos_x, |
| 949 jfloat raw_pos_y) { | 961 jfloat raw_pos_y, |
| 962 jint android_tool_type_0, |
| 963 jint android_tool_type_1, |
| 964 jint android_button_state) { |
| 950 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 965 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 951 // Avoid synthesizing a touch event if it cannot be forwarded. | 966 // Avoid synthesizing a touch event if it cannot be forwarded. |
| 952 if (!rwhv) | 967 if (!rwhv) |
| 953 return false; | 968 return false; |
| 954 | 969 |
| 955 MotionEventAndroid event(1.f / dpi_scale(), | 970 MotionEventAndroid event(1.f / dpi_scale(), |
| 956 env, | 971 env, |
| 957 motion_event, | 972 motion_event, |
| 958 time_ms, | 973 time_ms, |
| 959 android_action, | 974 android_action, |
| 960 pointer_count, | 975 pointer_count, |
| 961 history_size, | 976 history_size, |
| 962 action_index, | 977 action_index, |
| 963 pos_x_0, | 978 pos_x_0, |
| 964 pos_y_0, | 979 pos_y_0, |
| 965 pos_x_1, | 980 pos_x_1, |
| 966 pos_y_1, | 981 pos_y_1, |
| 967 pointer_id_0, | 982 pointer_id_0, |
| 968 pointer_id_1, | 983 pointer_id_1, |
| 969 touch_major_0, | 984 touch_major_0, |
| 970 touch_major_1, | 985 touch_major_1, |
| 971 raw_pos_x, | 986 raw_pos_x, |
| 972 raw_pos_y); | 987 raw_pos_y, |
| 988 android_tool_type_0, |
| 989 android_tool_type_1, |
| 990 android_button_state); |
| 973 | 991 |
| 974 return rwhv->OnTouchEvent(event); | 992 bool result = rwhv->OnTouchEvent(event); |
| 993 |
| 994 // Select text and show handles if necessary. |
| 995 if (result && ShouldConvertToMouseEvent(event)) { |
| 996 Java_ContentViewCore_showSelectionHandlesAutomatically(env, obj); |
| 997 switch (event.GetAction()) { |
| 998 case ui::MotionEvent::ACTION_DOWN: |
| 999 web_contents_->Unselect(); |
| 1000 mouse_drag_start_x_ = pos_x_0; |
| 1001 mouse_drag_start_y_ = pos_y_0; |
| 1002 break; |
| 1003 case ui::MotionEvent::ACTION_MOVE: |
| 1004 SelectBetweenCoordinates(env, obj, mouse_drag_start_x_, |
| 1005 mouse_drag_start_y_, pos_x_0, pos_y_0); |
| 1006 break; |
| 1007 case ui::MotionEvent::ACTION_UP: |
| 1008 SelectBetweenCoordinates(env, obj, mouse_drag_start_x_, |
| 1009 mouse_drag_start_y_, pos_x_0, pos_y_0); |
| 1010 break; |
| 1011 case ui::MotionEvent::ACTION_CANCEL: |
| 1012 web_contents_->Unselect(); |
| 1013 break; |
| 1014 default: |
| 1015 break; |
| 1016 } |
| 1017 } |
| 1018 return result; |
| 975 } | 1019 } |
| 976 | 1020 |
| 977 float ContentViewCoreImpl::GetDpiScale() const { | 1021 float ContentViewCoreImpl::GetDpiScale() const { |
| 978 return dpi_scale_; | 1022 return dpi_scale_; |
| 979 } | 1023 } |
| 980 | 1024 |
| 981 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, | 1025 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, |
| 982 jobject obj, | 1026 jobject obj, |
| 983 jlong time_ms, | 1027 jlong time_ms, |
| 984 jfloat x, | 1028 jfloat x, |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1604 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1648 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1605 retained_objects_set); | 1649 retained_objects_set); |
| 1606 return reinterpret_cast<intptr_t>(view); | 1650 return reinterpret_cast<intptr_t>(view); |
| 1607 } | 1651 } |
| 1608 | 1652 |
| 1609 bool RegisterContentViewCore(JNIEnv* env) { | 1653 bool RegisterContentViewCore(JNIEnv* env) { |
| 1610 return RegisterNativesImpl(env); | 1654 return RegisterNativesImpl(env); |
| 1611 } | 1655 } |
| 1612 | 1656 |
| 1613 } // namespace content | 1657 } // namespace content |
| OLD | NEW |