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 "content/renderer/gpu/input_event_filter.h" | 10 #include "content/renderer/gpu/input_event_filter.h" |
| 11 #include "content/renderer/gpu/input_handler_wrapper.h" | |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa rameters.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebActiveWheelFlingPa rameters.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dler.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositorInputHan dlerClient.h" | |
| 13 | 13 |
| 14 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
| 15 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) | 15 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
| 16 #include <sys/resource.h> | 16 #include <sys/resource.h> |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 using WebKit::WebCompositorInputHandler; | |
| 20 using WebKit::WebInputEvent; | 19 using WebKit::WebInputEvent; |
| 21 | 20 |
| 22 namespace content { | 21 namespace content { |
| 23 | 22 |
| 24 //------------------------------------------------------------------------------ | |
| 25 | |
| 26 class InputHandlerManager::InputHandlerWrapper | |
| 27 : public WebKit::WebCompositorInputHandlerClient, | |
| 28 public base::RefCountedThreadSafe<InputHandlerWrapper> { | |
| 29 public: | |
| 30 InputHandlerWrapper(InputHandlerManager* input_handler_manager, | |
| 31 int routing_id, | |
| 32 WebKit::WebCompositorInputHandler* input_handler, | |
| 33 const scoped_refptr<base::MessageLoopProxy>& main_loop, | |
| 34 const base::WeakPtr<RenderViewImpl>& render_view_impl) | |
| 35 : input_handler_manager_(input_handler_manager), | |
| 36 routing_id_(routing_id), | |
| 37 input_handler_(input_handler), | |
| 38 main_loop_(main_loop), | |
| 39 render_view_impl_(render_view_impl) { | |
| 40 input_handler_->setClient(this); | |
| 41 } | |
| 42 | |
| 43 virtual void transferActiveWheelFlingAnimation( | |
| 44 const WebKit::WebActiveWheelFlingParameters& params) { | |
| 45 main_loop_->PostTask( | |
| 46 FROM_HERE, | |
| 47 base::Bind(&RenderViewImpl::TransferActiveWheelFlingAnimation, | |
| 48 render_view_impl_, params)); | |
| 49 } | |
| 50 | |
| 51 int routing_id() const { return routing_id_; } | |
| 52 WebKit::WebCompositorInputHandler* input_handler() const { | |
| 53 return input_handler_; | |
| 54 } | |
| 55 | |
| 56 // WebCompositorInputHandlerClient methods: | |
| 57 | |
| 58 virtual void willShutdown() { | |
| 59 input_handler_manager_->RemoveInputHandler(routing_id_); | |
| 60 } | |
| 61 | |
| 62 virtual void didHandleInputEvent() { | |
| 63 input_handler_manager_->filter_->DidHandleInputEvent(); | |
| 64 } | |
| 65 | |
| 66 virtual void didNotHandleInputEvent(bool send_to_widget) { | |
| 67 input_handler_manager_->filter_->DidNotHandleInputEvent(send_to_widget); | |
| 68 } | |
| 69 | |
| 70 private: | |
| 71 friend class base::RefCountedThreadSafe<InputHandlerWrapper>; | |
| 72 | |
| 73 virtual ~InputHandlerWrapper() { | |
| 74 input_handler_->setClient(NULL); | |
| 75 } | |
| 76 | |
| 77 InputHandlerManager* input_handler_manager_; | |
| 78 int routing_id_; | |
| 79 WebKit::WebCompositorInputHandler* input_handler_; | |
| 80 scoped_refptr<base::MessageLoopProxy> main_loop_; | |
| 81 | |
| 82 // Can only be accessed on the main thread. | |
| 83 base::WeakPtr<RenderViewImpl> render_view_impl_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(InputHandlerWrapper); | |
| 86 }; | |
| 87 | |
| 88 //------------------------------------------------------------------------------ | |
| 89 | |
| 90 #if defined(OS_ANDROID) | 23 #if defined(OS_ANDROID) |
| 91 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) | 24 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
| 92 namespace { | 25 namespace { |
| 93 void SetHighThreadPriority() { | 26 void SetHighThreadPriority() { |
| 94 int nice_value = -6; // High priority. | 27 int nice_value = -6; // High priority. |
| 95 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); | 28 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); |
| 96 } | 29 } |
| 97 } | 30 } |
| 98 #endif | 31 #endif |
| 99 | 32 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 114 | 47 |
| 115 InputHandlerManager::~InputHandlerManager() { | 48 InputHandlerManager::~InputHandlerManager() { |
| 116 } | 49 } |
| 117 | 50 |
| 118 IPC::ChannelProxy::MessageFilter* | 51 IPC::ChannelProxy::MessageFilter* |
| 119 InputHandlerManager::GetMessageFilter() const { | 52 InputHandlerManager::GetMessageFilter() const { |
| 120 return filter_; | 53 return filter_; |
| 121 } | 54 } |
| 122 | 55 |
| 123 void InputHandlerManager::AddInputHandler( | 56 void InputHandlerManager::AddInputHandler( |
| 124 int routing_id, int input_handler_id, | 57 int routing_id, |
| 58 const base::WeakPtr<cc::InputHandler>& input_handler, | |
| 125 const base::WeakPtr<RenderViewImpl>& render_view_impl) { | 59 const base::WeakPtr<RenderViewImpl>& render_view_impl) { |
| 126 DCHECK(!message_loop_proxy_->BelongsToCurrentThread()); | 60 DCHECK(!message_loop_proxy_->BelongsToCurrentThread()); |
| 127 | 61 |
| 128 message_loop_proxy_->PostTask( | 62 message_loop_proxy_->PostTask( |
| 129 FROM_HERE, | 63 FROM_HERE, |
| 130 base::Bind(&InputHandlerManager::AddInputHandlerOnCompositorThread, | 64 base::Bind(&InputHandlerManager::AddInputHandlerOnCompositorThread, |
| 131 base::Unretained(this), | 65 base::Unretained(this), |
| 132 routing_id, | 66 routing_id, |
| 133 input_handler_id, | |
| 134 base::MessageLoopProxy::current(), | 67 base::MessageLoopProxy::current(), |
| 68 input_handler, | |
| 135 render_view_impl)); | 69 render_view_impl)); |
| 136 } | 70 } |
| 137 | 71 |
| 138 void InputHandlerManager::AddInputHandlerOnCompositorThread( | 72 void InputHandlerManager::AddInputHandlerOnCompositorThread( |
| 139 int routing_id, int input_handler_id, | 73 int routing_id, |
| 140 const scoped_refptr<base::MessageLoopProxy>& main_loop, | 74 const scoped_refptr<base::MessageLoopProxy>& main_loop, |
| 75 const base::WeakPtr<cc::InputHandler>& input_handler, | |
| 141 const base::WeakPtr<RenderViewImpl>& render_view_impl) { | 76 const base::WeakPtr<RenderViewImpl>& render_view_impl) { |
| 142 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 77 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 143 | 78 |
| 144 WebCompositorInputHandler* input_handler = | 79 // The handler could be gone by this point if the compositor has shut down. |
| 145 WebCompositorInputHandler::fromIdentifier(input_handler_id); | |
| 146 if (!input_handler) | 80 if (!input_handler) |
| 147 return; | 81 return; |
| 148 | 82 |
| 149 if (input_handlers_.count(routing_id) != 0) { | 83 // The same handler may be registered for a route multiple times. |
| 150 // It's valid to call AddInputHandler() for the same routing id with the | 84 if (input_handlers_.count(routing_id) != 0) |
| 151 // same input_handler many times, but it's not valid to change the | |
| 152 // input_handler for a route. | |
| 153 DCHECK_EQ(input_handlers_[routing_id]->input_handler(), input_handler); | |
|
danakj
2013/05/06 16:33:39
Is it now okay to change input handler for a route
| |
| 154 return; | 85 return; |
| 155 } | |
| 156 | 86 |
| 157 TRACE_EVENT0("InputHandlerManager::AddInputHandler", "AddingRoute"); | 87 TRACE_EVENT0("InputHandlerManager::AddInputHandler", "AddingRoute"); |
| 158 filter_->AddRoute(routing_id); | 88 filter_->AddRoute(routing_id); |
| 159 input_handlers_[routing_id] = | 89 input_handlers_[routing_id] = |
| 160 make_scoped_refptr(new InputHandlerWrapper(this, | 90 make_scoped_refptr(new InputHandlerWrapper(this, |
| 161 routing_id, input_handler, main_loop, render_view_impl)); | 91 routing_id, main_loop, input_handler, render_view_impl)); |
| 162 } | 92 } |
| 163 | 93 |
| 164 void InputHandlerManager::RemoveInputHandler(int routing_id) { | 94 void InputHandlerManager::RemoveInputHandler(int routing_id) { |
| 165 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 95 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 166 | 96 |
| 167 TRACE_EVENT0("InputHandlerManager::RemoveInputHandler", "RemovingRoute"); | 97 TRACE_EVENT0("InputHandlerManager::RemoveInputHandler", "RemovingRoute"); |
| 168 | 98 |
| 169 filter_->RemoveRoute(routing_id); | 99 filter_->RemoveRoute(routing_id); |
| 170 input_handlers_.erase(routing_id); | 100 input_handlers_.erase(routing_id); |
| 171 } | 101 } |
| 172 | 102 |
| 173 void InputHandlerManager::HandleInputEvent( | 103 void InputHandlerManager::HandleInputEvent( |
| 174 int routing_id, | 104 int routing_id, |
| 175 const WebInputEvent* input_event) { | 105 const WebInputEvent* input_event) { |
| 176 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 106 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 177 | 107 |
| 178 InputHandlerMap::iterator it = input_handlers_.find(routing_id); | 108 InputHandlerMap::iterator it = input_handlers_.find(routing_id); |
| 179 if (it == input_handlers_.end()) { | 109 if (it == input_handlers_.end()) { |
| 180 TRACE_EVENT0("InputHandlerManager::HandleInputEvent", | 110 TRACE_EVENT0("InputHandlerManager::HandleInputEvent", |
| 181 "NoInputHandlerFound"); | 111 "NoInputHandlerFound"); |
| 182 // Oops, we no longer have an interested input handler.. | 112 // Oops, we no longer have an interested input handler.. |
| 183 filter_->DidNotHandleInputEvent(true); | 113 filter_->DidNotHandleInputEvent(true); |
| 184 return; | 114 return; |
| 185 } | 115 } |
| 186 | 116 |
| 187 it->second->input_handler()->handleInputEvent(*input_event); | 117 it->second->input_handler_proxy()->HandleInputEvent(*input_event); |
| 188 } | 118 } |
| 189 | 119 |
| 190 } // namespace content | 120 } // namespace content |
| OLD | NEW |