OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_UI_INPUT_HANDLER_H_ |
| 6 #define MOJO_UI_INPUT_HANDLER_H_ |
| 7 |
| 8 #include "mojo/public/cpp/bindings/binding.h" |
| 9 #include "mojo/public/cpp/system/macros.h" |
| 10 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
| 11 #include "mojo/services/ui/input/interfaces/input_connection.mojom.h" |
| 12 |
| 13 namespace mojo { |
| 14 namespace ui { |
| 15 |
| 16 // Holds an |InputConnection| and sets its |InputListener|. |
| 17 // |
| 18 // This class is intended to be included as a member of a View that wants to |
| 19 // receive input using the following pattern. |
| 20 // |
| 21 // class MyView : public mojo::ui::BaseView, public mojo::ui::InputListener { |
| 22 // public: |
| 23 // MyView(mojo::ApplicationImpl* app_impl, |
| 24 // const mojo::ui::ViewProvider::CreateViewCallback& |
| 25 // create_view_callback) |
| 26 // : BaseView(app_impl, "MyView", create_view_callback), |
| 27 // input_handler_(view_service_provider(), this) {} |
| 28 // ~MyView() override {} |
| 29 // |
| 30 // private: |
| 31 // // |InputListener|: |
| 32 // void OnEvent(mojo::EventPtr event, |
| 33 // const OnEventCallback& callback) override; |
| 34 // |
| 35 // mojo::ui::InputHandler input_handler_; |
| 36 // |
| 37 // MOJO_DISALLOW_COPY_AND_ASSIGN(MyView); |
| 38 // }; |
| 39 class InputHandler { |
| 40 public: |
| 41 // Creates an input connection associated with the specified view host. |
| 42 InputHandler(mojo::ServiceProvider* service_provider, |
| 43 mojo::ui::InputListener* listener); |
| 44 ~InputHandler(); |
| 45 |
| 46 // Gets the input connection. |
| 47 mojo::ui::InputConnection* connection() { return connection_.get(); } |
| 48 |
| 49 private: |
| 50 mojo::Binding<mojo::ui::InputListener> listener_binding_; |
| 51 mojo::ui::InputConnectionPtr connection_; |
| 52 |
| 53 MOJO_DISALLOW_COPY_AND_ASSIGN(InputHandler); |
| 54 }; |
| 55 |
| 56 } // namespace ui |
| 57 } // namespace mojo |
| 58 |
| 59 #endif // MOJO_UI_INPUT_HANDLER_H_ |
OLD | NEW |