| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/accelerator.h" | 5 #include "components/mus/ws/event_matcher.h" |
| 6 | 6 |
| 7 #include "mojo/converters/geometry/geometry_type_converters.h" | 7 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 8 #include "mojo/converters/input_events/input_events_type_converters.h" | 8 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 9 | 9 |
| 10 namespace mus { | 10 namespace mus { |
| 11 namespace ws { | 11 namespace ws { |
| 12 | 12 |
| 13 Accelerator::Accelerator(uint32_t id, const mojom::EventMatcher& matcher) | 13 EventMatcher::EventMatcher(const mojom::EventMatcher& matcher) |
| 14 : id_(id), | 14 : fields_to_match_(NONE), |
| 15 fields_to_match_(NONE), | |
| 16 accelerator_phase_(matcher.accelerator_phase), | |
| 17 event_type_(ui::ET_UNKNOWN), | 15 event_type_(ui::ET_UNKNOWN), |
| 18 event_flags_(ui::EF_NONE), | 16 event_flags_(ui::EF_NONE), |
| 19 ignore_event_flags_(ui::EF_NONE), | 17 ignore_event_flags_(ui::EF_NONE), |
| 20 keyboard_code_(ui::VKEY_UNKNOWN), | 18 keyboard_code_(ui::VKEY_UNKNOWN), |
| 21 pointer_type_(ui::EventPointerType::POINTER_TYPE_UNKNOWN), | 19 pointer_type_(ui::EventPointerType::POINTER_TYPE_UNKNOWN) { |
| 22 weak_factory_(this) { | |
| 23 if (matcher.type_matcher) { | 20 if (matcher.type_matcher) { |
| 24 fields_to_match_ |= TYPE; | 21 fields_to_match_ |= TYPE; |
| 25 switch (matcher.type_matcher->type) { | 22 switch (matcher.type_matcher->type) { |
| 26 case mus::mojom::EventType::POINTER_DOWN: | 23 case mus::mojom::EventType::POINTER_DOWN: |
| 27 event_type_ = ui::ET_POINTER_DOWN; | 24 event_type_ = ui::ET_POINTER_DOWN; |
| 28 break; | 25 break; |
| 29 case mus::mojom::EventType::POINTER_MOVE: | 26 case mus::mojom::EventType::POINTER_MOVE: |
| 30 event_type_ = ui::ET_POINTER_MOVED; | 27 event_type_ = ui::ET_POINTER_MOVED; |
| 31 break; | 28 break; |
| 32 case mus::mojom::EventType::MOUSE_EXIT: | 29 case mus::mojom::EventType::MOUSE_EXIT: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 default: | 67 default: |
| 71 NOTREACHED(); | 68 NOTREACHED(); |
| 72 } | 69 } |
| 73 } | 70 } |
| 74 if (matcher.pointer_location_matcher) { | 71 if (matcher.pointer_location_matcher) { |
| 75 fields_to_match_ |= POINTER_LOCATION; | 72 fields_to_match_ |= POINTER_LOCATION; |
| 76 pointer_region_ = matcher.pointer_location_matcher->region.To<gfx::RectF>(); | 73 pointer_region_ = matcher.pointer_location_matcher->region.To<gfx::RectF>(); |
| 77 } | 74 } |
| 78 } | 75 } |
| 79 | 76 |
| 80 Accelerator::~Accelerator() {} | 77 EventMatcher::~EventMatcher() {} |
| 81 | 78 |
| 82 bool Accelerator::MatchesEvent(const ui::Event& event, | 79 bool EventMatcher::MatchesEvent(const ui::Event& event) const { |
| 83 const mojom::AcceleratorPhase phase) const { | |
| 84 if (accelerator_phase_ != phase) | |
| 85 return false; | |
| 86 if ((fields_to_match_ & TYPE) && event.type() != event_type_) | 80 if ((fields_to_match_ & TYPE) && event.type() != event_type_) |
| 87 return false; | 81 return false; |
| 88 int flags = event.flags() & ~ignore_event_flags_; | 82 int flags = event.flags() & ~ignore_event_flags_; |
| 89 if ((fields_to_match_ & FLAGS) && flags != event_flags_) | 83 if ((fields_to_match_ & FLAGS) && flags != event_flags_) |
| 90 return false; | 84 return false; |
| 91 if (fields_to_match_ & KEYBOARD_CODE) { | 85 if (fields_to_match_ & KEYBOARD_CODE) { |
| 92 if (!event.IsKeyEvent()) | 86 if (!event.IsKeyEvent()) |
| 93 return false; | 87 return false; |
| 94 if (keyboard_code_ != event.AsKeyEvent()->GetConflatedWindowsKeyCode()) | 88 if (keyboard_code_ != event.AsKeyEvent()->GetConflatedWindowsKeyCode()) |
| 95 return false; | 89 return false; |
| 96 } | 90 } |
| 97 if (fields_to_match_ & POINTER_KIND) { | 91 if (fields_to_match_ & POINTER_KIND) { |
| 98 if (!event.IsPointerEvent() || | 92 if (!event.IsPointerEvent() || |
| 99 pointer_type_ != event.AsPointerEvent()->pointer_details().pointer_type) | 93 pointer_type_ != event.AsPointerEvent()->pointer_details().pointer_type) |
| 100 return false; | 94 return false; |
| 101 } | 95 } |
| 102 if (fields_to_match_ & POINTER_LOCATION) { | 96 if (fields_to_match_ & POINTER_LOCATION) { |
| 103 // TODO(sad): The tricky part here is to make sure the same coord-space is | 97 // TODO(sad): The tricky part here is to make sure the same coord-space is |
| 104 // used for the location-region and the event-location. | 98 // used for the location-region and the event-location. |
| 105 NOTIMPLEMENTED(); | 99 NOTIMPLEMENTED(); |
| 106 return false; | 100 return false; |
| 107 } | 101 } |
| 108 | |
| 109 return true; | 102 return true; |
| 110 } | 103 } |
| 111 | 104 |
| 112 bool Accelerator::EqualEventMatcher(const Accelerator* other) const { | 105 bool EventMatcher::Equals(const EventMatcher& other) const { |
| 113 return fields_to_match_ == other->fields_to_match_ && | 106 return fields_to_match_ == other.fields_to_match_ && |
| 114 accelerator_phase_ == other->accelerator_phase_ && | 107 event_type_ == other.event_type_ && |
| 115 event_type_ == other->event_type_ && | 108 event_flags_ == other.event_flags_ && |
| 116 event_flags_ == other->event_flags_ && | 109 ignore_event_flags_ == other.ignore_event_flags_ && |
| 117 ignore_event_flags_ == other->ignore_event_flags_ && | 110 keyboard_code_ == other.keyboard_code_ && |
| 118 keyboard_code_ == other->keyboard_code_ && | 111 pointer_type_ == other.pointer_type_ && |
| 119 pointer_type_ == other->pointer_type_ && | 112 pointer_region_ == other.pointer_region_; |
| 120 pointer_region_ == other->pointer_region_; | |
| 121 } | 113 } |
| 122 | 114 |
| 123 } // namespace ws | 115 } // namespace ws |
| 124 } // namespace mus | 116 } // namespace mus |
| OLD | NEW |