| 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // All positions and sizes are in CSS pixels. | 372 // All positions and sizes are in CSS pixels. |
| 373 // Note that viewport_width/height is a best effort based. | 373 // Note that viewport_width/height is a best effort based. |
| 374 // ContentViewCore has the actual information about the physical viewport size. | 374 // ContentViewCore has the actual information about the physical viewport size. |
| 375 void ContentViewCoreImpl::UpdateFrameInfo( | 375 void ContentViewCoreImpl::UpdateFrameInfo( |
| 376 const gfx::Vector2dF& scroll_offset, | 376 const gfx::Vector2dF& scroll_offset, |
| 377 float page_scale_factor, | 377 float page_scale_factor, |
| 378 const gfx::Vector2dF& page_scale_factor_limits, | 378 const gfx::Vector2dF& page_scale_factor_limits, |
| 379 const gfx::SizeF& content_size, | 379 const gfx::SizeF& content_size, |
| 380 const gfx::SizeF& viewport_size, | 380 const gfx::SizeF& viewport_size, |
| 381 const gfx::Vector2dF& controls_offset, | 381 const gfx::Vector2dF& controls_offset, |
| 382 const gfx::Vector2dF& content_offset, | 382 const gfx::Vector2dF& content_offset) { |
| 383 float overdraw_bottom_height) { | |
| 384 JNIEnv* env = AttachCurrentThread(); | 383 JNIEnv* env = AttachCurrentThread(); |
| 385 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 384 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 386 if (obj.is_null()) | 385 if (obj.is_null()) |
| 387 return; | 386 return; |
| 388 | 387 |
| 389 window_android_->set_content_offset( | 388 window_android_->set_content_offset( |
| 390 gfx::ScaleVector2d(content_offset, dpi_scale_)); | 389 gfx::ScaleVector2d(content_offset, dpi_scale_)); |
| 391 | 390 |
| 392 Java_ContentViewCore_updateFrameInfo( | 391 Java_ContentViewCore_updateFrameInfo( |
| 393 env, obj.obj(), | 392 env, obj.obj(), |
| 394 scroll_offset.x(), | 393 scroll_offset.x(), |
| 395 scroll_offset.y(), | 394 scroll_offset.y(), |
| 396 page_scale_factor, | 395 page_scale_factor, |
| 397 page_scale_factor_limits.x(), | 396 page_scale_factor_limits.x(), |
| 398 page_scale_factor_limits.y(), | 397 page_scale_factor_limits.y(), |
| 399 content_size.width(), | 398 content_size.width(), |
| 400 content_size.height(), | 399 content_size.height(), |
| 401 viewport_size.width(), | 400 viewport_size.width(), |
| 402 viewport_size.height(), | 401 viewport_size.height(), |
| 403 controls_offset.y(), | 402 controls_offset.y(), |
| 404 content_offset.y(), | 403 content_offset.y()); |
| 405 overdraw_bottom_height); | |
| 406 } | 404 } |
| 407 | 405 |
| 408 void ContentViewCoreImpl::SetTitle(const base::string16& title) { | 406 void ContentViewCoreImpl::SetTitle(const base::string16& title) { |
| 409 JNIEnv* env = AttachCurrentThread(); | 407 JNIEnv* env = AttachCurrentThread(); |
| 410 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 408 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 411 if (obj.is_null()) | 409 if (obj.is_null()) |
| 412 return; | 410 return; |
| 413 ScopedJavaLocalRef<jstring> jtitle = | 411 ScopedJavaLocalRef<jstring> jtitle = |
| 414 ConvertUTF8ToJavaString(env, base::UTF16ToUTF8(title)); | 412 ConvertUTF8ToJavaString(env, base::UTF16ToUTF8(title)); |
| 415 Java_ContentViewCore_setTitle(env, obj.obj(), jtitle.obj()); | 413 Java_ContentViewCore_setTitle(env, obj.obj(), jtitle.obj()); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 void ContentViewCoreImpl::DidStopFlinging() { | 714 void ContentViewCoreImpl::DidStopFlinging() { |
| 717 JNIEnv* env = AttachCurrentThread(); | 715 JNIEnv* env = AttachCurrentThread(); |
| 718 | 716 |
| 719 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 717 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 720 if (!obj.is_null()) | 718 if (!obj.is_null()) |
| 721 Java_ContentViewCore_onNativeFlingStopped(env, obj.obj()); | 719 Java_ContentViewCore_onNativeFlingStopped(env, obj.obj()); |
| 722 } | 720 } |
| 723 | 721 |
| 724 gfx::Size ContentViewCoreImpl::GetViewSize() const { | 722 gfx::Size ContentViewCoreImpl::GetViewSize() const { |
| 725 gfx::Size size = GetViewportSizeDip(); | 723 gfx::Size size = GetViewportSizeDip(); |
| 726 gfx::Size offset = GetViewportSizeOffsetDip(); | 724 size.Enlarge(0, -GetTopControlsLayoutHeightDip()); |
| 727 size.Enlarge(-offset.width(), -offset.height()); | |
| 728 return size; | 725 return size; |
| 729 } | 726 } |
| 730 | 727 |
| 731 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { | 728 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { |
| 732 JNIEnv* env = AttachCurrentThread(); | 729 JNIEnv* env = AttachCurrentThread(); |
| 733 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 730 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 734 if (j_obj.is_null()) | 731 if (j_obj.is_null()) |
| 735 return gfx::Size(); | 732 return gfx::Size(); |
| 736 return gfx::Size( | 733 return gfx::Size( |
| 737 Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj.obj()), | 734 Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj.obj()), |
| 738 Java_ContentViewCore_getPhysicalBackingHeightPix(env, j_obj.obj())); | 735 Java_ContentViewCore_getPhysicalBackingHeightPix(env, j_obj.obj())); |
| 739 } | 736 } |
| 740 | 737 |
| 741 gfx::Size ContentViewCoreImpl::GetViewportSizePix() const { | 738 gfx::Size ContentViewCoreImpl::GetViewportSizePix() const { |
| 742 JNIEnv* env = AttachCurrentThread(); | 739 JNIEnv* env = AttachCurrentThread(); |
| 743 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 740 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 744 if (j_obj.is_null()) | 741 if (j_obj.is_null()) |
| 745 return gfx::Size(); | 742 return gfx::Size(); |
| 746 return gfx::Size( | 743 return gfx::Size( |
| 747 Java_ContentViewCore_getViewportWidthPix(env, j_obj.obj()), | 744 Java_ContentViewCore_getViewportWidthPix(env, j_obj.obj()), |
| 748 Java_ContentViewCore_getViewportHeightPix(env, j_obj.obj())); | 745 Java_ContentViewCore_getViewportHeightPix(env, j_obj.obj())); |
| 749 } | 746 } |
| 750 | 747 |
| 751 gfx::Size ContentViewCoreImpl::GetViewportSizeOffsetPix() const { | 748 int ContentViewCoreImpl::GetTopControlsLayoutHeightPix() const { |
| 752 JNIEnv* env = AttachCurrentThread(); | 749 JNIEnv* env = AttachCurrentThread(); |
| 753 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 750 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 754 if (j_obj.is_null()) | 751 if (j_obj.is_null()) |
| 755 return gfx::Size(); | 752 return 0; |
| 756 return gfx::Size( | 753 return Java_ContentViewCore_getTopControlsLayoutHeightPix(env, j_obj.obj()); |
| 757 Java_ContentViewCore_getViewportSizeOffsetWidthPix(env, j_obj.obj()), | |
| 758 Java_ContentViewCore_getViewportSizeOffsetHeightPix(env, j_obj.obj())); | |
| 759 } | 754 } |
| 760 | 755 |
| 761 gfx::Size ContentViewCoreImpl::GetViewportSizeDip() const { | 756 gfx::Size ContentViewCoreImpl::GetViewportSizeDip() const { |
| 762 return gfx::ToCeiledSize( | 757 return gfx::ToCeiledSize( |
| 763 gfx::ScaleSize(GetViewportSizePix(), 1.0f / dpi_scale())); | 758 gfx::ScaleSize(GetViewportSizePix(), 1.0f / dpi_scale())); |
| 764 } | 759 } |
| 765 | 760 |
| 766 gfx::Size ContentViewCoreImpl::GetViewportSizeOffsetDip() const { | 761 float ContentViewCoreImpl::GetTopControlsLayoutHeightDip() const { |
| 767 return gfx::ToCeiledSize( | 762 return GetTopControlsLayoutHeightPix() / dpi_scale(); |
| 768 gfx::ScaleSize(GetViewportSizeOffsetPix(), 1.0f / dpi_scale())); | |
| 769 } | |
| 770 | |
| 771 float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const { | |
| 772 JNIEnv* env = AttachCurrentThread(); | |
| 773 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | |
| 774 if (j_obj.is_null()) | |
| 775 return 0.f; | |
| 776 return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj()) | |
| 777 / dpi_scale(); | |
| 778 } | 763 } |
| 779 | 764 |
| 780 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { | 765 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { |
| 781 root_layer_->InsertChild(layer, 0); | 766 root_layer_->InsertChild(layer, 0); |
| 782 root_layer_->SetIsDrawable(false); | 767 root_layer_->SetIsDrawable(false); |
| 783 } | 768 } |
| 784 | 769 |
| 785 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { | 770 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { |
| 786 layer->RemoveFromParent(); | 771 layer->RemoveFromParent(); |
| 787 | 772 |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1508 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1524 retained_objects_set); | 1509 retained_objects_set); |
| 1525 return reinterpret_cast<intptr_t>(view); | 1510 return reinterpret_cast<intptr_t>(view); |
| 1526 } | 1511 } |
| 1527 | 1512 |
| 1528 bool RegisterContentViewCore(JNIEnv* env) { | 1513 bool RegisterContentViewCore(JNIEnv* env) { |
| 1529 return RegisterNativesImpl(env); | 1514 return RegisterNativesImpl(env); |
| 1530 } | 1515 } |
| 1531 | 1516 |
| 1532 } // namespace content | 1517 } // namespace content |
| OLD | NEW |