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

Side by Side Diff: ui/base/accelerators/accelerator_manager.cc

Issue 2586333003: Make mash register initial batch of accelerators in single shot. (Closed)
Patch Set: Add unimplemented methods Created 3 years, 12 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/accelerators/accelerator_manager.h" 5 #include "ui/base/accelerators/accelerator_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/base/accelerators/accelerator_manager_delegate.h" 10 #include "ui/base/accelerators/accelerator_manager_delegate.h"
11 11
12 namespace ui { 12 namespace ui {
13 13
14 AcceleratorManager::AcceleratorManager(AcceleratorManagerDelegate* delegate) 14 AcceleratorManager::AcceleratorManager(AcceleratorManagerDelegate* delegate)
15 : delegate_(delegate) {} 15 : delegate_(delegate) {}
16 16
17 AcceleratorManager::~AcceleratorManager() { 17 AcceleratorManager::~AcceleratorManager() {
18 } 18 }
19 19
20 void AcceleratorManager::Register(const Accelerator& accelerator, 20 void AcceleratorManager::Register(const Accelerator& accelerator,
21 HandlerPriority priority, 21 HandlerPriority priority,
22 AcceleratorTarget* target) { 22 AcceleratorTarget* target) {
23 DCHECK(target); 23 DCHECK(target);
24 AcceleratorTargetList& targets = accelerators_[accelerator].second; 24 AcceleratorTargetList& targets = accelerators_[accelerator].second;
25 DCHECK(std::find(targets.begin(), targets.end(), target) == targets.end()) 25 DCHECK(std::find(targets.begin(), targets.end(), target) == targets.end())
26 << "Registering the same target multiple times"; 26 << "Registering the same target multiple times";
27 const bool is_first_target_for_accelerator = targets.empty(); 27 // const bool is_first_target_for_accelerator = targets.empty();
28 28
29 // All priority accelerators go to the front of the line. 29 // All priority accelerators go to the front of the line.
30 if (priority == kHighPriority) { 30 if (priority == kHighPriority) {
31 DCHECK(!accelerators_[accelerator].first) 31 DCHECK(!accelerators_[accelerator].first)
32 << "Only one high-priority handler can be registered"; 32 << "Only one high-priority handler can be registered";
33 targets.push_front(target); 33 targets.push_front(target);
34 // Mark that we have a priority accelerator at the front. 34 // Mark that we have a priority accelerator at the front.
35 accelerators_[accelerator].first = true; 35 accelerators_[accelerator].first = true;
36 } else { 36 } else {
37 // We are registering a normal priority handler. If no priority accelerator 37 // We are registering a normal priority handler. If no priority accelerator
38 // handler has been registered before us, just add the new handler to the 38 // handler has been registered before us, just add the new handler to the
39 // front. Otherwise, register it after the first (only) priority handler. 39 // front. Otherwise, register it after the first (only) priority handler.
40 if (!accelerators_[accelerator].first) 40 if (!accelerators_[accelerator].first)
41 targets.push_front(target); 41 targets.push_front(target);
42 else 42 else
43 targets.insert(++targets.begin(), target); 43 targets.insert(++targets.begin(), target);
44 } 44 }
45 if (is_first_target_for_accelerator && delegate_) 45 }
46 delegate_->OnAcceleratorRegistered(accelerator); 46
47 void AcceleratorManager::Registers(std::vector<ui::Accelerator>& accelerators) {
48 if (delegate_)
49 delegate_->OnAcceleratorsRegistered(accelerators);
47 } 50 }
48 51
49 void AcceleratorManager::Unregister(const Accelerator& accelerator, 52 void AcceleratorManager::Unregister(const Accelerator& accelerator,
50 AcceleratorTarget* target) { 53 AcceleratorTarget* target) {
51 AcceleratorMap::iterator map_iter = accelerators_.find(accelerator); 54 AcceleratorMap::iterator map_iter = accelerators_.find(accelerator);
52 if (map_iter == accelerators_.end()) { 55 if (map_iter == accelerators_.end()) {
53 NOTREACHED() << "Unregistering non-existing accelerator"; 56 NOTREACHED() << "Unregistering non-existing accelerator";
54 return; 57 return;
55 } 58 }
56 59
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 targets->remove(target); 133 targets->remove(target);
131 if (!targets->empty()) 134 if (!targets->empty())
132 return; 135 return;
133 const ui::Accelerator accelerator = map_iter->first; 136 const ui::Accelerator accelerator = map_iter->first;
134 accelerators_.erase(map_iter); 137 accelerators_.erase(map_iter);
135 if (delegate_) 138 if (delegate_)
136 delegate_->OnAcceleratorUnregistered(accelerator); 139 delegate_->OnAcceleratorUnregistered(accelerator);
137 } 140 }
138 141
139 } // namespace ui 142 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698