summaryrefslogtreecommitdiffstats
path: root/ash/accelerators
diff options
context:
space:
mode:
authorskuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 22:05:38 +0000
committerskuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 22:05:38 +0000
commit12abb20ae922d192978205a9259d663cd0aeeb3d (patch)
treee37dfffe1134658a8a8d832d5faed5c95f24766e /ash/accelerators
parent4a2697a63edf3887cd7663e45db4a97fc6553bc8 (diff)
downloadchromium_src-12abb20ae922d192978205a9259d663cd0aeeb3d.zip
chromium_src-12abb20ae922d192978205a9259d663cd0aeeb3d.tar.gz
chromium_src-12abb20ae922d192978205a9259d663cd0aeeb3d.tar.bz2
Adding Alt+<number> accelerator key
BUG=117481 TEST=None Review URL: http://codereview.chromium.org/9677046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127805 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/accelerators')
-rw-r--r--ash/accelerators/accelerator_controller.cc57
-rw-r--r--ash/accelerators/accelerator_controller.h14
-rw-r--r--ash/accelerators/accelerator_table.cc18
-rw-r--r--ash/accelerators/accelerator_table.h9
4 files changed, 93 insertions, 5 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index b43b5f4..993978d6 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -282,6 +282,33 @@ bool AcceleratorController::AcceleratorPressed(
if (ime_control_delegate_.get())
return ime_control_delegate_->HandleSwitchIme(accelerator);
break;
+ case SELECT_WIN_0:
+ SwitchToWindow(0);
+ break;
+ case SELECT_WIN_1:
+ SwitchToWindow(1);
+ break;
+ case SELECT_WIN_2:
+ SwitchToWindow(2);
+ break;
+ case SELECT_WIN_3:
+ SwitchToWindow(3);
+ break;
+ case SELECT_WIN_4:
+ SwitchToWindow(4);
+ break;
+ case SELECT_WIN_5:
+ SwitchToWindow(5);
+ break;
+ case SELECT_WIN_6:
+ SwitchToWindow(6);
+ break;
+ case SELECT_WIN_7:
+ SwitchToWindow(7);
+ break;
+ case SELECT_LAST_WIN:
+ SwitchToWindow(-1);
+ break;
#if !defined(NDEBUG)
case ROTATE_SCREEN:
return HandleRotateScreen();
@@ -300,6 +327,36 @@ bool AcceleratorController::AcceleratorPressed(
return false;
}
+void AcceleratorController::SwitchToWindow(int window) {
+ const LauncherItems& items =
+ Shell::GetInstance()->launcher()->model()->items();
+ int item_count =
+ Shell::GetInstance()->launcher()->model()->item_count();
+ int indexes_left = window >= 0 ? window : item_count;
+ int found_index = -1;
+
+ // Iterating until we have hit the index we are interested in which
+ // is true once indexes_left becomes negative.
+ for (int i = 0; i < item_count && indexes_left >= 0; i++) {
+ if (items[i].type != TYPE_APP_LIST &&
+ items[i].type != TYPE_BROWSER_SHORTCUT) {
+ found_index = i;
+ indexes_left--;
+ }
+ }
+
+ // There are two ways how found_index can be valid: a.) the nth item was
+ // found (which is true when indexes_left is -1) or b.) the last item was
+ // requested (which is true when index was passed in as a negative number).
+ if (found_index >= 0 && (indexes_left == -1 || window < 0) &&
+ items[found_index].status == ash::STATUS_RUNNING) {
+ // Then set this one as active.
+ LauncherItem new_item(items[found_index]);
+ new_item.status = STATUS_ACTIVE;
+ Shell::GetInstance()->launcher()->model()->Set(found_index, new_item);
+ }
+}
+
bool AcceleratorController::CanHandleAccelerators() const {
return true;
}
diff --git a/ash/accelerators/accelerator_controller.h b/ash/accelerators/accelerator_controller.h
index d04e5d7..e1a5f18 100644
--- a/ash/accelerators/accelerator_controller.h
+++ b/ash/accelerators/accelerator_controller.h
@@ -34,20 +34,20 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
AcceleratorController();
virtual ~AcceleratorController();
- // Register a global keyboard accelerator for the specified target. If
+ // Registers a global keyboard accelerator for the specified target. If
// multiple targets are registered for an accelerator, a target registered
// later has higher priority.
void Register(const ui::Accelerator& accelerator,
ui::AcceleratorTarget* target);
- // Unregister the specified keyboard accelerator for the specified target.
+ // Unregisters the specified keyboard accelerator for the specified target.
void Unregister(const ui::Accelerator& accelerator,
ui::AcceleratorTarget* target);
- // Unregister all keyboard accelerators for the specified target.
+ // Unregisters all keyboard accelerators for the specified target.
void UnregisterAll(ui::AcceleratorTarget* target);
- // Activate the target associated with the specified accelerator.
+ // Activates the target associated with the specified accelerator.
// First, AcceleratorPressed handler of the most recently registered target
// is called, and if that handler processes the event (i.e. returns true),
// this method immediately returns. If not, we do the same thing on the next
@@ -74,9 +74,13 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
}
private:
- // Initialize the accelerators this class handles as a target.
+ // Initializes the accelerators this class handles as a target.
void Init();
+ // Switches to a 0-indexed (in order of creation) window.
+ // A negative index switches to the last window in the list.
+ void SwitchToWindow(int window);
+
scoped_ptr<ui::AcceleratorManager> accelerator_manager_;
scoped_ptr<BrightnessControlDelegate> brightness_control_delegate_;
diff --git a/ash/accelerators/accelerator_table.cc b/ash/accelerators/accelerator_table.cc
index ba9ed05..98b5d48 100644
--- a/ash/accelerators/accelerator_table.cc
+++ b/ash/accelerators/accelerator_table.cc
@@ -68,6 +68,24 @@ const AcceleratorData kAcceleratorData[] = {
{ ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_VOLUME_UP, false, false, false,
VOLUME_UP },
{ ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_F1, true, true, false, SHOW_OAK },
+ { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_1, false, false, true,
+ SELECT_WIN_0 },
+ { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_2, false, false, true,
+ SELECT_WIN_1 },
+ { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_3, false, false, true,
+ SELECT_WIN_2 },
+ { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_4, false, false, true,
+ SELECT_WIN_3 },
+ { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_5, false, false, true,
+ SELECT_WIN_4 },
+ { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_6, false, false, true,
+ SELECT_WIN_5 },
+ { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_7, false, false, true,
+ SELECT_WIN_6 },
+ { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_8, false, false, true,
+ SELECT_WIN_7 },
+ { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_9, false, false, true,
+ SELECT_LAST_WIN },
#if !defined(NDEBUG)
{ ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_HOME, false, true, false,
ROTATE_SCREEN },
diff --git a/ash/accelerators/accelerator_table.h b/ash/accelerators/accelerator_table.h
index 31f5a70..d9fcdc0 100644
--- a/ash/accelerators/accelerator_table.h
+++ b/ash/accelerators/accelerator_table.h
@@ -30,6 +30,15 @@ enum AcceleratorAction {
#if defined(OS_CHROMEOS)
LOCK_SCREEN,
#endif
+ SELECT_WIN_0,
+ SELECT_WIN_1,
+ SELECT_WIN_2,
+ SELECT_WIN_3,
+ SELECT_WIN_4,
+ SELECT_WIN_5,
+ SELECT_WIN_6,
+ SELECT_WIN_7,
+ SELECT_LAST_WIN,
#if !defined(NDEBUG)
PRINT_LAYER_HIERARCHY,
PRINT_WINDOW_HIERARCHY,