| 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" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "mojo/converters/geometry/geometry_type_converters.h" | 13 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 14 #include "mojo/public/cpp/application/connect.h" | 14 #include "mojo/public/cpp/application/connect.h" |
| 15 #include "mojo/public/cpp/system/data_pipe.h" | 15 #include "mojo/public/cpp/system/data_pipe.h" |
| 16 #include "mojo/public/interfaces/application/shell.mojom.h" | 16 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 17 #include "mojo/services/public/cpp/view_manager/view.h" | 17 #include "mojo/services/public/cpp/view_manager/view.h" |
| 18 #include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h" | 18 #include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h" |
| 19 #include "skia/ext/refptr.h" | 19 #include "skia/ext/refptr.h" |
| 20 #include "sky/compositor/layer.h" |
| 21 #include "sky/compositor/layer_host.h" |
| 20 #include "sky/engine/public/platform/Platform.h" | 22 #include "sky/engine/public/platform/Platform.h" |
| 21 #include "sky/engine/public/platform/WebHTTPHeaderVisitor.h" | 23 #include "sky/engine/public/platform/WebHTTPHeaderVisitor.h" |
| 22 #include "sky/engine/public/web/Sky.h" | 24 #include "sky/engine/public/web/Sky.h" |
| 23 #include "sky/engine/public/web/WebConsoleMessage.h" | 25 #include "sky/engine/public/web/WebConsoleMessage.h" |
| 24 #include "sky/engine/public/web/WebDocument.h" | 26 #include "sky/engine/public/web/WebDocument.h" |
| 25 #include "sky/engine/public/web/WebElement.h" | 27 #include "sky/engine/public/web/WebElement.h" |
| 26 #include "sky/engine/public/web/WebInputEvent.h" | 28 #include "sky/engine/public/web/WebInputEvent.h" |
| 27 #include "sky/engine/public/web/WebLocalFrame.h" | 29 #include "sky/engine/public/web/WebLocalFrame.h" |
| 28 #include "sky/engine/public/web/WebScriptSource.h" | 30 #include "sky/engine/public/web/WebScriptSource.h" |
| 29 #include "sky/engine/public/web/WebSettings.h" | 31 #include "sky/engine/public/web/WebSettings.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 navigator_host_.set_service_provider(imported_services_.get()); | 118 navigator_host_.set_service_provider(imported_services_.get()); |
| 117 exported_services->AddService(&inspector_service_factory_); | 119 exported_services->AddService(&inspector_service_factory_); |
| 118 | 120 |
| 119 Load(response_.Pass()); | 121 Load(response_.Pass()); |
| 120 | 122 |
| 121 gfx::Size size = root_->bounds().To<gfx::Rect>().size(); | 123 gfx::Size size = root_->bounds().To<gfx::Rect>().size(); |
| 122 web_view_->resize(size); | 124 web_view_->resize(size); |
| 123 // TODO(abarth): We should ask the view whether it is focused instead of | 125 // TODO(abarth): We should ask the view whether it is focused instead of |
| 124 // assuming that we're focused. | 126 // assuming that we're focused. |
| 125 web_view_->setFocus(true); | 127 web_view_->setFocus(true); |
| 128 #if !ENABLE_SKY_COMPOSITOR |
| 126 web_layer_tree_view_impl_->setViewportSize(size); | 129 web_layer_tree_view_impl_->setViewportSize(size); |
| 127 web_layer_tree_view_impl_->set_view(root_); | 130 web_layer_tree_view_impl_->set_view(root_); |
| 131 #endif |
| 128 root_->AddObserver(this); | 132 root_->AddObserver(this); |
| 129 } | 133 } |
| 130 | 134 |
| 131 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { | 135 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { |
| 132 // TODO(aa): Need to figure out how shutdown works. | 136 // TODO(aa): Need to figure out how shutdown works. |
| 133 } | 137 } |
| 134 | 138 |
| 135 void DocumentView::Load(mojo::URLResponsePtr response) { | 139 void DocumentView::Load(mojo::URLResponsePtr response) { |
| 136 web_view_ = blink::WebView::create(this); | 140 web_view_ = blink::WebView::create(this); |
| 141 #if !ENABLE_SKY_COMPOSITOR |
| 137 web_layer_tree_view_impl_->set_widget(web_view_); | 142 web_layer_tree_view_impl_->set_widget(web_view_); |
| 143 #endif |
| 138 ConfigureSettings(web_view_->settings()); | 144 ConfigureSettings(web_view_->settings()); |
| 139 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | 145 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); |
| 140 GURL url(response->url); | 146 web_view_->mainFrame()->load(GURL(response->url), response->body.Pass()); |
| 141 web_view_->mainFrame()->load(url, response->body.Pass()); | |
| 142 } | 147 } |
| 143 | 148 |
| 144 blink::WebLayerTreeView* DocumentView::initializeLayerTreeView() { | 149 blink::WebLayerTreeView* DocumentView::initializeLayerTreeView() { |
| 150 #if ENABLE_SKY_COMPOSITOR |
| 151 layer_host_.reset(new LayerHost(this)); |
| 152 root_layer_ = make_scoped_refptr(new Layer(this)); |
| 153 layer_host_->SetRootLayer(root_layer_); |
| 154 return nullptr; |
| 155 #else |
| 145 mojo::ServiceProviderPtr surfaces_service_provider; | 156 mojo::ServiceProviderPtr surfaces_service_provider; |
| 146 shell_->ConnectToApplication("mojo:surfaces_service", | 157 shell_->ConnectToApplication("mojo:surfaces_service", |
| 147 mojo::GetProxy(&surfaces_service_provider)); | 158 mojo::GetProxy(&surfaces_service_provider)); |
| 148 mojo::InterfacePtr<mojo::SurfacesService> surfaces_service; | 159 mojo::InterfacePtr<mojo::SurfacesService> surfaces_service; |
| 149 mojo::ConnectToService(surfaces_service_provider.get(), &surfaces_service); | 160 mojo::ConnectToService(surfaces_service_provider.get(), &surfaces_service); |
| 150 | 161 |
| 151 mojo::ServiceProviderPtr gpu_service_provider; | 162 mojo::ServiceProviderPtr gpu_service_provider; |
| 152 // TODO(jamesr): Should be mojo:gpu_service | 163 // TODO(jamesr): Should be mojo:gpu_service |
| 153 shell_->ConnectToApplication("mojo:native_viewport_service", | 164 shell_->ConnectToApplication("mojo:native_viewport_service", |
| 154 mojo::GetProxy(&gpu_service_provider)); | 165 mojo::GetProxy(&gpu_service_provider)); |
| 155 mojo::InterfacePtr<mojo::Gpu> gpu_service; | 166 mojo::InterfacePtr<mojo::Gpu> gpu_service; |
| 156 mojo::ConnectToService(gpu_service_provider.get(), &gpu_service); | 167 mojo::ConnectToService(gpu_service_provider.get(), &gpu_service); |
| 157 web_layer_tree_view_impl_.reset(new WebLayerTreeViewImpl( | 168 web_layer_tree_view_impl_.reset(new WebLayerTreeViewImpl( |
| 158 compositor_thread_, surfaces_service.Pass(), gpu_service.Pass())); | 169 compositor_thread_, surfaces_service.Pass(), gpu_service.Pass())); |
| 159 | 170 |
| 160 return web_layer_tree_view_impl_.get(); | 171 return web_layer_tree_view_impl_.get(); |
| 172 #endif |
| 161 } | 173 } |
| 162 | 174 |
| 175 #if ENABLE_SKY_COMPOSITOR |
| 176 |
| 177 mojo::Shell* DocumentView::GetShell() { |
| 178 return shell_.get(); |
| 179 } |
| 180 |
| 181 void DocumentView::BeginFrame(base::TimeTicks frame_time) { |
| 182 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); |
| 183 double deadline_sec = frame_time_sec; |
| 184 double interval_sec = 1.0/60; |
| 185 blink::WebBeginFrameArgs web_begin_frame_args( |
| 186 frame_time_sec, deadline_sec, interval_sec); |
| 187 web_view_->beginFrame(web_begin_frame_args); |
| 188 web_view_->layout(); |
| 189 blink::WebSize size = web_view_->size(); |
| 190 root_layer_->SetSize(gfx::Size(size.width, size.height)); |
| 191 } |
| 192 |
| 193 void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { |
| 194 root_->SetSurfaceId(surface_id.Pass()); |
| 195 } |
| 196 |
| 197 void DocumentView::PaintContents(SkCanvas* canvas, const gfx::Rect& clip) { |
| 198 blink::WebRect rect(clip.x(), clip.y(), clip.width(), clip.height()); |
| 199 web_view_->paint(canvas, rect); |
| 200 } |
| 201 |
| 202 #endif // ENABLE_SKY_COMPOSITOR |
| 203 |
| 163 void DocumentView::scheduleAnimation() { | 204 void DocumentView::scheduleAnimation() { |
| 164 DCHECK(web_view_); | 205 DCHECK(web_view_); |
| 165 | 206 |
| 207 #if ENABLE_SKY_COMPOSITOR |
| 208 layer_host_->SetNeedsAnimate(); |
| 209 #else |
| 166 if (!web_view_->settings()->compositorIsEnabled()) | 210 if (!web_view_->settings()->compositorIsEnabled()) |
| 167 web_layer_tree_view_impl_->setNeedsAnimate(); | 211 web_layer_tree_view_impl_->setNeedsAnimate(); |
| 212 #endif |
| 168 } | 213 } |
| 169 | 214 |
| 170 mojo::View* DocumentView::createChildFrame(const blink::WebURL& url) { | 215 mojo::View* DocumentView::createChildFrame(const blink::WebURL& url) { |
| 171 if (!root_) | 216 if (!root_) |
| 172 return nullptr; | 217 return nullptr; |
| 173 | 218 |
| 174 mojo::View* child = mojo::View::Create(root_->view_manager()); | 219 mojo::View* child = mojo::View::Create(root_->view_manager()); |
| 175 child->SetVisible(true); | 220 child->SetVisible(true); |
| 176 root_->AddChild(child); | 221 root_->AddChild(child); |
| 177 child->Embed(mojo::String::From(url.string().utf8())); | 222 child->Embed(mojo::String::From(url.string().utf8())); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 mojo::Shell* DocumentView::Shell() { | 269 mojo::Shell* DocumentView::Shell() { |
| 225 return shell_.get(); | 270 return shell_.get(); |
| 226 } | 271 } |
| 227 | 272 |
| 228 void DocumentView::OnViewBoundsChanged(mojo::View* view, | 273 void DocumentView::OnViewBoundsChanged(mojo::View* view, |
| 229 const mojo::Rect& old_bounds, | 274 const mojo::Rect& old_bounds, |
| 230 const mojo::Rect& new_bounds) { | 275 const mojo::Rect& new_bounds) { |
| 231 DCHECK_EQ(view, root_); | 276 DCHECK_EQ(view, root_); |
| 232 gfx::Size size = new_bounds.To<gfx::Rect>().size(); | 277 gfx::Size size = new_bounds.To<gfx::Rect>().size(); |
| 233 web_view_->resize(size); | 278 web_view_->resize(size); |
| 279 #if !ENABLE_SKY_COMPOSITOR |
| 234 web_layer_tree_view_impl_->setViewportSize(size); | 280 web_layer_tree_view_impl_->setViewportSize(size); |
| 281 #endif |
| 235 } | 282 } |
| 236 | 283 |
| 237 void DocumentView::OnViewFocusChanged(mojo::View* gained_focus, | 284 void DocumentView::OnViewFocusChanged(mojo::View* gained_focus, |
| 238 mojo::View* lost_focus) { | 285 mojo::View* lost_focus) { |
| 239 if (root_ == lost_focus) { | 286 if (root_ == lost_focus) { |
| 240 web_view_->setFocus(false); | 287 web_view_->setFocus(false); |
| 241 } else if (root_ == gained_focus) { | 288 } else if (root_ == gained_focus) { |
| 242 web_view_->setFocus(true); | 289 web_view_->setFocus(true); |
| 243 } | 290 } |
| 244 } | 291 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 void DocumentView::StartDebuggerInspectorBackend() { | 325 void DocumentView::StartDebuggerInspectorBackend() { |
| 279 if (!inspector_backend_) { | 326 if (!inspector_backend_) { |
| 280 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_.get())); | 327 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_.get())); |
| 281 inspector_backend_.reset( | 328 inspector_backend_.reset( |
| 282 new inspector::InspectorBackendMojo(inspector_host_.get())); | 329 new inspector::InspectorBackendMojo(inspector_host_.get())); |
| 283 } | 330 } |
| 284 inspector_backend_->Connect(); | 331 inspector_backend_->Connect(); |
| 285 } | 332 } |
| 286 | 333 |
| 287 } // namespace sky | 334 } // namespace sky |
| OLD | NEW |