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