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

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

Issue 2586333003: Make mash register initial batch of accelerators in single shot. (Closed)
Patch Set: Remove temporary vector. Add comments. Add AddAcceleratorToVector to use in OnAcceleratorRegistered… Created 4 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 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..d6ba8feae843434efc831b96eb365f3e25be6872 100644
--- a/ui/base/accelerators/accelerator_manager.cc
+++ b/ui/base/accelerators/accelerator_manager.cc
@@ -17,33 +17,48 @@ 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)
+
+ // This vector only pick in |accelerators| each accelerator which appears for
mfomitchev 2016/12/22 21:18:55 Accelerators which haven't already been registered
thanhph 2016/12/24 18:52:16 Done.
+ // the first time in AcceleratorTargetList. Same accelerator with different
+ // target won't be added later.
+ std::vector<ui::Accelerator> first_target_accelerators;
mfomitchev 2016/12/22 21:18:55 Repeat: Just call this |new_accelerators|
thanhph 2016/12/24 18:52:16 Done.
+
+ for (auto iter = accelerators.begin(); iter != accelerators.end(); ++iter) {
+ 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)
+ first_target_accelerators.push_back(accelerator);
}
- if (is_first_target_for_accelerator && delegate_)
- delegate_->OnAcceleratorRegistered(accelerator);
+
+ if (delegate_ && !first_target_accelerators.empty())
+ delegate_->OnAcceleratorsRegistered(first_target_accelerators);
}
void AcceleratorManager::Unregister(const Accelerator& accelerator,

Powered by Google App Engine
This is Rietveld 408576698