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

Unified Diff: components/mus/ws/event_dispatcher.cc

Issue 1759273002: Add AcceleratorType to EventMatcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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_dispatcher.cc
diff --git a/components/mus/ws/event_dispatcher.cc b/components/mus/ws/event_dispatcher.cc
index ead61660ad570645411ad7e55eec1f77a37ee403..a37b73a1307d40fcf7a43f8dfb6473cdbaf7ba37 100644
--- a/components/mus/ws/event_dispatcher.cc
+++ b/components/mus/ws/event_dispatcher.cc
@@ -58,11 +58,16 @@ class EventMatcher {
public:
explicit EventMatcher(const mojom::EventMatcher& matcher)
: fields_to_match_(NONE),
+ accelerator_type_(mojom::AcceleratorType::PRE_TARGET),
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.accelerator_matcher) {
+ fields_to_match_ |= ACCELERATOR_TYPE;
+ accelerator_type_ = matcher.accelerator_matcher->accelerator_type;
+ }
if (matcher.type_matcher) {
fields_to_match_ |= TYPE;
switch (matcher.type_matcher->type) {
@@ -124,7 +129,10 @@ class EventMatcher {
~EventMatcher() {}
- bool MatchesEvent(const ui::Event& event) const {
+ bool MatchesEvent(const ui::Event& event,
+ const mojom::AcceleratorType type) const {
+ if ((fields_to_match_ & ACCELERATOR_TYPE) && accelerator_type_ != type)
+ return false;
if ((fields_to_match_ & TYPE) && event.type() != event_type_)
return false;
int flags = event.flags() & ~ignore_event_flags_;
@@ -154,6 +162,7 @@ class EventMatcher {
bool Equals(const EventMatcher& matcher) const {
return fields_to_match_ == matcher.fields_to_match_ &&
+ accelerator_type_ == matcher.accelerator_type_ &&
event_type_ == matcher.event_type_ &&
event_flags_ == matcher.event_flags_ &&
ignore_event_flags_ == matcher.ignore_event_flags_ &&
@@ -170,9 +179,11 @@ class EventMatcher {
KEYBOARD_CODE = 1 << 2,
POINTER_KIND = 1 << 3,
POINTER_LOCATION = 1 << 4,
+ ACCELERATOR_TYPE = 1 << 5,
};
uint32_t fields_to_match_;
+ mojom::AcceleratorType accelerator_type_;
ui::EventType event_type_;
// Bitfields of kEventFlag* and kMouseEventFlag* values in
// input_event_constants.mojom.
@@ -296,7 +307,8 @@ void EventDispatcher::ProcessEvent(const ui::Event& event) {
const ui::KeyEvent* key_event = event.AsKeyEvent();
if (event.type() == ui::ET_KEY_PRESSED && !key_event->is_char()) {
uint32_t accelerator = 0u;
- if (FindAccelerator(*key_event, &accelerator)) {
+ if (FindAccelerator(*key_event, mojom::AcceleratorType::PRE_TARGET,
+ &accelerator)) {
delegate_->OnAccelerator(accelerator, event);
return;
}
@@ -504,9 +516,10 @@ bool EventDispatcher::IsObservingWindow(ServerWindow* window) {
}
bool EventDispatcher::FindAccelerator(const ui::KeyEvent& event,
+ const mojom::AcceleratorType type,
uint32_t* accelerator_id) {
for (const auto& pair : accelerators_) {
- if (pair.second.MatchesEvent(event)) {
+ if (pair.second.MatchesEvent(event, type)) {
*accelerator_id = pair.first;
return true;
}

Powered by Google App Engine
This is Rietveld 408576698