| 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 JNIEnv* env = AttachCurrentThread(); |
| 393 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 394 if (j_obj.is_null()) |
| 395 return; |
| 396 |
| 397 if (!Java_ContentViewCore_onForwardingGestureEvent( |
| 398 env, j_obj.obj(), |
| 399 ToContentViewGestureHandlerType(event.type), event.x, event.y)) |
| 400 return; |
| 401 |
| 402 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 403 if (rwhv) |
| 404 rwhv->SendGestureEvent(event); |
| 405 } |
| 406 |
| 305 RenderWidgetHostViewAndroid* | 407 RenderWidgetHostViewAndroid* |
| 306 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { | 408 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { |
| 307 RenderWidgetHostView* rwhv = NULL; | 409 RenderWidgetHostView* rwhv = NULL; |
| 308 if (web_contents_) { | 410 if (web_contents_) { |
| 309 rwhv = web_contents_->GetRenderWidgetHostView(); | 411 rwhv = web_contents_->GetRenderWidgetHostView(); |
| 310 if (web_contents_->ShowingInterstitialPage()) { | 412 if (web_contents_->ShowingInterstitialPage()) { |
| 311 rwhv = static_cast<InterstitialPageImpl*>( | 413 rwhv = static_cast<InterstitialPageImpl*>( |
| 312 web_contents_->GetInterstitialPage())-> | 414 web_contents_->GetInterstitialPage())-> |
| 313 GetRenderViewHost()->GetView(); | 415 GetRenderViewHost()->GetView(); |
| 314 } | 416 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 590 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
| 489 } | 591 } |
| 490 ScopedJavaLocalRef<jobjectArray> items_array( | 592 ScopedJavaLocalRef<jobjectArray> items_array( |
| 491 base::android::ToJavaArrayOfStrings(env, labels)); | 593 base::android::ToJavaArrayOfStrings(env, labels)); |
| 492 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), | 594 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), |
| 493 items_array.obj(), enabled_array.obj(), | 595 items_array.obj(), enabled_array.obj(), |
| 494 multiple, selected_array.obj()); | 596 multiple, selected_array.obj()); |
| 495 } | 597 } |
| 496 | 598 |
| 497 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { | 599 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { |
| 600 gesture_event_queue_.OnTouchEventAck(ack_result); |
| 601 } |
| 602 |
| 603 void ContentViewCoreImpl::OnUnhandledFlingStartEventAck(bool had_consumer, |
| 604 float vx, |
| 605 float vy) { |
| 498 JNIEnv* env = AttachCurrentThread(); | 606 JNIEnv* env = AttachCurrentThread(); |
| 499 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 607 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 500 if (j_obj.is_null()) | 608 if (j_obj.is_null()) |
| 501 return; | 609 return; |
| 502 Java_ContentViewCore_confirmTouchEvent(env, j_obj.obj(), | 610 Java_ContentViewCore_onUnhandledFlingStartEventAck(env, j_obj.obj(), |
| 503 static_cast<jint>(ack_result)); | 611 had_consumer, vx, vy); |
| 504 } | |
| 505 | |
| 506 void ContentViewCoreImpl::OnFlingStartEventAck(InputEventAckState ack_result) { | |
| 507 JNIEnv* env = AttachCurrentThread(); | |
| 508 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | |
| 509 if (j_obj.is_null()) | |
| 510 return; | |
| 511 Java_ContentViewCore_onFlingStartEventAck(env, j_obj.obj(), | |
| 512 static_cast<jint>(ack_result)); | |
| 513 } | 612 } |
| 514 | 613 |
| 515 void ContentViewCoreImpl::OnScrollBeginEventAck() { | 614 void ContentViewCoreImpl::OnScrollBeginEventAck() { |
| 516 JNIEnv* env = AttachCurrentThread(); | 615 JNIEnv* env = AttachCurrentThread(); |
| 517 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 616 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 518 if (j_obj.is_null()) | 617 if (j_obj.is_null()) |
| 519 return; | 618 return; |
| 520 Java_ContentViewCore_onScrollBeginEventAck(env, j_obj.obj()); | 619 Java_ContentViewCore_onScrollBeginEventAck(env, j_obj.obj()); |
| 521 } | 620 } |
| 522 | 621 |
| 523 void ContentViewCoreImpl::OnScrollUpdateGestureConsumed() { | 622 void ContentViewCoreImpl::OnScrollUpdateGestureConsumed() { |
| 524 JNIEnv* env = AttachCurrentThread(); | 623 JNIEnv* env = AttachCurrentThread(); |
| 525 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 624 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 526 if (j_obj.is_null()) | 625 if (j_obj.is_null()) |
| 527 return; | 626 return; |
| 528 Java_ContentViewCore_onScrollUpdateGestureConsumed(env, j_obj.obj()); | 627 Java_ContentViewCore_onScrollUpdateGestureConsumed(env, j_obj.obj()); |
| 529 } | 628 } |
| 530 | 629 |
| 531 void ContentViewCoreImpl::OnScrollEndEventAck() { | 630 void ContentViewCoreImpl::OnScrollEndEventAck() { |
| 532 JNIEnv* env = AttachCurrentThread(); | 631 JNIEnv* env = AttachCurrentThread(); |
| 533 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 632 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 534 if (j_obj.is_null()) | 633 if (j_obj.is_null()) |
| 535 return; | 634 return; |
| 536 Java_ContentViewCore_onScrollEndEventAck(env, j_obj.obj()); | 635 Java_ContentViewCore_onScrollEndEventAck(env, j_obj.obj()); |
| 537 } | 636 } |
| 538 | 637 |
| 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 } | |
| 548 | |
| 549 bool ContentViewCoreImpl::HasFocus() { | 638 bool ContentViewCoreImpl::HasFocus() { |
| 550 JNIEnv* env = AttachCurrentThread(); | 639 JNIEnv* env = AttachCurrentThread(); |
| 551 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 640 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 552 if (obj.is_null()) | 641 if (obj.is_null()) |
| 553 return false; | 642 return false; |
| 554 return Java_ContentViewCore_hasFocus(env, obj.obj()); | 643 return Java_ContentViewCore_hasFocus(env, obj.obj()); |
| 555 } | 644 } |
| 556 | 645 |
| 557 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { | 646 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { |
| 558 JNIEnv* env = AttachCurrentThread(); | 647 JNIEnv* env = AttachCurrentThread(); |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 | 1001 |
| 913 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, | 1002 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, |
| 914 jobject obj, | 1003 jobject obj, |
| 915 jint orientation) { | 1004 jint orientation) { |
| 916 if (device_orientation_ != orientation) { | 1005 if (device_orientation_ != orientation) { |
| 917 device_orientation_ = orientation; | 1006 device_orientation_ = orientation; |
| 918 SendOrientationChangeEventInternal(); | 1007 SendOrientationChangeEventInternal(); |
| 919 } | 1008 } |
| 920 } | 1009 } |
| 921 | 1010 |
| 922 jboolean ContentViewCoreImpl::SendTouchEvent(JNIEnv* env, | 1011 void ContentViewCoreImpl::OnTouchEventHandlingBegin(JNIEnv* env, |
| 923 jobject obj, | 1012 jobject obj, |
| 924 jlong time_ms, | 1013 jlong time_ms, |
| 925 jint type, | 1014 jint type, |
| 926 jobjectArray pts) { | 1015 jobjectArray pts) { |
| 1016 DCHECK(!handling_touch_event_); |
| 1017 handling_touch_event_ = true; |
| 1018 |
| 1019 blink::WebTouchEvent event; |
| 1020 TouchPoint::BuildWebTouchEvent(env, type, time_ms, GetDpiScale(), pts, event); |
| 1021 pending_touch_event_ = event; |
| 1022 |
| 1023 pending_gesture_packet_ = GestureEventPacket::FromTouch(event); |
| 1024 } |
| 1025 |
| 1026 void ContentViewCoreImpl::OnTouchEventHandlingEnd(JNIEnv* env, jobject obj) { |
| 1027 DCHECK(handling_touch_event_); |
| 1028 handling_touch_event_ = false; |
| 1029 |
| 927 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1030 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 928 if (rwhv) { | 1031 if (!rwhv) |
| 929 using blink::WebTouchEvent; | 1032 return; |
| 930 blink::WebTouchEvent event; | 1033 |
| 931 TouchPoint::BuildWebTouchEvent(env, type, time_ms, GetDpiScale(), pts, | 1034 // Note: Order is important here, as the touch may be ack'ed synchronously |
| 932 event); | 1035 gesture_event_queue_.OnGestureEventPacket(pending_gesture_packet_); |
| 933 rwhv->SendTouchEvent(event); | 1036 rwhv->SendTouchEvent(pending_touch_event_); |
| 934 return true; | |
| 935 } | |
| 936 return false; | |
| 937 } | 1037 } |
| 938 | 1038 |
| 939 float ContentViewCoreImpl::GetTouchPaddingDip() { | 1039 float ContentViewCoreImpl::GetTouchPaddingDip() { |
| 940 return 48.0f / GetDpiScale(); | 1040 return 48.0f / GetDpiScale(); |
| 941 } | 1041 } |
| 942 | 1042 |
| 943 float ContentViewCoreImpl::GetDpiScale() const { | 1043 float ContentViewCoreImpl::GetDpiScale() const { |
| 944 return dpi_scale_; | 1044 return dpi_scale_; |
| 945 } | 1045 } |
| 946 | 1046 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 } | 1096 } |
| 997 | 1097 |
| 998 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( | 1098 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( |
| 999 WebInputEvent::Type type, int64 time_ms, float x, float y) const { | 1099 WebInputEvent::Type type, int64 time_ms, float x, float y) const { |
| 1000 return WebGestureEventBuilder::Build( | 1100 return WebGestureEventBuilder::Build( |
| 1001 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); | 1101 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); |
| 1002 } | 1102 } |
| 1003 | 1103 |
| 1004 void ContentViewCoreImpl::SendGestureEvent( | 1104 void ContentViewCoreImpl::SendGestureEvent( |
| 1005 const blink::WebGestureEvent& event) { | 1105 const blink::WebGestureEvent& event) { |
| 1006 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1106 // Gestures received while |handling_touch_event_| will accumulate until |
| 1007 if (rwhv) | 1107 // touch handling finishes, at which point they will be forwarded to the |
| 1008 rwhv->SendGestureEvent(event); | 1108 // |gesture_event_queue_|. |
| 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 gesture_event_queue_.OnGestureEventPacket( |
| 1119 GestureEventPacket::FromTouchTimeout(event)); |
| 1120 return; |
| 1121 } |
| 1122 |
| 1123 // If |event| was not (directly or indirectly) touch-derived, treat it as |
| 1124 // a synthetic gesture event. |
| 1125 SendSyntheticGestureEvent(event); |
| 1126 } |
| 1127 |
| 1128 void ContentViewCoreImpl::SendSyntheticGestureEvent( |
| 1129 const blink::WebGestureEvent& event) { |
| 1130 // Synthetic gestures (e.g., those not generated directly by touches |
| 1131 // for which we expect an ack), should be forwarded directly. |
| 1132 ForwardGestureEvent(event); |
| 1009 } | 1133 } |
| 1010 | 1134 |
| 1011 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, | 1135 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, |
| 1012 jobject obj, | 1136 jobject obj, |
| 1013 jlong time_ms, | 1137 jlong time_ms, |
| 1014 jfloat x, | 1138 jfloat x, |
| 1015 jfloat y, | 1139 jfloat y, |
| 1016 jfloat hintx, | 1140 jfloat hintx, |
| 1017 jfloat hinty) { | 1141 jfloat hinty) { |
| 1018 WebGestureEvent event = MakeGestureEvent( | 1142 WebGestureEvent event = MakeGestureEvent( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 SendGestureEvent(event); | 1182 SendGestureEvent(event); |
| 1059 } | 1183 } |
| 1060 | 1184 |
| 1061 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, | 1185 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, |
| 1062 jfloat x, jfloat y, | 1186 jfloat x, jfloat y, |
| 1063 jboolean disambiguation_popup_tap) { | 1187 jboolean disambiguation_popup_tap) { |
| 1064 WebGestureEvent event = MakeGestureEvent( | 1188 WebGestureEvent event = MakeGestureEvent( |
| 1065 WebInputEvent::GestureTap, time_ms, x, y); | 1189 WebInputEvent::GestureTap, time_ms, x, y); |
| 1066 | 1190 |
| 1067 event.data.tap.tapCount = 1; | 1191 event.data.tap.tapCount = 1; |
| 1068 if (!disambiguation_popup_tap) { | 1192 |
| 1069 const float touch_padding_dip = GetTouchPaddingDip(); | 1193 // Disambiguation popup gestures are treated as synthetic because their |
| 1070 event.data.tap.width = touch_padding_dip; | 1194 // generating touches were never forwarded to the renderer. |
| 1071 event.data.tap.height = touch_padding_dip; | 1195 if (disambiguation_popup_tap) { |
| 1196 SendSyntheticGestureEvent(event); |
| 1197 return; |
| 1072 } | 1198 } |
| 1073 | 1199 |
| 1200 const float touch_padding_dip = GetTouchPaddingDip(); |
| 1201 event.data.tap.width = touch_padding_dip; |
| 1202 event.data.tap.height = touch_padding_dip; |
| 1074 SendGestureEvent(event); | 1203 SendGestureEvent(event); |
| 1075 } | 1204 } |
| 1076 | 1205 |
| 1077 void ContentViewCoreImpl::SingleTapUnconfirmed(JNIEnv* env, jobject obj, | 1206 void ContentViewCoreImpl::SingleTapUnconfirmed(JNIEnv* env, jobject obj, |
| 1078 jlong time_ms, | 1207 jlong time_ms, |
| 1079 jfloat x, jfloat y) { | 1208 jfloat x, jfloat y) { |
| 1080 WebGestureEvent event = MakeGestureEvent( | 1209 WebGestureEvent event = MakeGestureEvent( |
| 1081 WebInputEvent::GestureTapUnconfirmed, time_ms, x, y); | 1210 WebInputEvent::GestureTapUnconfirmed, time_ms, x, y); |
| 1082 | 1211 |
| 1083 event.data.tap.tapCount = 1; | 1212 event.data.tap.tapCount = 1; |
| 1084 | 1213 |
| 1085 const float touch_padding_dip = GetTouchPaddingDip(); | 1214 const float touch_padding_dip = GetTouchPaddingDip(); |
| 1086 event.data.tap.width = touch_padding_dip; | 1215 event.data.tap.width = touch_padding_dip; |
| 1087 event.data.tap.height = touch_padding_dip; | 1216 event.data.tap.height = touch_padding_dip; |
| 1088 | 1217 |
| 1089 SendGestureEvent(event); | 1218 SendGestureEvent(event); |
| 1090 } | 1219 } |
| 1091 | 1220 |
| 1092 void ContentViewCoreImpl::ShowPressState(JNIEnv* env, jobject obj, | 1221 void ContentViewCoreImpl::ShowPress(JNIEnv* env, jobject obj, |
| 1093 jlong time_ms, | 1222 jlong time_ms, |
| 1094 jfloat x, jfloat y) { | 1223 jfloat x, jfloat y) { |
| 1095 WebGestureEvent event = MakeGestureEvent( | 1224 WebGestureEvent event = MakeGestureEvent( |
| 1096 WebInputEvent::GestureShowPress, time_ms, x, y); | 1225 WebInputEvent::GestureShowPress, time_ms, x, y); |
| 1097 SendGestureEvent(event); | 1226 SendGestureEvent(event); |
| 1098 } | 1227 } |
| 1099 | 1228 |
| 1100 void ContentViewCoreImpl::TapCancel(JNIEnv* env, | 1229 void ContentViewCoreImpl::TapCancel(JNIEnv* env, |
| 1101 jobject obj, | 1230 jobject obj, |
| 1102 jlong time_ms, | 1231 jlong time_ms, |
| 1103 jfloat x, | 1232 jfloat x, |
| 1104 jfloat y) { | 1233 jfloat y) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1121 WebInputEvent::GestureDoubleTap, time_ms, x, y); | 1250 WebInputEvent::GestureDoubleTap, time_ms, x, y); |
| 1122 SendGestureEvent(event); | 1251 SendGestureEvent(event); |
| 1123 } | 1252 } |
| 1124 | 1253 |
| 1125 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, | 1254 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, |
| 1126 jfloat x, jfloat y, | 1255 jfloat x, jfloat y, |
| 1127 jboolean disambiguation_popup_tap) { | 1256 jboolean disambiguation_popup_tap) { |
| 1128 WebGestureEvent event = MakeGestureEvent( | 1257 WebGestureEvent event = MakeGestureEvent( |
| 1129 WebInputEvent::GestureLongPress, time_ms, x, y); | 1258 WebInputEvent::GestureLongPress, time_ms, x, y); |
| 1130 | 1259 |
| 1131 if (!disambiguation_popup_tap) { | 1260 // Disambiguation popup gestures are treated as synthetic because their |
| 1132 const float touch_padding_dip = GetTouchPaddingDip(); | 1261 // generating touches were never forwarded to the renderer. |
| 1133 event.data.longPress.width = touch_padding_dip; | 1262 if (disambiguation_popup_tap) { |
| 1134 event.data.longPress.height = touch_padding_dip; | 1263 SendSyntheticGestureEvent(event); |
| 1264 return; |
| 1135 } | 1265 } |
| 1136 | 1266 |
| 1267 const float touch_padding_dip = GetTouchPaddingDip(); |
| 1268 event.data.longPress.width = touch_padding_dip; |
| 1269 event.data.longPress.height = touch_padding_dip; |
| 1137 SendGestureEvent(event); | 1270 SendGestureEvent(event); |
| 1138 } | 1271 } |
| 1139 | 1272 |
| 1140 void ContentViewCoreImpl::LongTap(JNIEnv* env, jobject obj, jlong time_ms, | 1273 void ContentViewCoreImpl::LongTap(JNIEnv* env, jobject obj, jlong time_ms, |
| 1141 jfloat x, jfloat y, | 1274 jfloat x, jfloat y, |
| 1142 jboolean disambiguation_popup_tap) { | 1275 jboolean disambiguation_popup_tap) { |
| 1143 WebGestureEvent event = MakeGestureEvent( | 1276 WebGestureEvent event = MakeGestureEvent( |
| 1144 WebInputEvent::GestureLongTap, time_ms, x, y); | 1277 WebInputEvent::GestureLongTap, time_ms, x, y); |
| 1145 | 1278 |
| 1146 if (!disambiguation_popup_tap) { | 1279 // Disambiguation popup gestures are treated as synthetic because their |
| 1147 const float touch_padding_dip = GetTouchPaddingDip(); | 1280 // generating touches were never forwarded to the renderer. |
| 1148 event.data.longPress.width = touch_padding_dip; | 1281 if (disambiguation_popup_tap) { |
| 1149 event.data.longPress.height = touch_padding_dip; | 1282 SendSyntheticGestureEvent(event); |
| 1283 return; |
| 1150 } | 1284 } |
| 1151 | 1285 |
| 1286 const float touch_padding_dip = GetTouchPaddingDip(); |
| 1287 event.data.longPress.width = touch_padding_dip; |
| 1288 event.data.longPress.height = touch_padding_dip; |
| 1152 SendGestureEvent(event); | 1289 SendGestureEvent(event); |
| 1153 } | 1290 } |
| 1154 | 1291 |
| 1155 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, | 1292 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, |
| 1156 jfloat x, jfloat y) { | 1293 jfloat x, jfloat y) { |
| 1157 WebGestureEvent event = MakeGestureEvent( | 1294 WebGestureEvent event = MakeGestureEvent( |
| 1158 WebInputEvent::GesturePinchBegin, time_ms, x, y); | 1295 WebInputEvent::GesturePinchBegin, time_ms, x, y); |
| 1159 SendGestureEvent(event); | 1296 SendGestureEvent(event); |
| 1160 } | 1297 } |
| 1161 | 1298 |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1842 reinterpret_cast<ui::ViewAndroid*>(view_android), |
| 1706 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1843 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
| 1707 return reinterpret_cast<intptr_t>(view); | 1844 return reinterpret_cast<intptr_t>(view); |
| 1708 } | 1845 } |
| 1709 | 1846 |
| 1710 bool RegisterContentViewCore(JNIEnv* env) { | 1847 bool RegisterContentViewCore(JNIEnv* env) { |
| 1711 return RegisterNativesImpl(env); | 1848 return RegisterNativesImpl(env); |
| 1712 } | 1849 } |
| 1713 | 1850 |
| 1714 } // namespace content | 1851 } // namespace content |
| OLD | NEW |