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

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

Issue 2586333003: Make mash register initial batch of accelerators in single shot. (Closed)
Patch Set: Fix comments. Move inline function to .h 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
« no previous file with comments | « ui/base/accelerators/accelerator_manager.h ('k') | ui/base/accelerators/accelerator_manager_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7b4308adc20e2ecbcedc68803af181d8bdad2fa5 100644
--- a/ui/base/accelerators/accelerator_manager.cc
+++ b/ui/base/accelerators/accelerator_manager.cc
@@ -17,33 +17,43 @@ 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 (const ui::Accelerator& accelerator : accelerators) {
+ 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,
« no previous file with comments | « ui/base/accelerators/accelerator_manager.h ('k') | ui/base/accelerators/accelerator_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698