Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: content/renderer/gpu/input_handler_manager.cc

Issue 15920002: Fix WebView compositor input handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make InputEventAckState public Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #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::WebInputEvent; 19 using WebKit::WebInputEvent;
20 20
21 namespace content { 21 namespace content {
22 22
23 #if defined(OS_ANDROID) 23 #if defined(OS_ANDROID)
24 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) 24 // TODO(epenner): Move thread priorities to base. (crbug.com/170549)
25 namespace { 25 namespace {
26 void SetHighThreadPriority() { 26 void SetHighThreadPriority() {
27 int nice_value = -6; // High priority. 27 int nice_value = -6; // High priority.
28 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); 28 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value);
29 } 29 }
30 } 30 }
31 #endif 31 #endif
32 32
33 InputHandlerManager::InputHandlerManager( 33 InputHandlerManager::InputHandlerManager(
34 IPC::Listener* main_listener,
35 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy) 34 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy)
36 : message_loop_proxy_(message_loop_proxy) { 35 : message_loop_proxy_(message_loop_proxy),
37 filter_ = 36 client_(NULL) {
38 new InputEventFilter(main_listener,
39 message_loop_proxy,
40 base::Bind(&InputHandlerManager::HandleInputEvent,
41 base::Unretained(this)));
42 #if defined(OS_ANDROID) 37 #if defined(OS_ANDROID)
43 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) 38 // TODO(epenner): Move thread priorities to base. (crbug.com/170549)
44 message_loop_proxy->PostTask(FROM_HERE, base::Bind(&SetHighThreadPriority)); 39 message_loop_proxy_->PostTask(FROM_HERE, base::Bind(&SetHighThreadPriority));
45 #endif 40 #endif
46 } 41 }
47 42
48 InputHandlerManager::~InputHandlerManager() { 43 InputHandlerManager::~InputHandlerManager() {
49 } 44 }
50 45
51 IPC::ChannelProxy::MessageFilter* 46 void InputHandlerManager::BindToClient(InputHandlerManagerClient* client) {
52 InputHandlerManager::GetMessageFilter() const { 47 DCHECK(!client_ || !client);
53 return filter_; 48 client_ = client;
54 } 49 }
55 50
56 void InputHandlerManager::AddInputHandler( 51 void InputHandlerManager::AddInputHandler(
57 int routing_id, 52 int routing_id,
58 const base::WeakPtr<cc::InputHandler>& input_handler, 53 const base::WeakPtr<cc::InputHandler>& input_handler,
59 const base::WeakPtr<RenderViewImpl>& render_view_impl) { 54 const base::WeakPtr<RenderViewImpl>& render_view_impl) {
60 DCHECK(!message_loop_proxy_->BelongsToCurrentThread()); 55 if (message_loop_proxy_->BelongsToCurrentThread()) {
61 56 AddInputHandlerOnCompositorThread(routing_id,
62 message_loop_proxy_->PostTask( 57 base::MessageLoopProxy::current(),
63 FROM_HERE, 58 input_handler,
64 base::Bind(&InputHandlerManager::AddInputHandlerOnCompositorThread, 59 render_view_impl);
65 base::Unretained(this), 60 } else {
66 routing_id, 61 message_loop_proxy_->PostTask(
67 base::MessageLoopProxy::current(), 62 FROM_HERE,
68 input_handler, 63 base::Bind(&InputHandlerManager::AddInputHandlerOnCompositorThread,
69 render_view_impl)); 64 base::Unretained(this),
65 routing_id,
66 base::MessageLoopProxy::current(),
67 input_handler,
68 render_view_impl));
69 }
70 } 70 }
71 71
72 void InputHandlerManager::AddInputHandlerOnCompositorThread( 72 void InputHandlerManager::AddInputHandlerOnCompositorThread(
73 int routing_id, 73 int routing_id,
74 const scoped_refptr<base::MessageLoopProxy>& main_loop, 74 const scoped_refptr<base::MessageLoopProxy>& main_loop,
75 const base::WeakPtr<cc::InputHandler>& input_handler, 75 const base::WeakPtr<cc::InputHandler>& input_handler,
76 const base::WeakPtr<RenderViewImpl>& render_view_impl) { 76 const base::WeakPtr<RenderViewImpl>& render_view_impl) {
77 DCHECK(client_);
77 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); 78 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
78 79
79 // The handler could be gone by this point if the compositor has shut down. 80 // The handler could be gone by this point if the compositor has shut down.
80 if (!input_handler) 81 if (!input_handler)
81 return; 82 return;
82 83
83 // The same handler may be registered for a route multiple times. 84 // The same handler may be registered for a route multiple times.
84 if (input_handlers_.count(routing_id) != 0) 85 if (input_handlers_.count(routing_id) != 0)
85 return; 86 return;
86 87
87 TRACE_EVENT0("InputHandlerManager::AddInputHandler", "AddingRoute"); 88 TRACE_EVENT0("InputHandlerManager::AddInputHandler", "AddingRoute");
88 filter_->AddRoute(routing_id); 89 client_->DidAddInputHandler(routing_id);
89 input_handlers_[routing_id] = 90 input_handlers_[routing_id] =
90 make_scoped_refptr(new InputHandlerWrapper(this, 91 make_scoped_refptr(new InputHandlerWrapper(this,
91 routing_id, main_loop, input_handler, render_view_impl)); 92 routing_id, main_loop, input_handler, render_view_impl));
92 } 93 }
93 94
94 void InputHandlerManager::RemoveInputHandler(int routing_id) { 95 void InputHandlerManager::RemoveInputHandler(int routing_id) {
96 DCHECK(client_);
95 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); 97 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
96 98
97 TRACE_EVENT0("InputHandlerManager::RemoveInputHandler", "RemovingRoute"); 99 TRACE_EVENT0("InputHandlerManager::RemoveInputHandler", "RemovingRoute");
98 100
99 filter_->RemoveRoute(routing_id); 101 client_->DidRemoveInputHandler(routing_id);
100 input_handlers_.erase(routing_id); 102 input_handlers_.erase(routing_id);
101 } 103 }
102 104
103 void InputHandlerManager::HandleInputEvent( 105 void InputHandlerManager::HandleInputEvent(
104 int routing_id, 106 int routing_id,
105 const WebInputEvent* input_event) { 107 const WebInputEvent* input_event) {
108 DCHECK(client_);
106 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); 109 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
107 110
108 InputHandlerMap::iterator it = input_handlers_.find(routing_id); 111 InputHandlerMap::iterator it = input_handlers_.find(routing_id);
109 if (it == input_handlers_.end()) { 112 if (it == input_handlers_.end()) {
110 TRACE_EVENT0("InputHandlerManager::HandleInputEvent", 113 TRACE_EVENT0("InputHandlerManager::HandleInputEvent",
111 "NoInputHandlerFound"); 114 "NoInputHandlerFound");
112 // Oops, we no longer have an interested input handler.. 115 // Oops, we no longer have an interested input handler..
113 filter_->DidNotHandleInputEvent(true); 116 client_->DidNotHandleInputEvent(true);
114 return; 117 return;
115 } 118 }
116 119
117 it->second->input_handler_proxy()->HandleInputEvent(*input_event); 120 it->second->input_handler_proxy()->HandleInputEvent(*input_event);
118 } 121 }
119 122
120 } // namespace content 123 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698