| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 return true; | 52 return true; |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 class EventMatcher { | 57 class EventMatcher { |
| 58 public: | 58 public: |
| 59 explicit EventMatcher(const mojom::EventMatcher& matcher) | 59 explicit EventMatcher(const mojom::EventMatcher& matcher) |
| 60 : fields_to_match_(NONE), | 60 : fields_to_match_(NONE), |
| 61 accelerator_phase_(mojom::AcceleratorPhase::PRE_TARGET), |
| 61 event_type_(ui::ET_UNKNOWN), | 62 event_type_(ui::ET_UNKNOWN), |
| 62 event_flags_(ui::EF_NONE), | 63 event_flags_(ui::EF_NONE), |
| 63 ignore_event_flags_(ui::EF_NONE), | 64 ignore_event_flags_(ui::EF_NONE), |
| 64 keyboard_code_(ui::VKEY_UNKNOWN), | 65 keyboard_code_(ui::VKEY_UNKNOWN), |
| 65 pointer_type_(ui::EventPointerType::POINTER_TYPE_UNKNOWN) { | 66 pointer_type_(ui::EventPointerType::POINTER_TYPE_UNKNOWN) { |
| 67 if (matcher.accelerator_matcher) { |
| 68 fields_to_match_ |= ACCELERATOR_PHASE; |
| 69 accelerator_phase_ = matcher.accelerator_matcher->accelerator_phase; |
| 70 } |
| 66 if (matcher.type_matcher) { | 71 if (matcher.type_matcher) { |
| 67 fields_to_match_ |= TYPE; | 72 fields_to_match_ |= TYPE; |
| 68 switch (matcher.type_matcher->type) { | 73 switch (matcher.type_matcher->type) { |
| 69 case mus::mojom::EventType::POINTER_DOWN: | 74 case mus::mojom::EventType::POINTER_DOWN: |
| 70 event_type_ = ui::ET_POINTER_DOWN; | 75 event_type_ = ui::ET_POINTER_DOWN; |
| 71 break; | 76 break; |
| 72 case mus::mojom::EventType::POINTER_MOVE: | 77 case mus::mojom::EventType::POINTER_MOVE: |
| 73 event_type_ = ui::ET_POINTER_MOVED; | 78 event_type_ = ui::ET_POINTER_MOVED; |
| 74 break; | 79 break; |
| 75 case mus::mojom::EventType::MOUSE_EXIT: | 80 case mus::mojom::EventType::MOUSE_EXIT: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 122 } |
| 118 if (matcher.pointer_location_matcher) { | 123 if (matcher.pointer_location_matcher) { |
| 119 fields_to_match_ |= POINTER_LOCATION; | 124 fields_to_match_ |= POINTER_LOCATION; |
| 120 pointer_region_ = | 125 pointer_region_ = |
| 121 matcher.pointer_location_matcher->region.To<gfx::RectF>(); | 126 matcher.pointer_location_matcher->region.To<gfx::RectF>(); |
| 122 } | 127 } |
| 123 } | 128 } |
| 124 | 129 |
| 125 ~EventMatcher() {} | 130 ~EventMatcher() {} |
| 126 | 131 |
| 127 bool MatchesEvent(const ui::Event& event) const { | 132 bool MatchesEvent(const ui::Event& event, |
| 133 const mojom::AcceleratorPhase phase) const { |
| 134 if ((fields_to_match_ & ACCELERATOR_PHASE) && accelerator_phase_ != phase) |
| 135 return false; |
| 128 if ((fields_to_match_ & TYPE) && event.type() != event_type_) | 136 if ((fields_to_match_ & TYPE) && event.type() != event_type_) |
| 129 return false; | 137 return false; |
| 130 int flags = event.flags() & ~ignore_event_flags_; | 138 int flags = event.flags() & ~ignore_event_flags_; |
| 131 if ((fields_to_match_ & FLAGS) && flags != event_flags_) | 139 if ((fields_to_match_ & FLAGS) && flags != event_flags_) |
| 132 return false; | 140 return false; |
| 133 if (fields_to_match_ & KEYBOARD_CODE) { | 141 if (fields_to_match_ & KEYBOARD_CODE) { |
| 134 if (!event.IsKeyEvent()) | 142 if (!event.IsKeyEvent()) |
| 135 return false; | 143 return false; |
| 136 if (keyboard_code_ != event.AsKeyEvent()->GetConflatedWindowsKeyCode()) | 144 if (keyboard_code_ != event.AsKeyEvent()->GetConflatedWindowsKeyCode()) |
| 137 return false; | 145 return false; |
| 138 } | 146 } |
| 139 if (fields_to_match_ & POINTER_KIND) { | 147 if (fields_to_match_ & POINTER_KIND) { |
| 140 if (!event.IsPointerEvent() || | 148 if (!event.IsPointerEvent() || |
| 141 pointer_type_ != | 149 pointer_type_ != |
| 142 event.AsPointerEvent()->pointer_details().pointer_type) | 150 event.AsPointerEvent()->pointer_details().pointer_type) |
| 143 return false; | 151 return false; |
| 144 } | 152 } |
| 145 if (fields_to_match_ & POINTER_LOCATION) { | 153 if (fields_to_match_ & POINTER_LOCATION) { |
| 146 // TODO(sad): The tricky part here is to make sure the same coord-space is | 154 // TODO(sad): The tricky part here is to make sure the same coord-space is |
| 147 // used for the location-region and the event-location. | 155 // used for the location-region and the event-location. |
| 148 NOTIMPLEMENTED(); | 156 NOTIMPLEMENTED(); |
| 149 return false; | 157 return false; |
| 150 } | 158 } |
| 151 | 159 |
| 152 return true; | 160 return true; |
| 153 } | 161 } |
| 154 | 162 |
| 155 bool Equals(const EventMatcher& matcher) const { | 163 bool Equals(const EventMatcher& matcher) const { |
| 156 return fields_to_match_ == matcher.fields_to_match_ && | 164 return fields_to_match_ == matcher.fields_to_match_ && |
| 165 accelerator_phase_ == matcher.accelerator_phase_ && |
| 157 event_type_ == matcher.event_type_ && | 166 event_type_ == matcher.event_type_ && |
| 158 event_flags_ == matcher.event_flags_ && | 167 event_flags_ == matcher.event_flags_ && |
| 159 ignore_event_flags_ == matcher.ignore_event_flags_ && | 168 ignore_event_flags_ == matcher.ignore_event_flags_ && |
| 160 keyboard_code_ == matcher.keyboard_code_ && | 169 keyboard_code_ == matcher.keyboard_code_ && |
| 161 pointer_type_ == matcher.pointer_type_ && | 170 pointer_type_ == matcher.pointer_type_ && |
| 162 pointer_region_ == matcher.pointer_region_; | 171 pointer_region_ == matcher.pointer_region_; |
| 163 } | 172 } |
| 164 | 173 |
| 165 private: | 174 private: |
| 166 enum MatchFields { | 175 enum MatchFields { |
| 167 NONE = 0, | 176 NONE = 0, |
| 168 TYPE = 1 << 0, | 177 TYPE = 1 << 0, |
| 169 FLAGS = 1 << 1, | 178 FLAGS = 1 << 1, |
| 170 KEYBOARD_CODE = 1 << 2, | 179 KEYBOARD_CODE = 1 << 2, |
| 171 POINTER_KIND = 1 << 3, | 180 POINTER_KIND = 1 << 3, |
| 172 POINTER_LOCATION = 1 << 4, | 181 POINTER_LOCATION = 1 << 4, |
| 182 ACCELERATOR_PHASE = 1 << 5, |
| 173 }; | 183 }; |
| 174 | 184 |
| 175 uint32_t fields_to_match_; | 185 uint32_t fields_to_match_; |
| 186 mojom::AcceleratorPhase accelerator_phase_; |
| 176 ui::EventType event_type_; | 187 ui::EventType event_type_; |
| 177 // Bitfields of kEventFlag* and kMouseEventFlag* values in | 188 // Bitfields of kEventFlag* and kMouseEventFlag* values in |
| 178 // input_event_constants.mojom. | 189 // input_event_constants.mojom. |
| 179 int event_flags_; | 190 int event_flags_; |
| 180 int ignore_event_flags_; | 191 int ignore_event_flags_; |
| 181 uint16_t keyboard_code_; | 192 uint16_t keyboard_code_; |
| 182 ui::EventPointerType pointer_type_; | 193 ui::EventPointerType pointer_type_; |
| 183 gfx::RectF pointer_region_; | 194 gfx::RectF pointer_region_; |
| 184 }; | 195 }; |
| 185 | 196 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 300 } |
| 290 | 301 |
| 291 void EventDispatcher::ProcessEvent(const ui::Event& event) { | 302 void EventDispatcher::ProcessEvent(const ui::Event& event) { |
| 292 if (!root_) | 303 if (!root_) |
| 293 return; | 304 return; |
| 294 | 305 |
| 295 if (event.IsKeyEvent()) { | 306 if (event.IsKeyEvent()) { |
| 296 const ui::KeyEvent* key_event = event.AsKeyEvent(); | 307 const ui::KeyEvent* key_event = event.AsKeyEvent(); |
| 297 if (event.type() == ui::ET_KEY_PRESSED && !key_event->is_char()) { | 308 if (event.type() == ui::ET_KEY_PRESSED && !key_event->is_char()) { |
| 298 uint32_t accelerator = 0u; | 309 uint32_t accelerator = 0u; |
| 299 if (FindAccelerator(*key_event, &accelerator)) { | 310 if (FindAccelerator(*key_event, mojom::AcceleratorPhase::PRE_TARGET, |
| 311 &accelerator)) { |
| 300 delegate_->OnAccelerator(accelerator, event); | 312 delegate_->OnAccelerator(accelerator, event); |
| 301 return; | 313 return; |
| 302 } | 314 } |
| 303 } | 315 } |
| 304 ProcessKeyEvent(*key_event); | 316 ProcessKeyEvent(*key_event); |
| 305 return; | 317 return; |
| 306 } | 318 } |
| 307 | 319 |
| 308 if (event.IsPointerEvent()) { | 320 if (event.IsPointerEvent()) { |
| 309 ProcessPointerEvent(*event.AsPointerEvent()); | 321 ProcessPointerEvent(*event.AsPointerEvent()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 509 |
| 498 bool EventDispatcher::IsObservingWindow(ServerWindow* window) { | 510 bool EventDispatcher::IsObservingWindow(ServerWindow* window) { |
| 499 for (const auto& pair : pointer_targets_) { | 511 for (const auto& pair : pointer_targets_) { |
| 500 if (pair.second.window == window) | 512 if (pair.second.window == window) |
| 501 return true; | 513 return true; |
| 502 } | 514 } |
| 503 return false; | 515 return false; |
| 504 } | 516 } |
| 505 | 517 |
| 506 bool EventDispatcher::FindAccelerator(const ui::KeyEvent& event, | 518 bool EventDispatcher::FindAccelerator(const ui::KeyEvent& event, |
| 519 const mojom::AcceleratorPhase phase, |
| 507 uint32_t* accelerator_id) { | 520 uint32_t* accelerator_id) { |
| 508 for (const auto& pair : accelerators_) { | 521 for (const auto& pair : accelerators_) { |
| 509 if (pair.second.MatchesEvent(event)) { | 522 if (pair.second.MatchesEvent(event, phase)) { |
| 510 *accelerator_id = pair.first; | 523 *accelerator_id = pair.first; |
| 511 return true; | 524 return true; |
| 512 } | 525 } |
| 513 } | 526 } |
| 514 return false; | 527 return false; |
| 515 } | 528 } |
| 516 | 529 |
| 517 void EventDispatcher::OnWillChangeWindowHierarchy(ServerWindow* window, | 530 void EventDispatcher::OnWillChangeWindowHierarchy(ServerWindow* window, |
| 518 ServerWindow* new_parent, | 531 ServerWindow* new_parent, |
| 519 ServerWindow* old_parent) { | 532 ServerWindow* old_parent) { |
| 520 CancelPointerEventsToTarget(window); | 533 CancelPointerEventsToTarget(window); |
| 521 } | 534 } |
| 522 | 535 |
| 523 void EventDispatcher::OnWindowVisibilityChanged(ServerWindow* window) { | 536 void EventDispatcher::OnWindowVisibilityChanged(ServerWindow* window) { |
| 524 CancelPointerEventsToTarget(window); | 537 CancelPointerEventsToTarget(window); |
| 525 } | 538 } |
| 526 | 539 |
| 527 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { | 540 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { |
| 528 CancelPointerEventsToTarget(window); | 541 CancelPointerEventsToTarget(window); |
| 529 | 542 |
| 530 if (mouse_cursor_source_window_ == window) | 543 if (mouse_cursor_source_window_ == window) |
| 531 mouse_cursor_source_window_ = nullptr; | 544 mouse_cursor_source_window_ = nullptr; |
| 532 } | 545 } |
| 533 | 546 |
| 534 } // namespace ws | 547 } // namespace ws |
| 535 } // namespace mus | 548 } // namespace mus |
| OLD | NEW |