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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // Currently, the only use case we have for overriding a user agent involves | 189 // Currently, the only use case we have for overriding a user agent involves |
190 // spoofing a desktop Linux user agent for "Request desktop site". | 190 // spoofing a desktop Linux user agent for "Request desktop site". |
191 // Automatically set it for all WebContents so that it is available when a | 191 // Automatically set it for all WebContents so that it is available when a |
192 // NavigationEntry requires the user agent to be overridden. | 192 // NavigationEntry requires the user agent to be overridden. |
193 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 193 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
194 std::string product = content::GetContentClient()->GetProduct(); | 194 std::string product = content::GetContentClient()->GetProduct(); |
195 std::string spoofed_ua = | 195 std::string spoofed_ua = |
196 webkit_glue::BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 196 webkit_glue::BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
197 web_contents->SetUserAgentOverride(spoofed_ua); | 197 web_contents->SetUserAgentOverride(spoofed_ua); |
198 | 198 |
| 199 touch_to_gesture_queue_.reset(new TouchToGestureQueue(this)); |
| 200 |
199 InitWebContents(); | 201 InitWebContents(); |
200 } | 202 } |
201 | 203 |
202 ContentViewCoreImpl::~ContentViewCoreImpl() { | 204 ContentViewCoreImpl::~ContentViewCoreImpl() { |
203 JNIEnv* env = base::android::AttachCurrentThread(); | 205 JNIEnv* env = base::android::AttachCurrentThread(); |
204 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 206 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
205 java_ref_.reset(); | 207 java_ref_.reset(); |
206 if (!j_obj.is_null()) { | 208 if (!j_obj.is_null()) { |
207 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 209 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
208 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); | 210 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after 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::ForwardTouchEvent( |
| 310 const blink::WebTouchEvent& event) { |
| 311 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 312 if (!rwhv) |
| 313 return; |
| 314 rwhv->SendTouchEvent(event); |
| 315 } |
| 316 |
| 317 void ContentViewCoreImpl::ForwardGestureEvent( |
| 318 const blink::WebGestureEvent& event) { |
| 319 JNIEnv* env = AttachCurrentThread(); |
| 320 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 321 if (j_obj.is_null()) |
| 322 return; |
| 323 |
| 324 if (Java_ContentViewCore_filterGesture( |
| 325 env, j_obj.obj(), event.type, event.x, event.y)) |
| 326 return; |
| 327 |
| 328 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
| 329 if (!rwhva) |
| 330 return; |
| 331 |
| 332 rwhva->SendGestureEvent(event); |
| 333 } |
| 334 |
307 RenderWidgetHostViewAndroid* | 335 RenderWidgetHostViewAndroid* |
308 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { | 336 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { |
309 RenderWidgetHostView* rwhv = NULL; | 337 RenderWidgetHostView* rwhv = NULL; |
310 if (web_contents_) { | 338 if (web_contents_) { |
311 rwhv = web_contents_->GetRenderWidgetHostView(); | 339 rwhv = web_contents_->GetRenderWidgetHostView(); |
312 if (web_contents_->ShowingInterstitialPage()) { | 340 if (web_contents_->ShowingInterstitialPage()) { |
313 rwhv = static_cast<InterstitialPageImpl*>( | 341 rwhv = static_cast<InterstitialPageImpl*>( |
314 web_contents_->GetInterstitialPage())-> | 342 web_contents_->GetInterstitialPage())-> |
315 GetRenderViewHost()->GetView(); | 343 GetRenderViewHost()->GetView(); |
316 } | 344 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 518 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
491 } | 519 } |
492 ScopedJavaLocalRef<jobjectArray> items_array( | 520 ScopedJavaLocalRef<jobjectArray> items_array( |
493 base::android::ToJavaArrayOfStrings(env, labels)); | 521 base::android::ToJavaArrayOfStrings(env, labels)); |
494 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), | 522 Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), |
495 items_array.obj(), enabled_array.obj(), | 523 items_array.obj(), enabled_array.obj(), |
496 multiple, selected_array.obj()); | 524 multiple, selected_array.obj()); |
497 } | 525 } |
498 | 526 |
499 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { | 527 void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { |
| 528 touch_to_gesture_queue_->OnTouchEventAck(ack_result); |
| 529 } |
| 530 |
| 531 void ContentViewCoreImpl::UnhandledFlingStartEvent(float vx, float vy) { |
500 JNIEnv* env = AttachCurrentThread(); | 532 JNIEnv* env = AttachCurrentThread(); |
501 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 533 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
502 if (j_obj.is_null()) | 534 if (j_obj.is_null()) |
503 return; | 535 return; |
504 Java_ContentViewCore_confirmTouchEvent(env, j_obj.obj(), | 536 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 } | 537 } |
515 | 538 |
516 void ContentViewCoreImpl::OnScrollUpdateGestureConsumed() { | 539 void ContentViewCoreImpl::OnScrollUpdateGestureConsumed() { |
517 JNIEnv* env = AttachCurrentThread(); | 540 JNIEnv* env = AttachCurrentThread(); |
518 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 541 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
519 if (j_obj.is_null()) | 542 if (j_obj.is_null()) |
520 return; | 543 return; |
521 Java_ContentViewCore_onScrollUpdateGestureConsumed(env, j_obj.obj()); | 544 Java_ContentViewCore_onScrollUpdateGestureConsumed(env, j_obj.obj()); |
522 } | 545 } |
523 | 546 |
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() { | 547 bool ContentViewCoreImpl::HasFocus() { |
535 JNIEnv* env = AttachCurrentThread(); | 548 JNIEnv* env = AttachCurrentThread(); |
536 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 549 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
537 if (obj.is_null()) | 550 if (obj.is_null()) |
538 return false; | 551 return false; |
539 return Java_ContentViewCore_hasFocus(env, obj.obj()); | 552 return Java_ContentViewCore_hasFocus(env, obj.obj()); |
540 } | 553 } |
541 | 554 |
542 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { | 555 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { |
543 JNIEnv* env = AttachCurrentThread(); | 556 JNIEnv* env = AttachCurrentThread(); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 | 902 |
890 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, | 903 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, |
891 jobject obj, | 904 jobject obj, |
892 jint orientation) { | 905 jint orientation) { |
893 if (device_orientation_ != orientation) { | 906 if (device_orientation_ != orientation) { |
894 device_orientation_ = orientation; | 907 device_orientation_ = orientation; |
895 SendOrientationChangeEventInternal(); | 908 SendOrientationChangeEventInternal(); |
896 } | 909 } |
897 } | 910 } |
898 | 911 |
899 jboolean ContentViewCoreImpl::SendTouchEvent(JNIEnv* env, | 912 void ContentViewCoreImpl::OnTouchEventHandlingBegin(JNIEnv* env, |
900 jobject obj, | 913 jobject obj, |
901 jlong time_ms, | 914 jlong time_ms, |
902 jint type, | 915 jint type, |
903 jobjectArray pts) { | 916 jobjectArray pts) { |
904 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 917 blink::WebTouchEvent event; |
905 if (rwhv) { | 918 TouchPoint::BuildWebTouchEvent(env, type, time_ms, GetDpiScale(), pts, event); |
906 using blink::WebTouchEvent; | 919 touch_to_gesture_queue_->OnTouchEventHandlingBegin(event); |
907 blink::WebTouchEvent event; | 920 } |
908 TouchPoint::BuildWebTouchEvent(env, type, time_ms, GetDpiScale(), pts, | 921 |
909 event); | 922 void ContentViewCoreImpl::OnTouchEventHandlingEnd(JNIEnv* env, jobject obj) { |
910 rwhv->SendTouchEvent(event); | 923 touch_to_gesture_queue_->OnTouchEventHandlingEnd(); |
911 return true; | |
912 } | |
913 return false; | |
914 } | 924 } |
915 | 925 |
916 float ContentViewCoreImpl::GetTouchPaddingDip() { | 926 float ContentViewCoreImpl::GetTouchPaddingDip() { |
917 return 48.0f / GetDpiScale(); | 927 return 48.0f / GetDpiScale(); |
918 } | 928 } |
919 | 929 |
920 float ContentViewCoreImpl::GetDpiScale() const { | 930 float ContentViewCoreImpl::GetDpiScale() const { |
921 return dpi_scale_; | 931 return dpi_scale_; |
922 } | 932 } |
923 | 933 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 } | 983 } |
974 | 984 |
975 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( | 985 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( |
976 WebInputEvent::Type type, int64 time_ms, float x, float y) const { | 986 WebInputEvent::Type type, int64 time_ms, float x, float y) const { |
977 return WebGestureEventBuilder::Build( | 987 return WebGestureEventBuilder::Build( |
978 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); | 988 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); |
979 } | 989 } |
980 | 990 |
981 void ContentViewCoreImpl::SendGestureEvent( | 991 void ContentViewCoreImpl::SendGestureEvent( |
982 const blink::WebGestureEvent& event) { | 992 const blink::WebGestureEvent& event) { |
983 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 993 touch_to_gesture_queue_->OnGestureEvent(event); |
984 if (rwhv) | |
985 rwhv->SendGestureEvent(event); | |
986 } | 994 } |
987 | 995 |
988 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, | 996 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, |
989 jobject obj, | 997 jobject obj, |
990 jlong time_ms, | 998 jlong time_ms, |
991 jfloat x, | 999 jfloat x, |
992 jfloat y, | 1000 jfloat y, |
993 jfloat hintx, | 1001 jfloat hintx, |
994 jfloat hinty) { | 1002 jfloat hinty) { |
995 WebGestureEvent event = MakeGestureEvent( | 1003 WebGestureEvent event = MakeGestureEvent( |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1690 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1683 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1691 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1684 return reinterpret_cast<intptr_t>(view); | 1692 return reinterpret_cast<intptr_t>(view); |
1685 } | 1693 } |
1686 | 1694 |
1687 bool RegisterContentViewCore(JNIEnv* env) { | 1695 bool RegisterContentViewCore(JNIEnv* env) { |
1688 return RegisterNativesImpl(env); | 1696 return RegisterNativesImpl(env); |
1689 } | 1697 } |
1690 | 1698 |
1691 } // namespace content | 1699 } // namespace content |
OLD | NEW |