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

Unified Diff: ui/base/accelerators/accelerator_manager.cc

Issue 2586333003: Make mash register initial batch of accelerators in single shot. (Closed)
Patch Set: fix nits/format and refactor AcceleratorControllerTest.Register. Created 3 years, 11 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: ui/base/accelerators/accelerator_manager.cc
diff --git a/ui/base/accelerators/accelerator_manager.cc b/ui/base/accelerators/accelerator_manager.cc
index fad3bf66eebfd288ced3eb05e517c03de3b53e89..6e730cccfae0f0d30de17521fdd9052d7444290e 100644
--- a/ui/base/accelerators/accelerator_manager.cc
+++ b/ui/base/accelerators/accelerator_manager.cc
@@ -17,33 +17,44 @@ AcceleratorManager::AcceleratorManager(AcceleratorManagerDelegate* delegate)
AcceleratorManager::~AcceleratorManager() {
}
-void AcceleratorManager::Register(const Accelerator& accelerator,
- HandlerPriority priority,
- AcceleratorTarget* target) {
+void AcceleratorManager::Register(
+ const std::vector<ui::Accelerator>& accelerators,
+ HandlerPriority priority,
+ AcceleratorTarget* target) {
DCHECK(target);
- AcceleratorTargetList& targets = accelerators_[accelerator].second;
- DCHECK(std::find(targets.begin(), targets.end(), target) == targets.end())
- << "Registering the same target multiple times";
- const bool is_first_target_for_accelerator = targets.empty();
-
- // All priority accelerators go to the front of the line.
- if (priority == kHighPriority) {
- DCHECK(!accelerators_[accelerator].first)
- << "Only one high-priority handler can be registered";
- targets.push_front(target);
- // Mark that we have a priority accelerator at the front.
- accelerators_[accelerator].first = true;
- } else {
- // We are registering a normal priority handler. If no priority accelerator
- // handler has been registered before us, just add the new handler to the
- // front. Otherwise, register it after the first (only) priority handler.
- if (!accelerators_[accelerator].first)
+
+ // Accelerators which haven't already been registered with any target.
+ std::vector<ui::Accelerator> new_accelerators;
+ for (auto iter = accelerators.begin(); iter != accelerators.end(); ++iter) {
sky 2017/01/28 00:09:15 for (const ui::Accelerator& accelerator : accelera
thanhph1 2017/01/30 16:37:54 Done, thanks!
+ const Accelerator& accelerator = *iter;
+
+ AcceleratorTargetList& targets = accelerators_[accelerator].second;
+ DCHECK(std::find(targets.begin(), targets.end(), target) == targets.end())
+ << "Registering the same target multiple times";
+ const bool is_first_target_for_accelerator = targets.empty();
+
+ // All priority accelerators go to the front of the line.
+ if (priority == kHighPriority) {
+ DCHECK(!accelerators_[accelerator].first)
+ << "Only one high-priority handler can be registered";
targets.push_front(target);
- else
- targets.insert(++targets.begin(), target);
+ // Mark that we have a priority accelerator at the front.
+ accelerators_[accelerator].first = true;
+ } else {
+ // We are registering a normal priority handler. If no priority
+ // accelerator handler has been registered before us, just add the new
+ // handler to the front. Otherwise, register it after the first (only)
+ // priority handler.
+ if (!accelerators_[accelerator].first)
+ targets.push_front(target);
+ else
+ targets.insert(++targets.begin(), target);
+ }
+ if (is_first_target_for_accelerator)
+ new_accelerators.push_back(accelerator);
}
- if (is_first_target_for_accelerator && delegate_)
- delegate_->OnAcceleratorRegistered(accelerator);
+ if (delegate_ && !new_accelerators.empty())
+ delegate_->OnAcceleratorsRegistered(new_accelerators);
}
void AcceleratorManager::Unregister(const Accelerator& accelerator,

Powered by Google App Engine
This is Rietveld 408576698