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 158 matching lines...) Loading... |
169 java_ref_(env, obj), | 169 java_ref_(env, obj), |
170 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 170 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
171 root_layer_(cc::Layer::Create()), | 171 root_layer_(cc::Layer::Create()), |
172 vsync_interval_(base::TimeDelta::FromMicroseconds( | 172 vsync_interval_(base::TimeDelta::FromMicroseconds( |
173 kDefaultVSyncIntervalMicros)), | 173 kDefaultVSyncIntervalMicros)), |
174 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( | 174 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( |
175 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), | 175 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), |
176 view_android_(view_android), | 176 view_android_(view_android), |
177 window_android_(window_android), | 177 window_android_(window_android), |
178 device_orientation_(0), | 178 device_orientation_(0), |
179 geolocation_needs_pause_(false) { | 179 geolocation_needs_pause_(false), |
| 180 gesture_event_queue_(new GestureEventQueue(this)), |
| 181 handling_touch_event_(false) { |
180 CHECK(web_contents) << | 182 CHECK(web_contents) << |
181 "A ContentViewCoreImpl should be created with a valid WebContents."; | 183 "A ContentViewCoreImpl should be created with a valid WebContents."; |
182 | 184 |
183 // TODO(leandrogracia): make use of the hardware_accelerated argument. | 185 // TODO(leandrogracia): make use of the hardware_accelerated argument. |
184 | 186 |
185 const gfx::Display& display = | 187 const gfx::Display& display = |
186 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 188 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
187 dpi_scale_ = display.device_scale_factor(); | 189 dpi_scale_ = display.device_scale_factor(); |
188 | 190 |
189 // Currently, the only use case we have for overriding a user agent involves | 191 // Currently, the only use case we have for overriding a user agent involves |
(...skipping 107 matching lines...) Loading... |
297 break; | 299 break; |
298 } | 300 } |
299 } | 301 } |
300 } | 302 } |
301 | 303 |
302 void ContentViewCoreImpl::RenderViewReady() { | 304 void ContentViewCoreImpl::RenderViewReady() { |
303 if (device_orientation_ != 0) | 305 if (device_orientation_ != 0) |
304 SendOrientationChangeEventInternal(); | 306 SendOrientationChangeEventInternal(); |
305 } | 307 } |
306 | 308 |
| 309 void ContentViewCoreImpl::ForwardGestureEvent( |
| 310 const blink::WebGestureEvent& event) { |
| 311 JNIEnv* env = AttachCurrentThread(); |
| 312 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 313 if (j_obj.is_null()) |
| 314 return; |
| 315 |
| 316 if (Java_ContentViewCore_onForwardingGestureEvent( |
| 317 env, j_obj.obj(), event.type, event.x, event.y)) |
| 318 return; |
| 319 |
| 320 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 321 if (rwhv) |
| 322 rwhv->SendGestureEvent(event); |
| 323 } |
| 324 |
307 RenderWidgetHostViewAndroid* | 325 RenderWidgetHostViewAndroid* |
308 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { | 326 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { |
309 RenderWidgetHostView* rwhv = NULL; | 327 RenderWidgetHostView* rwhv = NULL; |
310 if (web_contents_) { | 328 if (web_contents_) { |
311 rwhv = web_contents_->GetRenderWidgetHostView(); | 329 rwhv = web_contents_->GetRenderWidgetHostView(); |
312 if (web_contents_->ShowingInterstitialPage()) { | 330 if (web_contents_->ShowingInterstitialPage()) { |
313 rwhv = static_cast<InterstitialPageImpl*>( | 331 rwhv = static_cast<InterstitialPageImpl*>( |
314 web_contents_->GetInterstitialPage())-> | 332 web_contents_->GetInterstitialPage())-> |
315 GetRenderViewHost()->GetView(); | 333 GetRenderViewHost()->GetView(); |
316 } | 334 } |
(...skipping 173 matching lines...) Loading... |
490 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 508 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
491 } | 509 } |
492 ScopedJavaLocalRef<jobjectArray> items_array( | 510 ScopedJavaLocalRef<jobjectArray> items_array( |
493 base::android::ToJavaArrayOfStrings(env, labels)); | 511 base::android::ToJavaArrayOfStrings(env, labels)); |
494 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), | 512 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), |
495 items_array.obj(), enabled_array.obj(), | 513 items_array.obj(), enabled_array.obj(), |
496 multiple, selected_array.obj()); | 514 multiple, selected_array.obj()); |
497 } | 515 } |
498 | 516 |
499 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { | 517 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { |
| 518 gesture_event_queue_->OnTouchEventAck(ack_result); |
| 519 } |
| 520 |
| 521 void ContentViewCoreImpl::UnhandledFlingStartEvent(float vx, float vy) { |
500 JNIEnv* env = AttachCurrentThread(); | 522 JNIEnv* env = AttachCurrentThread(); |
501 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 523 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
502 if (j_obj.is_null()) | 524 if (j_obj.is_null()) |
503 return; | 525 return; |
504 Java_ContentViewCore_confirmTouchEvent(env, j_obj.obj(), | 526 Java_ContentViewCore_unhandledFlingStartEvent(env, j_obj.obj(), vx, vy); |
505 static_cast<jint>(ack_result)); | |
506 } | |
507 | |
508 void ContentViewCoreImpl::UnhandledFlingStartEvent() { | |
509 JNIEnv* env = AttachCurrentThread(); | |
510 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | |
511 if (j_obj.is_null()) | |
512 return; | |
513 Java_ContentViewCore_unhandledFlingStartEvent(env, j_obj.obj()); | |
514 } | 527 } |
515 | 528 |
516 void ContentViewCoreImpl::OnScrollUpdateGestureConsumed() { | 529 void ContentViewCoreImpl::OnScrollUpdateGestureConsumed() { |
517 JNIEnv* env = AttachCurrentThread(); | 530 JNIEnv* env = AttachCurrentThread(); |
518 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 531 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
519 if (j_obj.is_null()) | 532 if (j_obj.is_null()) |
520 return; | 533 return; |
521 Java_ContentViewCore_onScrollUpdateGestureConsumed(env, j_obj.obj()); | 534 Java_ContentViewCore_onScrollUpdateGestureConsumed(env, j_obj.obj()); |
522 } | 535 } |
523 | 536 |
524 void ContentViewCoreImpl::HasTouchEventHandlers(bool need_touch_events) { | |
525 JNIEnv* env = AttachCurrentThread(); | |
526 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | |
527 if (j_obj.is_null()) | |
528 return; | |
529 Java_ContentViewCore_hasTouchEventHandlers(env, | |
530 j_obj.obj(), | |
531 need_touch_events); | |
532 } | |
533 | |
534 bool ContentViewCoreImpl::HasFocus() { | 537 bool ContentViewCoreImpl::HasFocus() { |
535 JNIEnv* env = AttachCurrentThread(); | 538 JNIEnv* env = AttachCurrentThread(); |
536 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 539 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
537 if (obj.is_null()) | 540 if (obj.is_null()) |
538 return false; | 541 return false; |
539 return Java_ContentViewCore_hasFocus(env, obj.obj()); | 542 return Java_ContentViewCore_hasFocus(env, obj.obj()); |
540 } | 543 } |
541 | 544 |
542 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { | 545 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { |
543 JNIEnv* env = AttachCurrentThread(); | 546 JNIEnv* env = AttachCurrentThread(); |
(...skipping 345 matching lines...) Loading... |
889 | 892 |
890 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, | 893 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, |
891 jobject obj, | 894 jobject obj, |
892 jint orientation) { | 895 jint orientation) { |
893 if (device_orientation_ != orientation) { | 896 if (device_orientation_ != orientation) { |
894 device_orientation_ = orientation; | 897 device_orientation_ = orientation; |
895 SendOrientationChangeEventInternal(); | 898 SendOrientationChangeEventInternal(); |
896 } | 899 } |
897 } | 900 } |
898 | 901 |
899 jboolean ContentViewCoreImpl::SendTouchEvent(JNIEnv* env, | 902 void ContentViewCoreImpl::OnTouchEventHandlingBegin(JNIEnv* env, |
900 jobject obj, | 903 jobject obj, |
901 jlong time_ms, | 904 jlong time_ms, |
902 jint type, | 905 jint type, |
903 jobjectArray pts) { | 906 jobjectArray pts) { |
| 907 DCHECK(!handling_touch_event_); |
| 908 handling_touch_event_ = true; |
| 909 |
| 910 blink::WebTouchEvent event; |
| 911 TouchPoint::BuildWebTouchEvent(env, type, time_ms, GetDpiScale(), pts, event); |
| 912 pending_touch_event_ = event; |
| 913 |
| 914 pending_gesture_packet_ = GestureEventPacket::FromTouch(event); |
| 915 } |
| 916 |
| 917 void ContentViewCoreImpl::OnTouchEventHandlingEnd(JNIEnv* env, jobject obj) { |
| 918 DCHECK(handling_touch_event_); |
| 919 handling_touch_event_ = false; |
| 920 |
| 921 gesture_event_queue_->OnGestureEventPacket(pending_gesture_packet_); |
| 922 |
904 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 923 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
905 if (rwhv) { | 924 if (rwhv) |
906 using blink::WebTouchEvent; | 925 rwhv->SendTouchEvent(pending_touch_event_); |
907 blink::WebTouchEvent event; | |
908 TouchPoint::BuildWebTouchEvent(env, type, time_ms, GetDpiScale(), pts, | |
909 event); | |
910 rwhv->SendTouchEvent(event); | |
911 return true; | |
912 } | |
913 return false; | |
914 } | 926 } |
915 | 927 |
916 float ContentViewCoreImpl::GetTouchPaddingDip() { | 928 float ContentViewCoreImpl::GetTouchPaddingDip() { |
917 return 48.0f / GetDpiScale(); | 929 return 48.0f / GetDpiScale(); |
918 } | 930 } |
919 | 931 |
920 float ContentViewCoreImpl::GetDpiScale() const { | 932 float ContentViewCoreImpl::GetDpiScale() const { |
921 return dpi_scale_; | 933 return dpi_scale_; |
922 } | 934 } |
923 | 935 |
(...skipping 49 matching lines...) Loading... |
973 } | 985 } |
974 | 986 |
975 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( | 987 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( |
976 WebInputEvent::Type type, int64 time_ms, float x, float y) const { | 988 WebInputEvent::Type type, int64 time_ms, float x, float y) const { |
977 return WebGestureEventBuilder::Build( | 989 return WebGestureEventBuilder::Build( |
978 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); | 990 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); |
979 } | 991 } |
980 | 992 |
981 void ContentViewCoreImpl::SendGestureEvent( | 993 void ContentViewCoreImpl::SendGestureEvent( |
982 const blink::WebGestureEvent& event) { | 994 const blink::WebGestureEvent& event) { |
983 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 995 if (handling_touch_event_) { |
984 if (rwhv) | 996 pending_gesture_packet_.Push(event); |
985 rwhv->SendGestureEvent(event); | 997 return; |
| 998 } |
| 999 gesture_event_queue_->OnGestureEventPacket( |
| 1000 GestureEventPacket::FromGesture(event)); |
986 } | 1001 } |
987 | 1002 |
988 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, | 1003 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, |
989 jobject obj, | 1004 jobject obj, |
990 jlong time_ms, | 1005 jlong time_ms, |
991 jfloat x, | 1006 jfloat x, |
992 jfloat y, | 1007 jfloat y, |
993 jfloat hintx, | 1008 jfloat hintx, |
994 jfloat hinty) { | 1009 jfloat hinty) { |
995 WebGestureEvent event = MakeGestureEvent( | 1010 WebGestureEvent event = MakeGestureEvent( |
(...skipping 686 matching lines...) Loading... |
1682 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1697 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1683 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1698 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1684 return reinterpret_cast<intptr_t>(view); | 1699 return reinterpret_cast<intptr_t>(view); |
1685 } | 1700 } |
1686 | 1701 |
1687 bool RegisterContentViewCore(JNIEnv* env) { | 1702 bool RegisterContentViewCore(JNIEnv* env) { |
1688 return RegisterNativesImpl(env); | 1703 return RegisterNativesImpl(env); |
1689 } | 1704 } |
1690 | 1705 |
1691 } // namespace content | 1706 } // namespace content |
OLD | NEW |