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

Side by Side Diff: services/ui/ws/event_dispatcher.cc

Issue 2125883003: Adds ability for pre-target accelerators to not consume events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 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 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 "services/ui/ws/event_dispatcher.h" 5 #include "services/ui/ws/event_dispatcher.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "services/ui/ws/accelerator.h" 10 #include "services/ui/ws/accelerator.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return true; 246 return true;
247 } 247 }
248 248
249 void EventDispatcher::RemoveAccelerator(uint32_t id) { 249 void EventDispatcher::RemoveAccelerator(uint32_t id) {
250 auto it = accelerators_.find(id); 250 auto it = accelerators_.find(id);
251 // Clients may pass bogus ids. 251 // Clients may pass bogus ids.
252 if (it != accelerators_.end()) 252 if (it != accelerators_.end())
253 accelerators_.erase(it); 253 accelerators_.erase(it);
254 } 254 }
255 255
256 void EventDispatcher::ProcessEvent(const ui::Event& event) { 256 void EventDispatcher::ProcessEvent(const ui::Event& event,
257 AcceleratorMatchPhase match_phase) {
257 if (event.IsKeyEvent()) { 258 if (event.IsKeyEvent()) {
sadrul 2016/07/08 15:40:43 Should we add some debug check here to verify that
sky 2016/07/08 16:23:51 Done.
258 const ui::KeyEvent* key_event = event.AsKeyEvent(); 259 const ui::KeyEvent* key_event = event.AsKeyEvent();
259 if (event.type() == ui::ET_KEY_PRESSED && !key_event->is_char()) { 260 if (event.type() == ui::ET_KEY_PRESSED && !key_event->is_char() &&
261 match_phase == AcceleratorMatchPhase::ANY) {
260 Accelerator* pre_target = 262 Accelerator* pre_target =
261 FindAccelerator(*key_event, ui::mojom::AcceleratorPhase::PRE_TARGET); 263 FindAccelerator(*key_event, ui::mojom::AcceleratorPhase::PRE_TARGET);
262 if (pre_target) { 264 if (pre_target) {
263 delegate_->OnAccelerator(pre_target->id(), event); 265 delegate_->OnAccelerator(
266 pre_target->id(), event,
267 EventDispatcherDelegate::AcceleratorPhase::PRE);
264 return; 268 return;
265 } 269 }
266 } 270 }
267 ProcessKeyEvent(*key_event); 271 ProcessKeyEvent(*key_event, match_phase);
268 return; 272 return;
269 } 273 }
270 274
271 if (event.IsPointerEvent() || event.IsMouseWheelEvent()) { 275 if (event.IsPointerEvent() || event.IsMouseWheelEvent()) {
272 ProcessLocatedEvent(*event.AsLocatedEvent()); 276 ProcessLocatedEvent(*event.AsLocatedEvent());
273 return; 277 return;
274 } 278 }
275 279
276 NOTREACHED(); 280 NOTREACHED();
277 } 281 }
278 282
279 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event) { 283 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event,
284 AcceleratorMatchPhase match_phase) {
280 Accelerator* post_target = 285 Accelerator* post_target =
281 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET); 286 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET);
282 ServerWindow* focused_window = 287 ServerWindow* focused_window =
283 delegate_->GetFocusedWindowForEventDispatcher(); 288 delegate_->GetFocusedWindowForEventDispatcher();
284 if (focused_window) { 289 if (focused_window) {
285 // Assume key events are for the client area. 290 // Assume key events are for the client area.
286 const bool in_nonclient_area = false; 291 const bool in_nonclient_area = false;
287 const ClientSpecificId client_id = 292 const ClientSpecificId client_id =
288 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area); 293 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area);
289 delegate_->DispatchInputEventToWindow(focused_window, client_id, event, 294 delegate_->DispatchInputEventToWindow(focused_window, client_id, event,
290 post_target); 295 post_target);
291 return; 296 return;
292 } 297 }
293 delegate_->OnEventTargetNotFound(event); 298 delegate_->OnEventTargetNotFound(event);
294 if (post_target) 299 if (post_target)
295 delegate_->OnAccelerator(post_target->id(), event); 300 delegate_->OnAccelerator(post_target->id(), event,
301 EventDispatcherDelegate::AcceleratorPhase::POST);
296 } 302 }
297 303
298 void EventDispatcher::ProcessLocatedEvent(const ui::LocatedEvent& event) { 304 void EventDispatcher::ProcessLocatedEvent(const ui::LocatedEvent& event) {
299 DCHECK(event.IsPointerEvent() || event.IsMouseWheelEvent()); 305 DCHECK(event.IsPointerEvent() || event.IsMouseWheelEvent());
300 const bool is_mouse_event = 306 const bool is_mouse_event =
301 event.IsMousePointerEvent() || event.IsMouseWheelEvent(); 307 event.IsMousePointerEvent() || event.IsMouseWheelEvent();
302 308
303 if (is_mouse_event) { 309 if (is_mouse_event) {
304 mouse_pointer_last_location_ = event.location(); 310 mouse_pointer_last_location_ = event.location();
305 delegate_->OnMouseCursorLocationChanged(event.root_location()); 311 delegate_->OnMouseCursorLocationChanged(event.root_location());
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 if (!it->second) { 510 if (!it->second) {
505 window->RemoveObserver(this); 511 window->RemoveObserver(this);
506 observed_windows_.erase(it); 512 observed_windows_.erase(it);
507 } 513 }
508 } 514 }
509 515
510 Accelerator* EventDispatcher::FindAccelerator( 516 Accelerator* EventDispatcher::FindAccelerator(
511 const ui::KeyEvent& event, 517 const ui::KeyEvent& event,
512 const ui::mojom::AcceleratorPhase phase) { 518 const ui::mojom::AcceleratorPhase phase) {
513 for (const auto& pair : accelerators_) { 519 for (const auto& pair : accelerators_) {
514 if (pair.second->MatchesEvent(event, phase)) { 520 if (pair.second->MatchesEvent(event, phase))
515 return pair.second.get(); 521 return pair.second.get();
516 }
517 } 522 }
518 return nullptr; 523 return nullptr;
519 } 524 }
520 525
521 ServerWindow* EventDispatcher::FindDeepestVisibleWindowForEvents( 526 ServerWindow* EventDispatcher::FindDeepestVisibleWindowForEvents(
522 gfx::Point* location) { 527 gfx::Point* location) {
523 ServerWindow* root = delegate_->GetRootWindowContaining(*location); 528 ServerWindow* root = delegate_->GetRootWindowContaining(*location);
524 if (!root) 529 if (!root)
525 return nullptr; 530 return nullptr;
526 531
(...skipping 23 matching lines...) Expand all
550 555
551 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { 556 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) {
552 CancelPointerEventsToTarget(window); 557 CancelPointerEventsToTarget(window);
553 558
554 if (mouse_cursor_source_window_ == window) 559 if (mouse_cursor_source_window_ == window)
555 mouse_cursor_source_window_ = nullptr; 560 mouse_cursor_source_window_ = nullptr;
556 } 561 }
557 562
558 } // namespace ws 563 } // namespace ws
559 } // namespace ui 564 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698