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 15 matching lines...) Expand all Loading... |
26 #include "content/browser/media/android/browser_media_player_manager.h" | 26 #include "content/browser/media/android/browser_media_player_manager.h" |
27 #include "content/browser/renderer_host/compositor_impl_android.h" | 27 #include "content/browser/renderer_host/compositor_impl_android.h" |
28 #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
" |
29 #include "content/browser/renderer_host/java/java_bound_object.h" | 29 #include "content/browser/renderer_host/java/java_bound_object.h" |
30 #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" |
31 #include "content/browser/renderer_host/render_view_host_impl.h" | 31 #include "content/browser/renderer_host/render_view_host_impl.h" |
32 #include "content/browser/renderer_host/render_widget_host_impl.h" | 32 #include "content/browser/renderer_host/render_widget_host_impl.h" |
33 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 33 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
34 #include "content/browser/ssl/ssl_host_state.h" | 34 #include "content/browser/ssl/ssl_host_state.h" |
35 #include "content/browser/web_contents/web_contents_view_android.h" | 35 #include "content/browser/web_contents/web_contents_view_android.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" |
37 #include "content/common/view_messages.h" | 38 #include "content/common/view_messages.h" |
38 #include "content/public/browser/browser_accessibility_state.h" | 39 #include "content/public/browser/browser_accessibility_state.h" |
39 #include "content/public/browser/browser_context.h" | 40 #include "content/public/browser/browser_context.h" |
40 #include "content/public/browser/favicon_status.h" | 41 #include "content/public/browser/favicon_status.h" |
41 #include "content/public/browser/notification_details.h" | 42 #include "content/public/browser/notification_details.h" |
42 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
43 #include "content/public/browser/notification_source.h" | 44 #include "content/public/browser/notification_source.h" |
44 #include "content/public/browser/notification_types.h" | 45 #include "content/public/browser/notification_types.h" |
45 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 JNIEnv* env, | 104 JNIEnv* env, |
104 const gfx::Rect& rect) { | 105 const gfx::Rect& rect) { |
105 return ScopedJavaLocalRef<jobject>( | 106 return ScopedJavaLocalRef<jobject>( |
106 Java_ContentViewCore_createRect(env, | 107 Java_ContentViewCore_createRect(env, |
107 static_cast<int>(rect.x()), | 108 static_cast<int>(rect.x()), |
108 static_cast<int>(rect.y()), | 109 static_cast<int>(rect.y()), |
109 static_cast<int>(rect.right()), | 110 static_cast<int>(rect.right()), |
110 static_cast<int>(rect.bottom()))); | 111 static_cast<int>(rect.bottom()))); |
111 } | 112 } |
112 | 113 |
| 114 bool PossiblyTriggeredByTouchTimeout(const WebGestureEvent& event) { |
| 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 // These values should match exactly those in ContentViewGestureHandler. |
| 135 enum ContentViewGestureHandlerType { |
| 136 GESTURE_SHOW_PRESS = 0, |
| 137 GESTURE_DOUBLE_TAP = 1, |
| 138 GESTURE_SINGLE_TAP_UP = 2, |
| 139 GESTURE_SINGLE_TAP_CONFIRMED = 3, |
| 140 GESTURE_SINGLE_TAP_UNCONFIRMED = 4, |
| 141 GESTURE_LONG_PRESS = 5, |
| 142 GESTURE_SCROLL_START = 6, |
| 143 GESTURE_SCROLL_BY = 7, |
| 144 GESTURE_SCROLL_END = 8, |
| 145 GESTURE_FLING_START = 9, |
| 146 GESTURE_FLING_CANCEL = 10, |
| 147 GESTURE_PINCH_BEGIN = 11, |
| 148 GESTURE_PINCH_BY = 12, |
| 149 GESTURE_PINCH_END = 13, |
| 150 GESTURE_TAP_CANCEL = 14, |
| 151 GESTURE_LONG_TAP = 15, |
| 152 GESTURE_TAP_DOWN = 16 |
| 153 }; |
| 154 switch (type) { |
| 155 case WebInputEvent::GestureScrollBegin: |
| 156 return GESTURE_SCROLL_START; |
| 157 case WebInputEvent::GestureScrollEnd: |
| 158 return GESTURE_SCROLL_END; |
| 159 case WebInputEvent::GestureScrollUpdate: |
| 160 return GESTURE_SCROLL_BY; |
| 161 case WebInputEvent::GestureFlingStart: |
| 162 return GESTURE_FLING_START; |
| 163 case WebInputEvent::GestureFlingCancel: |
| 164 return GESTURE_FLING_CANCEL; |
| 165 case WebInputEvent::GestureShowPress: |
| 166 return GESTURE_SHOW_PRESS; |
| 167 case WebInputEvent::GestureTap: |
| 168 return GESTURE_SINGLE_TAP_CONFIRMED; |
| 169 case WebInputEvent::GestureTapUnconfirmed: |
| 170 return GESTURE_SINGLE_TAP_UNCONFIRMED; |
| 171 case WebInputEvent::GestureTapDown: |
| 172 return GESTURE_TAP_DOWN; |
| 173 case WebInputEvent::GestureTapCancel: |
| 174 return GESTURE_TAP_CANCEL; |
| 175 case WebInputEvent::GestureDoubleTap: |
| 176 return GESTURE_DOUBLE_TAP; |
| 177 case WebInputEvent::GestureLongPress: |
| 178 return GESTURE_LONG_PRESS; |
| 179 case WebInputEvent::GestureLongTap: |
| 180 return GESTURE_LONG_TAP; |
| 181 case WebInputEvent::GesturePinchBegin: |
| 182 return GESTURE_PINCH_BEGIN; |
| 183 case WebInputEvent::GesturePinchEnd: |
| 184 return GESTURE_PINCH_END; |
| 185 case WebInputEvent::GesturePinchUpdate: |
| 186 return GESTURE_PINCH_BY; |
| 187 case WebInputEvent::GestureTwoFingerTap: |
| 188 case WebInputEvent::GestureScrollUpdateWithoutPropagation: |
| 189 default: |
| 190 NOTREACHED() << "Invalid source gesture type: " |
| 191 << WebInputEventTraits::GetName(type); |
| 192 return -1; |
| 193 }; |
| 194 } |
| 195 |
113 } // namespace | 196 } // namespace |
114 | 197 |
115 // Enables a callback when the underlying WebContents is destroyed, to enable | 198 // Enables a callback when the underlying WebContents is destroyed, to enable |
116 // nulling the back-pointer. | 199 // nulling the back-pointer. |
117 class ContentViewCoreImpl::ContentViewUserData | 200 class ContentViewCoreImpl::ContentViewUserData |
118 : public base::SupportsUserData::Data { | 201 : public base::SupportsUserData::Data { |
119 public: | 202 public: |
120 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core) | 203 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core) |
121 : content_view_core_(content_view_core) { | 204 : content_view_core_(content_view_core) { |
122 } | 205 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 java_ref_(env, obj), | 252 java_ref_(env, obj), |
170 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 253 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
171 root_layer_(cc::Layer::Create()), | 254 root_layer_(cc::Layer::Create()), |
172 vsync_interval_(base::TimeDelta::FromMicroseconds( | 255 vsync_interval_(base::TimeDelta::FromMicroseconds( |
173 kDefaultVSyncIntervalMicros)), | 256 kDefaultVSyncIntervalMicros)), |
174 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( | 257 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( |
175 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), | 258 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), |
176 view_android_(view_android), | 259 view_android_(view_android), |
177 window_android_(window_android), | 260 window_android_(window_android), |
178 device_orientation_(0), | 261 device_orientation_(0), |
179 geolocation_needs_pause_(false) { | 262 geolocation_needs_pause_(false), |
| 263 gesture_event_queue_(this), |
| 264 handling_touch_event_(false) { |
180 CHECK(web_contents) << | 265 CHECK(web_contents) << |
181 "A ContentViewCoreImpl should be created with a valid WebContents."; | 266 "A ContentViewCoreImpl should be created with a valid WebContents."; |
182 | 267 |
183 const gfx::Display& display = | 268 const gfx::Display& display = |
184 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 269 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
185 dpi_scale_ = display.device_scale_factor(); | 270 dpi_scale_ = display.device_scale_factor(); |
186 | 271 |
187 // Currently, the only use case we have for overriding a user agent involves | 272 // Currently, the only use case we have for overriding a user agent involves |
188 // spoofing a desktop Linux user agent for "Request desktop site". | 273 // spoofing a desktop Linux user agent for "Request desktop site". |
189 // Automatically set it for all WebContents so that it is available when a | 274 // Automatically set it for all WebContents so that it is available when a |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 break; | 380 break; |
296 } | 381 } |
297 } | 382 } |
298 } | 383 } |
299 | 384 |
300 void ContentViewCoreImpl::RenderViewReady() { | 385 void ContentViewCoreImpl::RenderViewReady() { |
301 if (device_orientation_ != 0) | 386 if (device_orientation_ != 0) |
302 SendOrientationChangeEventInternal(); | 387 SendOrientationChangeEventInternal(); |
303 } | 388 } |
304 | 389 |
| 390 void ContentViewCoreImpl::ForwardGestureEvent( |
| 391 const blink::WebGestureEvent& event) { |
| 392 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 393 if (rwhv) |
| 394 rwhv->SendGestureEvent(event); |
| 395 } |
| 396 |
305 RenderWidgetHostViewAndroid* | 397 RenderWidgetHostViewAndroid* |
306 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { | 398 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { |
307 RenderWidgetHostView* rwhv = NULL; | 399 RenderWidgetHostView* rwhv = NULL; |
308 if (web_contents_) { | 400 if (web_contents_) { |
309 rwhv = web_contents_->GetRenderWidgetHostView(); | 401 rwhv = web_contents_->GetRenderWidgetHostView(); |
310 if (web_contents_->ShowingInterstitialPage()) { | 402 if (web_contents_->ShowingInterstitialPage()) { |
311 rwhv = static_cast<InterstitialPageImpl*>( | 403 rwhv = static_cast<InterstitialPageImpl*>( |
312 web_contents_->GetInterstitialPage())-> | 404 web_contents_->GetInterstitialPage())-> |
313 GetRenderViewHost()->GetView(); | 405 GetRenderViewHost()->GetView(); |
314 } | 406 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 580 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
489 } | 581 } |
490 ScopedJavaLocalRef<jobjectArray> items_array( | 582 ScopedJavaLocalRef<jobjectArray> items_array( |
491 base::android::ToJavaArrayOfStrings(env, labels)); | 583 base::android::ToJavaArrayOfStrings(env, labels)); |
492 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), | 584 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), |
493 items_array.obj(), enabled_array.obj(), | 585 items_array.obj(), enabled_array.obj(), |
494 multiple, selected_array.obj()); | 586 multiple, selected_array.obj()); |
495 } | 587 } |
496 | 588 |
497 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { | 589 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { |
| 590 gesture_event_queue_.OnTouchEventAck(ack_result); |
| 591 } |
| 592 |
| 593 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, |
| 594 InputEventAckState ack_result) { |
498 JNIEnv* env = AttachCurrentThread(); | 595 JNIEnv* env = AttachCurrentThread(); |
499 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 596 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
500 if (j_obj.is_null()) | 597 if (j_obj.is_null()) |
501 return; | 598 return; |
502 Java_ContentViewCore_confirmTouchEvent(env, j_obj.obj(), | 599 |
503 static_cast<jint>(ack_result)); | 600 switch (event.type) { |
| 601 case WebInputEvent::GestureFlingStart: |
| 602 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) { |
| 603 Java_ContentViewCore_onFlingStartEventConsumed(env, j_obj.obj(), |
| 604 event.data.flingStart.velocityX, event.data.flingStart.velocityY); |
| 605 } else { |
| 606 // If a scroll ends with a fling, a GESTURE_SCROLL_END is never sent. |
| 607 // However, if that fling went unconsumed, we still need to let the |
| 608 // listeners know that scrolling has ended. |
| 609 Java_ContentViewCore_onScrollEndEventAck(env, j_obj.obj()); |
| 610 } |
| 611 |
| 612 if (ack_result == INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS) { |
| 613 Java_ContentViewCore_onFlingStartEventHadNoConsumer(env, j_obj.obj(), |
| 614 event.data.flingStart.velocityX, event.data.flingStart.velocityY); |
| 615 } |
| 616 break; |
| 617 case WebInputEvent::GestureFlingCancel: |
| 618 Java_ContentViewCore_onFlingCancelEventAck(env, j_obj.obj()); |
| 619 break; |
| 620 case WebInputEvent::GestureScrollBegin: |
| 621 Java_ContentViewCore_onScrollBeginEventAck(env, j_obj.obj()); |
| 622 break; |
| 623 case WebInputEvent::GestureScrollUpdate: |
| 624 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) |
| 625 Java_ContentViewCore_onScrollUpdateGestureConsumed(env, j_obj.obj()); |
| 626 break; |
| 627 case WebInputEvent::GestureScrollEnd: |
| 628 Java_ContentViewCore_onScrollEndEventAck(env, j_obj.obj()); |
| 629 break; |
| 630 case WebInputEvent::GesturePinchBegin: |
| 631 Java_ContentViewCore_onPinchBeginEventAck(env, j_obj.obj()); |
| 632 break; |
| 633 case WebInputEvent::GesturePinchEnd: |
| 634 Java_ContentViewCore_onPinchEndEventAck(env, j_obj.obj()); |
| 635 break; |
| 636 default: |
| 637 break; |
| 638 } |
504 } | 639 } |
505 | 640 |
506 void ContentViewCoreImpl::OnFlingStartEventAck(InputEventAckState ack_result) { | 641 bool ContentViewCoreImpl::FilterInputEvent(const blink::WebInputEvent& event) { |
| 642 if (!WebInputEvent::isGestureEventType(event.type)) |
| 643 return false; |
| 644 |
507 JNIEnv* env = AttachCurrentThread(); | 645 JNIEnv* env = AttachCurrentThread(); |
508 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 646 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
509 if (j_obj.is_null()) | 647 if (j_obj.is_null()) |
510 return; | 648 return false; |
511 Java_ContentViewCore_onFlingStartEventAck(env, j_obj.obj(), | |
512 static_cast<jint>(ack_result)); | |
513 } | |
514 | 649 |
515 void ContentViewCoreImpl::OnScrollBeginEventAck() { | 650 const blink::WebGestureEvent& gesture = |
516 JNIEnv* env = AttachCurrentThread(); | 651 static_cast<const blink::WebGestureEvent&>(event); |
517 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 652 int gesture_type = ToContentViewGestureHandlerType(event.type); |
518 if (j_obj.is_null()) | 653 return Java_ContentViewCore_filterGestureEvent(env, |
519 return; | 654 j_obj.obj(), |
520 Java_ContentViewCore_onScrollBeginEventAck(env, j_obj.obj()); | 655 gesture_type, |
521 } | 656 gesture.x, |
522 | 657 gesture.y); |
523 void ContentViewCoreImpl::OnScrollUpdateGestureConsumed() { | |
524 JNIEnv* env = AttachCurrentThread(); | |
525 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | |
526 if (j_obj.is_null()) | |
527 return; | |
528 Java_ContentViewCore_onScrollUpdateGestureConsumed(env, j_obj.obj()); | |
529 } | |
530 | |
531 void ContentViewCoreImpl::OnScrollEndEventAck() { | |
532 JNIEnv* env = AttachCurrentThread(); | |
533 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | |
534 if (j_obj.is_null()) | |
535 return; | |
536 Java_ContentViewCore_onScrollEndEventAck(env, j_obj.obj()); | |
537 } | |
538 | |
539 void ContentViewCoreImpl::HasTouchEventHandlers(bool need_touch_events) { | |
540 JNIEnv* env = AttachCurrentThread(); | |
541 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | |
542 if (j_obj.is_null()) | |
543 return; | |
544 Java_ContentViewCore_hasTouchEventHandlers(env, | |
545 j_obj.obj(), | |
546 need_touch_events); | |
547 } | 658 } |
548 | 659 |
549 bool ContentViewCoreImpl::HasFocus() { | 660 bool ContentViewCoreImpl::HasFocus() { |
550 JNIEnv* env = AttachCurrentThread(); | 661 JNIEnv* env = AttachCurrentThread(); |
551 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 662 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
552 if (obj.is_null()) | 663 if (obj.is_null()) |
553 return false; | 664 return false; |
554 return Java_ContentViewCore_hasFocus(env, obj.obj()); | 665 return Java_ContentViewCore_hasFocus(env, obj.obj()); |
555 } | 666 } |
556 | 667 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 | 1023 |
913 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, | 1024 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, |
914 jobject obj, | 1025 jobject obj, |
915 jint orientation) { | 1026 jint orientation) { |
916 if (device_orientation_ != orientation) { | 1027 if (device_orientation_ != orientation) { |
917 device_orientation_ = orientation; | 1028 device_orientation_ = orientation; |
918 SendOrientationChangeEventInternal(); | 1029 SendOrientationChangeEventInternal(); |
919 } | 1030 } |
920 } | 1031 } |
921 | 1032 |
922 jboolean ContentViewCoreImpl::SendTouchEvent(JNIEnv* env, | 1033 void ContentViewCoreImpl::OnTouchEventHandlingBegin(JNIEnv* env, |
923 jobject obj, | 1034 jobject obj, |
924 jlong time_ms, | 1035 jlong time_ms, |
925 jint type, | 1036 jint type, |
926 jobjectArray pts) { | 1037 jobjectArray pts) { |
| 1038 DCHECK(!handling_touch_event_); |
| 1039 handling_touch_event_ = true; |
| 1040 |
| 1041 blink::WebTouchEvent event; |
| 1042 TouchPoint::BuildWebTouchEvent(env, type, time_ms, GetDpiScale(), pts, event); |
| 1043 pending_touch_event_ = event; |
| 1044 |
| 1045 pending_gesture_packet_ = GestureEventPacket::FromTouch(event); |
| 1046 } |
| 1047 |
| 1048 void ContentViewCoreImpl::OnTouchEventHandlingEnd(JNIEnv* env, jobject obj) { |
| 1049 DCHECK(handling_touch_event_); |
| 1050 handling_touch_event_ = false; |
| 1051 |
927 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1052 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
928 if (rwhv) { | 1053 if (!rwhv) |
929 using blink::WebTouchEvent; | 1054 return; |
930 blink::WebTouchEvent event; | 1055 |
931 TouchPoint::BuildWebTouchEvent(env, type, time_ms, GetDpiScale(), pts, | 1056 // Note: Order is important here, as the touch may be ack'ed synchronously |
932 event); | 1057 gesture_event_queue_.OnGestureEventPacket(pending_gesture_packet_); |
933 rwhv->SendTouchEvent(event); | 1058 rwhv->SendTouchEvent(pending_touch_event_); |
934 return true; | |
935 } | |
936 return false; | |
937 } | 1059 } |
938 | 1060 |
939 float ContentViewCoreImpl::GetTouchPaddingDip() { | 1061 float ContentViewCoreImpl::GetTouchPaddingDip() { |
940 return 48.0f / GetDpiScale(); | 1062 return 48.0f / GetDpiScale(); |
941 } | 1063 } |
942 | 1064 |
943 float ContentViewCoreImpl::GetDpiScale() const { | 1065 float ContentViewCoreImpl::GetDpiScale() const { |
944 return dpi_scale_; | 1066 return dpi_scale_; |
945 } | 1067 } |
946 | 1068 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 } | 1118 } |
997 | 1119 |
998 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( | 1120 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( |
999 WebInputEvent::Type type, int64 time_ms, float x, float y) const { | 1121 WebInputEvent::Type type, int64 time_ms, float x, float y) const { |
1000 return WebGestureEventBuilder::Build( | 1122 return WebGestureEventBuilder::Build( |
1001 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); | 1123 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); |
1002 } | 1124 } |
1003 | 1125 |
1004 void ContentViewCoreImpl::SendGestureEvent( | 1126 void ContentViewCoreImpl::SendGestureEvent( |
1005 const blink::WebGestureEvent& event) { | 1127 const blink::WebGestureEvent& event) { |
1006 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1128 // Gestures received while |handling_touch_event_| will accumulate until |
1007 if (rwhv) | 1129 // touch handling finishes, at which point the gestures will be pushed to the |
1008 rwhv->SendGestureEvent(event); | 1130 // |gesture_event_queue_|. |
| 1131 if (handling_touch_event_) { |
| 1132 pending_gesture_packet_.Push(event); |
| 1133 return; |
| 1134 } |
| 1135 |
| 1136 // TODO(jdduke): In general, timeout-based gestures *should* have the same |
| 1137 // timestamp as the initial TouchStart of the current sequence. We should |
| 1138 // verify that this is true, and use that as another timeout check. |
| 1139 if (PossiblyTriggeredByTouchTimeout(event)) { |
| 1140 gesture_event_queue_.OnGestureEventPacket( |
| 1141 GestureEventPacket::FromTouchTimeout(event)); |
| 1142 return; |
| 1143 } |
| 1144 |
| 1145 // If |event| was not (directly or indirectly) touch-derived, treat it as |
| 1146 // a synthetic gesture event. |
| 1147 SendSyntheticGestureEvent(event); |
| 1148 } |
| 1149 |
| 1150 void ContentViewCoreImpl::SendSyntheticGestureEvent( |
| 1151 const blink::WebGestureEvent& event) { |
| 1152 // Synthetic gestures (e.g., those not generated directly by touches |
| 1153 // for which we expect an ack), should be forwarded directly. |
| 1154 ForwardGestureEvent(event); |
1009 } | 1155 } |
1010 | 1156 |
1011 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, | 1157 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, |
1012 jobject obj, | 1158 jobject obj, |
1013 jlong time_ms, | 1159 jlong time_ms, |
1014 jfloat x, | 1160 jfloat x, |
1015 jfloat y, | 1161 jfloat y, |
1016 jfloat hintx, | 1162 jfloat hintx, |
1017 jfloat hinty) { | 1163 jfloat hinty) { |
1018 WebGestureEvent event = MakeGestureEvent( | 1164 WebGestureEvent event = MakeGestureEvent( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 SendGestureEvent(event); | 1204 SendGestureEvent(event); |
1059 } | 1205 } |
1060 | 1206 |
1061 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, | 1207 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, |
1062 jfloat x, jfloat y, | 1208 jfloat x, jfloat y, |
1063 jboolean disambiguation_popup_tap) { | 1209 jboolean disambiguation_popup_tap) { |
1064 WebGestureEvent event = MakeGestureEvent( | 1210 WebGestureEvent event = MakeGestureEvent( |
1065 WebInputEvent::GestureTap, time_ms, x, y); | 1211 WebInputEvent::GestureTap, time_ms, x, y); |
1066 | 1212 |
1067 event.data.tap.tapCount = 1; | 1213 event.data.tap.tapCount = 1; |
1068 if (!disambiguation_popup_tap) { | 1214 |
1069 const float touch_padding_dip = GetTouchPaddingDip(); | 1215 // Disambiguation popup gestures are treated as synthetic because their |
1070 event.data.tap.width = touch_padding_dip; | 1216 // generating touches were never forwarded to the renderer. |
1071 event.data.tap.height = touch_padding_dip; | 1217 if (disambiguation_popup_tap) { |
| 1218 SendSyntheticGestureEvent(event); |
| 1219 return; |
1072 } | 1220 } |
1073 | 1221 |
| 1222 const float touch_padding_dip = GetTouchPaddingDip(); |
| 1223 event.data.tap.width = touch_padding_dip; |
| 1224 event.data.tap.height = touch_padding_dip; |
1074 SendGestureEvent(event); | 1225 SendGestureEvent(event); |
1075 } | 1226 } |
1076 | 1227 |
1077 void ContentViewCoreImpl::SingleTapUnconfirmed(JNIEnv* env, jobject obj, | 1228 void ContentViewCoreImpl::SingleTapUnconfirmed(JNIEnv* env, jobject obj, |
1078 jlong time_ms, | 1229 jlong time_ms, |
1079 jfloat x, jfloat y) { | 1230 jfloat x, jfloat y) { |
1080 WebGestureEvent event = MakeGestureEvent( | 1231 WebGestureEvent event = MakeGestureEvent( |
1081 WebInputEvent::GestureTapUnconfirmed, time_ms, x, y); | 1232 WebInputEvent::GestureTapUnconfirmed, time_ms, x, y); |
1082 | 1233 |
1083 event.data.tap.tapCount = 1; | 1234 event.data.tap.tapCount = 1; |
1084 | 1235 |
1085 const float touch_padding_dip = GetTouchPaddingDip(); | 1236 const float touch_padding_dip = GetTouchPaddingDip(); |
1086 event.data.tap.width = touch_padding_dip; | 1237 event.data.tap.width = touch_padding_dip; |
1087 event.data.tap.height = touch_padding_dip; | 1238 event.data.tap.height = touch_padding_dip; |
1088 | 1239 |
1089 SendGestureEvent(event); | 1240 SendGestureEvent(event); |
1090 } | 1241 } |
1091 | 1242 |
1092 void ContentViewCoreImpl::ShowPressState(JNIEnv* env, jobject obj, | 1243 void ContentViewCoreImpl::ShowPress(JNIEnv* env, jobject obj, |
1093 jlong time_ms, | 1244 jlong time_ms, |
1094 jfloat x, jfloat y) { | 1245 jfloat x, jfloat y) { |
1095 WebGestureEvent event = MakeGestureEvent( | 1246 WebGestureEvent event = MakeGestureEvent( |
1096 WebInputEvent::GestureShowPress, time_ms, x, y); | 1247 WebInputEvent::GestureShowPress, time_ms, x, y); |
1097 SendGestureEvent(event); | 1248 SendGestureEvent(event); |
1098 } | 1249 } |
1099 | 1250 |
1100 void ContentViewCoreImpl::TapCancel(JNIEnv* env, | 1251 void ContentViewCoreImpl::TapCancel(JNIEnv* env, |
1101 jobject obj, | 1252 jobject obj, |
1102 jlong time_ms, | 1253 jlong time_ms, |
1103 jfloat x, | 1254 jfloat x, |
1104 jfloat y) { | 1255 jfloat y) { |
(...skipping 16 matching lines...) Expand all Loading... |
1121 WebInputEvent::GestureDoubleTap, time_ms, x, y); | 1272 WebInputEvent::GestureDoubleTap, time_ms, x, y); |
1122 SendGestureEvent(event); | 1273 SendGestureEvent(event); |
1123 } | 1274 } |
1124 | 1275 |
1125 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, | 1276 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, |
1126 jfloat x, jfloat y, | 1277 jfloat x, jfloat y, |
1127 jboolean disambiguation_popup_tap) { | 1278 jboolean disambiguation_popup_tap) { |
1128 WebGestureEvent event = MakeGestureEvent( | 1279 WebGestureEvent event = MakeGestureEvent( |
1129 WebInputEvent::GestureLongPress, time_ms, x, y); | 1280 WebInputEvent::GestureLongPress, time_ms, x, y); |
1130 | 1281 |
1131 if (!disambiguation_popup_tap) { | 1282 // Disambiguation popup gestures are treated as synthetic because their |
1132 const float touch_padding_dip = GetTouchPaddingDip(); | 1283 // generating touches were never forwarded to the renderer. |
1133 event.data.longPress.width = touch_padding_dip; | 1284 if (disambiguation_popup_tap) { |
1134 event.data.longPress.height = touch_padding_dip; | 1285 SendSyntheticGestureEvent(event); |
| 1286 return; |
1135 } | 1287 } |
1136 | 1288 |
| 1289 const float touch_padding_dip = GetTouchPaddingDip(); |
| 1290 event.data.longPress.width = touch_padding_dip; |
| 1291 event.data.longPress.height = touch_padding_dip; |
1137 SendGestureEvent(event); | 1292 SendGestureEvent(event); |
1138 } | 1293 } |
1139 | 1294 |
1140 void ContentViewCoreImpl::LongTap(JNIEnv* env, jobject obj, jlong time_ms, | 1295 void ContentViewCoreImpl::LongTap(JNIEnv* env, jobject obj, jlong time_ms, |
1141 jfloat x, jfloat y, | 1296 jfloat x, jfloat y, |
1142 jboolean disambiguation_popup_tap) { | 1297 jboolean disambiguation_popup_tap) { |
1143 WebGestureEvent event = MakeGestureEvent( | 1298 WebGestureEvent event = MakeGestureEvent( |
1144 WebInputEvent::GestureLongTap, time_ms, x, y); | 1299 WebInputEvent::GestureLongTap, time_ms, x, y); |
1145 | 1300 |
1146 if (!disambiguation_popup_tap) { | 1301 // Disambiguation popup gestures are treated as synthetic because their |
1147 const float touch_padding_dip = GetTouchPaddingDip(); | 1302 // generating touches were never forwarded to the renderer. |
1148 event.data.longPress.width = touch_padding_dip; | 1303 if (disambiguation_popup_tap) { |
1149 event.data.longPress.height = touch_padding_dip; | 1304 SendSyntheticGestureEvent(event); |
| 1305 return; |
1150 } | 1306 } |
1151 | 1307 |
| 1308 const float touch_padding_dip = GetTouchPaddingDip(); |
| 1309 event.data.longPress.width = touch_padding_dip; |
| 1310 event.data.longPress.height = touch_padding_dip; |
1152 SendGestureEvent(event); | 1311 SendGestureEvent(event); |
1153 } | 1312 } |
1154 | 1313 |
1155 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, | 1314 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, |
1156 jfloat x, jfloat y) { | 1315 jfloat x, jfloat y) { |
1157 WebGestureEvent event = MakeGestureEvent( | 1316 WebGestureEvent event = MakeGestureEvent( |
1158 WebInputEvent::GesturePinchBegin, time_ms, x, y); | 1317 WebInputEvent::GesturePinchBegin, time_ms, x, y); |
1159 SendGestureEvent(event); | 1318 SendGestureEvent(event); |
1160 } | 1319 } |
1161 | 1320 |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1871 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1713 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1872 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1714 return reinterpret_cast<intptr_t>(view); | 1873 return reinterpret_cast<intptr_t>(view); |
1715 } | 1874 } |
1716 | 1875 |
1717 bool RegisterContentViewCore(JNIEnv* env) { | 1876 bool RegisterContentViewCore(JNIEnv* env) { |
1718 return RegisterNativesImpl(env); | 1877 return RegisterNativesImpl(env); |
1719 } | 1878 } |
1720 | 1879 |
1721 } // namespace content | 1880 } // namespace content |
OLD | NEW |