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

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

Issue 9402018: Experimental Extension Keybinding (first cut). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 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/views/accessible_pane_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/accelerators/accelerator_manager.cc
===================================================================
--- ui/base/accelerators/accelerator_manager.cc (revision 123221)
+++ ui/base/accelerators/accelerator_manager.cc (working copy)
@@ -17,11 +17,29 @@
}
void AcceleratorManager::Register(const Accelerator& accelerator,
+ HandlerPriority priority,
AcceleratorTarget* target) {
- AcceleratorTargetList& targets = accelerators_[accelerator];
+ AcceleratorTargetList& targets = accelerators_[accelerator].second;
DCHECK(std::find(targets.begin(), targets.end(), target) == targets.end())
<< "Registering the same target multiple times";
- targets.push_front(target);
+
+ // All priority accelerators go to the front of the line.
+ if (priority) {
+ DCHECK(!accelerators_[accelerator].first)
+ << "Only one _priority_ handler can be registered";
+ targets.push_front(target);
+ // Mark that we have a priority accelerator at the front.
+ accelerators_[accelerator].first = true;
+ return;
+ }
+
+ // 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);
}
void AcceleratorManager::Unregister(const Accelerator& accelerator,
@@ -32,7 +50,7 @@
return;
}
- AcceleratorTargetList* targets = &map_iter->second;
+ AcceleratorTargetList* targets = &map_iter->second.second;
AcceleratorTargetList::iterator target_iter =
std::find(targets->begin(), targets->end(), target);
if (target_iter == targets->end()) {
@@ -40,13 +58,19 @@
return;
}
+ // Check to see if we have a priority handler and whether we are removing it.
+ if (accelerators_[accelerator].first && target_iter == targets->begin()) {
+ // We've are taking the priority accelerator away, flip the priority flag.
+ accelerators_[accelerator].first = false;
+ }
+
targets->erase(target_iter);
}
void AcceleratorManager::UnregisterAll(AcceleratorTarget* target) {
for (AcceleratorMap::iterator map_iter = accelerators_.begin();
map_iter != accelerators_.end(); ++map_iter) {
- AcceleratorTargetList* targets = &map_iter->second;
+ AcceleratorTargetList* targets = &map_iter->second.second;
targets->remove(target);
}
}
@@ -57,7 +81,7 @@
if (map_iter != accelerators_.end() && ShouldHandle(accelerator)) {
// We have to copy the target list here, because an AcceleratorPressed
// event handler may modify the list.
- AcceleratorTargetList targets(map_iter->second);
+ AcceleratorTargetList targets(map_iter->second.second);
for (AcceleratorTargetList::iterator iter = targets.begin();
iter != targets.end(); ++iter) {
if ((*iter)->CanHandleAccelerators() &&
@@ -74,11 +98,26 @@
AcceleratorTarget* AcceleratorManager::GetCurrentTarget(
const Accelerator& accelerator) const {
AcceleratorMap::const_iterator map_iter = accelerators_.find(accelerator);
- if (map_iter == accelerators_.end() || map_iter->second.empty())
+ if (map_iter == accelerators_.end() || map_iter->second.second.empty())
return NULL;
- return map_iter->second.front();
+ return map_iter->second.second.front();
}
+bool AcceleratorManager::HasPriorityHandler(
+ const Accelerator& accelerator) const {
+ AcceleratorMap::const_iterator map_iter = accelerators_.find(accelerator);
+ if (map_iter == accelerators_.end() || map_iter->second.second.empty())
+ return false;
+
+ // Check if we have a priority handler. If not, there's no more work needed.
+ if (!map_iter->second.first)
+ return false;
+
+ // If the priority handler says it cannot handle the accelerator, we must not
+ // count it as one.
+ return map_iter->second.second.front()->CanHandleAccelerators();
+}
+
bool AcceleratorManager::ShouldHandle(const Accelerator& accelerator) const {
if (accelerator.type() != ET_KEY_RELEASED &&
accelerator.type() != ET_TRANSLATED_KEY_RELEASE) {
« no previous file with comments | « ui/base/accelerators/accelerator_manager.h ('k') | ui/views/accessible_pane_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698