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

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

Issue 2520093003: WindowManagerClient::AddAccelerator() should take an array (Closed)
Patch Set: Modify helper to return vector and leverage helper in other files.Rename/format code. 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..2771d3a60deaa684823d5d474bbdf42a5ff47a98 100644
--- a/services/ui/ws/event_dispatcher.cc
+++ b/services/ui/ws/event_dispatcher.cc
@@ -244,16 +244,28 @@ 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> accelerators) {
+ bool all_new_accelerators = true;
+ for (auto iter = accelerators.begin(); iter != 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 already exists, skip it.
+ 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)
+ all_new_accelerators = false;
+ else
+ accelerators_.insert(Entry(iter->get()->id, std::move(accelerator)));
}
- 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