OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/web_contents/web_contents_view_android.h" | 5 #include "content/browser/web_contents/web_contents_view_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/bind.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "cc/layers/layer.h" | 11 #include "cc/layers/layer.h" |
11 #include "content/browser/android/content_view_core_impl.h" | 12 #include "content/browser/android/content_view_core_impl.h" |
12 #include "content/browser/frame_host/interstitial_page_impl.h" | 13 #include "content/browser/frame_host/interstitial_page_impl.h" |
13 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 14 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
14 #include "content/browser/renderer_host/render_view_host_factory.h" | 15 #include "content/browser/renderer_host/render_view_host_factory.h" |
15 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
16 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
17 #include "content/public/browser/render_widget_host.h" | 18 #include "content/public/browser/render_widget_host.h" |
18 #include "content/public/browser/web_contents_delegate.h" | 19 #include "content/public/browser/web_contents_delegate.h" |
19 #include "content/public/common/drop_data.h" | 20 #include "content/public/common/drop_data.h" |
20 #include "ui/display/screen.h" | 21 #include "ui/display/screen.h" |
21 #include "ui/gfx/android/device_display_info.h" | 22 #include "ui/gfx/android/device_display_info.h" |
22 #include "ui/gfx/android/java_bitmap.h" | 23 #include "ui/gfx/android/java_bitmap.h" |
23 #include "ui/gfx/image/image_skia.h" | 24 #include "ui/gfx/image/image_skia.h" |
24 | 25 |
| 26 using base::Bind; |
| 27 using base::Unretained; |
25 using base::android::AttachCurrentThread; | 28 using base::android::AttachCurrentThread; |
26 using base::android::ConvertUTF16ToJavaString; | 29 using base::android::ConvertUTF16ToJavaString; |
27 using base::android::JavaRef; | 30 using base::android::JavaRef; |
28 using base::android::ScopedJavaLocalRef; | 31 using base::android::ScopedJavaLocalRef; |
29 | 32 |
30 namespace content { | 33 namespace content { |
31 | 34 |
32 // static | 35 // static |
33 void WebContentsView::GetDefaultScreenInfo(ScreenInfo* results) { | 36 void WebContentsView::GetDefaultScreenInfo(ScreenInfo* results) { |
34 const display::Display& display = | 37 const display::Display& display = |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 WebContentsViewDelegate* delegate) | 80 WebContentsViewDelegate* delegate) |
78 : web_contents_(web_contents), | 81 : web_contents_(web_contents), |
79 content_view_core_(NULL), | 82 content_view_core_(NULL), |
80 delegate_(delegate), | 83 delegate_(delegate), |
81 synchronous_compositor_client_(nullptr) { | 84 synchronous_compositor_client_(nullptr) { |
82 } | 85 } |
83 | 86 |
84 WebContentsViewAndroid::~WebContentsViewAndroid() { | 87 WebContentsViewAndroid::~WebContentsViewAndroid() { |
85 if (view_.GetLayer()) | 88 if (view_.GetLayer()) |
86 view_.GetLayer()->RemoveFromParent(); | 89 view_.GetLayer()->RemoveFromParent(); |
| 90 view_.reset_physical_backing_size_changed_handler(); |
87 } | 91 } |
88 | 92 |
89 void WebContentsViewAndroid::SetContentViewCore( | 93 void WebContentsViewAndroid::SetContentViewCore( |
90 ContentViewCoreImpl* content_view_core) { | 94 ContentViewCoreImpl* content_view_core) { |
91 content_view_core_ = content_view_core; | 95 content_view_core_ = content_view_core; |
92 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 96 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
93 web_contents_->GetRenderWidgetHostView()); | 97 web_contents_->GetRenderWidgetHostView()); |
94 if (rwhv) | 98 if (rwhv) |
95 rwhv->SetContentViewCore(content_view_core_); | 99 rwhv->SetContentViewCore(content_view_core_); |
96 | 100 |
97 if (web_contents_->ShowingInterstitialPage()) { | 101 if (web_contents_->ShowingInterstitialPage()) { |
98 rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 102 rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
99 web_contents_->GetInterstitialPage() | 103 web_contents_->GetInterstitialPage() |
100 ->GetMainFrame() | 104 ->GetMainFrame() |
101 ->GetRenderViewHost() | 105 ->GetRenderViewHost() |
102 ->GetWidget() | 106 ->GetWidget() |
103 ->GetView()); | 107 ->GetView()); |
104 if (rwhv) | 108 if (rwhv) |
105 rwhv->SetContentViewCore(content_view_core_); | 109 rwhv->SetContentViewCore(content_view_core_); |
106 } | 110 } |
| 111 |
| 112 view_.reset_physical_backing_size_changed_handler( |
| 113 Bind(&WebContentsViewAndroid::OnPhysicalBackingSizeChanged, |
| 114 Unretained(this))); |
| 115 } |
| 116 |
| 117 void WebContentsViewAndroid::OnPhysicalBackingSizeChanged(int width, |
| 118 int height) { |
| 119 gfx::Size physical_size(width, height); |
| 120 view_.GetLayer()->SetBounds(physical_size); |
| 121 |
| 122 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 123 web_contents_->GetRenderWidgetHostView()); |
| 124 if (rwhv) { |
| 125 web_contents_->SendScreenRects(); |
| 126 rwhv->WasResized(); |
| 127 } |
107 } | 128 } |
108 | 129 |
109 gfx::NativeView WebContentsViewAndroid::GetNativeView() const { | 130 gfx::NativeView WebContentsViewAndroid::GetNativeView() const { |
110 return const_cast<gfx::NativeView>(&view_); | 131 return const_cast<gfx::NativeView>(&view_); |
111 } | 132 } |
112 | 133 |
113 gfx::NativeView WebContentsViewAndroid::GetContentNativeView() const { | 134 gfx::NativeView WebContentsViewAndroid::GetContentNativeView() const { |
114 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); | 135 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); |
115 if (rwhv) | 136 if (rwhv) |
116 return rwhv->GetNativeView(); | 137 return rwhv->GetNativeView(); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 // This is called when we the renderer asks us to take focus back (i.e., it has | 369 // This is called when we the renderer asks us to take focus back (i.e., it has |
349 // iterated past the last focusable element on the page). | 370 // iterated past the last focusable element on the page). |
350 void WebContentsViewAndroid::TakeFocus(bool reverse) { | 371 void WebContentsViewAndroid::TakeFocus(bool reverse) { |
351 if (web_contents_->GetDelegate() && | 372 if (web_contents_->GetDelegate() && |
352 web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse)) | 373 web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse)) |
353 return; | 374 return; |
354 web_contents_->GetRenderWidgetHostView()->Focus(); | 375 web_contents_->GetRenderWidgetHostView()->Focus(); |
355 } | 376 } |
356 | 377 |
357 } // namespace content | 378 } // namespace content |
OLD | NEW |