| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 | 411 |
| 412 // All positions and sizes are in CSS pixels. | 412 // All positions and sizes are in CSS pixels. |
| 413 // Note that viewport_width/height is a best effort based. | 413 // Note that viewport_width/height is a best effort based. |
| 414 // ContentViewCore has the actual information about the physical viewport size. | 414 // ContentViewCore has the actual information about the physical viewport size. |
| 415 void ContentViewCoreImpl::UpdateFrameInfo( | 415 void ContentViewCoreImpl::UpdateFrameInfo( |
| 416 const gfx::Vector2dF& scroll_offset, | 416 const gfx::Vector2dF& scroll_offset, |
| 417 float page_scale_factor, | 417 float page_scale_factor, |
| 418 const gfx::Vector2dF& page_scale_factor_limits, | 418 const gfx::Vector2dF& page_scale_factor_limits, |
| 419 const gfx::SizeF& content_size, | 419 const gfx::SizeF& content_size, |
| 420 const gfx::SizeF& viewport_size, | 420 const gfx::SizeF& viewport_size, |
| 421 const gfx::Vector2dF& controls_offset, | 421 const float top_controls_height, |
| 422 const gfx::Vector2dF& content_offset, | 422 const float top_controls_shown_ratio, |
| 423 const float bottom_controls_height, |
| 424 const float bottom_controls_shown_ratio, |
| 423 bool is_mobile_optimized_hint, | 425 bool is_mobile_optimized_hint, |
| 424 const gfx::SelectionBound& selection_start) { | 426 const gfx::SelectionBound& selection_start) { |
| 425 JNIEnv* env = AttachCurrentThread(); | 427 JNIEnv* env = AttachCurrentThread(); |
| 426 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 428 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 427 if (obj.is_null() || !view_.GetWindowAndroid()) | 429 if (obj.is_null() || !view_.GetWindowAndroid()) |
| 428 return; | 430 return; |
| 429 | 431 |
| 430 view_.GetWindowAndroid()->set_content_offset( | 432 view_.GetWindowAndroid()->set_content_offset(gfx::ScaleVector2d( |
| 431 gfx::ScaleVector2d(content_offset, dpi_scale_)); | 433 gfx::Vector2dF(0.0f, top_controls_height * top_controls_shown_ratio), |
| 434 dpi_scale_)); |
| 432 | 435 |
| 433 page_scale_ = page_scale_factor; | 436 page_scale_ = page_scale_factor; |
| 434 | 437 |
| 435 // The CursorAnchorInfo API in Android only supports zero width selection | 438 // The CursorAnchorInfo API in Android only supports zero width selection |
| 436 // bounds. | 439 // bounds. |
| 437 const jboolean has_insertion_marker = | 440 const jboolean has_insertion_marker = |
| 438 selection_start.type() == gfx::SelectionBound::CENTER; | 441 selection_start.type() == gfx::SelectionBound::CENTER; |
| 439 const jboolean is_insertion_marker_visible = selection_start.visible(); | 442 const jboolean is_insertion_marker_visible = selection_start.visible(); |
| 440 const jfloat insertion_marker_horizontal = | 443 const jfloat insertion_marker_horizontal = |
| 441 has_insertion_marker ? selection_start.edge_top().x() : 0.0f; | 444 has_insertion_marker ? selection_start.edge_top().x() : 0.0f; |
| 442 const jfloat insertion_marker_top = | 445 const jfloat insertion_marker_top = |
| 443 has_insertion_marker ? selection_start.edge_top().y() : 0.0f; | 446 has_insertion_marker ? selection_start.edge_top().y() : 0.0f; |
| 444 const jfloat insertion_marker_bottom = | 447 const jfloat insertion_marker_bottom = |
| 445 has_insertion_marker ? selection_start.edge_bottom().y() : 0.0f; | 448 has_insertion_marker ? selection_start.edge_bottom().y() : 0.0f; |
| 446 | 449 |
| 447 Java_ContentViewCore_updateFrameInfo( | 450 Java_ContentViewCore_updateFrameInfo( |
| 448 env, obj, scroll_offset.x(), scroll_offset.y(), page_scale_factor, | 451 env, obj, scroll_offset.x(), scroll_offset.y(), page_scale_factor, |
| 449 page_scale_factor_limits.x(), page_scale_factor_limits.y(), | 452 page_scale_factor_limits.x(), page_scale_factor_limits.y(), |
| 450 content_size.width(), content_size.height(), viewport_size.width(), | 453 content_size.width(), content_size.height(), viewport_size.width(), |
| 451 viewport_size.height(), controls_offset.y(), content_offset.y(), | 454 viewport_size.height(), top_controls_height, top_controls_shown_ratio, |
| 455 bottom_controls_height, bottom_controls_shown_ratio, |
| 452 is_mobile_optimized_hint, has_insertion_marker, | 456 is_mobile_optimized_hint, has_insertion_marker, |
| 453 is_insertion_marker_visible, insertion_marker_horizontal, | 457 is_insertion_marker_visible, insertion_marker_horizontal, |
| 454 insertion_marker_top, insertion_marker_bottom); | 458 insertion_marker_top, insertion_marker_bottom); |
| 455 } | 459 } |
| 456 | 460 |
| 457 void ContentViewCoreImpl::SetTitle(const base::string16& title) { | 461 void ContentViewCoreImpl::SetTitle(const base::string16& title) { |
| 458 JNIEnv* env = AttachCurrentThread(); | 462 JNIEnv* env = AttachCurrentThread(); |
| 459 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 463 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 460 if (obj.is_null()) | 464 if (obj.is_null()) |
| 461 return; | 465 return; |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 | 755 |
| 752 gfx::Size size_dip = gfx::ScaleToCeiledSize(size_pix, 1.0f / dpi_scale()); | 756 gfx::Size size_dip = gfx::ScaleToCeiledSize(size_pix, 1.0f / dpi_scale()); |
| 753 if (DoTopControlsShrinkBlinkSize()) | 757 if (DoTopControlsShrinkBlinkSize()) |
| 754 size_dip.Enlarge(0, -GetTopControlsHeightDip()); | 758 size_dip.Enlarge(0, -GetTopControlsHeightDip()); |
| 755 return size_dip; | 759 return size_dip; |
| 756 } | 760 } |
| 757 | 761 |
| 758 gfx::Size ContentViewCoreImpl::GetViewSize() const { | 762 gfx::Size ContentViewCoreImpl::GetViewSize() const { |
| 759 gfx::Size size = GetViewportSizeDip(); | 763 gfx::Size size = GetViewportSizeDip(); |
| 760 if (DoTopControlsShrinkBlinkSize()) | 764 if (DoTopControlsShrinkBlinkSize()) |
| 761 size.Enlarge(0, -GetTopControlsHeightDip()); | 765 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip()); |
| 762 return size; | 766 return size; |
| 763 } | 767 } |
| 764 | 768 |
| 765 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { | 769 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { |
| 766 JNIEnv* env = AttachCurrentThread(); | 770 JNIEnv* env = AttachCurrentThread(); |
| 767 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 771 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 768 if (j_obj.is_null()) | 772 if (j_obj.is_null()) |
| 769 return gfx::Size(); | 773 return gfx::Size(); |
| 770 return gfx::Size( | 774 return gfx::Size( |
| 771 Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj), | 775 Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 782 } | 786 } |
| 783 | 787 |
| 784 int ContentViewCoreImpl::GetTopControlsHeightPix() const { | 788 int ContentViewCoreImpl::GetTopControlsHeightPix() const { |
| 785 JNIEnv* env = AttachCurrentThread(); | 789 JNIEnv* env = AttachCurrentThread(); |
| 786 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 790 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 787 if (j_obj.is_null()) | 791 if (j_obj.is_null()) |
| 788 return 0; | 792 return 0; |
| 789 return Java_ContentViewCore_getTopControlsHeightPix(env, j_obj); | 793 return Java_ContentViewCore_getTopControlsHeightPix(env, j_obj); |
| 790 } | 794 } |
| 791 | 795 |
| 796 int ContentViewCoreImpl::GetBottomControlsHeightPix() const { |
| 797 JNIEnv* env = AttachCurrentThread(); |
| 798 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 799 if (j_obj.is_null()) |
| 800 return 0; |
| 801 return Java_ContentViewCore_getBottomControlsHeightPix(env, j_obj.obj()); |
| 802 } |
| 803 |
| 792 gfx::Size ContentViewCoreImpl::GetViewportSizeDip() const { | 804 gfx::Size ContentViewCoreImpl::GetViewportSizeDip() const { |
| 793 return gfx::ScaleToCeiledSize(GetViewportSizePix(), 1.0f / dpi_scale()); | 805 return gfx::ScaleToCeiledSize(GetViewportSizePix(), 1.0f / dpi_scale()); |
| 794 } | 806 } |
| 795 | 807 |
| 796 bool ContentViewCoreImpl::DoTopControlsShrinkBlinkSize() const { | 808 bool ContentViewCoreImpl::DoTopControlsShrinkBlinkSize() const { |
| 797 JNIEnv* env = AttachCurrentThread(); | 809 JNIEnv* env = AttachCurrentThread(); |
| 798 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 810 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 799 if (j_obj.is_null()) | 811 if (j_obj.is_null()) |
| 800 return false; | 812 return false; |
| 801 return Java_ContentViewCore_doTopControlsShrinkBlinkSize(env, j_obj); | 813 return Java_ContentViewCore_doTopControlsShrinkBlinkSize(env, j_obj); |
| 802 } | 814 } |
| 803 | 815 |
| 804 float ContentViewCoreImpl::GetTopControlsHeightDip() const { | 816 float ContentViewCoreImpl::GetTopControlsHeightDip() const { |
| 805 return GetTopControlsHeightPix() / dpi_scale(); | 817 return GetTopControlsHeightPix() / dpi_scale(); |
| 806 } | 818 } |
| 807 | 819 |
| 820 float ContentViewCoreImpl::GetBottomControlsHeightDip() const { |
| 821 return GetBottomControlsHeightPix() / dpi_scale(); |
| 822 } |
| 823 |
| 808 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) { | 824 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) { |
| 809 if (!web_contents_) | 825 if (!web_contents_) |
| 810 return; | 826 return; |
| 811 | 827 |
| 812 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); | 828 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); |
| 813 } | 829 } |
| 814 | 830 |
| 815 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base, | 831 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base, |
| 816 const gfx::PointF& extent) { | 832 const gfx::PointF& extent) { |
| 817 if (!web_contents_) | 833 if (!web_contents_) |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 return ScopedJavaLocalRef<jobject>(); | 1604 return ScopedJavaLocalRef<jobject>(); |
| 1589 | 1605 |
| 1590 return view->GetJavaObject(); | 1606 return view->GetJavaObject(); |
| 1591 } | 1607 } |
| 1592 | 1608 |
| 1593 bool RegisterContentViewCore(JNIEnv* env) { | 1609 bool RegisterContentViewCore(JNIEnv* env) { |
| 1594 return RegisterNativesImpl(env); | 1610 return RegisterNativesImpl(env); |
| 1595 } | 1611 } |
| 1596 | 1612 |
| 1597 } // namespace content | 1613 } // namespace content |
| OLD | NEW |