OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sky/viewer/document_view.h" | 5 #include "sky/viewer/document_view.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 mojo::ServiceProviderPtr exposed_services) { | 111 mojo::ServiceProviderPtr exposed_services) { |
112 root_ = root; | 112 root_ = root; |
113 imported_services_ = exposed_services.Pass(); | 113 imported_services_ = exposed_services.Pass(); |
114 navigator_host_.set_service_provider(imported_services_.get()); | 114 navigator_host_.set_service_provider(imported_services_.get()); |
115 | 115 |
116 if (services.is_pending()) | 116 if (services.is_pending()) |
117 inspector_service_provider_impl_.Bind(services.Pass()); | 117 inspector_service_provider_impl_.Bind(services.Pass()); |
118 | 118 |
119 Load(response_.Pass()); | 119 Load(response_.Pass()); |
120 | 120 |
121 auto& bounds = root_->bounds(); | 121 UpdateRootSizeAndViewportMetrics(root_->bounds()); |
122 float device_pixel_ratio = GetDevicePixelRatio(); | |
123 web_view_->resize(blink::WebSize(bounds.width / device_pixel_ratio, | |
124 bounds.height / device_pixel_ratio)); | |
125 | 122 |
126 // TODO(abarth): We should ask the view whether it is focused instead of | 123 // TODO(abarth): We should ask the view whether it is focused instead of |
127 // assuming that we're focused. | 124 // assuming that we're focused. |
128 web_view_->setFocus(true); | 125 web_view_->setFocus(true); |
129 root_->AddObserver(this); | 126 root_->AddObserver(this); |
130 } | 127 } |
131 | 128 |
132 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { | 129 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { |
133 // TODO(aa): Need to figure out how shutdown works. | 130 // TODO(aa): Need to figure out how shutdown works. |
134 } | 131 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 260 } |
264 | 261 |
265 mojo::Shell* DocumentView::Shell() { | 262 mojo::Shell* DocumentView::Shell() { |
266 return shell_; | 263 return shell_; |
267 } | 264 } |
268 | 265 |
269 void DocumentView::OnViewBoundsChanged(mojo::View* view, | 266 void DocumentView::OnViewBoundsChanged(mojo::View* view, |
270 const mojo::Rect& old_bounds, | 267 const mojo::Rect& old_bounds, |
271 const mojo::Rect& new_bounds) { | 268 const mojo::Rect& new_bounds) { |
272 DCHECK_EQ(view, root_); | 269 DCHECK_EQ(view, root_); |
| 270 UpdateRootSizeAndViewportMetrics(new_bounds); |
| 271 } |
| 272 |
| 273 void DocumentView::OnViewViewportMetricsChanged( |
| 274 mojo::View* view, |
| 275 const mojo::ViewportMetrics& old_metrics, |
| 276 const mojo::ViewportMetrics& new_metrics) { |
| 277 DCHECK_EQ(view, root_); |
| 278 web_view_->setDeviceScaleFactor(GetDevicePixelRatio()); |
| 279 UpdateRootSizeAndViewportMetrics(root_->bounds()); |
| 280 } |
| 281 |
| 282 void DocumentView::UpdateRootSizeAndViewportMetrics( |
| 283 const mojo::Rect& new_bounds) { |
273 float device_pixel_ratio = GetDevicePixelRatio(); | 284 float device_pixel_ratio = GetDevicePixelRatio(); |
274 web_view_->resize(blink::WebSize(new_bounds.width / device_pixel_ratio, | 285 web_view_->resize(blink::WebSize(new_bounds.width / device_pixel_ratio, |
275 new_bounds.height / device_pixel_ratio)); | 286 new_bounds.height / device_pixel_ratio)); |
276 } | 287 } |
277 | 288 |
278 void DocumentView::OnViewFocusChanged(mojo::View* gained_focus, | 289 void DocumentView::OnViewFocusChanged(mojo::View* gained_focus, |
279 mojo::View* lost_focus) { | 290 mojo::View* lost_focus) { |
280 if (root_ == lost_focus) { | 291 if (root_ == lost_focus) { |
281 web_view_->setFocus(false); | 292 web_view_->setFocus(false); |
282 } else if (root_ == gained_focus) { | 293 } else if (root_ == gained_focus) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 void DocumentView::StartDebuggerInspectorBackend() { | 330 void DocumentView::StartDebuggerInspectorBackend() { |
320 if (!inspector_backend_) { | 331 if (!inspector_backend_) { |
321 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); | 332 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); |
322 inspector_backend_.reset( | 333 inspector_backend_.reset( |
323 new inspector::InspectorBackendMojo(inspector_host_.get())); | 334 new inspector::InspectorBackendMojo(inspector_host_.get())); |
324 } | 335 } |
325 inspector_backend_->Connect(); | 336 inspector_backend_->Connect(); |
326 } | 337 } |
327 | 338 |
328 } // namespace sky | 339 } // namespace sky |
OLD | NEW |