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

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

Issue 2128243003: Make most browser accelerators not repeat. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update comment in test Created 4 years, 3 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
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) { 30 if (priority == kHighPriority) {
31 DCHECK(!accelerators_[accelerator].first) 31 DCHECK(!accelerators_[accelerator].first)
32 << "Only one _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
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 targets->remove(target); 130 targets->remove(target);
131 if (!targets->empty()) 131 if (!targets->empty())
132 return; 132 return;
133 const ui::Accelerator accelerator = map_iter->first; 133 const ui::Accelerator accelerator = map_iter->first;
134 accelerators_.erase(map_iter); 134 accelerators_.erase(map_iter);
135 if (delegate_) 135 if (delegate_)
136 delegate_->OnAcceleratorUnregistered(accelerator); 136 delegate_->OnAcceleratorUnregistered(accelerator);
137 } 137 }
138 138
139 } // namespace ui 139 } // namespace ui
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698