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(content_offset); | 432 view_.GetWindowAndroid()->set_content_offset( |
| 433 gfx::Vector2dF(0.0f, top_controls_height * top_controls_shown_ratio)); |
431 | 434 |
432 page_scale_ = page_scale_factor; | 435 page_scale_ = page_scale_factor; |
433 | 436 |
434 // The CursorAnchorInfo API in Android only supports zero width selection | 437 // The CursorAnchorInfo API in Android only supports zero width selection |
435 // bounds. | 438 // bounds. |
436 const jboolean has_insertion_marker = | 439 const jboolean has_insertion_marker = |
437 selection_start.type() == gfx::SelectionBound::CENTER; | 440 selection_start.type() == gfx::SelectionBound::CENTER; |
438 const jboolean is_insertion_marker_visible = selection_start.visible(); | 441 const jboolean is_insertion_marker_visible = selection_start.visible(); |
439 const jfloat insertion_marker_horizontal = | 442 const jfloat insertion_marker_horizontal = |
440 has_insertion_marker ? selection_start.edge_top().x() : 0.0f; | 443 has_insertion_marker ? selection_start.edge_top().x() : 0.0f; |
441 const jfloat insertion_marker_top = | 444 const jfloat insertion_marker_top = |
442 has_insertion_marker ? selection_start.edge_top().y() : 0.0f; | 445 has_insertion_marker ? selection_start.edge_top().y() : 0.0f; |
443 const jfloat insertion_marker_bottom = | 446 const jfloat insertion_marker_bottom = |
444 has_insertion_marker ? selection_start.edge_bottom().y() : 0.0f; | 447 has_insertion_marker ? selection_start.edge_bottom().y() : 0.0f; |
445 | 448 |
446 Java_ContentViewCore_updateFrameInfo( | 449 Java_ContentViewCore_updateFrameInfo( |
447 env, obj, scroll_offset.x(), scroll_offset.y(), page_scale_factor, | 450 env, obj, scroll_offset.x(), scroll_offset.y(), page_scale_factor, |
448 page_scale_factor_limits.x(), page_scale_factor_limits.y(), | 451 page_scale_factor_limits.x(), page_scale_factor_limits.y(), |
449 content_size.width(), content_size.height(), viewport_size.width(), | 452 content_size.width(), content_size.height(), viewport_size.width(), |
450 viewport_size.height(), controls_offset.y(), content_offset.y(), | 453 viewport_size.height(), top_controls_height, top_controls_shown_ratio, |
| 454 bottom_controls_height, bottom_controls_shown_ratio, |
451 is_mobile_optimized_hint, has_insertion_marker, | 455 is_mobile_optimized_hint, has_insertion_marker, |
452 is_insertion_marker_visible, insertion_marker_horizontal, | 456 is_insertion_marker_visible, insertion_marker_horizontal, |
453 insertion_marker_top, insertion_marker_bottom); | 457 insertion_marker_top, insertion_marker_bottom); |
454 } | 458 } |
455 | 459 |
456 void ContentViewCoreImpl::SetTitle(const base::string16& title) { | 460 void ContentViewCoreImpl::SetTitle(const base::string16& title) { |
457 JNIEnv* env = AttachCurrentThread(); | 461 JNIEnv* env = AttachCurrentThread(); |
458 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 462 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
459 if (obj.is_null()) | 463 if (obj.is_null()) |
460 return; | 464 return; |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 | 754 |
751 gfx::Size size_dip = gfx::ScaleToCeiledSize(size_pix, 1.0f / dpi_scale()); | 755 gfx::Size size_dip = gfx::ScaleToCeiledSize(size_pix, 1.0f / dpi_scale()); |
752 if (DoTopControlsShrinkBlinkSize()) | 756 if (DoTopControlsShrinkBlinkSize()) |
753 size_dip.Enlarge(0, -GetTopControlsHeightDip()); | 757 size_dip.Enlarge(0, -GetTopControlsHeightDip()); |
754 return size_dip; | 758 return size_dip; |
755 } | 759 } |
756 | 760 |
757 gfx::Size ContentViewCoreImpl::GetViewSize() const { | 761 gfx::Size ContentViewCoreImpl::GetViewSize() const { |
758 gfx::Size size = GetViewportSizeDip(); | 762 gfx::Size size = GetViewportSizeDip(); |
759 if (DoTopControlsShrinkBlinkSize()) | 763 if (DoTopControlsShrinkBlinkSize()) |
760 size.Enlarge(0, -GetTopControlsHeightDip()); | 764 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip()); |
761 return size; | 765 return size; |
762 } | 766 } |
763 | 767 |
764 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { | 768 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { |
765 JNIEnv* env = AttachCurrentThread(); | 769 JNIEnv* env = AttachCurrentThread(); |
766 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 770 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
767 if (j_obj.is_null()) | 771 if (j_obj.is_null()) |
768 return gfx::Size(); | 772 return gfx::Size(); |
769 return gfx::Size( | 773 return gfx::Size( |
770 Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj), | 774 Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj), |
(...skipping 10 matching lines...) Expand all Loading... |
781 } | 785 } |
782 | 786 |
783 int ContentViewCoreImpl::GetTopControlsHeightPix() const { | 787 int ContentViewCoreImpl::GetTopControlsHeightPix() const { |
784 JNIEnv* env = AttachCurrentThread(); | 788 JNIEnv* env = AttachCurrentThread(); |
785 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 789 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
786 if (j_obj.is_null()) | 790 if (j_obj.is_null()) |
787 return 0; | 791 return 0; |
788 return Java_ContentViewCore_getTopControlsHeightPix(env, j_obj); | 792 return Java_ContentViewCore_getTopControlsHeightPix(env, j_obj); |
789 } | 793 } |
790 | 794 |
| 795 int ContentViewCoreImpl::GetBottomControlsHeightPix() const { |
| 796 JNIEnv* env = AttachCurrentThread(); |
| 797 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 798 if (j_obj.is_null()) |
| 799 return 0; |
| 800 return Java_ContentViewCore_getBottomControlsHeightPix(env, j_obj.obj()); |
| 801 } |
| 802 |
791 gfx::Size ContentViewCoreImpl::GetViewportSizeDip() const { | 803 gfx::Size ContentViewCoreImpl::GetViewportSizeDip() const { |
792 return gfx::ScaleToCeiledSize(GetViewportSizePix(), 1.0f / dpi_scale()); | 804 return gfx::ScaleToCeiledSize(GetViewportSizePix(), 1.0f / dpi_scale()); |
793 } | 805 } |
794 | 806 |
795 bool ContentViewCoreImpl::DoTopControlsShrinkBlinkSize() const { | 807 bool ContentViewCoreImpl::DoTopControlsShrinkBlinkSize() const { |
796 JNIEnv* env = AttachCurrentThread(); | 808 JNIEnv* env = AttachCurrentThread(); |
797 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 809 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
798 if (j_obj.is_null()) | 810 if (j_obj.is_null()) |
799 return false; | 811 return false; |
800 return Java_ContentViewCore_doTopControlsShrinkBlinkSize(env, j_obj); | 812 return Java_ContentViewCore_doTopControlsShrinkBlinkSize(env, j_obj); |
801 } | 813 } |
802 | 814 |
803 float ContentViewCoreImpl::GetTopControlsHeightDip() const { | 815 float ContentViewCoreImpl::GetTopControlsHeightDip() const { |
804 return GetTopControlsHeightPix() / dpi_scale(); | 816 return GetTopControlsHeightPix() / dpi_scale(); |
805 } | 817 } |
806 | 818 |
| 819 float ContentViewCoreImpl::GetBottomControlsHeightDip() const { |
| 820 return GetBottomControlsHeightPix() / dpi_scale(); |
| 821 } |
| 822 |
807 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) { | 823 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) { |
808 if (!web_contents_) | 824 if (!web_contents_) |
809 return; | 825 return; |
810 | 826 |
811 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); | 827 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); |
812 } | 828 } |
813 | 829 |
814 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base, | 830 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base, |
815 const gfx::PointF& extent) { | 831 const gfx::PointF& extent) { |
816 if (!web_contents_) | 832 if (!web_contents_) |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 return ScopedJavaLocalRef<jobject>(); | 1603 return ScopedJavaLocalRef<jobject>(); |
1588 | 1604 |
1589 return view->GetJavaObject(); | 1605 return view->GetJavaObject(); |
1590 } | 1606 } |
1591 | 1607 |
1592 bool RegisterContentViewCore(JNIEnv* env) { | 1608 bool RegisterContentViewCore(JNIEnv* env) { |
1593 return RegisterNativesImpl(env); | 1609 return RegisterNativesImpl(env); |
1594 } | 1610 } |
1595 | 1611 |
1596 } // namespace content | 1612 } // namespace content |
OLD | NEW |