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

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

Issue 1909733002: mus: Add EventObserver to allow passively listening to UI events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 "components/mus/ws/accelerator.h" 5 #include "components/mus/ws/accelerator.h"
6 6
7 #include "mojo/converters/geometry/geometry_type_converters.h"
8 #include "mojo/converters/input_events/input_events_type_converters.h"
9
10 namespace mus { 7 namespace mus {
11 namespace ws { 8 namespace ws {
12 9
13 Accelerator::Accelerator(uint32_t id, const mojom::EventMatcher& matcher) 10 Accelerator::Accelerator(uint32_t id, const mojom::EventMatcher& matcher)
14 : id_(id), 11 : id_(id),
15 fields_to_match_(NONE),
16 accelerator_phase_(matcher.accelerator_phase), 12 accelerator_phase_(matcher.accelerator_phase),
17 event_type_(ui::ET_UNKNOWN), 13 event_matcher_(matcher),
18 event_flags_(ui::EF_NONE), 14 weak_factory_(this) {}
19 ignore_event_flags_(ui::EF_NONE),
20 keyboard_code_(ui::VKEY_UNKNOWN),
21 pointer_type_(ui::EventPointerType::POINTER_TYPE_UNKNOWN),
22 weak_factory_(this) {
23 if (matcher.type_matcher) {
24 fields_to_match_ |= TYPE;
25 switch (matcher.type_matcher->type) {
26 case mus::mojom::EventType::POINTER_DOWN:
27 event_type_ = ui::ET_POINTER_DOWN;
28 break;
29 case mus::mojom::EventType::POINTER_MOVE:
30 event_type_ = ui::ET_POINTER_MOVED;
31 break;
32 case mus::mojom::EventType::MOUSE_EXIT:
33 event_type_ = ui::ET_POINTER_EXITED;
34 break;
35 case mus::mojom::EventType::POINTER_UP:
36 event_type_ = ui::ET_POINTER_UP;
37 break;
38 case mus::mojom::EventType::POINTER_CANCEL:
39 event_type_ = ui::ET_POINTER_CANCELLED;
40 break;
41 case mus::mojom::EventType::KEY_PRESSED:
42 event_type_ = ui::ET_KEY_PRESSED;
43 break;
44 case mus::mojom::EventType::KEY_RELEASED:
45 event_type_ = ui::ET_KEY_RELEASED;
46 break;
47 default:
48 NOTREACHED();
49 }
50 }
51 if (matcher.flags_matcher) {
52 fields_to_match_ |= FLAGS;
53 event_flags_ = matcher.flags_matcher->flags;
54 if (matcher.ignore_flags_matcher)
55 ignore_event_flags_ = matcher.ignore_flags_matcher->flags;
56 }
57 if (matcher.key_matcher) {
58 fields_to_match_ |= KEYBOARD_CODE;
59 keyboard_code_ = static_cast<uint16_t>(matcher.key_matcher->keyboard_code);
60 }
61 if (matcher.pointer_kind_matcher) {
62 fields_to_match_ |= POINTER_KIND;
63 switch (matcher.pointer_kind_matcher->pointer_kind) {
64 case mojom::PointerKind::MOUSE:
65 pointer_type_ = ui::EventPointerType::POINTER_TYPE_MOUSE;
66 break;
67 case mojom::PointerKind::TOUCH:
68 pointer_type_ = ui::EventPointerType::POINTER_TYPE_TOUCH;
69 break;
70 default:
71 NOTREACHED();
72 }
73 }
74 if (matcher.pointer_location_matcher) {
75 fields_to_match_ |= POINTER_LOCATION;
76 pointer_region_ = matcher.pointer_location_matcher->region.To<gfx::RectF>();
77 }
78 }
79 15
80 Accelerator::~Accelerator() {} 16 Accelerator::~Accelerator() {}
81 17
82 bool Accelerator::MatchesEvent(const ui::Event& event, 18 bool Accelerator::MatchesEvent(const ui::Event& event,
83 const mojom::AcceleratorPhase phase) const { 19 const mojom::AcceleratorPhase phase) const {
84 if (accelerator_phase_ != phase) 20 if (accelerator_phase_ != phase)
85 return false; 21 return false;
86 if ((fields_to_match_ & TYPE) && event.type() != event_type_) 22 if (!event_matcher_.MatchesEvent(event))
87 return false; 23 return false;
88 int flags = event.flags() & ~ignore_event_flags_;
89 if ((fields_to_match_ & FLAGS) && flags != event_flags_)
90 return false;
91 if (fields_to_match_ & KEYBOARD_CODE) {
92 if (!event.IsKeyEvent())
93 return false;
94 if (keyboard_code_ != event.AsKeyEvent()->GetConflatedWindowsKeyCode())
95 return false;
96 }
97 if (fields_to_match_ & POINTER_KIND) {
98 if (!event.IsPointerEvent() ||
99 pointer_type_ != event.AsPointerEvent()->pointer_details().pointer_type)
100 return false;
101 }
102 if (fields_to_match_ & POINTER_LOCATION) {
103 // 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.
105 NOTIMPLEMENTED();
106 return false;
107 }
108
109 return true; 24 return true;
110 } 25 }
111 26
112 bool Accelerator::EqualEventMatcher(const Accelerator* other) const { 27 bool Accelerator::EqualEventMatcher(const Accelerator* other) const {
113 return fields_to_match_ == other->fields_to_match_ && 28 return accelerator_phase_ == other->accelerator_phase_ &&
114 accelerator_phase_ == other->accelerator_phase_ && 29 event_matcher_.Equals(other->event_matcher_);
115 event_type_ == other->event_type_ &&
116 event_flags_ == other->event_flags_ &&
117 ignore_event_flags_ == other->ignore_event_flags_ &&
118 keyboard_code_ == other->keyboard_code_ &&
119 pointer_type_ == other->pointer_type_ &&
120 pointer_region_ == other->pointer_region_;
121 } 30 }
122 31
123 } // namespace ws 32 } // namespace ws
124 } // namespace mus 33 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698