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 "ui/views/corewm/compound_event_filter.h" | 5 #include "ui/views/corewm/compound_event_filter.h" |
6 | 6 |
7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "ui/aura/client/activation_client.h" | 9 #include "ui/aura/client/activation_client.h" |
10 #include "ui/aura/client/cursor_client.h" | 10 #include "ui/aura/client/cursor_client.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 if (ignored_keys.count(event.key_code()) > 0) | 63 if (ignored_keys.count(event.key_code()) > 0) |
64 return false; | 64 return false; |
65 | 65 |
66 return true; | 66 return true; |
67 #else // !defined(OS_CHROMEOS) | 67 #else // !defined(OS_CHROMEOS) |
68 return false; | 68 return false; |
69 #endif // defined(OS_CHROMEOS) | 69 #endif // defined(OS_CHROMEOS) |
70 } | 70 } |
71 | 71 |
| 72 // Returns true if the cursor should be hidden on touch events. |
| 73 bool ShouldHideCursorOnTouch() { |
| 74 #if defined(OS_CHROMEOS) |
| 75 return true; |
| 76 #else |
| 77 // Not necessary on windows as windows does it for us. If we do need this |
| 78 // funcionality on linux (non-chromeos) we need to make sure |
| 79 // CompoundEventFilter shows on the right root (it currently doesn't always). |
| 80 return false; |
| 81 #endif |
| 82 } |
| 83 |
72 } // namespace | 84 } // namespace |
73 | 85 |
74 //////////////////////////////////////////////////////////////////////////////// | 86 //////////////////////////////////////////////////////////////////////////////// |
75 // CompoundEventFilter, public: | 87 // CompoundEventFilter, public: |
76 | 88 |
77 CompoundEventFilter::CompoundEventFilter() : cursor_hidden_by_filter_(false) { | 89 CompoundEventFilter::CompoundEventFilter() : cursor_hidden_by_filter_(false) { |
78 } | 90 } |
79 | 91 |
80 CompoundEventFilter::~CompoundEventFilter() { | 92 CompoundEventFilter::~CompoundEventFilter() { |
81 // Additional filters are not owned by CompoundEventFilter and they | 93 // Additional filters are not owned by CompoundEventFilter and they |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 ObserverListBase<ui::EventHandler>::Iterator it(handlers_); | 178 ObserverListBase<ui::EventHandler>::Iterator it(handlers_); |
167 ui::EventHandler* handler; | 179 ui::EventHandler* handler; |
168 while (!event->stopped_propagation() && (handler = it.GetNext()) != NULL) | 180 while (!event->stopped_propagation() && (handler = it.GetNext()) != NULL) |
169 handler->OnTouchEvent(event); | 181 handler->OnTouchEvent(event); |
170 } | 182 } |
171 } | 183 } |
172 | 184 |
173 void CompoundEventFilter::SetCursorVisibilityOnEvent(aura::Window* target, | 185 void CompoundEventFilter::SetCursorVisibilityOnEvent(aura::Window* target, |
174 ui::Event* event, | 186 ui::Event* event, |
175 bool show) { | 187 bool show) { |
| 188 DCHECK(ShouldHideCursorOnTouch()); |
176 if (event->flags() & ui::EF_IS_SYNTHESIZED) | 189 if (event->flags() & ui::EF_IS_SYNTHESIZED) |
177 return; | 190 return; |
178 | 191 |
179 aura::client::CursorClient* client = | 192 aura::client::CursorClient* client = |
180 aura::client::GetCursorClient(target->GetRootWindow()); | 193 aura::client::GetCursorClient(target->GetRootWindow()); |
181 if (!client) | 194 if (!client) |
182 return; | 195 return; |
183 | 196 |
184 if (show && cursor_hidden_by_filter_) { | 197 if (show && cursor_hidden_by_filter_) { |
185 cursor_hidden_by_filter_ = false; | 198 cursor_hidden_by_filter_ = false; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 // It should also update the cursor for clicking and wheels for ChromeOS boot. | 247 // It should also update the cursor for clicking and wheels for ChromeOS boot. |
235 // When ChromeOS is booted, it hides the mouse cursor but immediate mouse | 248 // When ChromeOS is booted, it hides the mouse cursor but immediate mouse |
236 // operation will show the cursor. | 249 // operation will show the cursor. |
237 // We also update the cursor for mouse enter in case a mouse cursor is sent to | 250 // We also update the cursor for mouse enter in case a mouse cursor is sent to |
238 // outside of the root window and moved back for some reasons (e.g. running on | 251 // outside of the root window and moved back for some reasons (e.g. running on |
239 // on Desktop for testing, or a bug in pointer barrier). | 252 // on Desktop for testing, or a bug in pointer barrier). |
240 if (event->type() == ui::ET_MOUSE_ENTERED || | 253 if (event->type() == ui::ET_MOUSE_ENTERED || |
241 event->type() == ui::ET_MOUSE_MOVED || | 254 event->type() == ui::ET_MOUSE_MOVED || |
242 event->type() == ui::ET_MOUSE_PRESSED || | 255 event->type() == ui::ET_MOUSE_PRESSED || |
243 event->type() == ui::ET_MOUSEWHEEL) { | 256 event->type() == ui::ET_MOUSEWHEEL) { |
244 SetMouseEventsEnableStateOnEvent(window, event, true); | 257 if (ShouldHideCursorOnTouch()) { |
245 SetCursorVisibilityOnEvent(window, event, true); | 258 SetMouseEventsEnableStateOnEvent(window, event, true); |
| 259 SetCursorVisibilityOnEvent(window, event, true); |
| 260 } |
246 UpdateCursor(window, event); | 261 UpdateCursor(window, event); |
247 } | 262 } |
248 | 263 |
249 FilterMouseEvent(event); | 264 FilterMouseEvent(event); |
250 } | 265 } |
251 | 266 |
252 void CompoundEventFilter::OnScrollEvent(ui::ScrollEvent* event) { | 267 void CompoundEventFilter::OnScrollEvent(ui::ScrollEvent* event) { |
253 } | 268 } |
254 | 269 |
255 void CompoundEventFilter::OnTouchEvent(ui::TouchEvent* event) { | 270 void CompoundEventFilter::OnTouchEvent(ui::TouchEvent* event) { |
256 FilterTouchEvent(event); | 271 FilterTouchEvent(event); |
257 if (!event->handled() && event->type() == ui::ET_TOUCH_PRESSED && | 272 if (ShouldHideCursorOnTouch() && !event->handled() && |
| 273 event->type() == ui::ET_TOUCH_PRESSED && |
258 !aura::Env::GetInstance()->IsMouseButtonDown()) { | 274 !aura::Env::GetInstance()->IsMouseButtonDown()) { |
259 SetMouseEventsEnableStateOnEvent( | 275 SetMouseEventsEnableStateOnEvent( |
260 static_cast<aura::Window*>(event->target()), event, false); | 276 static_cast<aura::Window*>(event->target()), event, false); |
261 } | 277 } |
262 } | 278 } |
263 | 279 |
264 void CompoundEventFilter::OnGestureEvent(ui::GestureEvent* event) { | 280 void CompoundEventFilter::OnGestureEvent(ui::GestureEvent* event) { |
265 if (handlers_.might_have_observers()) { | 281 if (handlers_.might_have_observers()) { |
266 ObserverListBase<ui::EventHandler>::Iterator it(handlers_); | 282 ObserverListBase<ui::EventHandler>::Iterator it(handlers_); |
267 ui::EventHandler* handler; | 283 ui::EventHandler* handler; |
268 while (!event->stopped_propagation() && (handler = it.GetNext()) != NULL) | 284 while (!event->stopped_propagation() && (handler = it.GetNext()) != NULL) |
269 handler->OnGestureEvent(event); | 285 handler->OnGestureEvent(event); |
270 } | 286 } |
271 } | 287 } |
272 | 288 |
273 } // namespace corewm | 289 } // namespace corewm |
274 } // namespace views | 290 } // namespace views |
OLD | NEW |