Index: mojo/ui/input_handler.h |
diff --git a/mojo/ui/input_handler.h b/mojo/ui/input_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..50735848f24971844b3c35287a7028cc03694a41 |
--- /dev/null |
+++ b/mojo/ui/input_handler.h |
@@ -0,0 +1,59 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MOJO_UI_INPUT_HANDLER_H_ |
+#define MOJO_UI_INPUT_HANDLER_H_ |
+ |
+#include "mojo/public/cpp/bindings/binding.h" |
+#include "mojo/public/cpp/system/macros.h" |
+#include "mojo/public/interfaces/application/service_provider.mojom.h" |
+#include "mojo/services/ui/input/interfaces/input_connection.mojom.h" |
+ |
+namespace mojo { |
+namespace ui { |
+ |
+// Holds an |InputConnection| and sets its |InputListener|. |
+// |
+// This class is intended to be included as a member of a View that wants to |
+// receive input using the following pattern. |
+// |
+// class MyView : public mojo::ui::BaseView, public mojo::ui::InputListener { |
+// public: |
+// MyView(mojo::ApplicationImpl* app_impl, |
+// const mojo::ui::ViewProvider::CreateViewCallback& |
+// create_view_callback) |
+// : BaseView(app_impl, "MyView", create_view_callback), |
+// input_handler_(view_service_provider(), this) {} |
+// ~MyView() override {} |
+// |
+// private: |
+// // |InputListener|: |
+// void OnEvent(mojo::EventPtr event, |
+// const OnEventCallback& callback) override; |
+// |
+// mojo::ui::InputHandler input_handler_; |
+// |
+// MOJO_DISALLOW_COPY_AND_ASSIGN(MyView); |
+// }; |
+class InputHandler { |
+ public: |
+ // Creates an input connection associated with the specified view host. |
+ InputHandler(mojo::ServiceProvider* service_provider, |
+ mojo::ui::InputListener* listener); |
+ ~InputHandler(); |
+ |
+ // Gets the input connection. |
+ mojo::ui::InputConnection* connection() { return connection_.get(); } |
+ |
+ private: |
+ mojo::Binding<mojo::ui::InputListener> listener_binding_; |
+ mojo::ui::InputConnectionPtr connection_; |
+ |
+ MOJO_DISALLOW_COPY_AND_ASSIGN(InputHandler); |
+}; |
+ |
+} // namespace ui |
+} // namespace mojo |
+ |
+#endif // MOJO_UI_INPUT_HANDLER_H_ |