Chromium Code Reviews| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
| 11 #include "content/browser/android/content_view_core_impl.h" | 11 #include "content/browser/android/content_view_core_impl.h" |
| 12 #include "content/browser/frame_host/interstitial_page_impl.h" | 12 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 13 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 13 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 14 #include "content/browser/renderer_host/render_view_host_factory.h" | 14 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 15 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 16 #include "content/browser/web_contents/web_contents_android.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 |
| 25 using base::android::AttachCurrentThread; | 26 using base::android::AttachCurrentThread; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 39 results->device_scale_factor = display.device_scale_factor(); | 40 results->device_scale_factor = display.device_scale_factor(); |
| 40 results->orientation_angle = display.RotationAsDegree(); | 41 results->orientation_angle = display.RotationAsDegree(); |
| 41 results->orientation_type = | 42 results->orientation_type = |
| 42 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 43 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
| 43 gfx::DeviceDisplayInfo info; | 44 gfx::DeviceDisplayInfo info; |
| 44 results->depth = display.color_depth(); | 45 results->depth = display.color_depth(); |
| 45 results->depth_per_component = display.depth_per_component(); | 46 results->depth_per_component = display.depth_per_component(); |
| 46 results->is_monochrome = display.is_monochrome(); | 47 results->is_monochrome = display.is_monochrome(); |
| 47 } | 48 } |
| 48 | 49 |
| 50 // static | |
| 51 void SynchronousCompositor::SetClientForWebContents( | |
| 52 WebContents* contents, | |
| 53 SynchronousCompositorClient* client) { | |
| 54 DCHECK(contents); | |
| 55 DCHECK(client); | |
| 56 WebContentsViewAndroid* wcva = static_cast<WebContentsViewAndroid*>( | |
| 57 static_cast<WebContentsImpl*>(contents)->GetView()); | |
| 58 DCHECK(!wcva->synchronous_compositor_client()); | |
| 59 wcva->set_synchronous_compositor_client(client); | |
| 60 } | |
| 61 | |
| 49 WebContentsView* CreateWebContentsView( | 62 WebContentsView* CreateWebContentsView( |
| 50 WebContentsImpl* web_contents, | 63 WebContentsImpl* web_contents, |
| 51 WebContentsViewDelegate* delegate, | 64 WebContentsViewDelegate* delegate, |
| 52 RenderViewHostDelegateView** render_view_host_delegate_view) { | 65 RenderViewHostDelegateView** render_view_host_delegate_view) { |
| 53 WebContentsViewAndroid* rv = new WebContentsViewAndroid( | 66 WebContentsViewAndroid* rv = new WebContentsViewAndroid( |
| 54 web_contents, delegate); | 67 web_contents, delegate); |
| 55 *render_view_host_delegate_view = rv; | 68 *render_view_host_delegate_view = rv; |
| 56 return rv; | 69 return rv; |
| 57 } | 70 } |
| 58 | 71 |
| 59 WebContentsViewAndroid::WebContentsViewAndroid( | 72 WebContentsViewAndroid::WebContentsViewAndroid( |
| 60 WebContentsImpl* web_contents, | 73 WebContentsImpl* web_contents, |
| 61 WebContentsViewDelegate* delegate) | 74 WebContentsViewDelegate* delegate) |
| 62 : web_contents_(web_contents), | 75 : web_contents_(web_contents), |
| 63 content_view_core_(NULL), | 76 content_view_core_(NULL), |
| 64 delegate_(delegate) { | 77 delegate_(delegate), |
| 78 synchronous_compositor_client_(nullptr) { | |
| 65 } | 79 } |
| 66 | 80 |
| 67 WebContentsViewAndroid::~WebContentsViewAndroid() { | 81 WebContentsViewAndroid::~WebContentsViewAndroid() { |
| 68 if (view_.GetLayer()) | 82 if (view_.GetLayer()) |
| 69 view_.GetLayer()->RemoveFromParent(); | 83 view_.GetLayer()->RemoveFromParent(); |
| 70 } | 84 } |
| 71 | 85 |
| 72 void WebContentsViewAndroid::SetContentViewCore( | 86 void WebContentsViewAndroid::SetContentViewCore( |
| 73 ContentViewCoreImpl* content_view_core) { | 87 ContentViewCoreImpl* content_view_core) { |
| 74 content_view_core_ = content_view_core; | 88 content_view_core_ = content_view_core; |
| 75 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 89 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 76 web_contents_->GetRenderWidgetHostView()); | 90 web_contents_->GetRenderWidgetHostView()); |
| 77 if (rwhv) | 91 if (rwhv) { |
| 78 rwhv->SetContentViewCore(content_view_core_); | 92 rwhv->SetContentViewCore(content_view_core); |
| 79 | 93 SetSynchronousCompositorClientFor(rwhv); |
|
boliu
2016/11/08 16:50:13
I don't think this needs to be tied to CVC events
Jinsuk Kim
2016/11/08 17:18:30
Good to know. Done.
| |
| 94 } | |
| 80 if (web_contents_->ShowingInterstitialPage()) { | 95 if (web_contents_->ShowingInterstitialPage()) { |
| 81 rwhv = static_cast<RenderWidgetHostViewAndroid*>( | 96 rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
| 82 web_contents_->GetInterstitialPage() | 97 web_contents_->GetInterstitialPage() |
| 83 ->GetMainFrame() | 98 ->GetMainFrame() |
| 84 ->GetRenderViewHost() | 99 ->GetRenderViewHost() |
| 85 ->GetWidget() | 100 ->GetWidget() |
| 86 ->GetView()); | 101 ->GetView()); |
| 87 if (rwhv) | 102 if (rwhv) { |
| 88 rwhv->SetContentViewCore(content_view_core_); | 103 rwhv->SetContentViewCore(content_view_core); |
| 104 SetSynchronousCompositorClientFor(rwhv); | |
| 105 } | |
| 89 } | 106 } |
| 90 } | 107 } |
| 91 | 108 |
| 109 void WebContentsViewAndroid::SetSynchronousCompositorClientFor( | |
| 110 RenderWidgetHostViewAndroid* rwhv) { | |
| 111 if (synchronous_compositor_client_) | |
|
boliu
2016/11/08 16:50:13
no need for this check
Jinsuk Kim
2016/11/08 17:18:30
Done. Inlined now that it became just one liner.
| |
| 112 rwhv->set_synchronous_compositor_client(synchronous_compositor_client_); | |
| 113 } | |
| 114 | |
| 92 gfx::NativeView WebContentsViewAndroid::GetNativeView() const { | 115 gfx::NativeView WebContentsViewAndroid::GetNativeView() const { |
| 93 return const_cast<gfx::NativeView>(&view_); | 116 return const_cast<gfx::NativeView>(&view_); |
| 94 } | 117 } |
| 95 | 118 |
| 96 gfx::NativeView WebContentsViewAndroid::GetContentNativeView() const { | 119 gfx::NativeView WebContentsViewAndroid::GetContentNativeView() const { |
| 97 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); | 120 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); |
| 98 if (rwhv) | 121 if (rwhv) |
| 99 return rwhv->GetNativeView(); | 122 return rwhv->GetNativeView(); |
| 100 | 123 |
| 101 // TODO(sievers): This should return null. | 124 // TODO(sievers): This should return null. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 122 } | 145 } |
| 123 | 146 |
| 124 void WebContentsViewAndroid::SizeContents(const gfx::Size& size) { | 147 void WebContentsViewAndroid::SizeContents(const gfx::Size& size) { |
| 125 // TODO(klobag): Do we need to do anything else? | 148 // TODO(klobag): Do we need to do anything else? |
| 126 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); | 149 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); |
| 127 if (rwhv) | 150 if (rwhv) |
| 128 rwhv->SetSize(size); | 151 rwhv->SetSize(size); |
| 129 } | 152 } |
| 130 | 153 |
| 131 void WebContentsViewAndroid::Focus() { | 154 void WebContentsViewAndroid::Focus() { |
| 132 if (web_contents_->ShowingInterstitialPage()) | 155 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( |
|
boliu
2016/11/08 16:50:13
unrelated change
Jinsuk Kim
2016/11/08 17:18:30
Oops.. reverted.
| |
| 156 web_contents_->GetRenderWidgetHostView()); | |
| 157 if (web_contents_->ShowingInterstitialPage()) { | |
| 133 web_contents_->GetInterstitialPage()->Focus(); | 158 web_contents_->GetInterstitialPage()->Focus(); |
| 134 else | 159 if (content_view_core_) |
| 135 web_contents_->GetRenderWidgetHostView()->Focus(); | 160 content_view_core_->ForceUpdateImeAdapter(rwhv->GetNativeImeAdapter()); |
| 161 } else { | |
| 162 rwhv->Focus(); | |
| 163 } | |
| 136 } | 164 } |
| 137 | 165 |
| 138 void WebContentsViewAndroid::SetInitialFocus() { | 166 void WebContentsViewAndroid::SetInitialFocus() { |
| 139 if (web_contents_->FocusLocationBarByDefault()) | 167 if (web_contents_->FocusLocationBarByDefault()) |
| 140 web_contents_->SetFocusToLocationBar(false); | 168 web_contents_->SetFocusToLocationBar(false); |
| 141 else | 169 else |
| 142 Focus(); | 170 Focus(); |
| 143 } | 171 } |
| 144 | 172 |
| 145 void WebContentsViewAndroid::StoreFocus() { | 173 void WebContentsViewAndroid::StoreFocus() { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 // This is called when we the renderer asks us to take focus back (i.e., it has | 351 // This is called when we the renderer asks us to take focus back (i.e., it has |
| 324 // iterated past the last focusable element on the page). | 352 // iterated past the last focusable element on the page). |
| 325 void WebContentsViewAndroid::TakeFocus(bool reverse) { | 353 void WebContentsViewAndroid::TakeFocus(bool reverse) { |
| 326 if (web_contents_->GetDelegate() && | 354 if (web_contents_->GetDelegate() && |
| 327 web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse)) | 355 web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse)) |
| 328 return; | 356 return; |
| 329 web_contents_->GetRenderWidgetHostView()->Focus(); | 357 web_contents_->GetRenderWidgetHostView()->Focus(); |
| 330 } | 358 } |
| 331 | 359 |
| 332 } // namespace content | 360 } // namespace content |
| OLD | NEW |