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

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

Issue 1487333004: mus: Notify the client whether adding an accelerator was successful. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years 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
« no previous file with comments | « components/mus/ws/event_dispatcher.h ('k') | components/mus/ws/event_dispatcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/event_dispatcher.h" 5 #include "components/mus/ws/event_dispatcher.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "cc/surfaces/surface_hittest.h" 9 #include "cc/surfaces/surface_hittest.h"
10 #include "components/mus/surfaces/surfaces_state.h" 10 #include "components/mus/surfaces/surfaces_state.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 if (fields_to_match_ & POINTER_LOCATION) { 102 if (fields_to_match_ & POINTER_LOCATION) {
103 // TODO(sad): The tricky part here is to make sure the same coord-space is 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. 104 // used for the location-region and the event-location.
105 NOTIMPLEMENTED(); 105 NOTIMPLEMENTED();
106 return false; 106 return false;
107 } 107 }
108 108
109 return true; 109 return true;
110 } 110 }
111 111
112 #if !defined(NDEBUG)
113 bool Equals(const EventMatcher& matcher) const { 112 bool Equals(const EventMatcher& matcher) const {
114 return fields_to_match_ == matcher.fields_to_match_ && 113 return fields_to_match_ == matcher.fields_to_match_ &&
115 event_type_ == matcher.event_type_ && 114 event_type_ == matcher.event_type_ &&
116 event_flags_ == matcher.event_flags_ && 115 event_flags_ == matcher.event_flags_ &&
117 keyboard_code_ == matcher.keyboard_code_ && 116 keyboard_code_ == matcher.keyboard_code_ &&
118 pointer_kind_ == matcher.pointer_kind_ && 117 pointer_kind_ == matcher.pointer_kind_ &&
119 pointer_region_ == matcher.pointer_region_; 118 pointer_region_ == matcher.pointer_region_;
120 } 119 }
121 #endif
122 120
123 private: 121 private:
124 enum MatchFields { 122 enum MatchFields {
125 NONE = 0, 123 NONE = 0,
126 TYPE = 1 << 0, 124 TYPE = 1 << 0,
127 FLAGS = 1 << 1, 125 FLAGS = 1 << 1,
128 KEYBOARD_CODE = 1 << 2, 126 KEYBOARD_CODE = 1 << 2,
129 POINTER_KIND = 1 << 3, 127 POINTER_KIND = 1 << 3,
130 POINTER_LOCATION = 1 << 4, 128 POINTER_LOCATION = 1 << 4,
131 }; 129 };
(...skipping 14 matching lines...) Expand all
146 EventDispatcher::~EventDispatcher() { 144 EventDispatcher::~EventDispatcher() {
147 std::set<ServerWindow*> pointer_targets; 145 std::set<ServerWindow*> pointer_targets;
148 for (const auto& pair : pointer_targets_) { 146 for (const auto& pair : pointer_targets_) {
149 if (pair.second.window && 147 if (pair.second.window &&
150 pointer_targets.insert(pair.second.window).second) { 148 pointer_targets.insert(pair.second.window).second) {
151 pair.second.window->RemoveObserver(this); 149 pair.second.window->RemoveObserver(this);
152 } 150 }
153 } 151 }
154 } 152 }
155 153
156 void EventDispatcher::AddAccelerator(uint32_t id, 154 bool EventDispatcher::AddAccelerator(uint32_t id,
157 mojom::EventMatcherPtr event_matcher) { 155 mojom::EventMatcherPtr event_matcher) {
158 EventMatcher matcher(*event_matcher); 156 EventMatcher matcher(*event_matcher);
159 #if !defined(NDEBUG) 157 // If an accelerator with the same id or matcher already exists, then abort.
160 for (const auto& pair : accelerators_) { 158 for (const auto& pair : accelerators_) {
161 DCHECK_NE(pair.first, id); 159 if (pair.first == id || matcher.Equals(pair.second))
162 DCHECK(!matcher.Equals(pair.second)); 160 return false;
163 } 161 }
164 #endif
165 accelerators_.insert(Entry(id, matcher)); 162 accelerators_.insert(Entry(id, matcher));
163 return true;
166 } 164 }
167 165
168 void EventDispatcher::RemoveAccelerator(uint32_t id) { 166 void EventDispatcher::RemoveAccelerator(uint32_t id) {
169 auto it = accelerators_.find(id); 167 auto it = accelerators_.find(id);
170 DCHECK(it != accelerators_.end()); 168 DCHECK(it != accelerators_.end());
171 accelerators_.erase(it); 169 accelerators_.erase(it);
172 } 170 }
173 171
174 void EventDispatcher::OnEvent(mojom::EventPtr event) { 172 void EventDispatcher::OnEvent(mojom::EventPtr event) {
175 if (!root_) 173 if (!root_)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 void EventDispatcher::OnWindowVisibilityChanged(ServerWindow* window) { 308 void EventDispatcher::OnWindowVisibilityChanged(ServerWindow* window) {
311 CancelPointerEventsToTarget(window); 309 CancelPointerEventsToTarget(window);
312 } 310 }
313 311
314 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { 312 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) {
315 CancelPointerEventsToTarget(window); 313 CancelPointerEventsToTarget(window);
316 } 314 }
317 315
318 } // namespace ws 316 } // namespace ws
319 } // namespace mus 317 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/event_dispatcher.h ('k') | components/mus/ws/event_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698