Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/gpu/input_handler_manager.h" | 5 #include "content/renderer/gpu/input_handler_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "cc/input/input_handler.h" | 9 #include "cc/input/input_handler.h" |
| 10 #include "content/renderer/gpu/input_event_filter.h" | 10 #include "content/renderer/gpu/input_event_filter.h" |
| 11 #include "content/renderer/gpu/input_handler_manager_client.h" | |
| 11 #include "content/renderer/gpu/input_handler_wrapper.h" | 12 #include "content/renderer/gpu/input_handler_wrapper.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa rameters.h" | |
| 13 | 13 |
| 14 using WebKit::WebInputEvent; | 14 using WebKit::WebInputEvent; |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 InputHandlerManager::InputHandlerManager( | 18 InputHandlerManager::InputHandlerManager( |
| 19 IPC::Listener* main_listener, | |
| 20 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy) | 19 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy) |
| 21 : message_loop_proxy_(message_loop_proxy) { | 20 : message_loop_proxy_(message_loop_proxy) { |
| 22 filter_ = | |
| 23 new InputEventFilter(main_listener, | |
| 24 message_loop_proxy, | |
| 25 base::Bind(&InputHandlerManager::HandleInputEvent, | |
| 26 base::Unretained(this))); | |
| 27 } | 21 } |
| 28 | 22 |
| 29 InputHandlerManager::~InputHandlerManager() { | 23 InputHandlerManager::~InputHandlerManager() { |
|
joth
2013/05/31 18:05:08
should this unbind Handler() instance from the cli
jdduke (slow)
2013/05/31 20:48:24
You're absolutely right, I had that in and must ha
| |
| 30 } | 24 } |
| 31 | 25 |
| 32 IPC::ChannelProxy::MessageFilter* | 26 void InputHandlerManager::BindToClient(InputHandlerManagerClient* client) { |
| 33 InputHandlerManager::GetMessageFilter() const { | 27 DCHECK(!client_ || !client); |
| 34 return filter_; | 28 if (client_) |
| 29 client->DidBind(InputHandlerManagerClient::Handler()); | |
| 30 | |
| 31 client_ = client; | |
| 32 | |
| 33 if (client_) { | |
| 34 client->DidBind(base::Bind(&InputHandlerManager::HandleInputEvent, | |
| 35 base::Unretained(this))); | |
|
joth
2013/05/31 18:05:08
nit: intent to next open-paren
jdduke (slow)
2013/05/31 20:48:24
Done.
| |
| 36 } | |
| 35 } | 37 } |
| 36 | 38 |
| 37 void InputHandlerManager::AddInputHandler( | 39 void InputHandlerManager::AddInputHandler( |
| 38 int routing_id, | 40 int routing_id, |
| 39 const base::WeakPtr<cc::InputHandler>& input_handler, | 41 const base::WeakPtr<cc::InputHandler>& input_handler, |
| 40 const base::WeakPtr<RenderViewImpl>& render_view_impl) { | 42 const base::WeakPtr<RenderViewImpl>& render_view_impl) { |
| 41 DCHECK(!message_loop_proxy_->BelongsToCurrentThread()); | 43 if (message_loop_proxy_->BelongsToCurrentThread()) { |
| 42 | 44 AddInputHandlerOnCompositorThread(routing_id, |
| 43 message_loop_proxy_->PostTask( | 45 base::MessageLoopProxy::current(), |
| 44 FROM_HERE, | 46 input_handler, |
| 45 base::Bind(&InputHandlerManager::AddInputHandlerOnCompositorThread, | 47 render_view_impl); |
| 46 base::Unretained(this), | 48 } else { |
| 47 routing_id, | 49 message_loop_proxy_->PostTask( |
| 48 base::MessageLoopProxy::current(), | 50 FROM_HERE, |
| 49 input_handler, | 51 base::Bind(&InputHandlerManager::AddInputHandlerOnCompositorThread, |
| 50 render_view_impl)); | 52 base::Unretained(this), |
|
joth
2013/05/31 18:05:08
Any idea why the Unretained() is safe here? (I see
jdduke (slow)
2013/05/31 20:48:24
Right.
| |
| 53 routing_id, | |
| 54 base::MessageLoopProxy::current(), | |
| 55 input_handler, | |
| 56 render_view_impl)); | |
| 57 } | |
| 51 } | 58 } |
| 52 | 59 |
| 53 void InputHandlerManager::AddInputHandlerOnCompositorThread( | 60 void InputHandlerManager::AddInputHandlerOnCompositorThread( |
| 54 int routing_id, | 61 int routing_id, |
| 55 const scoped_refptr<base::MessageLoopProxy>& main_loop, | 62 const scoped_refptr<base::MessageLoopProxy>& main_loop, |
| 56 const base::WeakPtr<cc::InputHandler>& input_handler, | 63 const base::WeakPtr<cc::InputHandler>& input_handler, |
| 57 const base::WeakPtr<RenderViewImpl>& render_view_impl) { | 64 const base::WeakPtr<RenderViewImpl>& render_view_impl) { |
| 65 DCHECK(client_); | |
| 58 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 66 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 59 | 67 |
| 60 // The handler could be gone by this point if the compositor has shut down. | 68 // The handler could be gone by this point if the compositor has shut down. |
| 61 if (!input_handler) | 69 if (!input_handler) |
| 62 return; | 70 return; |
| 63 | 71 |
| 64 // The same handler may be registered for a route multiple times. | 72 // The same handler may be registered for a route multiple times. |
| 65 if (input_handlers_.count(routing_id) != 0) | 73 if (input_handlers_.count(routing_id) != 0) |
| 66 return; | 74 return; |
| 67 | 75 |
| 68 TRACE_EVENT0("InputHandlerManager::AddInputHandler", "AddingRoute"); | 76 TRACE_EVENT0("InputHandlerManager::AddInputHandler", "AddingRoute"); |
| 69 filter_->AddRoute(routing_id); | 77 client_->DidAddInputHandler(routing_id); |
| 70 input_handlers_[routing_id] = | 78 input_handlers_[routing_id] = |
| 71 make_scoped_refptr(new InputHandlerWrapper(this, | 79 make_scoped_refptr(new InputHandlerWrapper(this, |
| 72 routing_id, main_loop, input_handler, render_view_impl)); | 80 routing_id, main_loop, input_handler, render_view_impl)); |
| 73 } | 81 } |
| 74 | 82 |
| 75 void InputHandlerManager::RemoveInputHandler(int routing_id) { | 83 void InputHandlerManager::RemoveInputHandler(int routing_id) { |
| 84 DCHECK(client_); | |
| 76 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 85 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 77 | 86 |
| 78 TRACE_EVENT0("InputHandlerManager::RemoveInputHandler", "RemovingRoute"); | 87 TRACE_EVENT0("InputHandlerManager::RemoveInputHandler", "RemovingRoute"); |
| 79 | 88 |
| 80 filter_->RemoveRoute(routing_id); | 89 client_->DidRemoveInputHandler(routing_id); |
| 81 input_handlers_.erase(routing_id); | 90 input_handlers_.erase(routing_id); |
| 82 } | 91 } |
| 83 | 92 |
| 84 void InputHandlerManager::HandleInputEvent( | 93 void InputHandlerManager::HandleInputEvent( |
| 85 int routing_id, | 94 int routing_id, |
| 86 const WebInputEvent* input_event) { | 95 const WebInputEvent* input_event) { |
| 96 DCHECK(client_); | |
| 87 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 97 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 88 | 98 |
| 89 InputHandlerMap::iterator it = input_handlers_.find(routing_id); | 99 InputHandlerMap::iterator it = input_handlers_.find(routing_id); |
| 90 if (it == input_handlers_.end()) { | 100 if (it == input_handlers_.end()) { |
| 91 TRACE_EVENT0("InputHandlerManager::HandleInputEvent", | 101 TRACE_EVENT0("InputHandlerManager::HandleInputEvent", |
| 92 "NoInputHandlerFound"); | 102 "NoInputHandlerFound"); |
| 93 // Oops, we no longer have an interested input handler.. | 103 // Oops, we no longer have an interested input handler.. |
| 94 filter_->DidNotHandleInputEvent(true); | 104 client_->DidNotHandleInputEvent(true); |
| 95 return; | 105 return; |
| 96 } | 106 } |
| 97 | 107 |
| 98 it->second->input_handler_proxy()->HandleInputEvent(*input_event); | 108 it->second->input_handler_proxy()->HandleInputEvent(*input_event); |
| 99 } | 109 } |
| 100 | 110 |
| 101 } // namespace content | 111 } // namespace content |
| OLD | NEW |