| 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 "components/mus/ws/event_dispatcher.h" | 5 #include "components/mus/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 "components/mus/ws/accelerator.h" | 10 #include "components/mus/ws/accelerator.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 247 } |
| 248 | 248 |
| 249 void EventDispatcher::ProcessEvent(const ui::Event& event) { | 249 void EventDispatcher::ProcessEvent(const ui::Event& event) { |
| 250 if (!root_) // Tests may not have a root window. | 250 if (!root_) // Tests may not have a root window. |
| 251 return; | 251 return; |
| 252 | 252 |
| 253 if (event.IsKeyEvent()) { | 253 if (event.IsKeyEvent()) { |
| 254 const ui::KeyEvent* key_event = event.AsKeyEvent(); | 254 const ui::KeyEvent* key_event = event.AsKeyEvent(); |
| 255 if (event.type() == ui::ET_KEY_PRESSED && !key_event->is_char()) { | 255 if (event.type() == ui::ET_KEY_PRESSED && !key_event->is_char()) { |
| 256 Accelerator* pre_target = | 256 Accelerator* pre_target = |
| 257 FindAccelerator(*key_event, mojom::AcceleratorPhase::PRE_TARGET); | 257 FindAccelerator(*key_event, ui::mojom::AcceleratorPhase::PRE_TARGET); |
| 258 if (pre_target) { | 258 if (pre_target) { |
| 259 delegate_->OnAccelerator(pre_target->id(), event); | 259 delegate_->OnAccelerator(pre_target->id(), event); |
| 260 return; | 260 return; |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 ProcessKeyEvent(*key_event); | 263 ProcessKeyEvent(*key_event); |
| 264 return; | 264 return; |
| 265 } | 265 } |
| 266 | 266 |
| 267 if (event.IsPointerEvent() || event.IsMouseWheelEvent()) { | 267 if (event.IsPointerEvent() || event.IsMouseWheelEvent()) { |
| 268 ProcessLocatedEvent(*event.AsLocatedEvent()); | 268 ProcessLocatedEvent(*event.AsLocatedEvent()); |
| 269 return; | 269 return; |
| 270 } | 270 } |
| 271 | 271 |
| 272 NOTREACHED(); | 272 NOTREACHED(); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event) { | 275 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event) { |
| 276 Accelerator* post_target = | 276 Accelerator* post_target = |
| 277 FindAccelerator(event, mojom::AcceleratorPhase::POST_TARGET); | 277 FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET); |
| 278 ServerWindow* focused_window = | 278 ServerWindow* focused_window = |
| 279 delegate_->GetFocusedWindowForEventDispatcher(); | 279 delegate_->GetFocusedWindowForEventDispatcher(); |
| 280 if (focused_window) { | 280 if (focused_window) { |
| 281 delegate_->DispatchInputEventToWindow(focused_window, false, event, | 281 delegate_->DispatchInputEventToWindow(focused_window, false, event, |
| 282 post_target); | 282 post_target); |
| 283 return; | 283 return; |
| 284 } | 284 } |
| 285 delegate_->OnEventTargetNotFound(event); | 285 delegate_->OnEventTargetNotFound(event); |
| 286 if (post_target) | 286 if (post_target) |
| 287 delegate_->OnAccelerator(post_target->id(), event); | 287 delegate_->OnAccelerator(post_target->id(), event); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 DCHECK_LT(0u, it->second); | 490 DCHECK_LT(0u, it->second); |
| 491 it->second--; | 491 it->second--; |
| 492 if (!it->second) { | 492 if (!it->second) { |
| 493 window->RemoveObserver(this); | 493 window->RemoveObserver(this); |
| 494 observed_windows_.erase(it); | 494 observed_windows_.erase(it); |
| 495 } | 495 } |
| 496 } | 496 } |
| 497 | 497 |
| 498 Accelerator* EventDispatcher::FindAccelerator( | 498 Accelerator* EventDispatcher::FindAccelerator( |
| 499 const ui::KeyEvent& event, | 499 const ui::KeyEvent& event, |
| 500 const mojom::AcceleratorPhase phase) { | 500 const ui::mojom::AcceleratorPhase phase) { |
| 501 for (const auto& pair : accelerators_) { | 501 for (const auto& pair : accelerators_) { |
| 502 if (pair.second->MatchesEvent(event, phase)) { | 502 if (pair.second->MatchesEvent(event, phase)) { |
| 503 return pair.second.get(); | 503 return pair.second.get(); |
| 504 } | 504 } |
| 505 } | 505 } |
| 506 return nullptr; | 506 return nullptr; |
| 507 } | 507 } |
| 508 | 508 |
| 509 void EventDispatcher::OnWillChangeWindowHierarchy(ServerWindow* window, | 509 void EventDispatcher::OnWillChangeWindowHierarchy(ServerWindow* window, |
| 510 ServerWindow* new_parent, | 510 ServerWindow* new_parent, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 529 | 529 |
| 530 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { | 530 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { |
| 531 CancelPointerEventsToTarget(window); | 531 CancelPointerEventsToTarget(window); |
| 532 | 532 |
| 533 if (mouse_cursor_source_window_ == window) | 533 if (mouse_cursor_source_window_ == window) |
| 534 mouse_cursor_source_window_ = nullptr; | 534 mouse_cursor_source_window_ = nullptr; |
| 535 } | 535 } |
| 536 | 536 |
| 537 } // namespace ws | 537 } // namespace ws |
| 538 } // namespace mus | 538 } // namespace mus |
| OLD | NEW |