| 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 222 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 223 page_scale_(1), | 223 page_scale_(1), |
| 224 dpi_scale_(ui::GetScaleFactorForNativeView(&view_)), | 224 dpi_scale_(ui::GetScaleFactorForNativeView(&view_)), |
| 225 device_orientation_(0), | 225 device_orientation_(0), |
| 226 accessibility_enabled_(false) { | 226 accessibility_enabled_(false) { |
| 227 CHECK(web_contents) << | 227 CHECK(web_contents) << |
| 228 "A ContentViewCoreImpl should be created with a valid WebContents."; | 228 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 229 DCHECK(window_android); | 229 DCHECK(window_android); |
| 230 DCHECK(!view_android_delegate.is_null()); | 230 DCHECK(!view_android_delegate.is_null()); |
| 231 window_android->AddChild(&view_); | 231 window_android->AddChild(&view_); |
| 232 view_.SetLayer(cc::SolidColorLayer::Create()); | 232 view_.SetLayer(cc::Layer::Create()); |
| 233 view_.GetLayer()->SetBackgroundColor(GetBackgroundColor(env, obj)); | |
| 234 gfx::Size physical_size( | 233 gfx::Size physical_size( |
| 235 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 234 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 236 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 235 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 237 view_.GetLayer()->SetBounds(physical_size); | 236 view_.GetLayer()->SetBounds(physical_size); |
| 238 view_.GetLayer()->SetIsDrawable(true); | |
| 239 | 237 |
| 240 // Currently, the only use case we have for overriding a user agent involves | 238 // Currently, the only use case we have for overriding a user agent involves |
| 241 // spoofing a desktop Linux user agent for "Request desktop site". | 239 // spoofing a desktop Linux user agent for "Request desktop site". |
| 242 // Automatically set it for all WebContents so that it is available when a | 240 // Automatically set it for all WebContents so that it is available when a |
| 243 // NavigationEntry requires the user agent to be overridden. | 241 // NavigationEntry requires the user agent to be overridden. |
| 244 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 242 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
| 245 std::string product = content::GetContentClient()->GetProduct(); | 243 std::string product = content::GetContentClient()->GetProduct(); |
| 246 std::string spoofed_ua = | 244 std::string spoofed_ua = |
| 247 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 245 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
| 248 web_contents->SetUserAgentOverride(spoofed_ua); | 246 web_contents->SetUserAgentOverride(spoofed_ua); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 JNIEnv* env = AttachCurrentThread(); | 475 JNIEnv* env = AttachCurrentThread(); |
| 478 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 476 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 479 if (obj.is_null()) | 477 if (obj.is_null()) |
| 480 return; | 478 return; |
| 481 ScopedJavaLocalRef<jstring> jtitle = | 479 ScopedJavaLocalRef<jstring> jtitle = |
| 482 ConvertUTF8ToJavaString(env, base::UTF16ToUTF8(title)); | 480 ConvertUTF8ToJavaString(env, base::UTF16ToUTF8(title)); |
| 483 Java_ContentViewCore_setTitle(env, obj.obj(), jtitle.obj()); | 481 Java_ContentViewCore_setTitle(env, obj.obj(), jtitle.obj()); |
| 484 } | 482 } |
| 485 | 483 |
| 486 void ContentViewCoreImpl::OnBackgroundColorChanged(SkColor color) { | 484 void ContentViewCoreImpl::OnBackgroundColorChanged(SkColor color) { |
| 487 view_.GetLayer()->SetBackgroundColor(color); | |
| 488 | |
| 489 JNIEnv* env = AttachCurrentThread(); | 485 JNIEnv* env = AttachCurrentThread(); |
| 490 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 486 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 491 if (obj.is_null()) | 487 if (obj.is_null()) |
| 492 return; | 488 return; |
| 493 Java_ContentViewCore_onBackgroundColorChanged(env, obj.obj(), color); | 489 Java_ContentViewCore_onBackgroundColorChanged(env, obj.obj(), color); |
| 494 } | 490 } |
| 495 | 491 |
| 496 void ContentViewCoreImpl::ShowSelectPopupMenu( | 492 void ContentViewCoreImpl::ShowSelectPopupMenu( |
| 497 RenderFrameHost* frame, | 493 RenderFrameHost* frame, |
| 498 const gfx::Rect& bounds, | 494 const gfx::Rect& bounds, |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 822 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 827 if (j_obj.is_null()) | 823 if (j_obj.is_null()) |
| 828 return false; | 824 return false; |
| 829 return Java_ContentViewCore_doTopControlsShrinkBlinkSize(env, j_obj.obj()); | 825 return Java_ContentViewCore_doTopControlsShrinkBlinkSize(env, j_obj.obj()); |
| 830 } | 826 } |
| 831 | 827 |
| 832 float ContentViewCoreImpl::GetTopControlsHeightDip() const { | 828 float ContentViewCoreImpl::GetTopControlsHeightDip() const { |
| 833 return GetTopControlsHeightPix() / dpi_scale(); | 829 return GetTopControlsHeightPix() / dpi_scale(); |
| 834 } | 830 } |
| 835 | 831 |
| 836 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { | |
| 837 view_.GetLayer()->InsertChild(layer, 0); | |
| 838 view_.GetLayer()->SetIsDrawable(false); | |
| 839 } | |
| 840 | |
| 841 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { | |
| 842 layer->RemoveFromParent(); | |
| 843 | |
| 844 if (view_.GetLayer()->children().empty()) | |
| 845 view_.GetLayer()->SetIsDrawable(true); | |
| 846 } | |
| 847 | |
| 848 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) { | 832 void ContentViewCoreImpl::MoveRangeSelectionExtent(const gfx::PointF& extent) { |
| 849 if (!web_contents_) | 833 if (!web_contents_) |
| 850 return; | 834 return; |
| 851 | 835 |
| 852 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); | 836 web_contents_->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); |
| 853 } | 837 } |
| 854 | 838 |
| 855 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base, | 839 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& base, |
| 856 const gfx::PointF& extent) { | 840 const gfx::PointF& extent) { |
| 857 if (!web_contents_) | 841 if (!web_contents_) |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1648 return ScopedJavaLocalRef<jobject>(); | 1632 return ScopedJavaLocalRef<jobject>(); |
| 1649 | 1633 |
| 1650 return view->GetJavaObject(); | 1634 return view->GetJavaObject(); |
| 1651 } | 1635 } |
| 1652 | 1636 |
| 1653 bool RegisterContentViewCore(JNIEnv* env) { | 1637 bool RegisterContentViewCore(JNIEnv* env) { |
| 1654 return RegisterNativesImpl(env) && JNI_DragEvent::RegisterNativesImpl(env); | 1638 return RegisterNativesImpl(env) && JNI_DragEvent::RegisterNativesImpl(env); |
| 1655 } | 1639 } |
| 1656 | 1640 |
| 1657 } // namespace content | 1641 } // namespace content |
| OLD | NEW |