| 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "cc/surfaces/surface_hittest.h" | 10 #include "cc/surfaces/surface_hittest.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } | 189 } |
| 190 | 190 |
| 191 void EventDispatcher::RemoveAccelerator(uint32_t id) { | 191 void EventDispatcher::RemoveAccelerator(uint32_t id) { |
| 192 auto it = accelerators_.find(id); | 192 auto it = accelerators_.find(id); |
| 193 // Clients may pass bogus ids. | 193 // Clients may pass bogus ids. |
| 194 if (it != accelerators_.end()) | 194 if (it != accelerators_.end()) |
| 195 accelerators_.erase(it); | 195 accelerators_.erase(it); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void EventDispatcher::ProcessEvent(const ui::Event& event) { | 198 void EventDispatcher::ProcessEvent(const ui::Event& event) { |
| 199 if (!root_) | 199 if (!root_) // Tests may not have a root window. |
| 200 return; | 200 return; |
| 201 | 201 |
| 202 if (event.IsKeyEvent()) { | 202 if (event.IsKeyEvent()) { |
| 203 const ui::KeyEvent* key_event = event.AsKeyEvent(); | 203 const ui::KeyEvent* key_event = event.AsKeyEvent(); |
| 204 if (event.type() == ui::ET_KEY_PRESSED && !key_event->is_char()) { | 204 if (event.type() == ui::ET_KEY_PRESSED && !key_event->is_char()) { |
| 205 Accelerator* pre_target = | 205 Accelerator* pre_target = |
| 206 FindAccelerator(*key_event, mojom::AcceleratorPhase::PRE_TARGET); | 206 FindAccelerator(*key_event, mojom::AcceleratorPhase::PRE_TARGET); |
| 207 if (pre_target) { | 207 if (pre_target) { |
| 208 delegate_->OnAccelerator(pre_target->id(), event); | 208 delegate_->OnAccelerator(pre_target->id(), event); |
| 209 return; | 209 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 222 } | 222 } |
| 223 | 223 |
| 224 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event) { | 224 void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event) { |
| 225 Accelerator* post_target = | 225 Accelerator* post_target = |
| 226 FindAccelerator(event, mojom::AcceleratorPhase::POST_TARGET); | 226 FindAccelerator(event, mojom::AcceleratorPhase::POST_TARGET); |
| 227 ServerWindow* focused_window = | 227 ServerWindow* focused_window = |
| 228 delegate_->GetFocusedWindowForEventDispatcher(); | 228 delegate_->GetFocusedWindowForEventDispatcher(); |
| 229 if (focused_window) { | 229 if (focused_window) { |
| 230 delegate_->DispatchInputEventToWindow(focused_window, false, event, | 230 delegate_->DispatchInputEventToWindow(focused_window, false, event, |
| 231 post_target); | 231 post_target); |
| 232 } else if (post_target) { | 232 return; |
| 233 } |
| 234 delegate_->OnEventTargetNotFound(event); |
| 235 if (post_target) |
| 233 delegate_->OnAccelerator(post_target->id(), event); | 236 delegate_->OnAccelerator(post_target->id(), event); |
| 234 } | |
| 235 } | 237 } |
| 236 | 238 |
| 237 void EventDispatcher::ProcessLocatedEvent(const ui::LocatedEvent& event) { | 239 void EventDispatcher::ProcessLocatedEvent(const ui::LocatedEvent& event) { |
| 238 DCHECK(event.IsPointerEvent() || event.IsMouseWheelEvent()); | 240 DCHECK(event.IsPointerEvent() || event.IsMouseWheelEvent()); |
| 239 const bool is_mouse_event = | 241 const bool is_mouse_event = |
| 240 event.IsMousePointerEvent() || event.IsMouseWheelEvent(); | 242 event.IsMousePointerEvent() || event.IsMouseWheelEvent(); |
| 241 | 243 |
| 242 if (is_mouse_event) | 244 if (is_mouse_event) |
| 243 mouse_pointer_last_location_ = event.location(); | 245 mouse_pointer_last_location_ = event.location(); |
| 244 | 246 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 bool EventDispatcher::AreAnyPointersDown() const { | 375 bool EventDispatcher::AreAnyPointersDown() const { |
| 374 for (const auto& pair : pointer_targets_) { | 376 for (const auto& pair : pointer_targets_) { |
| 375 if (pair.second.is_pointer_down) | 377 if (pair.second.is_pointer_down) |
| 376 return true; | 378 return true; |
| 377 } | 379 } |
| 378 return false; | 380 return false; |
| 379 } | 381 } |
| 380 | 382 |
| 381 void EventDispatcher::DispatchToPointerTarget(const PointerTarget& target, | 383 void EventDispatcher::DispatchToPointerTarget(const PointerTarget& target, |
| 382 const ui::LocatedEvent& event) { | 384 const ui::LocatedEvent& event) { |
| 383 if (!target.window) | 385 if (!target.window) { |
| 386 delegate_->OnEventTargetNotFound(event); |
| 384 return; | 387 return; |
| 388 } |
| 385 | 389 |
| 386 gfx::Point location(event.location()); | 390 gfx::Point location(event.location()); |
| 387 gfx::Transform transform(GetTransformToWindow(surface_id_, target.window)); | 391 gfx::Transform transform(GetTransformToWindow(surface_id_, target.window)); |
| 388 transform.TransformPoint(&location); | 392 transform.TransformPoint(&location); |
| 389 std::unique_ptr<ui::Event> clone = ui::Event::Clone(event); | 393 std::unique_ptr<ui::Event> clone = ui::Event::Clone(event); |
| 390 clone->AsLocatedEvent()->set_location(location); | 394 clone->AsLocatedEvent()->set_location(location); |
| 391 // TODO(jonross): add post-target accelerator support once accelerators | 395 // TODO(jonross): add post-target accelerator support once accelerators |
| 392 // support pointer events. | 396 // support pointer events. |
| 393 delegate_->DispatchInputEventToWindow(target.window, target.in_nonclient_area, | 397 delegate_->DispatchInputEventToWindow(target.window, target.in_nonclient_area, |
| 394 *clone, nullptr); | 398 *clone, nullptr); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 450 |
| 447 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { | 451 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { |
| 448 CancelPointerEventsToTarget(window); | 452 CancelPointerEventsToTarget(window); |
| 449 | 453 |
| 450 if (mouse_cursor_source_window_ == window) | 454 if (mouse_cursor_source_window_ == window) |
| 451 mouse_cursor_source_window_ = nullptr; | 455 mouse_cursor_source_window_ = nullptr; |
| 452 } | 456 } |
| 453 | 457 |
| 454 } // namespace ws | 458 } // namespace ws |
| 455 } // namespace mus | 459 } // namespace mus |
| OLD | NEW |