Move gesture recognition from WindowManagerApp to Sky

In order to have a high-quality gesture system, we need to know many details
about the fine-grained structure of applications. For example, different parts
of the view might be interested in recognizing different gestures and when you
recognize a certain gesture depends on the set of possible gestures.

This CL is a first step towards implementing
https://github.com/domokit/mojo/blob/master/sky/specs/gestures.md by moving the
gesture recognition into Sky where finer-grained information will be available.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/868463010
This commit is contained in:
Adam Barth 2015-01-29 14:52:15 -08:00
parent 36e9c3e46e
commit 77e5182631
3 changed files with 38 additions and 8 deletions

View File

@ -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",
]
}

View File

@ -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> 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<blink::WebInputEvent> 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> ui_event(event.To<scoped_ptr<ui::Event>>());
ui::TouchEvent* touch_event = nullptr;
if (ui_event->IsTouchEvent()) {
touch_event = static_cast<ui::TouchEvent*>(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 {

View File

@ -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<mojo::ServiceProvider> services,
mojo::ServiceProviderPtr exported_services,
mojo::URLResponsePtr response,
mojo::Shell* shell);
virtual ~DocumentView();
~DocumentView() override;
base::WeakPtr<DocumentView> 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<Rasterizer> CreateRasterizer();