| OLD | NEW |
| 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 Loading... |
| 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) { |
| 258 #if !defined(NDEBUG) |
| 259 if (match_phase == AcceleratorMatchPhase::POST_ONLY) { |
| 260 // POST_ONLY should always be preceeded by ANY with the same event. |
| 261 DCHECK(previous_event_); |
| 262 // Event doesn't define ==, so this compares the key fields. |
| 263 DCHECK(event.type() == previous_event_->type() && |
| 264 event.time_stamp() == previous_event_->time_stamp() && |
| 265 event.flags() == previous_event_->flags()); |
| 266 DCHECK_EQ(previous_accelerator_match_phase_, AcceleratorMatchPhase::ANY); |
| 267 } |
| 268 previous_event_ = Event::Clone(event); |
| 269 previous_accelerator_match_phase_ = match_phase; |
| 270 #endif |
| 257 if (event.IsKeyEvent()) { | 271 if (event.IsKeyEvent()) { |
| 258 const ui::KeyEvent* key_event = event.AsKeyEvent(); | 272 const ui::KeyEvent* key_event = event.AsKeyEvent(); |
| 259 if (event.type() == ui::ET_KEY_PRESSED && !key_event->is_char()) { | 273 if (event.type() == ui::ET_KEY_PRESSED && !key_event->is_char() && |
| 274 match_phase == AcceleratorMatchPhase::ANY) { |
| 260 Accelerator* pre_target = | 275 Accelerator* pre_target = |
| 261 FindAccelerator(*key_event, ui::mojom::AcceleratorPhase::PRE_TARGET); | 276 FindAccelerator(*key_event, ui::mojom::AcceleratorPhase::PRE_TARGET); |
| 262 if (pre_target) { | 277 if (pre_target) { |
| 263 delegate_->OnAccelerator(pre_target->id(), event); | 278 delegate_->OnAccelerator( |
| 279 pre_target->id(), event, |
| 280 EventDispatcherDelegate::AcceleratorPhase::PRE); |
| 264 return; | 281 return; |
| 265 } | 282 } |
| 266 } | 283 } |
| 267 ProcessKeyEvent(*key_event); | 284 ProcessKeyEvent(*key_event, match_phase); |
| 268 return; | 285 return; |
| 269 } | 286 } |
| 270 | 287 |
| 271 if (event.IsPointerEvent() || event.IsMouseWheelEvent()) { | 288 if (event.IsPointerEvent() || event.IsMouseWheelEvent()) { |
| 272 ProcessLocatedEvent(*event.AsLocatedEvent()); | 289 ProcessLocatedEvent(*event.AsLocatedEvent()); |
| 273 return; | 290 return; |
| 274 } | 291 } |
| 275 | 292 |
| 276 NOTREACHED(); | 293 NOTREACHED(); |
| 277 } | 294 } |
| 278 | 295 |
| 279 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event) { | 296 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event, |
| 297 AcceleratorMatchPhase match_phase) { |
| 280 Accelerator* post_target = | 298 Accelerator* post_target = |
| 281 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET); | 299 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET); |
| 282 ServerWindow* focused_window = | 300 ServerWindow* focused_window = |
| 283 delegate_->GetFocusedWindowForEventDispatcher(); | 301 delegate_->GetFocusedWindowForEventDispatcher(); |
| 284 if (focused_window) { | 302 if (focused_window) { |
| 285 // Assume key events are for the client area. | 303 // Assume key events are for the client area. |
| 286 const bool in_nonclient_area = false; | 304 const bool in_nonclient_area = false; |
| 287 const ClientSpecificId client_id = | 305 const ClientSpecificId client_id = |
| 288 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area); | 306 delegate_->GetEventTargetClientId(focused_window, in_nonclient_area); |
| 289 delegate_->DispatchInputEventToWindow(focused_window, client_id, event, | 307 delegate_->DispatchInputEventToWindow(focused_window, client_id, event, |
| 290 post_target); | 308 post_target); |
| 291 return; | 309 return; |
| 292 } | 310 } |
| 293 delegate_->OnEventTargetNotFound(event); | 311 delegate_->OnEventTargetNotFound(event); |
| 294 if (post_target) | 312 if (post_target) |
| 295 delegate_->OnAccelerator(post_target->id(), event); | 313 delegate_->OnAccelerator(post_target->id(), event, |
| 314 EventDispatcherDelegate::AcceleratorPhase::POST); |
| 296 } | 315 } |
| 297 | 316 |
| 298 void EventDispatcher::ProcessLocatedEvent(const ui::LocatedEvent& event) { | 317 void EventDispatcher::ProcessLocatedEvent(const ui::LocatedEvent& event) { |
| 299 DCHECK(event.IsPointerEvent() || event.IsMouseWheelEvent()); | 318 DCHECK(event.IsPointerEvent() || event.IsMouseWheelEvent()); |
| 300 const bool is_mouse_event = | 319 const bool is_mouse_event = |
| 301 event.IsMousePointerEvent() || event.IsMouseWheelEvent(); | 320 event.IsMousePointerEvent() || event.IsMouseWheelEvent(); |
| 302 | 321 |
| 303 if (is_mouse_event) { | 322 if (is_mouse_event) { |
| 304 mouse_pointer_last_location_ = event.location(); | 323 mouse_pointer_last_location_ = event.location(); |
| 305 delegate_->OnMouseCursorLocationChanged(event.root_location()); | 324 delegate_->OnMouseCursorLocationChanged(event.root_location()); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 if (!it->second) { | 523 if (!it->second) { |
| 505 window->RemoveObserver(this); | 524 window->RemoveObserver(this); |
| 506 observed_windows_.erase(it); | 525 observed_windows_.erase(it); |
| 507 } | 526 } |
| 508 } | 527 } |
| 509 | 528 |
| 510 Accelerator* EventDispatcher::FindAccelerator( | 529 Accelerator* EventDispatcher::FindAccelerator( |
| 511 const ui::KeyEvent& event, | 530 const ui::KeyEvent& event, |
| 512 const ui::mojom::AcceleratorPhase phase) { | 531 const ui::mojom::AcceleratorPhase phase) { |
| 513 for (const auto& pair : accelerators_) { | 532 for (const auto& pair : accelerators_) { |
| 514 if (pair.second->MatchesEvent(event, phase)) { | 533 if (pair.second->MatchesEvent(event, phase)) |
| 515 return pair.second.get(); | 534 return pair.second.get(); |
| 516 } | |
| 517 } | 535 } |
| 518 return nullptr; | 536 return nullptr; |
| 519 } | 537 } |
| 520 | 538 |
| 521 ServerWindow* EventDispatcher::FindDeepestVisibleWindowForEvents( | 539 ServerWindow* EventDispatcher::FindDeepestVisibleWindowForEvents( |
| 522 gfx::Point* location) { | 540 gfx::Point* location) { |
| 523 ServerWindow* root = delegate_->GetRootWindowContaining(*location); | 541 ServerWindow* root = delegate_->GetRootWindowContaining(*location); |
| 524 if (!root) | 542 if (!root) |
| 525 return nullptr; | 543 return nullptr; |
| 526 | 544 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 550 | 568 |
| 551 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { | 569 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { |
| 552 CancelPointerEventsToTarget(window); | 570 CancelPointerEventsToTarget(window); |
| 553 | 571 |
| 554 if (mouse_cursor_source_window_ == window) | 572 if (mouse_cursor_source_window_ == window) |
| 555 mouse_cursor_source_window_ = nullptr; | 573 mouse_cursor_source_window_ = nullptr; |
| 556 } | 574 } |
| 557 | 575 |
| 558 } // namespace ws | 576 } // namespace ws |
| 559 } // namespace ui | 577 } // namespace ui |
| OLD | NEW |