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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
Index: components/mus/ws/event_matcher.cc
diff --git a/components/mus/ws/event_matcher.cc b/components/mus/ws/event_matcher.cc
index da45554d2ea8ca138a2810d55ff2d44416288905..298d3c7aac1967e09e99d68317268017ca9aabc7 100644
--- a/components/mus/ws/event_matcher.cc
+++ b/components/mus/ws/event_matcher.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <algorithm>
+
#include "components/mus/ws/event_matcher.h"
namespace mus {
@@ -9,37 +11,46 @@ namespace ws {
EventMatcher::EventMatcher(const mojom::EventMatcher& matcher)
: fields_to_match_(NONE),
- event_type_(ui::ET_UNKNOWN),
event_flags_(ui::EF_NONE),
ignore_event_flags_(ui::EF_NONE),
keyboard_code_(ui::VKEY_UNKNOWN),
pointer_type_(ui::EventPointerType::POINTER_TYPE_UNKNOWN) {
- if (matcher.type_matcher) {
+ if (matcher.type_matcher || matcher.types_matcher) {
fields_to_match_ |= TYPE;
- switch (matcher.type_matcher->type) {
- case ui::mojom::EventType::POINTER_DOWN:
- event_type_ = ui::ET_POINTER_DOWN;
- break;
- case ui::mojom::EventType::POINTER_MOVE:
- event_type_ = ui::ET_POINTER_MOVED;
- break;
- case ui::mojom::EventType::MOUSE_EXIT:
- event_type_ = ui::ET_POINTER_EXITED;
- break;
- case ui::mojom::EventType::POINTER_UP:
- event_type_ = ui::ET_POINTER_UP;
- break;
- case ui::mojom::EventType::POINTER_CANCEL:
- event_type_ = ui::ET_POINTER_CANCELLED;
- break;
- case ui::mojom::EventType::KEY_PRESSED:
- event_type_ = ui::ET_KEY_PRESSED;
- break;
- case ui::mojom::EventType::KEY_RELEASED:
- event_type_ = ui::ET_KEY_RELEASED;
- break;
- default:
- NOTREACHED();
+ std::vector<ui::mojom::EventType> event_types;
+ if (matcher.type_matcher) {
+ event_types.push_back(matcher.type_matcher->type);
+ } else {
+ for (ui::mojom::EventType event_type : matcher.types_matcher->types) {
+ event_types.push_back(event_type);
+ }
+ }
+ for (ui::mojom::EventType event_type : event_types) {
+ switch (event_type) {
+ case ui::mojom::EventType::POINTER_DOWN:
+ event_types_.push_back(ui::ET_POINTER_DOWN);
+ break;
+ case ui::mojom::EventType::POINTER_MOVE:
+ event_types_.push_back(ui::ET_POINTER_MOVED);
+ break;
+ case ui::mojom::EventType::MOUSE_EXIT:
+ event_types_.push_back(ui::ET_POINTER_EXITED);
+ break;
+ case ui::mojom::EventType::POINTER_UP:
+ event_types_.push_back(ui::ET_POINTER_UP);
+ break;
+ case ui::mojom::EventType::POINTER_CANCEL:
+ event_types_.push_back(ui::ET_POINTER_CANCELLED);
+ break;
+ case ui::mojom::EventType::KEY_PRESSED:
+ event_types_.push_back(ui::ET_KEY_PRESSED);
+ break;
+ case ui::mojom::EventType::KEY_RELEASED:
+ event_types_.push_back(ui::ET_KEY_RELEASED);
+ break;
+ default:
+ NOTREACHED();
+ }
}
}
if (matcher.flags_matcher) {
@@ -74,7 +85,9 @@ EventMatcher::EventMatcher(const mojom::EventMatcher& matcher)
EventMatcher::~EventMatcher() {}
bool EventMatcher::MatchesEvent(const ui::Event& event) const {
- if ((fields_to_match_ & TYPE) && event.type() != event_type_)
+ if ((fields_to_match_ & TYPE) &&
+ std::find(event_types_.begin(), event_types_.end(), event.type())
+ == event_types_.end())
return false;
int flags = event.flags() & ~ignore_event_flags_;
if ((fields_to_match_ & FLAGS) && flags != event_flags_)
@@ -101,7 +114,7 @@ bool EventMatcher::MatchesEvent(const ui::Event& event) const {
bool EventMatcher::Equals(const EventMatcher& other) const {
return fields_to_match_ == other.fields_to_match_ &&
- event_type_ == other.event_type_ &&
+ event_types_ == other.event_types_ &&
event_flags_ == other.event_flags_ &&
ignore_event_flags_ == other.ignore_event_flags_ &&
keyboard_code_ == other.keyboard_code_ &&

Powered by Google App Engine
This is Rietveld 408576698