diff --git a/viewer/BUILD.gn b/viewer/BUILD.gn index 53c493456cd..054aa09d3f5 100644 --- a/viewer/BUILD.gn +++ b/viewer/BUILD.gn @@ -44,6 +44,7 @@ mojo_native_application("viewer") { "//mojo/common", "//mojo/common:tracing_impl", "//mojo/converters/geometry", + "//mojo/converters/input_events", "//mojo/converters/surfaces", "//mojo/edk/js", "//mojo/icu", @@ -66,6 +67,7 @@ mojo_native_application("viewer") { "//sky/services/inspector:bindings", "//sky/services/testing:bindings", "//third_party/icu", + "//ui/events", "//url", ] } diff --git a/viewer/document_view.cc b/viewer/document_view.cc index 80ae7db9e62..d4c82e57bbb 100644 --- a/viewer/document_view.cc +++ b/viewer/document_view.cc @@ -11,6 +11,7 @@ #include "base/strings/string_util.h" #include "base/thread_task_runner_handle.h" #include "mojo/converters/geometry/geometry_type_converters.h" +#include "mojo/converters/input_events/input_events_type_converters.h" #include "mojo/public/cpp/application/connect.h" #include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/interfaces/application/shell.mojom.h" @@ -45,6 +46,7 @@ #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkDevice.h" +#include "ui/events/gestures/gesture_recognizer.h" #include "v8/include/v8.h" namespace sky { @@ -99,6 +101,7 @@ DocumentView::~DocumentView() { web_view_->close(); if (root_) root_->RemoveObserver(this); + ui::GestureRecognizer::Get()->CleanupStateForConsumer(this); } base::WeakPtr DocumentView::GetWeakPtr() { @@ -301,12 +304,33 @@ void DocumentView::OnViewDestroyed(mojo::View* view) { root_ = nullptr; } -void DocumentView::OnViewInputEvent( - mojo::View* view, const mojo::EventPtr& event) { +bool DocumentView::DispatchInputEvent(const mojo::EventPtr& event) { scoped_ptr web_event = ConvertEvent(event, GetDevicePixelRatio()); - if (web_event) - web_view_->handleInputEvent(*web_event); + return web_event && web_view_->handleInputEvent(*web_event); +} + +void DocumentView::OnViewInputEvent( + mojo::View* view, const mojo::EventPtr& event) { + + scoped_ptr ui_event(event.To>()); + ui::TouchEvent* touch_event = nullptr; + if (ui_event->IsTouchEvent()) { + touch_event = static_cast(ui_event.get()); + ui::GestureRecognizer::Get()->ProcessTouchEventPreDispatch( + *touch_event, this); + } + + bool handled = DispatchInputEvent(event); + + if (touch_event) { + ui::EventResult result = handled ? ui::ER_UNHANDLED : ui::ER_UNHANDLED; + if (auto gestures = ui::GestureRecognizer::Get()->ProcessTouchEventPostDispatch( + *touch_event, result, this)) { + for (auto& gesture : *gestures) + DispatchInputEvent(mojo::Event::From(*gesture)); + } + } } class InspectorHostImpl : public inspector::InspectorHost { diff --git a/viewer/document_view.h b/viewer/document_view.h index 3c57354cfa5..56568d5123f 100644 --- a/viewer/document_view.h +++ b/viewer/document_view.h @@ -23,6 +23,7 @@ #include "sky/engine/public/web/WebFrameClient.h" #include "sky/engine/public/web/WebViewClient.h" #include "sky/viewer/services/inspector_impl.h" +#include "ui/events/gestures/gesture_types.h" namespace mojo { class ViewManager; @@ -42,18 +43,19 @@ class Layer; class LayerHost; class DocumentView : public blink::ServiceProvider, - public blink::WebViewClient, public blink::WebFrameClient, + public blink::WebViewClient, + public mojo::ViewManagerDelegate, + public mojo::ViewObserver, public sky::LayerClient, public sky::LayerHostClient, - public mojo::ViewManagerDelegate, - public mojo::ViewObserver { + public ui::GestureConsumer { public: DocumentView(mojo::InterfaceRequest services, mojo::ServiceProviderPtr exported_services, mojo::URLResponsePtr response, mojo::Shell* shell); - virtual ~DocumentView(); + ~DocumentView() override; base::WeakPtr GetWeakPtr(); @@ -121,6 +123,8 @@ class DocumentView : public blink::ServiceProvider, void OnViewDestroyed(mojo::View* view) override; void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override; + bool DispatchInputEvent(const mojo::EventPtr& event); + void Load(mojo::URLResponsePtr response); float GetDevicePixelRatio() const; scoped_ptr CreateRasterizer();