Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 10 |
| 11 namespace ui { | 11 namespace ui { |
| 12 | 12 |
| 13 AcceleratorManager::AcceleratorManager() { | 13 AcceleratorManager::AcceleratorManager() { |
| 14 } | 14 } |
| 15 | 15 |
| 16 AcceleratorManager::~AcceleratorManager() { | 16 AcceleratorManager::~AcceleratorManager() { |
| 17 } | 17 } |
| 18 | 18 |
| 19 void AcceleratorManager::Register(const Accelerator& accelerator, | 19 void AcceleratorManager::Register(const Accelerator& accelerator, |
| 20 HandlerPriority priority, | 20 HandlerPriority priority, |
| 21 AcceleratorTarget* target) { | 21 AcceleratorTarget* target) { |
| 22 DCHECK(target); | 22 DCHECK(target); |
| 23 AcceleratorTargetList& targets = accelerators_[accelerator].second; | 23 AcceleratorTargetList& targets = accelerators_[accelerator].second; |
| 24 DCHECK(std::find(targets.begin(), targets.end(), target) == targets.end()) | 24 DCHECK(std::find(targets.begin(), targets.end(), target) == targets.end()) |
| 25 << "Registering the same target multiple times"; | 25 << "Registering the same target multiple times"; |
| 26 | 26 |
| 27 // All priority accelerators go to the front of the line. | 27 // All priority accelerators go to the front of the line. |
| 28 if (priority) { | 28 if (priority == kHighPriority) { |
|
Daniel Erat
2016/07/07 21:08:50
this isn't exactly related but i saw the old code
| |
| 29 DCHECK(!accelerators_[accelerator].first) | 29 DCHECK(!accelerators_[accelerator].first) |
| 30 << "Only one _priority_ handler can be registered"; | 30 << "Only one high-priority handler can be registered"; |
| 31 targets.push_front(target); | 31 targets.push_front(target); |
| 32 // Mark that we have a priority accelerator at the front. | 32 // Mark that we have a priority accelerator at the front. |
| 33 accelerators_[accelerator].first = true; | 33 accelerators_[accelerator].first = true; |
| 34 return; | 34 return; |
| 35 } | 35 } |
| 36 | 36 |
| 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) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 // Check if we have a priority handler. If not, there's no more work needed. | 109 // Check if we have a priority handler. If not, there's no more work needed. |
| 110 if (!map_iter->second.first) | 110 if (!map_iter->second.first) |
| 111 return false; | 111 return false; |
| 112 | 112 |
| 113 // If the priority handler says it cannot handle the accelerator, we must not | 113 // If the priority handler says it cannot handle the accelerator, we must not |
| 114 // count it as one. | 114 // count it as one. |
| 115 return map_iter->second.second.front()->CanHandleAccelerators(); | 115 return map_iter->second.second.front()->CanHandleAccelerators(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace ui | 118 } // namespace ui |
| OLD | NEW |