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

Unified Diff: services/ui/ws/event_dispatcher.cc

Issue 2520093003: WindowManagerClient::AddAccelerator() should take an array (Closed)
Patch Set: Create anonymous namespace helper for AcceleratorTransport mojom struct. Cleanup/format codes. Created 4 years, 1 month 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: services/ui/ws/event_dispatcher.cc
diff --git a/services/ui/ws/event_dispatcher.cc b/services/ui/ws/event_dispatcher.cc
index d6536cc9c8c5f50dd0a89caa1f0adcf42e9ded33..0656cfb732e1def446e93d35a995e33c47e75ce0 100644
--- a/services/ui/ws/event_dispatcher.cc
+++ b/services/ui/ws/event_dispatcher.cc
@@ -244,16 +244,30 @@ void EventDispatcher::UpdateCursorProviderByLastKnownLocation() {
}
}
-bool EventDispatcher::AddAccelerator(uint32_t id,
- mojom::EventMatcherPtr event_matcher) {
- std::unique_ptr<Accelerator> accelerator(new Accelerator(id, *event_matcher));
- // If an accelerator with the same id or matcher already exists, then abort.
- for (const auto& pair : accelerators_) {
- if (pair.first == id || accelerator->EqualEventMatcher(pair.second.get()))
- return false;
+bool EventDispatcher::AddAccelerators(
+ std::vector<ui::mojom::AcceleratorTransportPtr> multi_accelerators) {
+ bool all_new_accelerators = true;
+ for (auto iter = multi_accelerators.begin(); iter != multi_accelerators.end();
+ ++iter) {
+ std::unique_ptr<Accelerator> accelerator(
+ new Accelerator(iter->get()->id, *(iter->get()->event_matcher)));
+
+ // If an accelerator with the same id or matcher is already in the pool,
mfomitchev 2016/11/24 19:56:13 If an accelerator with the same id or matcher alre
thanhph 2016/11/29 00:08:29 Done.
+ // then try next accelerator.
+ bool accelerator_exists = false;
+ for (const auto& pair : accelerators_) {
+ if (pair.first == iter->get()->id ||
+ accelerator->EqualEventMatcher(pair.second.get())) {
+ accelerator_exists = true;
+ break;
+ }
+ }
+ if (!accelerator_exists)
mfomitchev 2016/11/24 19:56:13 Swap if/else: start with a true condition, so that
thanhph 2016/11/29 00:08:29 Done.
+ accelerators_.insert(Entry(iter->get()->id, std::move(accelerator)));
+ else
+ all_new_accelerators = false;
}
- accelerators_.insert(Entry(id, std::move(accelerator)));
- return true;
+ return all_new_accelerators;
}
void EventDispatcher::RemoveAccelerator(uint32_t id) {

Powered by Google App Engine
This is Rietveld 408576698