Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: content/browser/android/content_view_core_impl.cc

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

Powered by Google App Engine
This is Rietveld 408576698