| 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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "cc/layers/layer.h" | 17 #include "cc/layers/layer.h" |
| 18 #include "cc/output/begin_frame_args.h" | 18 #include "cc/output/begin_frame_args.h" |
| 19 #include "content/browser/android/gesture_event_type.h" | 19 #include "content/browser/android/gesture_event_type.h" |
| 20 #include "content/browser/android/interstitial_page_delegate_android.h" | 20 #include "content/browser/android/interstitial_page_delegate_android.h" |
| 21 #include "content/browser/android/load_url_params.h" | 21 #include "content/browser/android/load_url_params.h" |
| 22 #include "content/browser/frame_host/interstitial_page_impl.h" | 22 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 23 #include "content/browser/frame_host/navigation_controller_impl.h" | 23 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 24 #include "content/browser/frame_host/navigation_entry_impl.h" | 24 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 25 #include "content/browser/media/android/browser_media_player_manager.h" | 25 #include "content/browser/media/android/browser_media_player_manager.h" |
| 26 #include "content/browser/renderer_host/compositor_impl_android.h" | 26 #include "content/browser/renderer_host/compositor_impl_android.h" |
| 27 #include "content/browser/renderer_host/input/motion_event_android.h" |
| 27 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" | 28 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" |
| 28 #include "content/browser/renderer_host/java/java_bound_object.h" | 29 #include "content/browser/renderer_host/java/java_bound_object.h" |
| 29 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager
.h" | 30 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager
.h" |
| 30 #include "content/browser/renderer_host/render_view_host_impl.h" | 31 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 31 #include "content/browser/renderer_host/render_widget_host_impl.h" | 32 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 32 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 33 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 33 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.
h" | 34 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.
h" |
| 34 #include "content/browser/ssl/ssl_host_state.h" | 35 #include "content/browser/ssl/ssl_host_state.h" |
| 35 #include "content/browser/web_contents/web_contents_view_android.h" | 36 #include "content/browser/web_contents/web_contents_view_android.h" |
| 36 #include "content/common/input/web_input_event_traits.h" | 37 #include "content/common/input/web_input_event_traits.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 JNIEnv* env, | 106 JNIEnv* env, |
| 106 const gfx::Rect& rect) { | 107 const gfx::Rect& rect) { |
| 107 return ScopedJavaLocalRef<jobject>( | 108 return ScopedJavaLocalRef<jobject>( |
| 108 Java_ContentViewCore_createRect(env, | 109 Java_ContentViewCore_createRect(env, |
| 109 static_cast<int>(rect.x()), | 110 static_cast<int>(rect.x()), |
| 110 static_cast<int>(rect.y()), | 111 static_cast<int>(rect.y()), |
| 111 static_cast<int>(rect.right()), | 112 static_cast<int>(rect.right()), |
| 112 static_cast<int>(rect.bottom()))); | 113 static_cast<int>(rect.bottom()))); |
| 113 } | 114 } |
| 114 | 115 |
| 115 bool PossiblyTriggeredByTouchTimeout(const WebGestureEvent& event) { | 116 int ToGestureEventType(WebInputEvent::Type type) { |
| 116 switch (event.type) { | |
| 117 case WebInputEvent::GestureShowPress: | |
| 118 case WebInputEvent::GestureLongPress: | |
| 119 return true; | |
| 120 // On Android, a GestureTap may be sent after a certain timeout window | |
| 121 // if there is no GestureDoubleTap follow-up. | |
| 122 case WebInputEvent::GestureTap: | |
| 123 return true; | |
| 124 // On Android, a GestureTapCancel may be triggered by the loss of window | |
| 125 // focus (e.g., following a GestureLongPress). | |
| 126 case WebInputEvent::GestureTapCancel: | |
| 127 return true; | |
| 128 default: | |
| 129 break; | |
| 130 } | |
| 131 return false; | |
| 132 } | |
| 133 | |
| 134 int ToContentViewGestureHandlerType(WebInputEvent::Type type) { | |
| 135 switch (type) { | 117 switch (type) { |
| 136 case WebInputEvent::GestureScrollBegin: | 118 case WebInputEvent::GestureScrollBegin: |
| 137 return SCROLL_START; | 119 return SCROLL_START; |
| 138 case WebInputEvent::GestureScrollEnd: | 120 case WebInputEvent::GestureScrollEnd: |
| 139 return SCROLL_END; | 121 return SCROLL_END; |
| 140 case WebInputEvent::GestureScrollUpdate: | 122 case WebInputEvent::GestureScrollUpdate: |
| 141 return SCROLL_BY; | 123 return SCROLL_BY; |
| 142 case WebInputEvent::GestureFlingStart: | 124 case WebInputEvent::GestureFlingStart: |
| 143 return FLING_START; | 125 return FLING_START; |
| 144 case WebInputEvent::GestureFlingCancel: | 126 case WebInputEvent::GestureFlingCancel: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 167 return PINCH_BY; | 149 return PINCH_BY; |
| 168 case WebInputEvent::GestureTwoFingerTap: | 150 case WebInputEvent::GestureTwoFingerTap: |
| 169 case WebInputEvent::GestureScrollUpdateWithoutPropagation: | 151 case WebInputEvent::GestureScrollUpdateWithoutPropagation: |
| 170 default: | 152 default: |
| 171 NOTREACHED() << "Invalid source gesture type: " | 153 NOTREACHED() << "Invalid source gesture type: " |
| 172 << WebInputEventTraits::GetName(type); | 154 << WebInputEventTraits::GetName(type); |
| 173 return -1; | 155 return -1; |
| 174 }; | 156 }; |
| 175 } | 157 } |
| 176 | 158 |
| 159 float GetPrimaryDisplayDeviceScaleFactor() { |
| 160 const gfx::Display& display = |
| 161 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 162 return display.device_scale_factor(); |
| 163 } |
| 164 |
| 177 } // namespace | 165 } // namespace |
| 178 | 166 |
| 179 // Enables a callback when the underlying WebContents is destroyed, to enable | 167 // Enables a callback when the underlying WebContents is destroyed, to enable |
| 180 // nulling the back-pointer. | 168 // nulling the back-pointer. |
| 181 class ContentViewCoreImpl::ContentViewUserData | 169 class ContentViewCoreImpl::ContentViewUserData |
| 182 : public base::SupportsUserData::Data { | 170 : public base::SupportsUserData::Data { |
| 183 public: | 171 public: |
| 184 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core) | 172 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core) |
| 185 : content_view_core_(content_view_core) { | 173 : content_view_core_(content_view_core) { |
| 186 } | 174 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 214 |
| 227 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, | 215 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, |
| 228 jobject obj, | 216 jobject obj, |
| 229 WebContents* web_contents, | 217 WebContents* web_contents, |
| 230 ui::ViewAndroid* view_android, | 218 ui::ViewAndroid* view_android, |
| 231 ui::WindowAndroid* window_android) | 219 ui::WindowAndroid* window_android) |
| 232 : WebContentsObserver(web_contents), | 220 : WebContentsObserver(web_contents), |
| 233 java_ref_(env, obj), | 221 java_ref_(env, obj), |
| 234 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 222 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 235 root_layer_(cc::Layer::Create()), | 223 root_layer_(cc::Layer::Create()), |
| 224 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), |
| 236 vsync_interval_(base::TimeDelta::FromMicroseconds( | 225 vsync_interval_(base::TimeDelta::FromMicroseconds( |
| 237 kDefaultVSyncIntervalMicros)), | 226 kDefaultVSyncIntervalMicros)), |
| 238 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( | 227 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( |
| 239 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), | 228 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), |
| 240 view_android_(view_android), | 229 view_android_(view_android), |
| 241 window_android_(window_android), | 230 window_android_(window_android), |
| 231 gesture_provider_(this, 1.f / dpi_scale_), |
| 242 device_orientation_(0), | 232 device_orientation_(0), |
| 243 geolocation_needs_pause_(false), | 233 geolocation_needs_pause_(false) { |
| 244 touch_disposition_gesture_filter_(this), | |
| 245 handling_touch_event_(false) { | |
| 246 CHECK(web_contents) << | 234 CHECK(web_contents) << |
| 247 "A ContentViewCoreImpl should be created with a valid WebContents."; | 235 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 248 | 236 |
| 249 const gfx::Display& display = | |
| 250 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | |
| 251 dpi_scale_ = display.device_scale_factor(); | |
| 252 | |
| 253 // Currently, the only use case we have for overriding a user agent involves | 237 // Currently, the only use case we have for overriding a user agent involves |
| 254 // spoofing a desktop Linux user agent for "Request desktop site". | 238 // spoofing a desktop Linux user agent for "Request desktop site". |
| 255 // Automatically set it for all WebContents so that it is available when a | 239 // Automatically set it for all WebContents so that it is available when a |
| 256 // NavigationEntry requires the user agent to be overridden. | 240 // NavigationEntry requires the user agent to be overridden. |
| 257 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 241 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
| 258 std::string product = content::GetContentClient()->GetProduct(); | 242 std::string product = content::GetContentClient()->GetProduct(); |
| 259 std::string spoofed_ua = | 243 std::string spoofed_ua = |
| 260 webkit_glue::BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 244 webkit_glue::BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
| 261 web_contents->SetUserAgentOverride(spoofed_ua); | 245 web_contents->SetUserAgentOverride(spoofed_ua); |
| 262 | 246 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 break; | 351 break; |
| 368 } | 352 } |
| 369 } | 353 } |
| 370 } | 354 } |
| 371 | 355 |
| 372 void ContentViewCoreImpl::RenderViewReady() { | 356 void ContentViewCoreImpl::RenderViewReady() { |
| 373 if (device_orientation_ != 0) | 357 if (device_orientation_ != 0) |
| 374 SendOrientationChangeEventInternal(); | 358 SendOrientationChangeEventInternal(); |
| 375 } | 359 } |
| 376 | 360 |
| 377 void ContentViewCoreImpl::ForwardGestureEvent( | 361 void ContentViewCoreImpl::OnGestureEvent(const blink::WebGestureEvent& event) { |
| 378 const blink::WebGestureEvent& event) { | 362 SendGestureEvent(event); |
| 379 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | |
| 380 if (rwhv) | |
| 381 rwhv->SendGestureEvent(event); | |
| 382 } | 363 } |
| 383 | 364 |
| 384 RenderWidgetHostViewAndroid* | 365 RenderWidgetHostViewAndroid* |
| 385 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { | 366 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { |
| 386 RenderWidgetHostView* rwhv = NULL; | 367 RenderWidgetHostView* rwhv = NULL; |
| 387 if (web_contents_) { | 368 if (web_contents_) { |
| 388 rwhv = web_contents_->GetRenderWidgetHostView(); | 369 rwhv = web_contents_->GetRenderWidgetHostView(); |
| 389 if (web_contents_->ShowingInterstitialPage()) { | 370 if (web_contents_->ShowingInterstitialPage()) { |
| 390 rwhv = static_cast<InterstitialPageImpl*>( | 371 rwhv = static_cast<InterstitialPageImpl*>( |
| 391 web_contents_->GetInterstitialPage())-> | 372 web_contents_->GetInterstitialPage())-> |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 546 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
| 566 } | 547 } |
| 567 ScopedJavaLocalRef<jobjectArray> items_array( | 548 ScopedJavaLocalRef<jobjectArray> items_array( |
| 568 base::android::ToJavaArrayOfStrings(env, labels)); | 549 base::android::ToJavaArrayOfStrings(env, labels)); |
| 569 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), | 550 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), |
| 570 items_array.obj(), enabled_array.obj(), | 551 items_array.obj(), enabled_array.obj(), |
| 571 multiple, selected_array.obj()); | 552 multiple, selected_array.obj()); |
| 572 } | 553 } |
| 573 | 554 |
| 574 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { | 555 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { |
| 575 touch_disposition_gesture_filter_.OnTouchEventAck(ack_result); | 556 gesture_provider_.OnTouchEventAck(ack_result); |
| 576 } | 557 } |
| 577 | 558 |
| 578 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, | 559 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, |
| 579 InputEventAckState ack_result) { | 560 InputEventAckState ack_result) { |
| 580 JNIEnv* env = AttachCurrentThread(); | 561 JNIEnv* env = AttachCurrentThread(); |
| 581 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 562 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 582 if (j_obj.is_null()) | 563 if (j_obj.is_null()) |
| 583 return; | 564 return; |
| 584 | 565 |
| 585 switch (event.type) { | 566 switch (event.type) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 event.type != WebInputEvent::GestureLongPress) | 618 event.type != WebInputEvent::GestureLongPress) |
| 638 return false; | 619 return false; |
| 639 | 620 |
| 640 JNIEnv* env = AttachCurrentThread(); | 621 JNIEnv* env = AttachCurrentThread(); |
| 641 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 622 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 642 if (j_obj.is_null()) | 623 if (j_obj.is_null()) |
| 643 return false; | 624 return false; |
| 644 | 625 |
| 645 const blink::WebGestureEvent& gesture = | 626 const blink::WebGestureEvent& gesture = |
| 646 static_cast<const blink::WebGestureEvent&>(event); | 627 static_cast<const blink::WebGestureEvent&>(event); |
| 647 int gesture_type = ToContentViewGestureHandlerType(event.type); | 628 int gesture_type = ToGestureEventType(event.type); |
| 648 return Java_ContentViewCore_filterTapOrPressEvent(env, | 629 return Java_ContentViewCore_filterTapOrPressEvent(env, |
| 649 j_obj.obj(), | 630 j_obj.obj(), |
| 650 gesture_type, | 631 gesture_type, |
| 651 gesture.x * GetDpiScale(), | 632 gesture.x * GetDpiScale(), |
| 652 gesture.y * GetDpiScale()); | 633 gesture.y * GetDpiScale()); |
| 634 |
| 635 // TODO(jdduke): Also report double-tap UMA, crbug/347568. |
| 653 } | 636 } |
| 654 | 637 |
| 655 bool ContentViewCoreImpl::HasFocus() { | 638 bool ContentViewCoreImpl::HasFocus() { |
| 656 JNIEnv* env = AttachCurrentThread(); | 639 JNIEnv* env = AttachCurrentThread(); |
| 657 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 640 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 658 if (obj.is_null()) | 641 if (obj.is_null()) |
| 659 return false; | 642 return false; |
| 660 return Java_ContentViewCore_hasFocus(env, obj.obj()); | 643 return Java_ContentViewCore_hasFocus(env, obj.obj()); |
| 661 } | 644 } |
| 662 | 645 |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 | 987 |
| 1005 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, | 988 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, |
| 1006 jobject obj, | 989 jobject obj, |
| 1007 jint orientation) { | 990 jint orientation) { |
| 1008 if (device_orientation_ != orientation) { | 991 if (device_orientation_ != orientation) { |
| 1009 device_orientation_ = orientation; | 992 device_orientation_ = orientation; |
| 1010 SendOrientationChangeEventInternal(); | 993 SendOrientationChangeEventInternal(); |
| 1011 } | 994 } |
| 1012 } | 995 } |
| 1013 | 996 |
| 1014 void ContentViewCoreImpl::OnTouchEventHandlingBegin(JNIEnv* env, | 997 jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env, |
| 1015 jobject obj, | 998 jobject obj, |
| 1016 jobject motion_event) { | 999 jobject motion_event) { |
| 1017 DCHECK(!handling_touch_event_); | |
| 1018 handling_touch_event_ = true; | |
| 1019 | |
| 1020 pending_touch_event_ = | |
| 1021 WebTouchEventBuilder::Build(motion_event, GetDpiScale()); | |
| 1022 | |
| 1023 pending_gesture_packet_ = | |
| 1024 GestureEventPacket::FromTouch(pending_touch_event_); | |
| 1025 } | |
| 1026 | |
| 1027 void ContentViewCoreImpl::OnTouchEventHandlingEnd(JNIEnv* env, jobject obj) { | |
| 1028 if (!handling_touch_event_) | |
| 1029 return; | |
| 1030 | |
| 1031 GestureEventPacket gesture_packet; | |
| 1032 std::swap(gesture_packet, pending_gesture_packet_); | |
| 1033 | |
| 1034 handling_touch_event_ = false; | |
| 1035 | |
| 1036 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1000 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 1037 if (!rwhv) | 1001 if (!rwhv) |
| 1038 return; | 1002 return false; |
| 1039 | 1003 |
| 1040 // Note: Order is important here, as the touch may be ack'ed synchronously | 1004 MotionEventAndroid event(env, motion_event, false); |
| 1041 TouchDispositionGestureFilter::PacketResult result = | |
| 1042 touch_disposition_gesture_filter_.OnGestureEventPacket(gesture_packet); | |
| 1043 if (result != TouchDispositionGestureFilter::SUCCESS) { | |
| 1044 NOTREACHED() << "Invalid touch gesture sequence detected."; | |
| 1045 return; | |
| 1046 } | |
| 1047 rwhv->SendTouchEvent(pending_touch_event_); | |
| 1048 } | |
| 1049 | 1005 |
| 1050 float ContentViewCoreImpl::GetTouchPaddingDip() { | 1006 if (!gesture_provider_.OnTouchEvent(event)) |
| 1051 return 48.0f / GetDpiScale(); | 1007 return false; |
| 1008 |
| 1009 rwhv->SendTouchEvent(WebTouchEventBuilder::Build(event, GetDpiScale())); |
| 1010 return true; |
| 1052 } | 1011 } |
| 1053 | 1012 |
| 1054 float ContentViewCoreImpl::GetDpiScale() const { | 1013 float ContentViewCoreImpl::GetDpiScale() const { |
| 1055 return dpi_scale_; | 1014 return dpi_scale_; |
| 1056 } | 1015 } |
| 1057 | 1016 |
| 1058 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, | 1017 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, |
| 1059 jobject obj, | 1018 jobject obj, |
| 1060 jlong time_ms, | 1019 jlong time_ms, |
| 1061 jfloat x, | 1020 jfloat x, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 } | 1058 } |
| 1100 | 1059 |
| 1101 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( | 1060 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( |
| 1102 WebInputEvent::Type type, int64 time_ms, float x, float y) const { | 1061 WebInputEvent::Type type, int64 time_ms, float x, float y) const { |
| 1103 return WebGestureEventBuilder::Build( | 1062 return WebGestureEventBuilder::Build( |
| 1104 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); | 1063 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); |
| 1105 } | 1064 } |
| 1106 | 1065 |
| 1107 void ContentViewCoreImpl::SendGestureEvent( | 1066 void ContentViewCoreImpl::SendGestureEvent( |
| 1108 const blink::WebGestureEvent& event) { | 1067 const blink::WebGestureEvent& event) { |
| 1109 // Gestures received while |handling_touch_event_| will accumulate until | 1068 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 1110 // touch handling finishes, at which point the gestures will be pushed to the | 1069 if (rwhv) |
| 1111 // |touch_disposition_gesture_filter_|. | 1070 rwhv->SendGestureEvent(event); |
| 1112 if (handling_touch_event_) { | |
| 1113 pending_gesture_packet_.Push(event); | |
| 1114 return; | |
| 1115 } | |
| 1116 | |
| 1117 // TODO(jdduke): In general, timeout-based gestures *should* have the same | |
| 1118 // timestamp as the initial TouchStart of the current sequence. We should | |
| 1119 // verify that this is true, and use that as another timeout check. | |
| 1120 if (PossiblyTriggeredByTouchTimeout(event)) { | |
| 1121 TouchDispositionGestureFilter::PacketResult result = | |
| 1122 touch_disposition_gesture_filter_.OnGestureEventPacket( | |
| 1123 GestureEventPacket::FromTouchTimeout(event)); | |
| 1124 DCHECK_EQ(TouchDispositionGestureFilter::SUCCESS, result); | |
| 1125 return; | |
| 1126 } | |
| 1127 | |
| 1128 // If |event| was not (directly or indirectly) touch-derived, treat it as | |
| 1129 // a synthetic gesture event. | |
| 1130 SendSyntheticGestureEvent(event); | |
| 1131 } | |
| 1132 | |
| 1133 void ContentViewCoreImpl::SendSyntheticGestureEvent( | |
| 1134 const blink::WebGestureEvent& event) { | |
| 1135 // Synthetic gestures (e.g., those not generated directly by touches | |
| 1136 // for which we expect an ack), should be forwarded directly. | |
| 1137 ForwardGestureEvent(event); | |
| 1138 } | 1071 } |
| 1139 | 1072 |
| 1140 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, | 1073 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, |
| 1141 jobject obj, | 1074 jobject obj, |
| 1142 jlong time_ms, | 1075 jlong time_ms, |
| 1143 jfloat x, | 1076 jfloat x, |
| 1144 jfloat y, | 1077 jfloat y, |
| 1145 jfloat hintx, | 1078 jfloat hintx, |
| 1146 jfloat hinty) { | 1079 jfloat hinty) { |
| 1147 WebGestureEvent event = MakeGestureEvent( | 1080 WebGestureEvent event = MakeGestureEvent( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1165 event.data.scrollUpdate.deltaX = -dx / GetDpiScale(); | 1098 event.data.scrollUpdate.deltaX = -dx / GetDpiScale(); |
| 1166 event.data.scrollUpdate.deltaY = -dy / GetDpiScale(); | 1099 event.data.scrollUpdate.deltaY = -dy / GetDpiScale(); |
| 1167 | 1100 |
| 1168 SendGestureEvent(event); | 1101 SendGestureEvent(event); |
| 1169 } | 1102 } |
| 1170 | 1103 |
| 1171 void ContentViewCoreImpl::FlingStart(JNIEnv* env, jobject obj, jlong time_ms, | 1104 void ContentViewCoreImpl::FlingStart(JNIEnv* env, jobject obj, jlong time_ms, |
| 1172 jfloat x, jfloat y, jfloat vx, jfloat vy) { | 1105 jfloat x, jfloat y, jfloat vx, jfloat vy) { |
| 1173 WebGestureEvent event = MakeGestureEvent( | 1106 WebGestureEvent event = MakeGestureEvent( |
| 1174 WebInputEvent::GestureFlingStart, time_ms, x, y); | 1107 WebInputEvent::GestureFlingStart, time_ms, x, y); |
| 1175 | |
| 1176 event.data.flingStart.velocityX = vx / GetDpiScale(); | 1108 event.data.flingStart.velocityX = vx / GetDpiScale(); |
| 1177 event.data.flingStart.velocityY = vy / GetDpiScale(); | 1109 event.data.flingStart.velocityY = vy / GetDpiScale(); |
| 1178 | 1110 |
| 1179 SendGestureEvent(event); | 1111 SendGestureEvent(event); |
| 1180 } | 1112 } |
| 1181 | 1113 |
| 1182 void ContentViewCoreImpl::FlingCancel(JNIEnv* env, jobject obj, jlong time_ms) { | 1114 void ContentViewCoreImpl::FlingCancel(JNIEnv* env, jobject obj, jlong time_ms) { |
| 1183 WebGestureEvent event = MakeGestureEvent( | 1115 WebGestureEvent event = MakeGestureEvent( |
| 1184 WebInputEvent::GestureFlingCancel, time_ms, 0, 0); | 1116 WebInputEvent::GestureFlingCancel, time_ms, 0, 0); |
| 1185 SendGestureEvent(event); | 1117 SendGestureEvent(event); |
| 1186 } | 1118 } |
| 1187 | 1119 |
| 1188 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, | 1120 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, |
| 1189 jfloat x, jfloat y, | 1121 jfloat x, jfloat y) { |
| 1190 jboolean disambiguation_popup_tap) { | |
| 1191 WebGestureEvent event = MakeGestureEvent( | 1122 WebGestureEvent event = MakeGestureEvent( |
| 1192 WebInputEvent::GestureTap, time_ms, x, y); | 1123 WebInputEvent::GestureTap, time_ms, x, y); |
| 1193 | |
| 1194 event.data.tap.tapCount = 1; | 1124 event.data.tap.tapCount = 1; |
| 1195 | 1125 |
| 1196 // Disambiguation popup gestures are treated as synthetic because their | |
| 1197 // generating touches were never forwarded to the renderer. | |
| 1198 if (disambiguation_popup_tap) { | |
| 1199 SendSyntheticGestureEvent(event); | |
| 1200 return; | |
| 1201 } | |
| 1202 | |
| 1203 const float touch_padding_dip = GetTouchPaddingDip(); | |
| 1204 event.data.tap.width = touch_padding_dip; | |
| 1205 event.data.tap.height = touch_padding_dip; | |
| 1206 SendGestureEvent(event); | |
| 1207 } | |
| 1208 | |
| 1209 void ContentViewCoreImpl::SingleTapUnconfirmed(JNIEnv* env, jobject obj, | |
| 1210 jlong time_ms, | |
| 1211 jfloat x, jfloat y) { | |
| 1212 WebGestureEvent event = MakeGestureEvent( | |
| 1213 WebInputEvent::GestureTapUnconfirmed, time_ms, x, y); | |
| 1214 | |
| 1215 event.data.tap.tapCount = 1; | |
| 1216 | |
| 1217 const float touch_padding_dip = GetTouchPaddingDip(); | |
| 1218 event.data.tap.width = touch_padding_dip; | |
| 1219 event.data.tap.height = touch_padding_dip; | |
| 1220 | |
| 1221 SendGestureEvent(event); | 1126 SendGestureEvent(event); |
| 1222 } | 1127 } |
| 1223 | 1128 |
| 1224 void ContentViewCoreImpl::ShowPress(JNIEnv* env, jobject obj, | |
| 1225 jlong time_ms, | |
| 1226 jfloat x, jfloat y) { | |
| 1227 WebGestureEvent event = MakeGestureEvent( | |
| 1228 WebInputEvent::GestureShowPress, time_ms, x, y); | |
| 1229 SendGestureEvent(event); | |
| 1230 } | |
| 1231 | |
| 1232 void ContentViewCoreImpl::TapCancel(JNIEnv* env, | |
| 1233 jobject obj, | |
| 1234 jlong time_ms, | |
| 1235 jfloat x, | |
| 1236 jfloat y) { | |
| 1237 WebGestureEvent event = MakeGestureEvent( | |
| 1238 WebInputEvent::GestureTapCancel, time_ms, x, y); | |
| 1239 SendGestureEvent(event); | |
| 1240 } | |
| 1241 | |
| 1242 void ContentViewCoreImpl::TapDown(JNIEnv* env, jobject obj, | |
| 1243 jlong time_ms, | |
| 1244 jfloat x, jfloat y) { | |
| 1245 WebGestureEvent event = MakeGestureEvent( | |
| 1246 WebInputEvent::GestureTapDown, time_ms, x, y); | |
| 1247 SendGestureEvent(event); | |
| 1248 } | |
| 1249 | |
| 1250 void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, | 1129 void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, |
| 1251 jfloat x, jfloat y) { | 1130 jfloat x, jfloat y) { |
| 1252 WebGestureEvent event = MakeGestureEvent( | 1131 WebGestureEvent event = MakeGestureEvent( |
| 1253 WebInputEvent::GestureDoubleTap, time_ms, x, y); | 1132 WebInputEvent::GestureDoubleTap, time_ms, x, y); |
| 1254 SendGestureEvent(event); | 1133 SendGestureEvent(event); |
| 1255 } | 1134 } |
| 1256 | 1135 |
| 1257 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, | 1136 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, |
| 1258 jfloat x, jfloat y, | 1137 jfloat x, jfloat y) { |
| 1259 jboolean disambiguation_popup_tap) { | |
| 1260 WebGestureEvent event = MakeGestureEvent( | 1138 WebGestureEvent event = MakeGestureEvent( |
| 1261 WebInputEvent::GestureLongPress, time_ms, x, y); | 1139 WebInputEvent::GestureLongPress, time_ms, x, y); |
| 1262 | 1140 |
| 1263 // Disambiguation popup gestures are treated as synthetic because their | |
| 1264 // generating touches were never forwarded to the renderer. | |
| 1265 if (disambiguation_popup_tap) { | |
| 1266 SendSyntheticGestureEvent(event); | |
| 1267 return; | |
| 1268 } | |
| 1269 | |
| 1270 const float touch_padding_dip = GetTouchPaddingDip(); | |
| 1271 event.data.longPress.width = touch_padding_dip; | |
| 1272 event.data.longPress.height = touch_padding_dip; | |
| 1273 SendGestureEvent(event); | 1141 SendGestureEvent(event); |
| 1274 } | 1142 } |
| 1275 | 1143 |
| 1276 void ContentViewCoreImpl::LongTap(JNIEnv* env, jobject obj, jlong time_ms, | |
| 1277 jfloat x, jfloat y, | |
| 1278 jboolean disambiguation_popup_tap) { | |
| 1279 WebGestureEvent event = MakeGestureEvent( | |
| 1280 WebInputEvent::GestureLongTap, time_ms, x, y); | |
| 1281 | |
| 1282 // Disambiguation popup gestures are treated as synthetic because their | |
| 1283 // generating touches were never forwarded to the renderer. | |
| 1284 if (disambiguation_popup_tap) { | |
| 1285 SendSyntheticGestureEvent(event); | |
| 1286 return; | |
| 1287 } | |
| 1288 | |
| 1289 const float touch_padding_dip = GetTouchPaddingDip(); | |
| 1290 event.data.longPress.width = touch_padding_dip; | |
| 1291 event.data.longPress.height = touch_padding_dip; | |
| 1292 SendGestureEvent(event); | |
| 1293 } | |
| 1294 | |
| 1295 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, | 1144 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, |
| 1296 jfloat x, jfloat y) { | 1145 jfloat x, jfloat y) { |
| 1297 WebGestureEvent event = MakeGestureEvent( | 1146 WebGestureEvent event = MakeGestureEvent( |
| 1298 WebInputEvent::GesturePinchBegin, time_ms, x, y); | 1147 WebInputEvent::GesturePinchBegin, time_ms, x, y); |
| 1299 SendGestureEvent(event); | 1148 SendGestureEvent(event); |
| 1300 } | 1149 } |
| 1301 | 1150 |
| 1302 void ContentViewCoreImpl::PinchEnd(JNIEnv* env, jobject obj, jlong time_ms) { | 1151 void ContentViewCoreImpl::PinchEnd(JNIEnv* env, jobject obj, jlong time_ms) { |
| 1303 WebGestureEvent event = MakeGestureEvent( | 1152 WebGestureEvent event = MakeGestureEvent( |
| 1304 WebInputEvent::GesturePinchEnd, time_ms, 0, 0); | 1153 WebInputEvent::GesturePinchEnd, time_ms, 0, 0); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1326 } | 1175 } |
| 1327 | 1176 |
| 1328 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, | 1177 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, |
| 1329 jfloat x, jfloat y) { | 1178 jfloat x, jfloat y) { |
| 1330 if (GetRenderWidgetHostViewAndroid()) { | 1179 if (GetRenderWidgetHostViewAndroid()) { |
| 1331 GetRenderWidgetHostViewAndroid()->MoveCaret( | 1180 GetRenderWidgetHostViewAndroid()->MoveCaret( |
| 1332 gfx::Point(x / GetDpiScale(), y / GetDpiScale())); | 1181 gfx::Point(x / GetDpiScale(), y / GetDpiScale())); |
| 1333 } | 1182 } |
| 1334 } | 1183 } |
| 1335 | 1184 |
| 1185 void ContentViewCoreImpl::ResetGestureDetectors(JNIEnv* env, jobject obj) { |
| 1186 gesture_provider_.ResetGestureDetectors(); |
| 1187 } |
| 1188 |
| 1189 void ContentViewCoreImpl::IgnoreRemainingTouchEvents(JNIEnv* env, jobject obj) { |
| 1190 gesture_provider_.CancelActiveTouchSequence(); |
| 1191 } |
| 1192 |
| 1193 void ContentViewCoreImpl::OnWindowFocusLost(JNIEnv* env, jobject obj) { |
| 1194 gesture_provider_.CancelActiveTouchSequence(); |
| 1195 } |
| 1196 |
| 1197 void ContentViewCoreImpl::SetDoubleTapSupportForPageEnabled(JNIEnv* env, |
| 1198 jobject obj, |
| 1199 jboolean enabled) { |
| 1200 gesture_provider_.SetDoubleTapSupportForPageEnabled(enabled); |
| 1201 } |
| 1202 |
| 1203 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env, |
| 1204 jobject obj, |
| 1205 jboolean enabled) { |
| 1206 gesture_provider_.SetDoubleTapSupportForPlatformEnabled(enabled); |
| 1207 } |
| 1208 |
| 1209 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled(JNIEnv* env, |
| 1210 jobject obj, |
| 1211 jboolean enabled) { |
| 1212 gesture_provider_.SetMultiTouchSupportEnabled(enabled); |
| 1213 } |
| 1214 |
| 1336 void ContentViewCoreImpl::LoadIfNecessary(JNIEnv* env, jobject obj) { | 1215 void ContentViewCoreImpl::LoadIfNecessary(JNIEnv* env, jobject obj) { |
| 1337 web_contents_->GetController().LoadIfNecessary(); | 1216 web_contents_->GetController().LoadIfNecessary(); |
| 1338 } | 1217 } |
| 1339 | 1218 |
| 1340 void ContentViewCoreImpl::RequestRestoreLoad(JNIEnv* env, jobject obj) { | 1219 void ContentViewCoreImpl::RequestRestoreLoad(JNIEnv* env, jobject obj) { |
| 1341 web_contents_->GetController().SetNeedsReload(); | 1220 web_contents_->GetController().SetNeedsReload(); |
| 1342 } | 1221 } |
| 1343 | 1222 |
| 1344 void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) { | 1223 void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) { |
| 1345 web_contents_->Stop(); | 1224 web_contents_->Stop(); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 // If it was actually enabled globally, enable it for this RenderWidget now. | 1616 // If it was actually enabled globally, enable it for this RenderWidget now. |
| 1738 if (accessibility_state->IsAccessibleBrowser() && host_impl) | 1617 if (accessibility_state->IsAccessibleBrowser() && host_impl) |
| 1739 host_impl->AddAccessibilityMode(AccessibilityModeComplete); | 1618 host_impl->AddAccessibilityMode(AccessibilityModeComplete); |
| 1740 } else { | 1619 } else { |
| 1741 accessibility_state->ResetAccessibilityMode(); | 1620 accessibility_state->ResetAccessibilityMode(); |
| 1742 if (host_impl) | 1621 if (host_impl) |
| 1743 host_impl->ResetAccessibilityMode(); | 1622 host_impl->ResetAccessibilityMode(); |
| 1744 } | 1623 } |
| 1745 } | 1624 } |
| 1746 | 1625 |
| 1747 void ContentViewCoreImpl::SendSingleTapUma(JNIEnv* env, | |
| 1748 jobject obj, | |
| 1749 jint type, | |
| 1750 jint count) { | |
| 1751 UMA_HISTOGRAM_ENUMERATION("Event.SingleTapType", type, count); | |
| 1752 } | |
| 1753 | |
| 1754 void ContentViewCoreImpl::SendActionAfterDoubleTapUma(JNIEnv* env, | |
| 1755 jobject obj, | |
| 1756 jint type, | |
| 1757 jboolean has_delay, | |
| 1758 jint count) { | |
| 1759 // This UMA stat tracks a user's action after a double tap within | |
| 1760 // k seconds (where k == 5 currently). This UMA will tell us if | |
| 1761 // removing the tap gesture delay will lead to significantly more | |
| 1762 // accidental navigations after a double tap. | |
| 1763 if (has_delay) { | |
| 1764 UMA_HISTOGRAM_ENUMERATION("Event.ActionAfterDoubleTapWithDelay", type, | |
| 1765 count); | |
| 1766 } else { | |
| 1767 UMA_HISTOGRAM_ENUMERATION("Event.ActionAfterDoubleTapNoDelay", type, | |
| 1768 count); | |
| 1769 } | |
| 1770 } | |
| 1771 | |
| 1772 void ContentViewCoreImpl::SendOrientationChangeEventInternal() { | 1626 void ContentViewCoreImpl::SendOrientationChangeEventInternal() { |
| 1773 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1627 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 1774 if (rwhv) | 1628 if (rwhv) |
| 1775 rwhv->UpdateScreenInfo(rwhv->GetNativeView()); | 1629 rwhv->UpdateScreenInfo(rwhv->GetNativeView()); |
| 1776 | 1630 |
| 1777 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( | 1631 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( |
| 1778 web_contents_->GetRenderViewHost()); | 1632 web_contents_->GetRenderViewHost()); |
| 1779 rvhi->SendOrientationChangeEvent(device_orientation_); | 1633 rvhi->SendOrientationChangeEvent(device_orientation_); |
| 1780 | 1634 |
| 1781 // TODO(mlamouri): temporary plumbing for Screen Orientation, this will change | 1635 // TODO(mlamouri): temporary plumbing for Screen Orientation, this will change |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1712 reinterpret_cast<ui::ViewAndroid*>(view_android), |
| 1859 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1713 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
| 1860 return reinterpret_cast<intptr_t>(view); | 1714 return reinterpret_cast<intptr_t>(view); |
| 1861 } | 1715 } |
| 1862 | 1716 |
| 1863 bool RegisterContentViewCore(JNIEnv* env) { | 1717 bool RegisterContentViewCore(JNIEnv* env) { |
| 1864 return RegisterNativesImpl(env); | 1718 return RegisterNativesImpl(env); |
| 1865 } | 1719 } |
| 1866 | 1720 |
| 1867 } // namespace content | 1721 } // namespace content |
| OLD | NEW |