| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 143 |
| 144 services_provided_to_embedder_ = services_provided_to_embedder.Pass(); | 144 services_provided_to_embedder_ = services_provided_to_embedder.Pass(); |
| 145 services_provided_by_embedder_ = services_provided_by_embedder.Pass(); | 145 services_provided_by_embedder_ = services_provided_by_embedder.Pass(); |
| 146 | 146 |
| 147 Load(response_.Pass()); | 147 Load(response_.Pass()); |
| 148 | 148 |
| 149 UpdateRootSizeAndViewportMetrics(root_->bounds()); | 149 UpdateRootSizeAndViewportMetrics(root_->bounds()); |
| 150 | 150 |
| 151 // TODO(abarth): We should ask the view whether it is focused instead of | 151 // TODO(abarth): We should ask the view whether it is focused instead of |
| 152 // assuming that we're focused. | 152 // assuming that we're focused. |
| 153 web_view_->setFocus(true); | 153 if (web_view_) |
| 154 web_view_->setFocus(true); |
| 154 root_->AddObserver(this); | 155 root_->AddObserver(this); |
| 155 } | 156 } |
| 156 | 157 |
| 157 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { | 158 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { |
| 158 // TODO(aa): Need to figure out how shutdown works. | 159 // TODO(aa): Need to figure out how shutdown works. |
| 159 } | 160 } |
| 160 | 161 |
| 161 void DocumentView::Load(mojo::URLResponsePtr response) { | 162 void DocumentView::Load(mojo::URLResponsePtr response) { |
| 163 // Enable SkyView here. |
| 164 if (false) { |
| 165 sky_view_ = blink::SkyView::Create(this); |
| 166 initializeLayerTreeView(); |
| 167 sky_view_->Load(GURL(response->url), response.Pass()); |
| 168 return; |
| 169 } |
| 170 |
| 162 web_view_ = blink::WebView::create(this); | 171 web_view_ = blink::WebView::create(this); |
| 163 ConfigureSettings(web_view_->settings()); | 172 ConfigureSettings(web_view_->settings()); |
| 164 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | 173 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); |
| 165 web_view_->mainFrame()->loadFromDataPipeWithURL( | 174 web_view_->mainFrame()->loadFromDataPipeWithURL( |
| 166 response->body.Pass(), GURL(response->url)); | 175 response->body.Pass(), GURL(response->url)); |
| 167 } | 176 } |
| 168 | 177 |
| 169 void DocumentView::initializeLayerTreeView() { | 178 void DocumentView::initializeLayerTreeView() { |
| 170 layer_host_.reset(new LayerHost(this)); | 179 layer_host_.reset(new LayerHost(this)); |
| 171 root_layer_ = make_scoped_refptr(new Layer(this)); | 180 root_layer_ = make_scoped_refptr(new Layer(this)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 212 |
| 204 mojo::ScopedMessagePipeHandle DocumentView::TakeServiceRegistry() { | 213 mojo::ScopedMessagePipeHandle DocumentView::TakeServiceRegistry() { |
| 205 return service_registry_.PassInterface().PassHandle(); | 214 return service_registry_.PassInterface().PassHandle(); |
| 206 } | 215 } |
| 207 | 216 |
| 208 mojo::Shell* DocumentView::GetShell() { | 217 mojo::Shell* DocumentView::GetShell() { |
| 209 return shell_; | 218 return shell_; |
| 210 } | 219 } |
| 211 | 220 |
| 212 void DocumentView::BeginFrame(base::TimeTicks frame_time) { | 221 void DocumentView::BeginFrame(base::TimeTicks frame_time) { |
| 213 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); | 222 if (sky_view_) { |
| 214 double deadline_sec = frame_time_sec; | 223 sky_view_->BeginFrame(frame_time); |
| 215 double interval_sec = 1.0/60; | 224 root_layer_->SetSize(sky_view_->display_metrics().physical_size); |
| 216 blink::WebBeginFrameArgs web_begin_frame_args( | 225 } |
| 217 frame_time_sec, deadline_sec, interval_sec); | 226 if (web_view_) { |
| 218 web_view_->beginFrame(web_begin_frame_args); | 227 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); |
| 219 web_view_->layout(); | 228 double deadline_sec = frame_time_sec; |
| 220 blink::WebSize size = web_view_->size(); | 229 double interval_sec = 1.0/60; |
| 221 float device_pixel_ratio = GetDevicePixelRatio(); | 230 blink::WebBeginFrameArgs web_begin_frame_args( |
| 222 root_layer_->SetSize(gfx::Size(size.width * device_pixel_ratio, | 231 frame_time_sec, deadline_sec, interval_sec); |
| 223 size.height * device_pixel_ratio)); | 232 |
| 233 web_view_->beginFrame(web_begin_frame_args); |
| 234 web_view_->layout(); |
| 235 |
| 236 blink::WebSize size = web_view_->size(); |
| 237 float device_pixel_ratio = GetDevicePixelRatio(); |
| 238 root_layer_->SetSize(gfx::Size(size.width * device_pixel_ratio, |
| 239 size.height * device_pixel_ratio)); |
| 240 } |
| 224 } | 241 } |
| 225 | 242 |
| 226 void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { | 243 void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { |
| 227 if (root_) | 244 if (root_) |
| 228 root_->SetSurfaceId(surface_id.Pass()); | 245 root_->SetSurfaceId(surface_id.Pass()); |
| 229 } | 246 } |
| 230 | 247 |
| 231 void DocumentView::PaintContents(SkCanvas* canvas, const gfx::Rect& clip) { | 248 void DocumentView::PaintContents(SkCanvas* canvas, const gfx::Rect& clip) { |
| 232 blink::WebRect rect(clip.x(), clip.y(), clip.width(), clip.height()); | 249 blink::WebRect rect(clip.x(), clip.y(), clip.width(), clip.height()); |
| 233 web_view_->paint(canvas, rect); | 250 |
| 251 if (sky_view_) { |
| 252 skia::RefPtr<SkPicture> picture = sky_view_->Paint(); |
| 253 canvas->clear(SK_ColorBLACK); |
| 254 canvas->scale(GetDevicePixelRatio(), GetDevicePixelRatio()); |
| 255 if (picture) |
| 256 canvas->drawPicture(picture.get()); |
| 257 } |
| 258 |
| 259 if (web_view_) |
| 260 web_view_->paint(canvas, rect); |
| 234 } | 261 } |
| 235 | 262 |
| 236 void DocumentView::scheduleVisualUpdate() { | 263 void DocumentView::scheduleVisualUpdate() { |
| 237 DCHECK(web_view_); | |
| 238 layer_host_->SetNeedsAnimate(); | 264 layer_host_->SetNeedsAnimate(); |
| 239 } | 265 } |
| 240 | 266 |
| 241 blink::WebScreenInfo DocumentView::screenInfo() { | 267 blink::WebScreenInfo DocumentView::screenInfo() { |
| 242 DCHECK(root_); | 268 DCHECK(root_); |
| 243 auto& metrics = root_->viewport_metrics(); | 269 auto& metrics = root_->viewport_metrics(); |
| 244 blink::WebScreenInfo screen; | 270 blink::WebScreenInfo screen; |
| 245 screen.rect = blink::WebRect(0, 0, metrics.size->width, metrics.size->height); | 271 screen.rect = blink::WebRect(0, 0, metrics.size->width, metrics.size->height); |
| 246 screen.availableRect = screen.rect; | 272 screen.availableRect = screen.rect; |
| 247 screen.deviceScaleFactor = metrics.device_pixel_ratio; | 273 screen.deviceScaleFactor = metrics.device_pixel_ratio; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 const mojo::Rect& new_bounds) { | 332 const mojo::Rect& new_bounds) { |
| 307 DCHECK_EQ(view, root_); | 333 DCHECK_EQ(view, root_); |
| 308 UpdateRootSizeAndViewportMetrics(new_bounds); | 334 UpdateRootSizeAndViewportMetrics(new_bounds); |
| 309 } | 335 } |
| 310 | 336 |
| 311 void DocumentView::OnViewViewportMetricsChanged( | 337 void DocumentView::OnViewViewportMetricsChanged( |
| 312 mojo::View* view, | 338 mojo::View* view, |
| 313 const mojo::ViewportMetrics& old_metrics, | 339 const mojo::ViewportMetrics& old_metrics, |
| 314 const mojo::ViewportMetrics& new_metrics) { | 340 const mojo::ViewportMetrics& new_metrics) { |
| 315 DCHECK_EQ(view, root_); | 341 DCHECK_EQ(view, root_); |
| 316 web_view_->setDeviceScaleFactor(GetDevicePixelRatio()); | 342 |
| 343 if (web_view_) { |
| 344 web_view_->setDeviceScaleFactor(GetDevicePixelRatio()); |
| 345 } |
| 317 UpdateRootSizeAndViewportMetrics(root_->bounds()); | 346 UpdateRootSizeAndViewportMetrics(root_->bounds()); |
| 318 } | 347 } |
| 319 | 348 |
| 320 void DocumentView::UpdateRootSizeAndViewportMetrics( | 349 void DocumentView::UpdateRootSizeAndViewportMetrics( |
| 321 const mojo::Rect& new_bounds) { | 350 const mojo::Rect& new_bounds) { |
| 322 float device_pixel_ratio = GetDevicePixelRatio(); | 351 float device_pixel_ratio = GetDevicePixelRatio(); |
| 352 |
| 353 if (sky_view_) { |
| 354 blink::SkyDisplayMetrics metrics; |
| 355 mojo::Rect bounds = root_->bounds(); |
| 356 metrics.physical_size = blink::WebSize(bounds.width, bounds.height); |
| 357 metrics.device_pixel_ratio = device_pixel_ratio; |
| 358 sky_view_->SetDisplayMetrics(metrics); |
| 359 return; |
| 360 } |
| 361 |
| 323 web_view_->resize(blink::WebSize(new_bounds.width / device_pixel_ratio, | 362 web_view_->resize(blink::WebSize(new_bounds.width / device_pixel_ratio, |
| 324 new_bounds.height / device_pixel_ratio)); | 363 new_bounds.height / device_pixel_ratio)); |
| 325 } | 364 } |
| 326 | 365 |
| 327 void DocumentView::OnViewFocusChanged(mojo::View* gained_focus, | 366 void DocumentView::OnViewFocusChanged(mojo::View* gained_focus, |
| 328 mojo::View* lost_focus) { | 367 mojo::View* lost_focus) { |
| 368 if (sky_view_) |
| 369 return; |
| 329 if (root_ == lost_focus) { | 370 if (root_ == lost_focus) { |
| 330 web_view_->setFocus(false); | 371 web_view_->setFocus(false); |
| 331 } else if (root_ == gained_focus) { | 372 } else if (root_ == gained_focus) { |
| 332 web_view_->setFocus(true); | 373 web_view_->setFocus(true); |
| 333 } | 374 } |
| 334 } | 375 } |
| 335 | 376 |
| 336 void DocumentView::OnViewDestroyed(mojo::View* view) { | 377 void DocumentView::OnViewDestroyed(mojo::View* view) { |
| 337 DCHECK_EQ(view, root_); | 378 DCHECK_EQ(view, root_); |
| 338 | 379 |
| 339 root_ = nullptr; | 380 root_ = nullptr; |
| 340 } | 381 } |
| 341 | 382 |
| 342 void DocumentView::OnViewInputEvent( | 383 void DocumentView::OnViewInputEvent( |
| 343 mojo::View* view, const mojo::EventPtr& event) { | 384 mojo::View* view, const mojo::EventPtr& event) { |
| 344 float device_pixel_ratio = GetDevicePixelRatio(); | 385 float device_pixel_ratio = GetDevicePixelRatio(); |
| 345 scoped_ptr<blink::WebInputEvent> web_event = | 386 scoped_ptr<blink::WebInputEvent> web_event = |
| 346 ConvertEvent(event, device_pixel_ratio); | 387 ConvertEvent(event, device_pixel_ratio); |
| 347 if (!web_event) | 388 if (!web_event) |
| 348 return; | 389 return; |
| 349 | 390 |
| 391 if (sky_view_) { |
| 392 sky_view_->HandleInputEvent(*web_event); |
| 393 return; |
| 394 } |
| 395 |
| 350 ui::GestureRecognizer* recognizer = ui::GestureRecognizer::Get(); | 396 ui::GestureRecognizer* recognizer = ui::GestureRecognizer::Get(); |
| 351 scoped_ptr<ui::TouchEvent> touch_event = | 397 scoped_ptr<ui::TouchEvent> touch_event = |
| 352 ConvertToUITouchEvent(*web_event, device_pixel_ratio); | 398 ConvertToUITouchEvent(*web_event, device_pixel_ratio); |
| 353 if (touch_event) | 399 if (touch_event) |
| 354 recognizer->ProcessTouchEventPreDispatch(*touch_event, this); | 400 recognizer->ProcessTouchEventPreDispatch(*touch_event, this); |
| 355 | 401 |
| 356 bool handled = web_view_->handleInputEvent(*web_event); | 402 bool handled = web_view_->handleInputEvent(*web_event); |
| 357 | 403 |
| 358 if (touch_event) { | 404 if (touch_event) { |
| 359 ui::EventResult result = handled ? ui::ER_UNHANDLED : ui::ER_UNHANDLED; | 405 ui::EventResult result = handled ? ui::ER_UNHANDLED : ui::ER_UNHANDLED; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 378 mojo::Array<mojo::String> interface_names(1); | 424 mojo::Array<mojo::String> interface_names(1); |
| 379 interface_names[0] = mojo::ViewManagerClient::Name_; | 425 interface_names[0] = mojo::ViewManagerClient::Name_; |
| 380 mojo::ServiceProviderImpl* sp_impl(new mojo::ServiceProviderImpl()); | 426 mojo::ServiceProviderImpl* sp_impl(new mojo::ServiceProviderImpl()); |
| 381 sp_impl->AddService(&view_manager_client_factory_); | 427 sp_impl->AddService(&view_manager_client_factory_); |
| 382 mojo::ServiceProviderPtr sp; | 428 mojo::ServiceProviderPtr sp; |
| 383 service_registry_service_provider_binding_.reset( | 429 service_registry_service_provider_binding_.reset( |
| 384 new mojo::StrongBinding<mojo::ServiceProvider>(sp_impl, &sp)); | 430 new mojo::StrongBinding<mojo::ServiceProvider>(sp_impl, &sp)); |
| 385 service_registry_->AddServices(interface_names.Pass(), sp.Pass()); | 431 service_registry_->AddServices(interface_names.Pass(), sp.Pass()); |
| 386 } | 432 } |
| 387 | 433 |
| 434 void DocumentView::ScheduleFrame() { |
| 435 DCHECK(sky_view_); |
| 436 layer_host_->SetNeedsAnimate(); |
| 437 } |
| 438 |
| 388 } // namespace sky | 439 } // namespace sky |
| OLD | NEW |