| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 case blink::WebNavigationPolicyNewBackgroundTab: | 66 case blink::WebNavigationPolicyNewBackgroundTab: |
| 67 case blink::WebNavigationPolicyNewForegroundTab: | 67 case blink::WebNavigationPolicyNewForegroundTab: |
| 68 case blink::WebNavigationPolicyNewWindow: | 68 case blink::WebNavigationPolicyNewWindow: |
| 69 case blink::WebNavigationPolicyNewPopup: | 69 case blink::WebNavigationPolicyNewPopup: |
| 70 return mojo::TARGET_NEW_NODE; | 70 return mojo::TARGET_NEW_NODE; |
| 71 default: | 71 default: |
| 72 return mojo::TARGET_DEFAULT; | 72 return mojo::TARGET_DEFAULT; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 ui::EventType ConvertEventTypeToUIEventType(blink::WebInputEvent::Type type) { |
| 77 if (type == blink::WebInputEvent::PointerDown) |
| 78 return ui::ET_TOUCH_PRESSED; |
| 79 if (type == blink::WebInputEvent::PointerUp) |
| 80 return ui::ET_TOUCH_RELEASED; |
| 81 if (type == blink::WebInputEvent::PointerMove) |
| 82 return ui::ET_TOUCH_MOVED; |
| 83 DCHECK(type == blink::WebInputEvent::PointerCancel); |
| 84 return ui::ET_TOUCH_CANCELLED; |
| 85 } |
| 86 |
| 87 scoped_ptr<ui::TouchEvent> ConvertToUITouchEvent( |
| 88 const blink::WebInputEvent& event, |
| 89 float device_pixel_ratio) { |
| 90 if (!blink::WebInputEvent::isPointerEventType(event.type)) |
| 91 return nullptr; |
| 92 const blink::WebPointerEvent& pointer_event = |
| 93 static_cast<const blink::WebPointerEvent&>(event); |
| 94 return make_scoped_ptr(new ui::TouchEvent( |
| 95 ConvertEventTypeToUIEventType(event.type), |
| 96 gfx::PointF(pointer_event.x * device_pixel_ratio, |
| 97 pointer_event.y * device_pixel_ratio), |
| 98 pointer_event.pointer, |
| 99 base::TimeDelta::FromMillisecondsD(pointer_event.timeStampMS))); |
| 100 } |
| 101 |
| 76 } // namespace | 102 } // namespace |
| 77 | 103 |
| 78 static int s_next_debugger_id = 1; | 104 static int s_next_debugger_id = 1; |
| 79 | 105 |
| 80 DocumentView::DocumentView( | 106 DocumentView::DocumentView( |
| 81 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 107 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 82 mojo::ServiceProviderPtr exported_services, | 108 mojo::ServiceProviderPtr exported_services, |
| 83 mojo::URLResponsePtr response, | 109 mojo::URLResponsePtr response, |
| 84 mojo::Shell* shell) | 110 mojo::Shell* shell) |
| 85 : response_(response.Pass()), | 111 : response_(response.Pass()), |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 web_view_->setFocus(true); | 323 web_view_->setFocus(true); |
| 298 } | 324 } |
| 299 } | 325 } |
| 300 | 326 |
| 301 void DocumentView::OnViewDestroyed(mojo::View* view) { | 327 void DocumentView::OnViewDestroyed(mojo::View* view) { |
| 302 DCHECK_EQ(view, root_); | 328 DCHECK_EQ(view, root_); |
| 303 | 329 |
| 304 root_ = nullptr; | 330 root_ = nullptr; |
| 305 } | 331 } |
| 306 | 332 |
| 307 bool DocumentView::DispatchInputEvent(const mojo::EventPtr& event) { | |
| 308 scoped_ptr<blink::WebInputEvent> web_event = | |
| 309 ConvertEvent(event, GetDevicePixelRatio()); | |
| 310 return web_event && web_view_->handleInputEvent(*web_event); | |
| 311 } | |
| 312 | |
| 313 void DocumentView::OnViewInputEvent( | 333 void DocumentView::OnViewInputEvent( |
| 314 mojo::View* view, const mojo::EventPtr& event) { | 334 mojo::View* view, const mojo::EventPtr& event) { |
| 335 float device_pixel_ratio = GetDevicePixelRatio(); |
| 336 scoped_ptr<blink::WebInputEvent> web_event = |
| 337 ConvertEvent(event, device_pixel_ratio); |
| 338 if (!web_event) |
| 339 return; |
| 315 | 340 |
| 316 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event>>()); | 341 ui::GestureRecognizer* recognizer = ui::GestureRecognizer::Get(); |
| 317 ui::TouchEvent* touch_event = nullptr; | 342 scoped_ptr<ui::TouchEvent> touch_event = |
| 318 if (ui_event->IsTouchEvent()) { | 343 ConvertToUITouchEvent(*web_event, device_pixel_ratio); |
| 319 touch_event = static_cast<ui::TouchEvent*>(ui_event.get()); | 344 if (touch_event) |
| 320 ui::GestureRecognizer::Get()->ProcessTouchEventPreDispatch( | 345 recognizer->ProcessTouchEventPreDispatch(*touch_event, this); |
| 321 *touch_event, this); | |
| 322 } | |
| 323 | 346 |
| 324 bool handled = DispatchInputEvent(event); | 347 bool handled = web_view_->handleInputEvent(*web_event); |
| 325 | 348 |
| 326 if (touch_event) { | 349 if (touch_event) { |
| 327 ui::EventResult result = handled ? ui::ER_UNHANDLED : ui::ER_UNHANDLED; | 350 ui::EventResult result = handled ? ui::ER_UNHANDLED : ui::ER_UNHANDLED; |
| 328 if (auto gestures = ui::GestureRecognizer::Get()->ProcessTouchEventPostDispa
tch( | 351 if (auto gestures = recognizer->ProcessTouchEventPostDispatch( |
| 329 *touch_event, result, this)) { | 352 *touch_event, result, this)) { |
| 330 for (auto& gesture : *gestures) | 353 for (auto& gesture : *gestures) { |
| 331 DispatchInputEvent(mojo::Event::From(*gesture)); | 354 scoped_ptr<blink::WebInputEvent> gesture_event = |
| 355 ConvertEvent(mojo::Event::From(*gesture), device_pixel_ratio); |
| 356 if (gesture_event) |
| 357 web_view_->handleInputEvent(*gesture_event); |
| 358 } |
| 332 } | 359 } |
| 333 } | 360 } |
| 334 } | 361 } |
| 335 | 362 |
| 336 class InspectorHostImpl : public inspector::InspectorHost { | 363 class InspectorHostImpl : public inspector::InspectorHost { |
| 337 public: | 364 public: |
| 338 InspectorHostImpl(blink::WebView* web_view, mojo::Shell* shell) | 365 InspectorHostImpl(blink::WebView* web_view, mojo::Shell* shell) |
| 339 : web_view_(web_view), shell_(shell) {} | 366 : web_view_(web_view), shell_(shell) {} |
| 340 | 367 |
| 341 virtual ~InspectorHostImpl() {} | 368 virtual ~InspectorHostImpl() {} |
| (...skipping 12 matching lines...) Expand all Loading... |
| 354 void DocumentView::StartDebuggerInspectorBackend() { | 381 void DocumentView::StartDebuggerInspectorBackend() { |
| 355 if (!inspector_backend_) { | 382 if (!inspector_backend_) { |
| 356 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); | 383 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); |
| 357 inspector_backend_.reset( | 384 inspector_backend_.reset( |
| 358 new inspector::InspectorBackendMojo(inspector_host_.get())); | 385 new inspector::InspectorBackendMojo(inspector_host_.get())); |
| 359 } | 386 } |
| 360 inspector_backend_->Connect(); | 387 inspector_backend_->Connect(); |
| 361 } | 388 } |
| 362 | 389 |
| 363 } // namespace sky | 390 } // namespace sky |
| OLD | NEW |