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/native_web_touch_event.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 66 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 |
113 bool PossiblyTriggeredByTouchTimeout(const WebGestureEvent& event) { | 114 int ToGestureEventType(WebInputEvent::Type type) { |
114 switch (event.type) { | |
115 case WebInputEvent::GestureShowPress: | |
116 case WebInputEvent::GestureLongPress: | |
117 return true; | |
118 // On Android, a GestureTap may be sent after a certain timeout window | |
119 // if there is no GestureDoubleTap follow-up. | |
120 case WebInputEvent::GestureTap: | |
121 return true; | |
122 // On Android, a GestureTapCancel may be triggered by the loss of window | |
123 // focus (e.g., following a GestureLongPress). | |
124 case WebInputEvent::GestureTapCancel: | |
125 return true; | |
126 default: | |
127 break; | |
128 } | |
129 return false; | |
130 } | |
131 | |
132 int ToContentViewGestureHandlerType(WebInputEvent::Type type) { | |
133 switch (type) { | 115 switch (type) { |
134 case WebInputEvent::GestureScrollBegin: | 116 case WebInputEvent::GestureScrollBegin: |
135 return SCROLL_START; | 117 return SCROLL_START; |
136 case WebInputEvent::GestureScrollEnd: | 118 case WebInputEvent::GestureScrollEnd: |
137 return SCROLL_END; | 119 return SCROLL_END; |
138 case WebInputEvent::GestureScrollUpdate: | 120 case WebInputEvent::GestureScrollUpdate: |
139 return SCROLL_BY; | 121 return SCROLL_BY; |
140 case WebInputEvent::GestureFlingStart: | 122 case WebInputEvent::GestureFlingStart: |
141 return FLING_START; | 123 return FLING_START; |
142 case WebInputEvent::GestureFlingCancel: | 124 case WebInputEvent::GestureFlingCancel: |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 java_ref_(env, obj), | 213 java_ref_(env, obj), |
232 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 214 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
233 root_layer_(cc::Layer::Create()), | 215 root_layer_(cc::Layer::Create()), |
234 vsync_interval_(base::TimeDelta::FromMicroseconds( | 216 vsync_interval_(base::TimeDelta::FromMicroseconds( |
235 kDefaultVSyncIntervalMicros)), | 217 kDefaultVSyncIntervalMicros)), |
236 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( | 218 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( |
237 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), | 219 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), |
238 view_android_(view_android), | 220 view_android_(view_android), |
239 window_android_(window_android), | 221 window_android_(window_android), |
240 device_orientation_(0), | 222 device_orientation_(0), |
241 geolocation_needs_pause_(false), | 223 geolocation_needs_pause_(false) { |
242 touch_disposition_gesture_filter_(this), | |
243 handling_touch_event_(false) { | |
244 CHECK(web_contents) << | 224 CHECK(web_contents) << |
245 "A ContentViewCoreImpl should be created with a valid WebContents."; | 225 "A ContentViewCoreImpl should be created with a valid WebContents."; |
246 | 226 |
247 const gfx::Display& display = | 227 const gfx::Display& display = |
248 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 228 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
249 dpi_scale_ = display.device_scale_factor(); | 229 dpi_scale_ = display.device_scale_factor(); |
250 | 230 |
251 // Currently, the only use case we have for overriding a user agent involves | 231 // Currently, the only use case we have for overriding a user agent involves |
252 // spoofing a desktop Linux user agent for "Request desktop site". | 232 // spoofing a desktop Linux user agent for "Request desktop site". |
253 // Automatically set it for all WebContents so that it is available when a | 233 // Automatically set it for all WebContents so that it is available when a |
254 // NavigationEntry requires the user agent to be overridden. | 234 // NavigationEntry requires the user agent to be overridden. |
255 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 235 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
256 std::string product = content::GetContentClient()->GetProduct(); | 236 std::string product = content::GetContentClient()->GetProduct(); |
257 std::string spoofed_ua = | 237 std::string spoofed_ua = |
258 webkit_glue::BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 238 webkit_glue::BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
259 web_contents->SetUserAgentOverride(spoofed_ua); | 239 web_contents->SetUserAgentOverride(spoofed_ua); |
260 | 240 |
| 241 gesture_provider_.reset(new ContentGestureProvider(this, 1.f/ dpi_scale_)); |
| 242 |
261 InitWebContents(); | 243 InitWebContents(); |
262 } | 244 } |
263 | 245 |
264 ContentViewCoreImpl::~ContentViewCoreImpl() { | 246 ContentViewCoreImpl::~ContentViewCoreImpl() { |
265 JNIEnv* env = base::android::AttachCurrentThread(); | 247 JNIEnv* env = base::android::AttachCurrentThread(); |
266 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 248 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
267 java_ref_.reset(); | 249 java_ref_.reset(); |
268 if (!j_obj.is_null()) { | 250 if (!j_obj.is_null()) { |
269 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 251 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
270 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); | 252 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 break; | 347 break; |
366 } | 348 } |
367 } | 349 } |
368 } | 350 } |
369 | 351 |
370 void ContentViewCoreImpl::RenderViewReady() { | 352 void ContentViewCoreImpl::RenderViewReady() { |
371 if (device_orientation_ != 0) | 353 if (device_orientation_ != 0) |
372 SendOrientationChangeEventInternal(); | 354 SendOrientationChangeEventInternal(); |
373 } | 355 } |
374 | 356 |
375 void ContentViewCoreImpl::ForwardGestureEvent( | 357 void ContentViewCoreImpl::OnGestureEvent(const blink::WebGestureEvent& event) { |
376 const blink::WebGestureEvent& event) { | 358 SendGestureEvent(event); |
377 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | |
378 if (rwhv) | |
379 rwhv->SendGestureEvent(event); | |
380 } | 359 } |
381 | 360 |
382 RenderWidgetHostViewAndroid* | 361 RenderWidgetHostViewAndroid* |
383 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { | 362 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { |
384 RenderWidgetHostView* rwhv = NULL; | 363 RenderWidgetHostView* rwhv = NULL; |
385 if (web_contents_) { | 364 if (web_contents_) { |
386 rwhv = web_contents_->GetRenderWidgetHostView(); | 365 rwhv = web_contents_->GetRenderWidgetHostView(); |
387 if (web_contents_->ShowingInterstitialPage()) { | 366 if (web_contents_->ShowingInterstitialPage()) { |
388 rwhv = static_cast<InterstitialPageImpl*>( | 367 rwhv = static_cast<InterstitialPageImpl*>( |
389 web_contents_->GetInterstitialPage())-> | 368 web_contents_->GetInterstitialPage())-> |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 536 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
558 } | 537 } |
559 ScopedJavaLocalRef<jobjectArray> items_array( | 538 ScopedJavaLocalRef<jobjectArray> items_array( |
560 base::android::ToJavaArrayOfStrings(env, labels)); | 539 base::android::ToJavaArrayOfStrings(env, labels)); |
561 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), | 540 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), |
562 items_array.obj(), enabled_array.obj(), | 541 items_array.obj(), enabled_array.obj(), |
563 multiple, selected_array.obj()); | 542 multiple, selected_array.obj()); |
564 } | 543 } |
565 | 544 |
566 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { | 545 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { |
567 touch_disposition_gesture_filter_.OnTouchEventAck(ack_result); | 546 gesture_provider_->OnTouchEventAck(ack_result); |
568 } | 547 } |
569 | 548 |
570 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, | 549 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, |
571 InputEventAckState ack_result) { | 550 InputEventAckState ack_result) { |
572 JNIEnv* env = AttachCurrentThread(); | 551 JNIEnv* env = AttachCurrentThread(); |
573 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 552 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
574 if (j_obj.is_null()) | 553 if (j_obj.is_null()) |
575 return; | 554 return; |
576 | 555 |
577 switch (event.type) { | 556 switch (event.type) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 event.type != WebInputEvent::GestureLongPress) | 604 event.type != WebInputEvent::GestureLongPress) |
626 return false; | 605 return false; |
627 | 606 |
628 JNIEnv* env = AttachCurrentThread(); | 607 JNIEnv* env = AttachCurrentThread(); |
629 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 608 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
630 if (j_obj.is_null()) | 609 if (j_obj.is_null()) |
631 return false; | 610 return false; |
632 | 611 |
633 const blink::WebGestureEvent& gesture = | 612 const blink::WebGestureEvent& gesture = |
634 static_cast<const blink::WebGestureEvent&>(event); | 613 static_cast<const blink::WebGestureEvent&>(event); |
635 int gesture_type = ToContentViewGestureHandlerType(event.type); | 614 int gesture_type = ToGestureEventType(event.type); |
636 return Java_ContentViewCore_filterTapOrPressEvent(env, | 615 return Java_ContentViewCore_filterTapOrPressEvent(env, |
637 j_obj.obj(), | 616 j_obj.obj(), |
638 gesture_type, | 617 gesture_type, |
639 gesture.x, | 618 gesture.x, |
640 gesture.y); | 619 gesture.y); |
641 } | 620 } |
642 | 621 |
643 bool ContentViewCoreImpl::HasFocus() { | 622 bool ContentViewCoreImpl::HasFocus() { |
644 JNIEnv* env = AttachCurrentThread(); | 623 JNIEnv* env = AttachCurrentThread(); |
645 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 624 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 | 988 |
1010 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, | 989 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, |
1011 jobject obj, | 990 jobject obj, |
1012 jint orientation) { | 991 jint orientation) { |
1013 if (device_orientation_ != orientation) { | 992 if (device_orientation_ != orientation) { |
1014 device_orientation_ = orientation; | 993 device_orientation_ = orientation; |
1015 SendOrientationChangeEventInternal(); | 994 SendOrientationChangeEventInternal(); |
1016 } | 995 } |
1017 } | 996 } |
1018 | 997 |
1019 void ContentViewCoreImpl::OnTouchEventHandlingBegin(JNIEnv* env, | 998 jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env, |
1020 jobject obj, | 999 jobject obj, |
1021 jobject motion_event) { | 1000 jobject motion_event) { |
1022 DCHECK(!handling_touch_event_); | |
1023 handling_touch_event_ = true; | |
1024 | |
1025 pending_touch_event_ = | |
1026 WebTouchEventBuilder::Build(motion_event, GetDpiScale()); | |
1027 | |
1028 pending_gesture_packet_ = | |
1029 GestureEventPacket::FromTouch(pending_touch_event_); | |
1030 } | |
1031 | |
1032 void ContentViewCoreImpl::OnTouchEventHandlingEnd(JNIEnv* env, jobject obj) { | |
1033 DCHECK(handling_touch_event_); | |
1034 handling_touch_event_ = false; | |
1035 | |
1036 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1001 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
1037 if (!rwhv) | 1002 if (!rwhv) |
1038 return; | 1003 return false; |
1039 | 1004 |
1040 // Note: Order is important here, as the touch may be ack'ed synchronously | 1005 NativeWebTouchEvent touch_event(motion_event, false, GetDpiScale()); |
1041 TouchDispositionGestureFilter::PacketResult result = | 1006 |
1042 touch_disposition_gesture_filter_.OnGestureEventPacket( | 1007 if (!gesture_provider_->OnTouchEvent(touch_event)) |
1043 pending_gesture_packet_); | 1008 return false; |
1044 if (result != TouchDispositionGestureFilter::SUCCESS) { | 1009 |
1045 NOTREACHED() << "Invalid touch gesture sequence detected."; | 1010 rwhv->SendTouchEvent(touch_event); |
1046 return; | 1011 return true; |
1047 } | |
1048 rwhv->SendTouchEvent(pending_touch_event_); | |
1049 } | 1012 } |
1050 | 1013 |
1051 float ContentViewCoreImpl::GetTouchPaddingDip() { | 1014 float ContentViewCoreImpl::GetTouchPaddingDip() { |
1052 return 48.0f / GetDpiScale(); | 1015 return 48.0f / GetDpiScale(); |
1053 } | 1016 } |
1054 | 1017 |
1055 float ContentViewCoreImpl::GetDpiScale() const { | 1018 float ContentViewCoreImpl::GetDpiScale() const { |
1056 return dpi_scale_; | 1019 return dpi_scale_; |
1057 } | 1020 } |
1058 | 1021 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 } | 1071 } |
1109 | 1072 |
1110 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( | 1073 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( |
1111 WebInputEvent::Type type, int64 time_ms, float x, float y) const { | 1074 WebInputEvent::Type type, int64 time_ms, float x, float y) const { |
1112 return WebGestureEventBuilder::Build( | 1075 return WebGestureEventBuilder::Build( |
1113 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); | 1076 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); |
1114 } | 1077 } |
1115 | 1078 |
1116 void ContentViewCoreImpl::SendGestureEvent( | 1079 void ContentViewCoreImpl::SendGestureEvent( |
1117 const blink::WebGestureEvent& event) { | 1080 const blink::WebGestureEvent& event) { |
1118 // Gestures received while |handling_touch_event_| will accumulate until | 1081 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
1119 // touch handling finishes, at which point the gestures will be pushed to the | 1082 if (rwhv) |
1120 // |touch_disposition_gesture_filter_|. | 1083 rwhv->SendGestureEvent(event); |
1121 if (handling_touch_event_) { | |
1122 pending_gesture_packet_.Push(event); | |
1123 return; | |
1124 } | |
1125 | |
1126 // TODO(jdduke): In general, timeout-based gestures *should* have the same | |
1127 // timestamp as the initial TouchStart of the current sequence. We should | |
1128 // verify that this is true, and use that as another timeout check. | |
1129 if (PossiblyTriggeredByTouchTimeout(event)) { | |
1130 TouchDispositionGestureFilter::PacketResult result = | |
1131 touch_disposition_gesture_filter_.OnGestureEventPacket( | |
1132 GestureEventPacket::FromTouchTimeout(event)); | |
1133 DCHECK_EQ(TouchDispositionGestureFilter::SUCCESS, result); | |
1134 return; | |
1135 } | |
1136 | |
1137 // If |event| was not (directly or indirectly) touch-derived, treat it as | |
1138 // a synthetic gesture event. | |
1139 SendSyntheticGestureEvent(event); | |
1140 } | |
1141 | |
1142 void ContentViewCoreImpl::SendSyntheticGestureEvent( | |
1143 const blink::WebGestureEvent& event) { | |
1144 // Synthetic gestures (e.g., those not generated directly by touches | |
1145 // for which we expect an ack), should be forwarded directly. | |
1146 ForwardGestureEvent(event); | |
1147 } | 1084 } |
1148 | 1085 |
1149 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, | 1086 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, |
1150 jobject obj, | 1087 jobject obj, |
1151 jlong time_ms, | 1088 jlong time_ms, |
1152 jfloat x, | 1089 jfloat x, |
1153 jfloat y, | 1090 jfloat y, |
1154 jfloat hintx, | 1091 jfloat hintx, |
1155 jfloat hinty) { | 1092 jfloat hinty) { |
1156 WebGestureEvent event = MakeGestureEvent( | 1093 WebGestureEvent event = MakeGestureEvent( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 jfloat x, jfloat y, | 1135 jfloat x, jfloat y, |
1199 jboolean disambiguation_popup_tap) { | 1136 jboolean disambiguation_popup_tap) { |
1200 WebGestureEvent event = MakeGestureEvent( | 1137 WebGestureEvent event = MakeGestureEvent( |
1201 WebInputEvent::GestureTap, time_ms, x, y); | 1138 WebInputEvent::GestureTap, time_ms, x, y); |
1202 | 1139 |
1203 event.data.tap.tapCount = 1; | 1140 event.data.tap.tapCount = 1; |
1204 | 1141 |
1205 // Disambiguation popup gestures are treated as synthetic because their | 1142 // Disambiguation popup gestures are treated as synthetic because their |
1206 // generating touches were never forwarded to the renderer. | 1143 // generating touches were never forwarded to the renderer. |
1207 if (disambiguation_popup_tap) { | 1144 if (disambiguation_popup_tap) { |
1208 SendSyntheticGestureEvent(event); | 1145 SendGestureEvent(event); |
1209 return; | 1146 return; |
1210 } | 1147 } |
1211 | 1148 |
1212 const float touch_padding_dip = GetTouchPaddingDip(); | 1149 const float touch_padding_dip = GetTouchPaddingDip(); |
1213 event.data.tap.width = touch_padding_dip; | 1150 event.data.tap.width = touch_padding_dip; |
1214 event.data.tap.height = touch_padding_dip; | 1151 event.data.tap.height = touch_padding_dip; |
1215 SendGestureEvent(event); | 1152 SendGestureEvent(event); |
1216 } | 1153 } |
1217 | 1154 |
1218 void ContentViewCoreImpl::SingleTapUnconfirmed(JNIEnv* env, jobject obj, | |
1219 jlong time_ms, | |
1220 jfloat x, jfloat y) { | |
1221 WebGestureEvent event = MakeGestureEvent( | |
1222 WebInputEvent::GestureTapUnconfirmed, time_ms, x, y); | |
1223 | |
1224 event.data.tap.tapCount = 1; | |
1225 | |
1226 const float touch_padding_dip = GetTouchPaddingDip(); | |
1227 event.data.tap.width = touch_padding_dip; | |
1228 event.data.tap.height = touch_padding_dip; | |
1229 | |
1230 SendGestureEvent(event); | |
1231 } | |
1232 | |
1233 void ContentViewCoreImpl::ShowPress(JNIEnv* env, jobject obj, | |
1234 jlong time_ms, | |
1235 jfloat x, jfloat y) { | |
1236 WebGestureEvent event = MakeGestureEvent( | |
1237 WebInputEvent::GestureShowPress, time_ms, x, y); | |
1238 SendGestureEvent(event); | |
1239 } | |
1240 | |
1241 void ContentViewCoreImpl::TapCancel(JNIEnv* env, | |
1242 jobject obj, | |
1243 jlong time_ms, | |
1244 jfloat x, | |
1245 jfloat y) { | |
1246 WebGestureEvent event = MakeGestureEvent( | |
1247 WebInputEvent::GestureTapCancel, time_ms, x, y); | |
1248 SendGestureEvent(event); | |
1249 } | |
1250 | |
1251 void ContentViewCoreImpl::TapDown(JNIEnv* env, jobject obj, | |
1252 jlong time_ms, | |
1253 jfloat x, jfloat y) { | |
1254 WebGestureEvent event = MakeGestureEvent( | |
1255 WebInputEvent::GestureTapDown, time_ms, x, y); | |
1256 SendGestureEvent(event); | |
1257 } | |
1258 | |
1259 void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, | 1155 void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, |
1260 jfloat x, jfloat y) { | 1156 jfloat x, jfloat y) { |
1261 WebGestureEvent event = MakeGestureEvent( | 1157 WebGestureEvent event = MakeGestureEvent( |
1262 WebInputEvent::GestureDoubleTap, time_ms, x, y); | 1158 WebInputEvent::GestureDoubleTap, time_ms, x, y); |
1263 SendGestureEvent(event); | 1159 SendGestureEvent(event); |
1264 } | 1160 } |
1265 | 1161 |
1266 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, | 1162 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, |
1267 jfloat x, jfloat y, | 1163 jfloat x, jfloat y, |
1268 jboolean disambiguation_popup_tap) { | 1164 jboolean disambiguation_popup_tap) { |
1269 WebGestureEvent event = MakeGestureEvent( | 1165 WebGestureEvent event = MakeGestureEvent( |
1270 WebInputEvent::GestureLongPress, time_ms, x, y); | 1166 WebInputEvent::GestureLongPress, time_ms, x, y); |
1271 | 1167 |
1272 // Disambiguation popup gestures are treated as synthetic because their | 1168 // Disambiguation popup gestures are treated as synthetic because their |
1273 // generating touches were never forwarded to the renderer. | 1169 // generating touches were never forwarded to the renderer. |
1274 if (disambiguation_popup_tap) { | 1170 if (disambiguation_popup_tap) { |
1275 SendSyntheticGestureEvent(event); | 1171 SendGestureEvent(event); |
1276 return; | 1172 return; |
1277 } | 1173 } |
1278 | 1174 |
1279 const float touch_padding_dip = GetTouchPaddingDip(); | |
1280 event.data.longPress.width = touch_padding_dip; | |
1281 event.data.longPress.height = touch_padding_dip; | |
1282 SendGestureEvent(event); | |
1283 } | |
1284 | |
1285 void ContentViewCoreImpl::LongTap(JNIEnv* env, jobject obj, jlong time_ms, | |
1286 jfloat x, jfloat y, | |
1287 jboolean disambiguation_popup_tap) { | |
1288 WebGestureEvent event = MakeGestureEvent( | |
1289 WebInputEvent::GestureLongTap, time_ms, x, y); | |
1290 | |
1291 // Disambiguation popup gestures are treated as synthetic because their | |
1292 // generating touches were never forwarded to the renderer. | |
1293 if (disambiguation_popup_tap) { | |
1294 SendSyntheticGestureEvent(event); | |
1295 return; | |
1296 } | |
1297 | |
1298 const float touch_padding_dip = GetTouchPaddingDip(); | 1175 const float touch_padding_dip = GetTouchPaddingDip(); |
1299 event.data.longPress.width = touch_padding_dip; | 1176 event.data.longPress.width = touch_padding_dip; |
1300 event.data.longPress.height = touch_padding_dip; | 1177 event.data.longPress.height = touch_padding_dip; |
1301 SendGestureEvent(event); | 1178 SendGestureEvent(event); |
1302 } | 1179 } |
1303 | 1180 |
1304 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, | 1181 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, |
1305 jfloat x, jfloat y) { | 1182 jfloat x, jfloat y) { |
1306 WebGestureEvent event = MakeGestureEvent( | 1183 WebGestureEvent event = MakeGestureEvent( |
1307 WebInputEvent::GesturePinchBegin, time_ms, x, y); | 1184 WebInputEvent::GesturePinchBegin, time_ms, x, y); |
(...skipping 27 matching lines...) Expand all Loading... |
1335 } | 1212 } |
1336 | 1213 |
1337 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, | 1214 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, |
1338 jfloat x, jfloat y) { | 1215 jfloat x, jfloat y) { |
1339 if (GetRenderWidgetHostViewAndroid()) { | 1216 if (GetRenderWidgetHostViewAndroid()) { |
1340 GetRenderWidgetHostViewAndroid()->MoveCaret( | 1217 GetRenderWidgetHostViewAndroid()->MoveCaret( |
1341 gfx::Point(x / GetDpiScale(), y / GetDpiScale())); | 1218 gfx::Point(x / GetDpiScale(), y / GetDpiScale())); |
1342 } | 1219 } |
1343 } | 1220 } |
1344 | 1221 |
| 1222 void ContentViewCoreImpl::ResetGestureDetectors(JNIEnv* env, jobject obj) { |
| 1223 gesture_provider_->ResetGestureDetectors(); |
| 1224 } |
| 1225 |
| 1226 void ContentViewCoreImpl::IgnoreRemainingTouchEvents(JNIEnv* env, jobject obj) { |
| 1227 gesture_provider_->CancelActiveTouchSequence(); |
| 1228 } |
| 1229 |
| 1230 void ContentViewCoreImpl::OnWindowFocusLost(JNIEnv* env, jobject obj) { |
| 1231 gesture_provider_->CancelActiveTouchSequence(); |
| 1232 } |
| 1233 |
| 1234 void ContentViewCoreImpl::UpdateDoubleTapSupportForPage(JNIEnv* env, |
| 1235 jobject obj, |
| 1236 jboolean has_support) { |
| 1237 gesture_provider_->UpdateDoubleTapSupportForPage(has_support); |
| 1238 } |
| 1239 |
| 1240 void ContentViewCoreImpl::UpdateDoubleTapSupport(JNIEnv* env, |
| 1241 jobject obj, |
| 1242 jboolean has_support) { |
| 1243 gesture_provider_->UpdateDoubleTapSupportForPlatform(has_support); |
| 1244 } |
| 1245 |
| 1246 void ContentViewCoreImpl::UpdateMultiTouchZoomSupport(JNIEnv* env, |
| 1247 jobject obj, |
| 1248 jboolean has_support) { |
| 1249 gesture_provider_->UpdateMultiTouchSupport(has_support); |
| 1250 } |
| 1251 |
1345 void ContentViewCoreImpl::LoadIfNecessary(JNIEnv* env, jobject obj) { | 1252 void ContentViewCoreImpl::LoadIfNecessary(JNIEnv* env, jobject obj) { |
1346 web_contents_->GetController().LoadIfNecessary(); | 1253 web_contents_->GetController().LoadIfNecessary(); |
1347 } | 1254 } |
1348 | 1255 |
1349 void ContentViewCoreImpl::RequestRestoreLoad(JNIEnv* env, jobject obj) { | 1256 void ContentViewCoreImpl::RequestRestoreLoad(JNIEnv* env, jobject obj) { |
1350 web_contents_->GetController().SetNeedsReload(); | 1257 web_contents_->GetController().SetNeedsReload(); |
1351 } | 1258 } |
1352 | 1259 |
1353 void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) { | 1260 void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) { |
1354 web_contents_->Stop(); | 1261 web_contents_->Stop(); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 // If it was actually enabled globally, enable it for this RenderWidget now. | 1679 // If it was actually enabled globally, enable it for this RenderWidget now. |
1773 if (accessibility_state->IsAccessibleBrowser() && host_impl) | 1680 if (accessibility_state->IsAccessibleBrowser() && host_impl) |
1774 host_impl->AddAccessibilityMode(AccessibilityModeComplete); | 1681 host_impl->AddAccessibilityMode(AccessibilityModeComplete); |
1775 } else { | 1682 } else { |
1776 accessibility_state->ResetAccessibilityMode(); | 1683 accessibility_state->ResetAccessibilityMode(); |
1777 if (host_impl) | 1684 if (host_impl) |
1778 host_impl->ResetAccessibilityMode(); | 1685 host_impl->ResetAccessibilityMode(); |
1779 } | 1686 } |
1780 } | 1687 } |
1781 | 1688 |
1782 void ContentViewCoreImpl::SendSingleTapUma(JNIEnv* env, | |
1783 jobject obj, | |
1784 jint type, | |
1785 jint count) { | |
1786 UMA_HISTOGRAM_ENUMERATION("Event.SingleTapType", type, count); | |
1787 } | |
1788 | |
1789 void ContentViewCoreImpl::SendActionAfterDoubleTapUma(JNIEnv* env, | |
1790 jobject obj, | |
1791 jint type, | |
1792 jboolean has_delay, | |
1793 jint count) { | |
1794 // This UMA stat tracks a user's action after a double tap within | |
1795 // k seconds (where k == 5 currently). This UMA will tell us if | |
1796 // removing the tap gesture delay will lead to significantly more | |
1797 // accidental navigations after a double tap. | |
1798 if (has_delay) { | |
1799 UMA_HISTOGRAM_ENUMERATION("Event.ActionAfterDoubleTapWithDelay", type, | |
1800 count); | |
1801 } else { | |
1802 UMA_HISTOGRAM_ENUMERATION("Event.ActionAfterDoubleTapNoDelay", type, | |
1803 count); | |
1804 } | |
1805 } | |
1806 | |
1807 void ContentViewCoreImpl::SendOrientationChangeEventInternal() { | 1689 void ContentViewCoreImpl::SendOrientationChangeEventInternal() { |
1808 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1690 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
1809 if (rwhv) | 1691 if (rwhv) |
1810 rwhv->UpdateScreenInfo(rwhv->GetNativeView()); | 1692 rwhv->UpdateScreenInfo(rwhv->GetNativeView()); |
1811 | 1693 |
1812 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( | 1694 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( |
1813 web_contents_->GetRenderViewHost()); | 1695 web_contents_->GetRenderViewHost()); |
1814 rvhi->SendOrientationChangeEvent(device_orientation_); | 1696 rvhi->SendOrientationChangeEvent(device_orientation_); |
1815 } | 1697 } |
1816 | 1698 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1861 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1743 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1862 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1744 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1863 return reinterpret_cast<intptr_t>(view); | 1745 return reinterpret_cast<intptr_t>(view); |
1864 } | 1746 } |
1865 | 1747 |
1866 bool RegisterContentViewCore(JNIEnv* env) { | 1748 bool RegisterContentViewCore(JNIEnv* env) { |
1867 return RegisterNativesImpl(env); | 1749 return RegisterNativesImpl(env); |
1868 } | 1750 } |
1869 | 1751 |
1870 } // namespace content | 1752 } // namespace content |
OLD | NEW |