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