| 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 "ash/accelerators/accelerator_controller.h" | 5 #include "ash/accelerators/accelerator_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 bool HandleCycleWindowMRU(WindowCycleController::Direction direction, | 82 bool HandleCycleWindowMRU(WindowCycleController::Direction direction, |
| 83 bool is_alt_down) { | 83 bool is_alt_down) { |
| 84 Shell::GetInstance()-> | 84 Shell::GetInstance()-> |
| 85 window_cycle_controller()->HandleCycleWindow(direction, is_alt_down); | 85 window_cycle_controller()->HandleCycleWindow(direction, is_alt_down); |
| 86 // Always report we handled the key, even if the window didn't change. | 86 // Always report we handled the key, even if the window didn't change. |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 void HandleCycleWindowLinear(CycleDirection direction) { | 90 void HandleCycleWindowLinear(CycleDirection direction) { |
| 91 Shell::GetInstance()->launcher()->CycleWindowLinear(direction); | 91 Launcher::ForPrimaryDisplay()->CycleWindowLinear(direction); |
| 92 } | 92 } |
| 93 | 93 |
| 94 #if defined(OS_CHROMEOS) | 94 #if defined(OS_CHROMEOS) |
| 95 bool HandleLock() { | 95 bool HandleLock() { |
| 96 Shell::GetInstance()->delegate()->LockScreen(); | 96 Shell::GetInstance()->delegate()->LockScreen(); |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 | 99 |
| 100 bool HandleFileManager(bool as_dialog) { | 100 bool HandleFileManager(bool as_dialog) { |
| 101 Shell::GetInstance()->delegate()->OpenFileManager(as_dialog); | 101 Shell::GetInstance()->delegate()->OpenFileManager(as_dialog); |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 break; | 595 break; |
| 596 case VOLUME_DOWN: | 596 case VOLUME_DOWN: |
| 597 return shell->tray_delegate()->GetVolumeControlDelegate()-> | 597 return shell->tray_delegate()->GetVolumeControlDelegate()-> |
| 598 HandleVolumeDown(accelerator); | 598 HandleVolumeDown(accelerator); |
| 599 break; | 599 break; |
| 600 case VOLUME_UP: | 600 case VOLUME_UP: |
| 601 return shell->tray_delegate()->GetVolumeControlDelegate()-> | 601 return shell->tray_delegate()->GetVolumeControlDelegate()-> |
| 602 HandleVolumeUp(accelerator); | 602 HandleVolumeUp(accelerator); |
| 603 break; | 603 break; |
| 604 case FOCUS_LAUNCHER: | 604 case FOCUS_LAUNCHER: |
| 605 if (shell->launcher()) | 605 return shell->focus_cycler()->FocusWidget( |
| 606 return shell->focus_cycler()->FocusWidget(shell->launcher()->widget()); | 606 Launcher::ForPrimaryDisplay()->widget()); |
| 607 break; | 607 break; |
| 608 case FOCUS_NEXT_PANE: | 608 case FOCUS_NEXT_PANE: |
| 609 return HandleRotatePaneFocus(Shell::FORWARD); | 609 return HandleRotatePaneFocus(Shell::FORWARD); |
| 610 case FOCUS_PREVIOUS_PANE: | 610 case FOCUS_PREVIOUS_PANE: |
| 611 return HandleRotatePaneFocus(Shell::BACKWARD); | 611 return HandleRotatePaneFocus(Shell::BACKWARD); |
| 612 case FOCUS_SYSTEM_TRAY: | 612 case FOCUS_SYSTEM_TRAY: |
| 613 if (shell->system_tray()) | 613 if (shell->system_tray()) |
| 614 return shell->focus_cycler()->FocusWidget( | 614 return shell->focus_cycler()->FocusWidget( |
| 615 shell->system_tray()->GetWidget()); | 615 shell->system_tray()->GetWidget()); |
| 616 break; | 616 break; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 | 844 |
| 845 bool AcceleratorController::AcceleratorPressed( | 845 bool AcceleratorController::AcceleratorPressed( |
| 846 const ui::Accelerator& accelerator) { | 846 const ui::Accelerator& accelerator) { |
| 847 std::map<ui::Accelerator, int>::const_iterator it = | 847 std::map<ui::Accelerator, int>::const_iterator it = |
| 848 accelerators_.find(accelerator); | 848 accelerators_.find(accelerator); |
| 849 DCHECK(it != accelerators_.end()); | 849 DCHECK(it != accelerators_.end()); |
| 850 return PerformAction(static_cast<AcceleratorAction>(it->second), accelerator); | 850 return PerformAction(static_cast<AcceleratorAction>(it->second), accelerator); |
| 851 } | 851 } |
| 852 | 852 |
| 853 void AcceleratorController::SwitchToWindow(int window) { | 853 void AcceleratorController::SwitchToWindow(int window) { |
| 854 const LauncherItems& items = | 854 Launcher* launcher = Launcher::ForPrimaryDisplay(); |
| 855 Shell::GetInstance()->launcher()->model()->items(); | 855 const LauncherItems& items = launcher->model()->items(); |
| 856 int item_count = | 856 int item_count = launcher->model()->item_count(); |
| 857 Shell::GetInstance()->launcher()->model()->item_count(); | |
| 858 int indexes_left = window >= 0 ? window : item_count; | 857 int indexes_left = window >= 0 ? window : item_count; |
| 859 int found_index = -1; | 858 int found_index = -1; |
| 860 | 859 |
| 861 // Iterating until we have hit the index we are interested in which | 860 // Iterating until we have hit the index we are interested in which |
| 862 // is true once indexes_left becomes negative. | 861 // is true once indexes_left becomes negative. |
| 863 for (int i = 0; i < item_count && indexes_left >= 0; i++) { | 862 for (int i = 0; i < item_count && indexes_left >= 0; i++) { |
| 864 if (items[i].type != TYPE_APP_LIST && | 863 if (items[i].type != TYPE_APP_LIST && |
| 865 items[i].type != TYPE_BROWSER_SHORTCUT) { | 864 items[i].type != TYPE_BROWSER_SHORTCUT) { |
| 866 found_index = i; | 865 found_index = i; |
| 867 indexes_left--; | 866 indexes_left--; |
| 868 } | 867 } |
| 869 } | 868 } |
| 870 | 869 |
| 871 // There are two ways how found_index can be valid: a.) the nth item was | 870 // There are two ways how found_index can be valid: a.) the nth item was |
| 872 // found (which is true when indexes_left is -1) or b.) the last item was | 871 // found (which is true when indexes_left is -1) or b.) the last item was |
| 873 // requested (which is true when index was passed in as a negative number). | 872 // requested (which is true when index was passed in as a negative number). |
| 874 if (found_index >= 0 && (indexes_left == -1 || window < 0) && | 873 if (found_index >= 0 && (indexes_left == -1 || window < 0) && |
| 875 (items[found_index].status == ash::STATUS_RUNNING || | 874 (items[found_index].status == ash::STATUS_RUNNING || |
| 876 items[found_index].status == ash::STATUS_CLOSED)) { | 875 items[found_index].status == ash::STATUS_CLOSED)) { |
| 877 // Then set this one as active. | 876 // Then set this one as active. |
| 878 Shell::GetInstance()->launcher()->ActivateLauncherItem(found_index); | 877 launcher->ActivateLauncherItem(found_index); |
| 879 } | 878 } |
| 880 } | 879 } |
| 881 | 880 |
| 882 void AcceleratorController::RegisterAccelerators( | 881 void AcceleratorController::RegisterAccelerators( |
| 883 const AcceleratorData accelerators[], | 882 const AcceleratorData accelerators[], |
| 884 size_t accelerators_length) { | 883 size_t accelerators_length) { |
| 885 for (size_t i = 0; i < accelerators_length; ++i) { | 884 for (size_t i = 0; i < accelerators_length; ++i) { |
| 886 ui::Accelerator accelerator(accelerators[i].keycode, | 885 ui::Accelerator accelerator(accelerators[i].keycode, |
| 887 accelerators[i].modifiers); | 886 accelerators[i].modifiers); |
| 888 accelerator.set_type(accelerators[i].trigger_on_press ? | 887 accelerator.set_type(accelerators[i].trigger_on_press ? |
| 889 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED); | 888 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED); |
| 890 Register(accelerator, this); | 889 Register(accelerator, this); |
| 891 accelerators_.insert( | 890 accelerators_.insert( |
| 892 std::make_pair(accelerator, accelerators[i].action)); | 891 std::make_pair(accelerator, accelerators[i].action)); |
| 893 } | 892 } |
| 894 } | 893 } |
| 895 | 894 |
| 896 bool AcceleratorController::CanHandleAccelerators() const { | 895 bool AcceleratorController::CanHandleAccelerators() const { |
| 897 return true; | 896 return true; |
| 898 } | 897 } |
| 899 | 898 |
| 900 } // namespace ash | 899 } // namespace ash |
| OLD | NEW |