| 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/surfaces/public/interfaces/surfaces_service.mojom.h" | 17 #include "mojo/services/surfaces/public/interfaces/surfaces_service.mojom.h" |
| 18 #include "mojo/services/view_manager/public/cpp/view.h" | 18 #include "mojo/services/view_manager/public/cpp/view.h" |
| 19 #include "mojo/services/view_manager/public/cpp/view_manager.h" | 19 #include "mojo/services/view_manager/public/cpp/view_manager.h" |
| 20 #include "skia/ext/refptr.h" | 20 #include "skia/ext/refptr.h" |
| 21 #include "sky/compositor/layer.h" | 21 #include "sky/compositor/layer.h" |
| 22 #include "sky/compositor/layer_host.h" | 22 #include "sky/compositor/layer_host.h" |
| 23 #include "sky/engine/public/platform/Platform.h" | 23 #include "sky/engine/public/platform/Platform.h" |
| 24 #include "sky/engine/public/platform/WebHTTPHeaderVisitor.h" | 24 #include "sky/engine/public/platform/WebHTTPHeaderVisitor.h" |
| 25 #include "sky/engine/public/platform/WebScreenInfo.h" |
| 25 #include "sky/engine/public/web/Sky.h" | 26 #include "sky/engine/public/web/Sky.h" |
| 26 #include "sky/engine/public/web/WebConsoleMessage.h" | 27 #include "sky/engine/public/web/WebConsoleMessage.h" |
| 27 #include "sky/engine/public/web/WebDocument.h" | 28 #include "sky/engine/public/web/WebDocument.h" |
| 28 #include "sky/engine/public/web/WebElement.h" | 29 #include "sky/engine/public/web/WebElement.h" |
| 29 #include "sky/engine/public/web/WebInputEvent.h" | 30 #include "sky/engine/public/web/WebInputEvent.h" |
| 30 #include "sky/engine/public/web/WebLocalFrame.h" | 31 #include "sky/engine/public/web/WebLocalFrame.h" |
| 31 #include "sky/engine/public/web/WebScriptSource.h" | 32 #include "sky/engine/public/web/WebScriptSource.h" |
| 32 #include "sky/engine/public/web/WebSettings.h" | 33 #include "sky/engine/public/web/WebSettings.h" |
| 33 #include "sky/engine/public/web/WebView.h" | 34 #include "sky/engine/public/web/WebView.h" |
| 34 #include "sky/engine/v8_inspector/inspector_backend_mojo.h" | 35 #include "sky/engine/v8_inspector/inspector_backend_mojo.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 mojo::View* root, | 103 mojo::View* root, |
| 103 mojo::ServiceProviderImpl* exported_services, | 104 mojo::ServiceProviderImpl* exported_services, |
| 104 scoped_ptr<mojo::ServiceProvider> imported_services) { | 105 scoped_ptr<mojo::ServiceProvider> imported_services) { |
| 105 root_ = root; | 106 root_ = root; |
| 106 imported_services_ = imported_services.Pass(); | 107 imported_services_ = imported_services.Pass(); |
| 107 navigator_host_.set_service_provider(imported_services_.get()); | 108 navigator_host_.set_service_provider(imported_services_.get()); |
| 108 exported_services->AddService(&inspector_service_factory_); | 109 exported_services->AddService(&inspector_service_factory_); |
| 109 | 110 |
| 110 Load(response_.Pass()); | 111 Load(response_.Pass()); |
| 111 | 112 |
| 112 gfx::Size size = root_->bounds().To<gfx::Rect>().size(); | 113 auto& bounds = root_->bounds(); |
| 113 web_view_->resize(size); | 114 float device_pixel_ratio = GetDevicePixelRatio(); |
| 115 web_view_->resize(blink::WebSize(bounds.width / device_pixel_ratio, |
| 116 bounds.height / device_pixel_ratio)); |
| 117 |
| 114 // TODO(abarth): We should ask the view whether it is focused instead of | 118 // TODO(abarth): We should ask the view whether it is focused instead of |
| 115 // assuming that we're focused. | 119 // assuming that we're focused. |
| 116 web_view_->setFocus(true); | 120 web_view_->setFocus(true); |
| 117 root_->AddObserver(this); | 121 root_->AddObserver(this); |
| 118 } | 122 } |
| 119 | 123 |
| 120 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { | 124 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { |
| 121 // TODO(aa): Need to figure out how shutdown works. | 125 // TODO(aa): Need to figure out how shutdown works. |
| 122 } | 126 } |
| 123 | 127 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 144 | 148 |
| 145 void DocumentView::BeginFrame(base::TimeTicks frame_time) { | 149 void DocumentView::BeginFrame(base::TimeTicks frame_time) { |
| 146 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); | 150 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); |
| 147 double deadline_sec = frame_time_sec; | 151 double deadline_sec = frame_time_sec; |
| 148 double interval_sec = 1.0/60; | 152 double interval_sec = 1.0/60; |
| 149 blink::WebBeginFrameArgs web_begin_frame_args( | 153 blink::WebBeginFrameArgs web_begin_frame_args( |
| 150 frame_time_sec, deadline_sec, interval_sec); | 154 frame_time_sec, deadline_sec, interval_sec); |
| 151 web_view_->beginFrame(web_begin_frame_args); | 155 web_view_->beginFrame(web_begin_frame_args); |
| 152 web_view_->layout(); | 156 web_view_->layout(); |
| 153 blink::WebSize size = web_view_->size(); | 157 blink::WebSize size = web_view_->size(); |
| 154 root_layer_->SetSize(gfx::Size(size.width, size.height)); | 158 float device_pixel_ratio = GetDevicePixelRatio(); |
| 159 root_layer_->SetSize(gfx::Size(size.width * device_pixel_ratio, |
| 160 size.height * device_pixel_ratio)); |
| 155 } | 161 } |
| 156 | 162 |
| 157 void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { | 163 void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { |
| 158 if (root_) | 164 if (root_) |
| 159 root_->SetSurfaceId(surface_id.Pass()); | 165 root_->SetSurfaceId(surface_id.Pass()); |
| 160 } | 166 } |
| 161 | 167 |
| 162 void DocumentView::PaintContents(SkCanvas* canvas, const gfx::Rect& clip) { | 168 void DocumentView::PaintContents(SkCanvas* canvas, const gfx::Rect& clip) { |
| 163 blink::WebRect rect(clip.x(), clip.y(), clip.width(), clip.height()); | 169 blink::WebRect rect(clip.x(), clip.y(), clip.width(), clip.height()); |
| 164 web_view_->paint(canvas, rect); | 170 web_view_->paint(canvas, rect); |
| 165 } | 171 } |
| 166 | 172 |
| 167 void DocumentView::scheduleAnimation() { | 173 void DocumentView::scheduleAnimation() { |
| 168 DCHECK(web_view_); | 174 DCHECK(web_view_); |
| 169 layer_host_->SetNeedsAnimate(); | 175 layer_host_->SetNeedsAnimate(); |
| 170 } | 176 } |
| 171 | 177 |
| 178 blink::WebScreenInfo DocumentView::screenInfo() { |
| 179 DCHECK(root_); |
| 180 auto& metrics = root_->viewport_metrics(); |
| 181 blink::WebScreenInfo screen; |
| 182 screen.rect = blink::WebRect(0, 0, metrics.size->width, metrics.size->height); |
| 183 screen.availableRect = screen.rect; |
| 184 screen.deviceScaleFactor = metrics.device_pixel_ratio; |
| 185 return screen; |
| 186 } |
| 187 |
| 172 mojo::View* DocumentView::createChildFrame(const blink::WebURL& url) { | 188 mojo::View* DocumentView::createChildFrame(const blink::WebURL& url) { |
| 173 if (!root_) | 189 if (!root_) |
| 174 return nullptr; | 190 return nullptr; |
| 175 | 191 |
| 176 mojo::View* child = root_->view_manager()->CreateView(); | 192 mojo::View* child = root_->view_manager()->CreateView(); |
| 177 child->SetVisible(true); | 193 child->SetVisible(true); |
| 178 root_->AddChild(child); | 194 root_->AddChild(child); |
| 179 child->Embed(mojo::String::From(url.string().utf8())); | 195 child->Embed(mojo::String::From(url.string().utf8())); |
| 180 | 196 |
| 181 return child; | 197 return child; |
| 182 } | 198 } |
| 183 | 199 |
| 184 void DocumentView::frameDetached(blink::WebFrame* frame) { | 200 void DocumentView::frameDetached(blink::WebFrame* frame) { |
| 185 // |frame| is invalid after here. | 201 // |frame| is invalid after here. |
| 186 frame->close(); | 202 frame->close(); |
| 187 } | 203 } |
| 188 | 204 |
| 205 float DocumentView::GetDevicePixelRatio() const { |
| 206 if (root_) |
| 207 return root_->viewport_metrics().device_pixel_ratio; |
| 208 return 1.f; |
| 209 } |
| 210 |
| 189 blink::WebNavigationPolicy DocumentView::decidePolicyForNavigation( | 211 blink::WebNavigationPolicy DocumentView::decidePolicyForNavigation( |
| 190 const blink::WebFrameClient::NavigationPolicyInfo& info) { | 212 const blink::WebFrameClient::NavigationPolicyInfo& info) { |
| 191 | 213 |
| 192 navigator_host_->RequestNavigate( | 214 navigator_host_->RequestNavigate( |
| 193 WebNavigationPolicyToNavigationTarget(info.defaultPolicy), | 215 WebNavigationPolicyToNavigationTarget(info.defaultPolicy), |
| 194 mojo::URLRequest::From(info.urlRequest).Pass()); | 216 mojo::URLRequest::From(info.urlRequest).Pass()); |
| 195 | 217 |
| 196 return blink::WebNavigationPolicyIgnore; | 218 return blink::WebNavigationPolicyIgnore; |
| 197 } | 219 } |
| 198 | 220 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 void DocumentView::StartDebuggerInspectorBackend() { | 299 void DocumentView::StartDebuggerInspectorBackend() { |
| 278 if (!inspector_backend_) { | 300 if (!inspector_backend_) { |
| 279 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); | 301 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); |
| 280 inspector_backend_.reset( | 302 inspector_backend_.reset( |
| 281 new inspector::InspectorBackendMojo(inspector_host_.get())); | 303 new inspector::InspectorBackendMojo(inspector_host_.get())); |
| 282 } | 304 } |
| 283 inspector_backend_->Connect(); | 305 inspector_backend_->Connect(); |
| 284 } | 306 } |
| 285 | 307 |
| 286 } // namespace sky | 308 } // namespace sky |
| OLD | NEW |