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 #include "services/ui/input_manager/input_associate.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "mojo/public/cpp/bindings/interface_request.h" |
| 10 |
| 11 namespace input_manager { |
| 12 |
| 13 InputAssociate::InputAssociate() {} |
| 14 |
| 15 InputAssociate::~InputAssociate() {} |
| 16 |
| 17 void InputAssociate::Connect(mojo::ui::ViewInspectorPtr inspector, |
| 18 const ConnectCallback& callback) { |
| 19 DCHECK(inspector); // checked by mojom |
| 20 |
| 21 auto info = mojo::ui::ViewAssociateInfo::New(); |
| 22 info->view_service_names.push_back(mojo::ui::InputConnection::Name_); |
| 23 info->view_tree_service_names.push_back(mojo::ui::InputDispatcher::Name_); |
| 24 callback.Run(info.Pass()); |
| 25 } |
| 26 |
| 27 void InputAssociate::ConnectToViewService( |
| 28 mojo::ui::ViewTokenPtr view_token, |
| 29 const mojo::String& service_name, |
| 30 mojo::ScopedMessagePipeHandle client_handle) { |
| 31 DCHECK(view_token); // checked by mojom |
| 32 |
| 33 if (service_name == mojo::ui::InputConnection::Name_) { |
| 34 input_connections_.AddBinding( |
| 35 new InputConnectionImpl(this, view_token.Pass()), |
| 36 mojo::MakeRequest<mojo::ui::InputConnection>(client_handle.Pass())); |
| 37 } |
| 38 } |
| 39 |
| 40 void InputAssociate::ConnectToViewTreeService( |
| 41 mojo::ui::ViewTreeTokenPtr view_tree_token, |
| 42 const mojo::String& service_name, |
| 43 mojo::ScopedMessagePipeHandle client_handle) { |
| 44 DCHECK(view_tree_token); // checked by mojom |
| 45 |
| 46 if (service_name == mojo::ui::InputDispatcher::Name_) { |
| 47 input_dispatchers_.AddBinding( |
| 48 new InputDispatcherImpl(this, view_tree_token.Pass()), |
| 49 mojo::MakeRequest<mojo::ui::InputDispatcher>(client_handle.Pass())); |
| 50 } |
| 51 } |
| 52 |
| 53 void InputAssociate::SetListener(mojo::ui::ViewToken* view_token, |
| 54 mojo::ui::InputListenerPtr listener) { |
| 55 // TODO(jeffbrown): This simple hack just hooks up the first listener |
| 56 // ever seen. |
| 57 listener_ = listener.Pass(); |
| 58 } |
| 59 |
| 60 void InputAssociate::DispatchEvent(mojo::ui::ViewTreeToken* view_tree_token, |
| 61 mojo::EventPtr event) { |
| 62 if (listener_) |
| 63 listener_->OnEvent( |
| 64 event.Pass(), |
| 65 base::Bind(&InputAssociate::OnEventFinished, base::Unretained(this))); |
| 66 } |
| 67 |
| 68 void InputAssociate::OnEventFinished(bool handled) { |
| 69 // TODO: detect ANRs |
| 70 } |
| 71 |
| 72 InputAssociate::InputConnectionImpl::InputConnectionImpl( |
| 73 InputAssociate* associate, |
| 74 mojo::ui::ViewTokenPtr view_token) |
| 75 : associate_(associate), view_token_(view_token.Pass()) { |
| 76 DCHECK(associate_); |
| 77 DCHECK(view_token_); |
| 78 } |
| 79 |
| 80 InputAssociate::InputConnectionImpl::~InputConnectionImpl() {} |
| 81 |
| 82 void InputAssociate::InputConnectionImpl::SetListener( |
| 83 mojo::ui::InputListenerPtr listener) { |
| 84 associate_->SetListener(view_token_.get(), listener.Pass()); |
| 85 } |
| 86 |
| 87 InputAssociate::InputDispatcherImpl::InputDispatcherImpl( |
| 88 InputAssociate* associate, |
| 89 mojo::ui::ViewTreeTokenPtr view_tree_token) |
| 90 : associate_(associate), view_tree_token_(view_tree_token.Pass()) { |
| 91 DCHECK(associate_); |
| 92 DCHECK(view_tree_token_); |
| 93 } |
| 94 |
| 95 InputAssociate::InputDispatcherImpl::~InputDispatcherImpl() {} |
| 96 |
| 97 void InputAssociate::InputDispatcherImpl::DispatchEvent(mojo::EventPtr event) { |
| 98 associate_->DispatchEvent(view_tree_token_.get(), event.Pass()); |
| 99 } |
| 100 |
| 101 } // namespace input_manager |
OLD | NEW |