Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: components/mus/ws/event_matcher.cc

Issue 2092343002: Touch HUD app for mustash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm>
6
5 #include "components/mus/ws/event_matcher.h" 7 #include "components/mus/ws/event_matcher.h"
6 8
7 namespace mus { 9 namespace mus {
8 namespace ws { 10 namespace ws {
9 11
10 EventMatcher::EventMatcher(const mojom::EventMatcher& matcher) 12 EventMatcher::EventMatcher(const mojom::EventMatcher& matcher)
11 : fields_to_match_(NONE), 13 : fields_to_match_(NONE),
12 event_type_(ui::ET_UNKNOWN),
13 event_flags_(ui::EF_NONE), 14 event_flags_(ui::EF_NONE),
14 ignore_event_flags_(ui::EF_NONE), 15 ignore_event_flags_(ui::EF_NONE),
15 keyboard_code_(ui::VKEY_UNKNOWN), 16 keyboard_code_(ui::VKEY_UNKNOWN),
16 pointer_type_(ui::EventPointerType::POINTER_TYPE_UNKNOWN) { 17 pointer_type_(ui::EventPointerType::POINTER_TYPE_UNKNOWN) {
17 if (matcher.type_matcher) { 18 if (matcher.type_matcher || matcher.types_matcher) {
18 fields_to_match_ |= TYPE; 19 fields_to_match_ |= TYPE;
19 switch (matcher.type_matcher->type) { 20 std::vector<ui::mojom::EventType> event_types;
20 case ui::mojom::EventType::POINTER_DOWN: 21 if (matcher.type_matcher) {
21 event_type_ = ui::ET_POINTER_DOWN; 22 event_types.push_back(matcher.type_matcher->type);
22 break; 23 } else {
23 case ui::mojom::EventType::POINTER_MOVE: 24 for (ui::mojom::EventType event_type : matcher.types_matcher->types) {
24 event_type_ = ui::ET_POINTER_MOVED; 25 event_types.push_back(event_type);
25 break; 26 }
26 case ui::mojom::EventType::MOUSE_EXIT: 27 }
27 event_type_ = ui::ET_POINTER_EXITED; 28 for (ui::mojom::EventType event_type : event_types) {
28 break; 29 switch (event_type) {
29 case ui::mojom::EventType::POINTER_UP: 30 case ui::mojom::EventType::POINTER_DOWN:
30 event_type_ = ui::ET_POINTER_UP; 31 event_types_.push_back(ui::ET_POINTER_DOWN);
31 break; 32 break;
32 case ui::mojom::EventType::POINTER_CANCEL: 33 case ui::mojom::EventType::POINTER_MOVE:
33 event_type_ = ui::ET_POINTER_CANCELLED; 34 event_types_.push_back(ui::ET_POINTER_MOVED);
34 break; 35 break;
35 case ui::mojom::EventType::KEY_PRESSED: 36 case ui::mojom::EventType::MOUSE_EXIT:
36 event_type_ = ui::ET_KEY_PRESSED; 37 event_types_.push_back(ui::ET_POINTER_EXITED);
37 break; 38 break;
38 case ui::mojom::EventType::KEY_RELEASED: 39 case ui::mojom::EventType::POINTER_UP:
39 event_type_ = ui::ET_KEY_RELEASED; 40 event_types_.push_back(ui::ET_POINTER_UP);
40 break; 41 break;
41 default: 42 case ui::mojom::EventType::POINTER_CANCEL:
42 NOTREACHED(); 43 event_types_.push_back(ui::ET_POINTER_CANCELLED);
44 break;
45 case ui::mojom::EventType::KEY_PRESSED:
46 event_types_.push_back(ui::ET_KEY_PRESSED);
47 break;
48 case ui::mojom::EventType::KEY_RELEASED:
49 event_types_.push_back(ui::ET_KEY_RELEASED);
50 break;
51 default:
52 NOTREACHED();
53 }
43 } 54 }
44 } 55 }
45 if (matcher.flags_matcher) { 56 if (matcher.flags_matcher) {
46 fields_to_match_ |= FLAGS; 57 fields_to_match_ |= FLAGS;
47 event_flags_ = matcher.flags_matcher->flags; 58 event_flags_ = matcher.flags_matcher->flags;
48 if (matcher.ignore_flags_matcher) 59 if (matcher.ignore_flags_matcher)
49 ignore_event_flags_ = matcher.ignore_flags_matcher->flags; 60 ignore_event_flags_ = matcher.ignore_flags_matcher->flags;
50 } 61 }
51 if (matcher.key_matcher) { 62 if (matcher.key_matcher) {
52 fields_to_match_ |= KEYBOARD_CODE; 63 fields_to_match_ |= KEYBOARD_CODE;
(...skipping 14 matching lines...) Expand all
67 } 78 }
68 if (matcher.pointer_location_matcher) { 79 if (matcher.pointer_location_matcher) {
69 fields_to_match_ |= POINTER_LOCATION; 80 fields_to_match_ |= POINTER_LOCATION;
70 pointer_region_ = matcher.pointer_location_matcher->region; 81 pointer_region_ = matcher.pointer_location_matcher->region;
71 } 82 }
72 } 83 }
73 84
74 EventMatcher::~EventMatcher() {} 85 EventMatcher::~EventMatcher() {}
75 86
76 bool EventMatcher::MatchesEvent(const ui::Event& event) const { 87 bool EventMatcher::MatchesEvent(const ui::Event& event) const {
77 if ((fields_to_match_ & TYPE) && event.type() != event_type_) 88 if ((fields_to_match_ & TYPE) &&
89 std::find(event_types_.begin(), event_types_.end(), event.type())
90 == event_types_.end())
78 return false; 91 return false;
79 int flags = event.flags() & ~ignore_event_flags_; 92 int flags = event.flags() & ~ignore_event_flags_;
80 if ((fields_to_match_ & FLAGS) && flags != event_flags_) 93 if ((fields_to_match_ & FLAGS) && flags != event_flags_)
81 return false; 94 return false;
82 if (fields_to_match_ & KEYBOARD_CODE) { 95 if (fields_to_match_ & KEYBOARD_CODE) {
83 if (!event.IsKeyEvent()) 96 if (!event.IsKeyEvent())
84 return false; 97 return false;
85 if (keyboard_code_ != event.AsKeyEvent()->GetConflatedWindowsKeyCode()) 98 if (keyboard_code_ != event.AsKeyEvent()->GetConflatedWindowsKeyCode())
86 return false; 99 return false;
87 } 100 }
88 if (fields_to_match_ & POINTER_KIND) { 101 if (fields_to_match_ & POINTER_KIND) {
89 if (!event.IsPointerEvent() || 102 if (!event.IsPointerEvent() ||
90 pointer_type_ != event.AsPointerEvent()->pointer_details().pointer_type) 103 pointer_type_ != event.AsPointerEvent()->pointer_details().pointer_type)
91 return false; 104 return false;
92 } 105 }
93 if (fields_to_match_ & POINTER_LOCATION) { 106 if (fields_to_match_ & POINTER_LOCATION) {
94 // TODO(sad): The tricky part here is to make sure the same coord-space is 107 // TODO(sad): The tricky part here is to make sure the same coord-space is
95 // used for the location-region and the event-location. 108 // used for the location-region and the event-location.
96 NOTIMPLEMENTED(); 109 NOTIMPLEMENTED();
97 return false; 110 return false;
98 } 111 }
99 return true; 112 return true;
100 } 113 }
101 114
102 bool EventMatcher::Equals(const EventMatcher& other) const { 115 bool EventMatcher::Equals(const EventMatcher& other) const {
103 return fields_to_match_ == other.fields_to_match_ && 116 return fields_to_match_ == other.fields_to_match_ &&
104 event_type_ == other.event_type_ && 117 event_types_ == other.event_types_ &&
105 event_flags_ == other.event_flags_ && 118 event_flags_ == other.event_flags_ &&
106 ignore_event_flags_ == other.ignore_event_flags_ && 119 ignore_event_flags_ == other.ignore_event_flags_ &&
107 keyboard_code_ == other.keyboard_code_ && 120 keyboard_code_ == other.keyboard_code_ &&
108 pointer_type_ == other.pointer_type_ && 121 pointer_type_ == other.pointer_type_ &&
109 pointer_region_ == other.pointer_region_; 122 pointer_region_ == other.pointer_region_;
110 } 123 }
111 124
112 } // namespace ws 125 } // namespace ws
113 } // namespace mus 126 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698