| 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/renderer_host/render_widget_host_view_android.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.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/android/draw_delegate_impl.h" | 12 #include "content/browser/android/draw_delegate_impl.h" |
| 13 #include "content/browser/gpu/gpu_surface_tracker.h" | 13 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 14 #include "content/browser/renderer_host/render_widget_host_impl.h" | 14 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 15 #include "content/common/android/device_info.h" | 15 #include "content/common/android/device_info.h" |
| 16 #include "content/common/gpu/gpu_messages.h" | 16 #include "content/common/gpu/gpu_messages.h" |
| 17 #include "content/common/view_messages.h" | 17 #include "content/common/view_messages.h" |
| 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( | 22 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
| 22 RenderWidgetHostImpl* widget_host, | 23 RenderWidgetHostImpl* widget_host, |
| 23 ContentViewCoreImpl* content_view_core) | 24 ContentViewCoreImpl* content_view_core) |
| 24 : host_(widget_host), | 25 : host_(widget_host), |
| 25 // ContentViewCoreImpl represents the native side of the Java | 26 // ContentViewCoreImpl represents the native side of the Java |
| 26 // ContentViewCore. It being NULL means that it is not attached to the | 27 // ContentViewCore. It being NULL means that it is not attached to the |
| 27 // View system yet, so we treat it as hidden. | 28 // View system yet, so we treat it as hidden. |
| 28 is_hidden_(!content_view_core), | 29 is_hidden_(!content_view_core), |
| 29 content_view_core_(content_view_core), | 30 content_view_core_(content_view_core), |
| 30 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 31 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 32 texture_layer_(WebKit::WebExternalTextureLayer::create()) { |
| 31 host_->SetView(this); | 33 host_->SetView(this); |
| 32 // RenderWidgetHost is initialized as visible. If is_hidden_ is true, tell | 34 // RenderWidgetHost is initialized as visible. If is_hidden_ is true, tell |
| 33 // RenderWidgetHost to hide. | 35 // RenderWidgetHost to hide. |
| 34 if (is_hidden_) | 36 if (is_hidden_) |
| 35 host_->WasHidden(); | 37 host_->WasHidden(); |
| 38 texture_layer_->layer()->setDrawsContent(!is_hidden_); |
| 39 host_->AttachLayer(texture_layer_->layer()); |
| 36 } | 40 } |
| 37 | 41 |
| 38 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { | 42 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { |
| 39 } | 43 } |
| 40 | 44 |
| 41 void RenderWidgetHostViewAndroid::InitAsChild(gfx::NativeView parent_view) { | 45 void RenderWidgetHostViewAndroid::InitAsChild(gfx::NativeView parent_view) { |
| 42 NOTIMPLEMENTED(); | 46 NOTIMPLEMENTED(); |
| 43 } | 47 } |
| 44 | 48 |
| 45 void RenderWidgetHostViewAndroid::InitAsPopup( | 49 void RenderWidgetHostViewAndroid::InitAsPopup( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 host_->WasHidden(); | 83 host_->WasHidden(); |
| 80 } | 84 } |
| 81 | 85 |
| 82 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { | 86 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { |
| 83 // Update the size of the RWH. | 87 // Update the size of the RWH. |
| 84 if (requested_size_.width() != size.width() || | 88 if (requested_size_.width() != size.width() || |
| 85 requested_size_.height() != size.height()) { | 89 requested_size_.height() != size.height()) { |
| 86 requested_size_ = gfx::Size(size.width(), size.height()); | 90 requested_size_ = gfx::Size(size.width(), size.height()); |
| 87 host_->WasResized(); | 91 host_->WasResized(); |
| 88 } | 92 } |
| 93 texture_layer_->layer()->setBounds(size); |
| 89 } | 94 } |
| 90 | 95 |
| 91 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 96 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
| 92 if (rect.origin().x() || rect.origin().y()) { | 97 if (rect.origin().x() || rect.origin().y()) { |
| 93 VLOG(0) << "SetBounds not implemented for (x,y)!=(0,0)"; | 98 VLOG(0) << "SetBounds not implemented for (x,y)!=(0,0)"; |
| 94 } | 99 } |
| 95 SetSize(rect.size()); | 100 SetSize(rect.size()); |
| 96 } | 101 } |
| 97 | 102 |
| 98 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const { | 103 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 140 |
| 136 return content_view_core_->HasFocus(); | 141 return content_view_core_->HasFocus(); |
| 137 } | 142 } |
| 138 | 143 |
| 139 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { | 144 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { |
| 140 NOTIMPLEMENTED(); | 145 NOTIMPLEMENTED(); |
| 141 return false; | 146 return false; |
| 142 } | 147 } |
| 143 | 148 |
| 144 void RenderWidgetHostViewAndroid::Show() { | 149 void RenderWidgetHostViewAndroid::Show() { |
| 145 // nothing to do | 150 texture_layer_->layer()->setDrawsContent(true); |
| 146 } | 151 } |
| 147 | 152 |
| 148 void RenderWidgetHostViewAndroid::Hide() { | 153 void RenderWidgetHostViewAndroid::Hide() { |
| 149 // nothing to do | 154 texture_layer_->layer()->setDrawsContent(false); |
| 150 } | 155 } |
| 151 | 156 |
| 152 bool RenderWidgetHostViewAndroid::IsShowing() { | 157 bool RenderWidgetHostViewAndroid::IsShowing() { |
| 153 return !is_hidden_; | 158 return !is_hidden_; |
| 154 } | 159 } |
| 155 | 160 |
| 156 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { | 161 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { |
| 157 gfx::Size bounds = DrawDelegateImpl::GetInstance()->GetBounds(); | 162 gfx::Size bounds = DrawDelegateImpl::GetInstance()->GetBounds(); |
| 158 if (!bounds.IsEmpty()) | 163 if (!bounds.IsEmpty()) |
| 159 return gfx::Rect(bounds); | 164 return gfx::Rect(bounds); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 const std::vector<gfx::Rect>& copy_rects) { | 208 const std::vector<gfx::Rect>& copy_rects) { |
| 204 NOTIMPLEMENTED(); | 209 NOTIMPLEMENTED(); |
| 205 } | 210 } |
| 206 | 211 |
| 207 void RenderWidgetHostViewAndroid::RenderViewGone( | 212 void RenderWidgetHostViewAndroid::RenderViewGone( |
| 208 base::TerminationStatus status, int error_code) { | 213 base::TerminationStatus status, int error_code) { |
| 209 Destroy(); | 214 Destroy(); |
| 210 } | 215 } |
| 211 | 216 |
| 212 void RenderWidgetHostViewAndroid::Destroy() { | 217 void RenderWidgetHostViewAndroid::Destroy() { |
| 218 host_->RemoveLayer(texture_layer_->layer()); |
| 219 |
| 213 content_view_core_ = NULL; | 220 content_view_core_ = NULL; |
| 214 | 221 |
| 215 // The RenderWidgetHost's destruction led here, so don't call it. | 222 // The RenderWidgetHost's destruction led here, so don't call it. |
| 216 host_ = NULL; | 223 host_ = NULL; |
| 217 | 224 |
| 218 delete this; | 225 delete this; |
| 219 } | 226 } |
| 220 | 227 |
| 221 void RenderWidgetHostViewAndroid::SetTooltipText( | 228 void RenderWidgetHostViewAndroid::SetTooltipText( |
| 222 const string16& tooltip_text) { | 229 const string16& tooltip_text) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 NOTIMPLEMENTED(); | 270 NOTIMPLEMENTED(); |
| 264 callback.Run(false); | 271 callback.Run(false); |
| 265 } | 272 } |
| 266 | 273 |
| 267 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { | 274 void RenderWidgetHostViewAndroid::OnAcceleratedCompositingStateChange() { |
| 268 } | 275 } |
| 269 | 276 |
| 270 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( | 277 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( |
| 271 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, | 278 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, |
| 272 int gpu_host_id) { | 279 int gpu_host_id) { |
| 280 texture_layer_->setTextureId(params.surface_handle); |
| 281 texture_layer_->layer()->invalidate(); |
| 282 // TODO(sievers): The view and layer should get sized proactively. |
| 283 if (((gfx::Size)texture_layer_->layer()->bounds()).IsEmpty()) |
| 284 texture_layer_->layer()->setBounds( |
| 285 DrawDelegateImpl::GetInstance()->GetBounds()); |
| 273 DrawDelegateImpl::GetInstance()->OnSurfaceUpdated( | 286 DrawDelegateImpl::GetInstance()->OnSurfaceUpdated( |
| 274 params.surface_handle, | 287 params.surface_handle, |
| 275 this, | 288 this, |
| 276 base::Bind(&RenderWidgetHostImpl::AcknowledgeBufferPresent, | 289 base::Bind(&RenderWidgetHostImpl::AcknowledgeBufferPresent, |
| 277 params.route_id, gpu_host_id)); | 290 params.route_id, gpu_host_id)); |
| 278 } | 291 } |
| 279 | 292 |
| 280 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( | 293 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( |
| 281 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, | 294 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, |
| 282 int gpu_host_id) { | 295 int gpu_host_id) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 // RenderWidgetHostView, public: | 420 // RenderWidgetHostView, public: |
| 408 | 421 |
| 409 // static | 422 // static |
| 410 RenderWidgetHostView* | 423 RenderWidgetHostView* |
| 411 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 424 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
| 412 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 425 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 413 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 426 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
| 414 } | 427 } |
| 415 | 428 |
| 416 } // namespace content | 429 } // namespace content |
| OLD | NEW |