| 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/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "mojo/converters/geometry/geometry_type_converters.h" | 12 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 13 #include "mojo/converters/input_events/input_events_type_converters.h" | 13 #include "mojo/converters/input_events/input_events_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/view_manager/public/cpp/view.h" | 17 #include "mojo/services/view_manager/public/cpp/view.h" |
| 18 #include "mojo/services/view_manager/public/cpp/view_manager.h" | 18 #include "mojo/services/view_manager/public/cpp/view_manager.h" |
| 19 #include "mojo/services/view_manager/public/interfaces/view_manager.mojom.h" | 19 #include "mojo/services/view_manager/public/interfaces/view_manager.mojom.h" |
| 20 #include "skia/ext/refptr.h" | 20 #include "skia/ext/refptr.h" |
| 21 #include "sky/engine/public/platform/Platform.h" | 21 #include "sky/engine/public/platform/Platform.h" |
| 22 #include "sky/engine/public/platform/WebHTTPHeaderVisitor.h" | 22 #include "sky/engine/public/platform/WebHTTPHeaderVisitor.h" |
| 23 #include "sky/engine/public/platform/WebInputEvent.h" | 23 #include "sky/engine/public/platform/WebInputEvent.h" |
| 24 #include "sky/engine/public/platform/WebScreenInfo.h" | 24 #include "sky/engine/public/platform/WebScreenInfo.h" |
| 25 #include "sky/engine/public/web/Sky.h" | 25 #include "sky/engine/public/web/Sky.h" |
| 26 #include "sky/engine/public/web/WebConsoleMessage.h" | |
| 27 #include "sky/engine/public/web/WebDocument.h" | |
| 28 #include "sky/engine/public/web/WebElement.h" | |
| 29 #include "sky/engine/public/web/WebLocalFrame.h" | |
| 30 #include "sky/engine/public/web/WebScriptSource.h" | |
| 31 #include "sky/engine/public/web/WebSettings.h" | |
| 32 #include "sky/engine/public/web/WebView.h" | |
| 33 #include "sky/services/platform/url_request_types.h" | 26 #include "sky/services/platform/url_request_types.h" |
| 34 #include "sky/viewer/compositor/layer.h" | 27 #include "sky/viewer/compositor/layer.h" |
| 35 #include "sky/viewer/compositor/layer_host.h" | 28 #include "sky/viewer/compositor/layer_host.h" |
| 36 #include "sky/viewer/compositor/rasterizer_bitmap.h" | 29 #include "sky/viewer/compositor/rasterizer_bitmap.h" |
| 37 #include "sky/viewer/compositor/rasterizer_ganesh.h" | 30 #include "sky/viewer/compositor/rasterizer_ganesh.h" |
| 38 #include "sky/viewer/converters/input_event_types.h" | 31 #include "sky/viewer/converters/input_event_types.h" |
| 39 #include "sky/viewer/dart_library_provider_impl.h" | 32 #include "sky/viewer/dart_library_provider_impl.h" |
| 40 #include "sky/viewer/internals.h" | 33 #include "sky/viewer/internals.h" |
| 41 #include "sky/viewer/runtime_flags.h" | 34 #include "sky/viewer/runtime_flags.h" |
| 42 #include "third_party/skia/include/core/SkCanvas.h" | 35 #include "third_party/skia/include/core/SkCanvas.h" |
| 43 #include "third_party/skia/include/core/SkColor.h" | 36 #include "third_party/skia/include/core/SkColor.h" |
| 44 #include "third_party/skia/include/core/SkDevice.h" | 37 #include "third_party/skia/include/core/SkDevice.h" |
| 45 #include "ui/events/gestures/gesture_recognizer.h" | 38 #include "ui/events/gestures/gesture_recognizer.h" |
| 46 | 39 |
| 47 namespace sky { | 40 namespace sky { |
| 48 namespace { | 41 namespace { |
| 49 | 42 |
| 50 void ConfigureSettings(blink::WebSettings* settings) { | |
| 51 settings->setDefaultFixedFontSize(13); | |
| 52 settings->setDefaultFontSize(16); | |
| 53 settings->setLoadsImagesAutomatically(true); | |
| 54 } | |
| 55 | |
| 56 mojo::Target WebNavigationPolicyToNavigationTarget( | |
| 57 blink::WebNavigationPolicy policy) { | |
| 58 switch (policy) { | |
| 59 case blink::WebNavigationPolicyCurrentTab: | |
| 60 return mojo::TARGET_SOURCE_NODE; | |
| 61 case blink::WebNavigationPolicyNewBackgroundTab: | |
| 62 case blink::WebNavigationPolicyNewForegroundTab: | |
| 63 case blink::WebNavigationPolicyNewWindow: | |
| 64 case blink::WebNavigationPolicyNewPopup: | |
| 65 return mojo::TARGET_NEW_NODE; | |
| 66 default: | |
| 67 return mojo::TARGET_DEFAULT; | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 ui::EventType ConvertEventTypeToUIEventType(blink::WebInputEvent::Type type) { | 43 ui::EventType ConvertEventTypeToUIEventType(blink::WebInputEvent::Type type) { |
| 72 if (type == blink::WebInputEvent::PointerDown) | 44 if (type == blink::WebInputEvent::PointerDown) |
| 73 return ui::ET_TOUCH_PRESSED; | 45 return ui::ET_TOUCH_PRESSED; |
| 74 if (type == blink::WebInputEvent::PointerUp) | 46 if (type == blink::WebInputEvent::PointerUp) |
| 75 return ui::ET_TOUCH_RELEASED; | 47 return ui::ET_TOUCH_RELEASED; |
| 76 if (type == blink::WebInputEvent::PointerMove) | 48 if (type == blink::WebInputEvent::PointerMove) |
| 77 return ui::ET_TOUCH_MOVED; | 49 return ui::ET_TOUCH_MOVED; |
| 78 DCHECK(type == blink::WebInputEvent::PointerCancel); | 50 DCHECK(type == blink::WebInputEvent::PointerCancel); |
| 79 return ui::ET_TOUCH_CANCELLED; | 51 return ui::ET_TOUCH_CANCELLED; |
| 80 } | 52 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 110 | 82 |
| 111 DocumentView::DocumentView( | 83 DocumentView::DocumentView( |
| 112 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 84 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 113 mojo::ServiceProviderPtr exported_services, | 85 mojo::ServiceProviderPtr exported_services, |
| 114 mojo::URLResponsePtr response, | 86 mojo::URLResponsePtr response, |
| 115 mojo::Shell* shell) | 87 mojo::Shell* shell) |
| 116 : response_(response.Pass()), | 88 : response_(response.Pass()), |
| 117 exported_services_(services.Pass()), | 89 exported_services_(services.Pass()), |
| 118 imported_services_(exported_services.Pass()), | 90 imported_services_(exported_services.Pass()), |
| 119 shell_(shell), | 91 shell_(shell), |
| 120 web_view_(nullptr), | |
| 121 root_(nullptr), | 92 root_(nullptr), |
| 122 view_manager_client_factory_(shell_, this), | 93 view_manager_client_factory_(shell_, this), |
| 123 bitmap_rasterizer_(nullptr), | 94 bitmap_rasterizer_(nullptr), |
| 124 weak_factory_(this) { | 95 weak_factory_(this) { |
| 125 exported_services_.AddService(&view_manager_client_factory_); | 96 exported_services_.AddService(&view_manager_client_factory_); |
| 126 InitServiceRegistry(); | 97 InitServiceRegistry(); |
| 127 } | 98 } |
| 128 | 99 |
| 129 DocumentView::~DocumentView() { | 100 DocumentView::~DocumentView() { |
| 130 if (web_view_) | |
| 131 web_view_->close(); | |
| 132 if (root_) | 101 if (root_) |
| 133 root_->RemoveObserver(this); | 102 root_->RemoveObserver(this); |
| 134 ui::GestureRecognizer::Get()->CleanupStateForConsumer(this); | 103 ui::GestureRecognizer::Get()->CleanupStateForConsumer(this); |
| 135 } | 104 } |
| 136 | 105 |
| 137 base::WeakPtr<DocumentView> DocumentView::GetWeakPtr() { | 106 base::WeakPtr<DocumentView> DocumentView::GetWeakPtr() { |
| 138 return weak_factory_.GetWeakPtr(); | 107 return weak_factory_.GetWeakPtr(); |
| 139 } | 108 } |
| 140 | 109 |
| 141 void DocumentView::OnEmbed( | 110 void DocumentView::OnEmbed( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 152 &test_harness_); | 121 &test_harness_); |
| 153 } | 122 } |
| 154 | 123 |
| 155 services_provided_to_embedder_ = services_provided_to_embedder.Pass(); | 124 services_provided_to_embedder_ = services_provided_to_embedder.Pass(); |
| 156 services_provided_by_embedder_ = services_provided_by_embedder.Pass(); | 125 services_provided_by_embedder_ = services_provided_by_embedder.Pass(); |
| 157 | 126 |
| 158 Load(response_.Pass()); | 127 Load(response_.Pass()); |
| 159 | 128 |
| 160 UpdateRootSizeAndViewportMetrics(root_->bounds()); | 129 UpdateRootSizeAndViewportMetrics(root_->bounds()); |
| 161 | 130 |
| 162 // TODO(abarth): We should ask the view whether it is focused instead of | |
| 163 // assuming that we're focused. | |
| 164 if (web_view_) | |
| 165 web_view_->setFocus(true); | |
| 166 root_->AddObserver(this); | 131 root_->AddObserver(this); |
| 167 } | 132 } |
| 168 | 133 |
| 169 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { | 134 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { |
| 170 // TODO(aa): Need to figure out how shutdown works. | 135 // TODO(aa): Need to figure out how shutdown works. |
| 171 } | 136 } |
| 172 void DocumentView::Load(mojo::URLResponsePtr response) { | 137 void DocumentView::Load(mojo::URLResponsePtr response) { |
| 173 GURL responseURL(response->url); | 138 String name = String::fromUTF8(response->url); |
| 174 | 139 library_provider_.reset(new DartLibraryProviderImpl( |
| 175 if (!blink::WebView::shouldUseWebView(responseURL)) { | 140 blink::Platform::current()->networkService(), |
| 176 String name = String::fromUTF8(responseURL.spec()); | 141 CreatePrefetchedLibraryIfNeeded(name, response.Pass()))); |
| 177 library_provider_.reset(new DartLibraryProviderImpl( | 142 sky_view_ = blink::SkyView::Create(this); |
| 178 blink::Platform::current()->networkService(), | |
| 179 CreatePrefetchedLibraryIfNeeded(name, response.Pass()))); | |
| 180 sky_view_ = blink::SkyView::Create(this); | |
| 181 initializeLayerTreeView(); | |
| 182 sky_view_->RunFromLibrary(name, library_provider_.get()); | |
| 183 return; | |
| 184 } | |
| 185 | |
| 186 if (!RuntimeFlags::Get().testing()) | |
| 187 LOG(WARNING) << ".sky support is deprecated, please use .dart for main()"; | |
| 188 | |
| 189 web_view_ = blink::WebView::create(this); | |
| 190 ConfigureSettings(web_view_->settings()); | |
| 191 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | |
| 192 web_view_->mainFrame()->loadFromDataPipeWithURL( | |
| 193 response->body.Pass(), responseURL); | |
| 194 } | |
| 195 | |
| 196 void DocumentView::initializeLayerTreeView() { | |
| 197 layer_host_.reset(new LayerHost(this)); | 143 layer_host_.reset(new LayerHost(this)); |
| 198 root_layer_ = make_scoped_refptr(new Layer(this)); | 144 root_layer_ = make_scoped_refptr(new Layer(this)); |
| 199 root_layer_->set_rasterizer(CreateRasterizer()); | 145 root_layer_->set_rasterizer(CreateRasterizer()); |
| 200 layer_host_->SetRootLayer(root_layer_); | 146 layer_host_->SetRootLayer(root_layer_); |
| 147 |
| 148 sky_view_->RunFromLibrary(name, library_provider_.get()); |
| 201 } | 149 } |
| 202 | 150 |
| 203 scoped_ptr<Rasterizer> DocumentView::CreateRasterizer() { | 151 scoped_ptr<Rasterizer> DocumentView::CreateRasterizer() { |
| 204 if (!RuntimeFlags::Get().testing()) | 152 if (!RuntimeFlags::Get().testing()) |
| 205 return make_scoped_ptr(new RasterizerGanesh(layer_host_.get())); | 153 return make_scoped_ptr(new RasterizerGanesh(layer_host_.get())); |
| 206 // TODO(abarth): If we have more than one layer, we'll need to re-think how | 154 // TODO(abarth): If we have more than one layer, we'll need to re-think how |
| 207 // we capture pixels for testing; | 155 // we capture pixels for testing; |
| 208 DCHECK(!bitmap_rasterizer_); | 156 DCHECK(!bitmap_rasterizer_); |
| 209 bitmap_rasterizer_ = new RasterizerBitmap(layer_host_.get()); | 157 bitmap_rasterizer_ = new RasterizerBitmap(layer_host_.get()); |
| 210 return make_scoped_ptr(bitmap_rasterizer_); | 158 return make_scoped_ptr(bitmap_rasterizer_); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 234 | 182 |
| 235 mojo::Shell* DocumentView::GetShell() { | 183 mojo::Shell* DocumentView::GetShell() { |
| 236 return shell_; | 184 return shell_; |
| 237 } | 185 } |
| 238 | 186 |
| 239 void DocumentView::BeginFrame(base::TimeTicks frame_time) { | 187 void DocumentView::BeginFrame(base::TimeTicks frame_time) { |
| 240 if (sky_view_) { | 188 if (sky_view_) { |
| 241 sky_view_->BeginFrame(frame_time); | 189 sky_view_->BeginFrame(frame_time); |
| 242 root_layer_->SetSize(sky_view_->display_metrics().physical_size); | 190 root_layer_->SetSize(sky_view_->display_metrics().physical_size); |
| 243 } | 191 } |
| 244 if (web_view_) { | |
| 245 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); | |
| 246 double deadline_sec = frame_time_sec; | |
| 247 double interval_sec = 1.0/60; | |
| 248 blink::WebBeginFrameArgs web_begin_frame_args( | |
| 249 frame_time_sec, deadline_sec, interval_sec); | |
| 250 | |
| 251 web_view_->beginFrame(web_begin_frame_args); | |
| 252 web_view_->layout(); | |
| 253 | |
| 254 blink::WebSize size = web_view_->size(); | |
| 255 float device_pixel_ratio = GetDevicePixelRatio(); | |
| 256 root_layer_->SetSize(gfx::Size(size.width * device_pixel_ratio, | |
| 257 size.height * device_pixel_ratio)); | |
| 258 } | |
| 259 } | 192 } |
| 260 | 193 |
| 261 void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { | 194 void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { |
| 262 if (root_) | 195 if (root_) |
| 263 root_->SetSurfaceId(surface_id.Pass()); | 196 root_->SetSurfaceId(surface_id.Pass()); |
| 264 } | 197 } |
| 265 | 198 |
| 266 void DocumentView::PaintContents(SkCanvas* canvas, const gfx::Rect& clip) { | 199 void DocumentView::PaintContents(SkCanvas* canvas, const gfx::Rect& clip) { |
| 267 blink::WebRect rect(clip.x(), clip.y(), clip.width(), clip.height()); | 200 blink::WebRect rect(clip.x(), clip.y(), clip.width(), clip.height()); |
| 268 | 201 |
| 269 if (sky_view_) { | 202 if (sky_view_) { |
| 270 skia::RefPtr<SkPicture> picture = sky_view_->Paint(); | 203 skia::RefPtr<SkPicture> picture = sky_view_->Paint(); |
| 271 canvas->clear(SK_ColorBLACK); | 204 canvas->clear(SK_ColorBLACK); |
| 272 canvas->scale(GetDevicePixelRatio(), GetDevicePixelRatio()); | 205 canvas->scale(GetDevicePixelRatio(), GetDevicePixelRatio()); |
| 273 if (picture) | 206 if (picture) |
| 274 canvas->drawPicture(picture.get()); | 207 canvas->drawPicture(picture.get()); |
| 275 } | 208 } |
| 276 | |
| 277 if (web_view_) | |
| 278 web_view_->paint(canvas, rect); | |
| 279 } | |
| 280 | |
| 281 void DocumentView::scheduleVisualUpdate() { | |
| 282 layer_host_->SetNeedsAnimate(); | |
| 283 } | |
| 284 | |
| 285 blink::WebScreenInfo DocumentView::screenInfo() { | |
| 286 DCHECK(root_); | |
| 287 auto& metrics = root_->viewport_metrics(); | |
| 288 blink::WebScreenInfo screen; | |
| 289 screen.rect = blink::WebRect(0, 0, metrics.size->width, metrics.size->height); | |
| 290 screen.availableRect = screen.rect; | |
| 291 screen.deviceScaleFactor = metrics.device_pixel_ratio; | |
| 292 return screen; | |
| 293 } | |
| 294 | |
| 295 mojo::View* DocumentView::createChildFrame() { | |
| 296 if (!root_) | |
| 297 return nullptr; | |
| 298 | |
| 299 mojo::View* child = root_->view_manager()->CreateView(); | |
| 300 child->SetVisible(true); | |
| 301 root_->AddChild(child); | |
| 302 return child; | |
| 303 } | |
| 304 | |
| 305 void DocumentView::frameDetached(blink::WebFrame* frame) { | |
| 306 // |frame| is invalid after here. | |
| 307 frame->close(); | |
| 308 } | 209 } |
| 309 | 210 |
| 310 float DocumentView::GetDevicePixelRatio() const { | 211 float DocumentView::GetDevicePixelRatio() const { |
| 311 if (root_) | 212 if (root_) |
| 312 return root_->viewport_metrics().device_pixel_ratio; | 213 return root_->viewport_metrics().device_pixel_ratio; |
| 313 return 1.f; | 214 return 1.f; |
| 314 } | 215 } |
| 315 | 216 |
| 316 blink::WebNavigationPolicy DocumentView::decidePolicyForNavigation( | |
| 317 const blink::WebFrameClient::NavigationPolicyInfo& info) { | |
| 318 | |
| 319 if (navigator_host_.get()) { | |
| 320 navigator_host_->RequestNavigate( | |
| 321 WebNavigationPolicyToNavigationTarget(info.defaultPolicy), | |
| 322 mojo::URLRequest::From(info.urlRequest).Pass()); | |
| 323 } | |
| 324 | |
| 325 return blink::WebNavigationPolicyIgnore; | |
| 326 } | |
| 327 | |
| 328 void DocumentView::didAddMessageToConsole( | |
| 329 const blink::WebConsoleMessage& message, | |
| 330 const blink::WebString& source_name, | |
| 331 unsigned source_line, | |
| 332 const blink::WebString& stack_trace) { | |
| 333 } | |
| 334 | |
| 335 void DocumentView::didCreateIsolate(blink::WebLocalFrame* frame, | |
| 336 Dart_Isolate isolate) { | |
| 337 Internals::Create(isolate, this); | |
| 338 } | |
| 339 | |
| 340 void DocumentView::DidCreateIsolate(Dart_Isolate isolate) { | 217 void DocumentView::DidCreateIsolate(Dart_Isolate isolate) { |
| 341 Internals::Create(isolate, this); | 218 Internals::Create(isolate, this); |
| 342 } | 219 } |
| 343 | 220 |
| 344 blink::ServiceProvider* DocumentView::services() { | |
| 345 return this; | |
| 346 } | |
| 347 | |
| 348 mojo::NavigatorHost* DocumentView::NavigatorHost() { | 221 mojo::NavigatorHost* DocumentView::NavigatorHost() { |
| 349 return navigator_host_.get(); | 222 return navigator_host_.get(); |
| 350 } | 223 } |
| 351 | 224 |
| 352 void DocumentView::OnViewBoundsChanged(mojo::View* view, | 225 void DocumentView::OnViewBoundsChanged(mojo::View* view, |
| 353 const mojo::Rect& old_bounds, | 226 const mojo::Rect& old_bounds, |
| 354 const mojo::Rect& new_bounds) { | 227 const mojo::Rect& new_bounds) { |
| 355 DCHECK_EQ(view, root_); | 228 DCHECK_EQ(view, root_); |
| 356 UpdateRootSizeAndViewportMetrics(new_bounds); | 229 UpdateRootSizeAndViewportMetrics(new_bounds); |
| 357 } | 230 } |
| 358 | 231 |
| 359 void DocumentView::OnViewViewportMetricsChanged( | 232 void DocumentView::OnViewViewportMetricsChanged( |
| 360 mojo::View* view, | 233 mojo::View* view, |
| 361 const mojo::ViewportMetrics& old_metrics, | 234 const mojo::ViewportMetrics& old_metrics, |
| 362 const mojo::ViewportMetrics& new_metrics) { | 235 const mojo::ViewportMetrics& new_metrics) { |
| 363 DCHECK_EQ(view, root_); | 236 DCHECK_EQ(view, root_); |
| 364 | 237 |
| 365 if (web_view_) { | |
| 366 web_view_->setDeviceScaleFactor(GetDevicePixelRatio()); | |
| 367 } | |
| 368 UpdateRootSizeAndViewportMetrics(root_->bounds()); | 238 UpdateRootSizeAndViewportMetrics(root_->bounds()); |
| 369 } | 239 } |
| 370 | 240 |
| 371 void DocumentView::UpdateRootSizeAndViewportMetrics( | 241 void DocumentView::UpdateRootSizeAndViewportMetrics( |
| 372 const mojo::Rect& new_bounds) { | 242 const mojo::Rect& new_bounds) { |
| 373 float device_pixel_ratio = GetDevicePixelRatio(); | 243 float device_pixel_ratio = GetDevicePixelRatio(); |
| 374 | 244 |
| 375 if (sky_view_) { | 245 if (sky_view_) { |
| 376 blink::SkyDisplayMetrics metrics; | 246 blink::SkyDisplayMetrics metrics; |
| 377 mojo::Rect bounds = root_->bounds(); | 247 mojo::Rect bounds = root_->bounds(); |
| 378 metrics.physical_size = blink::WebSize(bounds.width, bounds.height); | 248 metrics.physical_size = blink::WebSize(bounds.width, bounds.height); |
| 379 metrics.device_pixel_ratio = device_pixel_ratio; | 249 metrics.device_pixel_ratio = device_pixel_ratio; |
| 380 sky_view_->SetDisplayMetrics(metrics); | 250 sky_view_->SetDisplayMetrics(metrics); |
| 381 return; | 251 return; |
| 382 } | 252 } |
| 383 | |
| 384 web_view_->resize(blink::WebSize(new_bounds.width / device_pixel_ratio, | |
| 385 new_bounds.height / device_pixel_ratio)); | |
| 386 } | 253 } |
| 387 | 254 |
| 388 void DocumentView::OnViewFocusChanged(mojo::View* gained_focus, | 255 void DocumentView::OnViewFocusChanged(mojo::View* gained_focus, |
| 389 mojo::View* lost_focus) { | 256 mojo::View* lost_focus) { |
| 390 if (sky_view_) | |
| 391 return; | |
| 392 if (root_ == lost_focus) { | |
| 393 web_view_->setFocus(false); | |
| 394 } else if (root_ == gained_focus) { | |
| 395 web_view_->setFocus(true); | |
| 396 } | |
| 397 } | 257 } |
| 398 | 258 |
| 399 void DocumentView::OnViewDestroyed(mojo::View* view) { | 259 void DocumentView::OnViewDestroyed(mojo::View* view) { |
| 400 DCHECK_EQ(view, root_); | 260 DCHECK_EQ(view, root_); |
| 401 | 261 |
| 402 root_ = nullptr; | 262 root_ = nullptr; |
| 403 } | 263 } |
| 404 | 264 |
| 405 void DocumentView::OnViewInputEvent( | 265 void DocumentView::OnViewInputEvent( |
| 406 mojo::View* view, const mojo::EventPtr& event) { | 266 mojo::View* view, const mojo::EventPtr& event) { |
| 407 float device_pixel_ratio = GetDevicePixelRatio(); | 267 float device_pixel_ratio = GetDevicePixelRatio(); |
| 408 scoped_ptr<blink::WebInputEvent> web_event = | 268 scoped_ptr<blink::WebInputEvent> web_event = |
| 409 ConvertEvent(event, device_pixel_ratio); | 269 ConvertEvent(event, device_pixel_ratio); |
| 410 if (!web_event) | 270 if (!web_event) |
| 411 return; | 271 return; |
| 412 | 272 |
| 413 ui::GestureRecognizer* recognizer = ui::GestureRecognizer::Get(); | 273 ui::GestureRecognizer* recognizer = ui::GestureRecognizer::Get(); |
| 414 scoped_ptr<ui::TouchEvent> touch_event = | 274 scoped_ptr<ui::TouchEvent> touch_event = |
| 415 ConvertToUITouchEvent(*web_event, device_pixel_ratio); | 275 ConvertToUITouchEvent(*web_event, device_pixel_ratio); |
| 416 if (touch_event) | 276 if (touch_event) |
| 417 recognizer->ProcessTouchEventPreDispatch(*touch_event, this); | 277 recognizer->ProcessTouchEventPreDispatch(*touch_event, this); |
| 418 | 278 |
| 419 bool handled = false; | 279 bool handled = false; |
| 420 | 280 |
| 421 if (web_view_) | |
| 422 handled = web_view_->handleInputEvent(*web_event); | |
| 423 if (sky_view_) | 281 if (sky_view_) |
| 424 sky_view_->HandleInputEvent(*web_event); | 282 sky_view_->HandleInputEvent(*web_event); |
| 425 | 283 |
| 426 if (touch_event) { | 284 if (touch_event) { |
| 427 ui::EventResult result = handled ? ui::ER_UNHANDLED : ui::ER_UNHANDLED; | 285 ui::EventResult result = handled ? ui::ER_UNHANDLED : ui::ER_UNHANDLED; |
| 428 if (auto gestures = recognizer->ProcessTouchEventPostDispatch( | 286 if (auto gestures = recognizer->ProcessTouchEventPostDispatch( |
| 429 *touch_event, result, this)) { | 287 *touch_event, result, this)) { |
| 430 for (auto& gesture : *gestures) { | 288 for (auto& gesture : *gestures) { |
| 431 scoped_ptr<blink::WebInputEvent> gesture_event = | 289 scoped_ptr<blink::WebInputEvent> gesture_event = |
| 432 ConvertEvent(*gesture, device_pixel_ratio); | 290 ConvertEvent(*gesture, device_pixel_ratio); |
| 433 if (gesture_event) { | 291 if (gesture_event) { |
| 434 if (web_view_) | |
| 435 web_view_->handleInputEvent(*gesture_event); | |
| 436 if (sky_view_) | 292 if (sky_view_) |
| 437 sky_view_->HandleInputEvent(*gesture_event); | 293 sky_view_->HandleInputEvent(*gesture_event); |
| 438 } | 294 } |
| 439 } | 295 } |
| 440 } | 296 } |
| 441 } | 297 } |
| 442 } | 298 } |
| 443 | 299 |
| 444 void DocumentView::StartDebuggerInspectorBackend() { | 300 void DocumentView::StartDebuggerInspectorBackend() { |
| 445 // FIXME: Do we need this for dart? | 301 // FIXME: Do we need this for dart? |
| (...skipping 10 matching lines...) Expand all Loading... |
| 456 new mojo::StrongBinding<mojo::ServiceProvider>(sp_impl, &sp)); | 312 new mojo::StrongBinding<mojo::ServiceProvider>(sp_impl, &sp)); |
| 457 service_registry_->AddServices(interface_names.Pass(), sp.Pass()); | 313 service_registry_->AddServices(interface_names.Pass(), sp.Pass()); |
| 458 } | 314 } |
| 459 | 315 |
| 460 void DocumentView::ScheduleFrame() { | 316 void DocumentView::ScheduleFrame() { |
| 461 DCHECK(sky_view_); | 317 DCHECK(sky_view_); |
| 462 layer_host_->SetNeedsAnimate(); | 318 layer_host_->SetNeedsAnimate(); |
| 463 } | 319 } |
| 464 | 320 |
| 465 } // namespace sky | 321 } // namespace sky |
| OLD | NEW |