| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 case Shell::BACKWARD: | 146 case Shell::BACKWARD: |
| 147 shell->focus_cycler()->RotateFocus(internal::FocusCycler::BACKWARD); | 147 shell->focus_cycler()->RotateFocus(internal::FocusCycler::BACKWARD); |
| 148 break; | 148 break; |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 | 153 |
| 154 // Rotates the default window container. | 154 // Rotates the default window container. |
| 155 bool HandleRotateWindows() { | 155 bool HandleRotateWindows() { |
| 156 if (!DebugShortcutsEnabled()) | |
| 157 return true; | |
| 158 | |
| 159 aura::Window* target = | 156 aura::Window* target = |
| 160 Shell::GetPrimaryRootWindowController()->GetContainer( | 157 Shell::GetPrimaryRootWindowController()->GetContainer( |
| 161 internal::kShellWindowId_DefaultContainer); | 158 internal::kShellWindowId_DefaultContainer); |
| 162 scoped_ptr<ui::LayerAnimationSequence> screen_rotation( | 159 scoped_ptr<ui::LayerAnimationSequence> screen_rotation( |
| 163 new ui::LayerAnimationSequence(new ash::ScreenRotation(360))); | 160 new ui::LayerAnimationSequence(new ash::ScreenRotation(360))); |
| 164 target->layer()->GetAnimator()->StartAnimation( | 161 target->layer()->GetAnimator()->StartAnimation( |
| 165 screen_rotation.release()); | 162 screen_rotation.release()); |
| 166 return true; | 163 return true; |
| 167 } | 164 } |
| 168 | 165 |
| 169 // Rotates the screen. | 166 // Rotates the screen. |
| 170 bool HandleRotateScreen() { | 167 bool HandleRotateScreen() { |
| 171 if (!DebugShortcutsEnabled()) | |
| 172 return true; | |
| 173 | |
| 174 static int i = 0; | 168 static int i = 0; |
| 175 int delta = 0; | 169 int delta = 0; |
| 176 switch (i) { | 170 switch (i) { |
| 177 case 0: delta = 90; break; | 171 case 0: delta = 90; break; |
| 178 case 1: delta = 90; break; | 172 case 1: delta = 90; break; |
| 179 case 2: delta = 90; break; | 173 case 2: delta = 90; break; |
| 180 case 3: delta = 90; break; | 174 case 3: delta = 90; break; |
| 181 case 4: delta = -90; break; | 175 case 4: delta = -90; break; |
| 182 case 5: delta = -90; break; | 176 case 5: delta = -90; break; |
| 183 case 6: delta = -90; break; | 177 case 6: delta = -90; break; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 195 set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 189 set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| 196 scoped_ptr<ui::LayerAnimationSequence> screen_rotation( | 190 scoped_ptr<ui::LayerAnimationSequence> screen_rotation( |
| 197 new ui::LayerAnimationSequence(new ash::ScreenRotation(delta))); | 191 new ui::LayerAnimationSequence(new ash::ScreenRotation(delta))); |
| 198 screen_rotation->AddObserver(root_window); | 192 screen_rotation->AddObserver(root_window); |
| 199 root_window->layer()->GetAnimator()-> | 193 root_window->layer()->GetAnimator()-> |
| 200 StartAnimation(screen_rotation.release()); | 194 StartAnimation(screen_rotation.release()); |
| 201 return true; | 195 return true; |
| 202 } | 196 } |
| 203 | 197 |
| 204 bool HandleToggleDesktopBackgroundMode() { | 198 bool HandleToggleDesktopBackgroundMode() { |
| 205 if (!DebugShortcutsEnabled()) | |
| 206 return true; | |
| 207 | |
| 208 DesktopBackgroundController* desktop_background_controller = | 199 DesktopBackgroundController* desktop_background_controller = |
| 209 Shell::GetInstance()->desktop_background_controller(); | 200 Shell::GetInstance()->desktop_background_controller(); |
| 210 if (desktop_background_controller->desktop_background_mode() == | 201 if (desktop_background_controller->desktop_background_mode() == |
| 211 DesktopBackgroundController::BACKGROUND_IMAGE) { | 202 DesktopBackgroundController::BACKGROUND_IMAGE) { |
| 212 desktop_background_controller->SetDesktopBackgroundSolidColorMode( | 203 desktop_background_controller->SetDesktopBackgroundSolidColorMode( |
| 213 SK_ColorBLACK); | 204 SK_ColorBLACK); |
| 214 } else { | 205 } else { |
| 215 ash::Shell::GetInstance()->user_wallpaper_delegate()-> | 206 ash::Shell::GetInstance()->user_wallpaper_delegate()-> |
| 216 InitializeWallpaper(); | 207 InitializeWallpaper(); |
| 217 } | 208 } |
| 218 return true; | 209 return true; |
| 219 } | 210 } |
| 220 | 211 |
| 221 bool HandleToggleRootWindowFullScreen() { | 212 bool HandleToggleRootWindowFullScreen() { |
| 222 if (!DebugShortcutsEnabled()) | |
| 223 return true; | |
| 224 | |
| 225 Shell::GetPrimaryRootWindow()->ToggleFullScreen(); | 213 Shell::GetPrimaryRootWindow()->ToggleFullScreen(); |
| 226 return true; | 214 return true; |
| 227 } | 215 } |
| 228 | 216 |
| 229 // Magnify the screen | 217 // Magnify the screen |
| 230 bool HandleMagnifyScreen(int delta_index) { | 218 bool HandleMagnifyScreen(int delta_index) { |
| 231 // TODO(yoshiki): Create the class like MagnifierStepScaleController, and | 219 // TODO(yoshiki): Create the class like MagnifierStepScaleController, and |
| 232 // move the following scale control to it. | 220 // move the following scale control to it. |
| 233 float scale = | 221 float scale = |
| 234 ash::Shell::GetInstance()->magnification_controller()->GetScale(); | 222 ash::Shell::GetInstance()->magnification_controller()->GetScale(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 actions_allowed_at_lock_screen_.insert( | 292 actions_allowed_at_lock_screen_.insert( |
| 305 kActionsAllowedAtLoginOrLockScreen[i]); | 293 kActionsAllowedAtLoginOrLockScreen[i]); |
| 306 } | 294 } |
| 307 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) { | 295 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) { |
| 308 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); | 296 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); |
| 309 } | 297 } |
| 310 for (size_t i = 0; i < kReservedActionsLength; ++i) { | 298 for (size_t i = 0; i < kReservedActionsLength; ++i) { |
| 311 reserved_actions_.insert(kReservedActions[i]); | 299 reserved_actions_.insert(kReservedActions[i]); |
| 312 } | 300 } |
| 313 | 301 |
| 314 for (size_t i = 0; i < kAcceleratorDataLength; ++i) { | 302 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); |
| 315 ui::Accelerator accelerator(kAcceleratorData[i].keycode, | 303 |
| 316 kAcceleratorData[i].modifiers); | 304 if (DebugShortcutsEnabled()) |
| 317 accelerator.set_type(kAcceleratorData[i].trigger_on_press ? | 305 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); |
| 318 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED); | |
| 319 Register(accelerator, this); | |
| 320 accelerators_.insert( | |
| 321 std::make_pair(accelerator, kAcceleratorData[i].action)); | |
| 322 } | |
| 323 } | 306 } |
| 324 | 307 |
| 325 void AcceleratorController::Register(const ui::Accelerator& accelerator, | 308 void AcceleratorController::Register(const ui::Accelerator& accelerator, |
| 326 ui::AcceleratorTarget* target) { | 309 ui::AcceleratorTarget* target) { |
| 327 accelerator_manager_->Register(accelerator, | 310 accelerator_manager_->Register(accelerator, |
| 328 ui::AcceleratorManager::kNormalPriority, | 311 ui::AcceleratorManager::kNormalPriority, |
| 329 target); | 312 target); |
| 330 } | 313 } |
| 331 | 314 |
| 332 void AcceleratorController::Unregister(const ui::Accelerator& accelerator, | 315 void AcceleratorController::Unregister(const ui::Accelerator& accelerator, |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 } | 617 } |
| 635 case ROTATE_WINDOWS: | 618 case ROTATE_WINDOWS: |
| 636 return HandleRotateWindows(); | 619 return HandleRotateWindows(); |
| 637 case ROTATE_SCREEN: | 620 case ROTATE_SCREEN: |
| 638 return HandleRotateScreen(); | 621 return HandleRotateScreen(); |
| 639 case TOGGLE_DESKTOP_BACKGROUND_MODE: | 622 case TOGGLE_DESKTOP_BACKGROUND_MODE: |
| 640 return HandleToggleDesktopBackgroundMode(); | 623 return HandleToggleDesktopBackgroundMode(); |
| 641 case TOGGLE_ROOT_WINDOW_FULL_SCREEN: | 624 case TOGGLE_ROOT_WINDOW_FULL_SCREEN: |
| 642 return HandleToggleRootWindowFullScreen(); | 625 return HandleToggleRootWindowFullScreen(); |
| 643 case DISPLAY_ADD_REMOVE: | 626 case DISPLAY_ADD_REMOVE: |
| 644 if (DebugShortcutsEnabled()) | 627 internal::MultiDisplayManager::AddRemoveDisplay(); |
| 645 internal::MultiDisplayManager::AddRemoveDisplay(); | |
| 646 return true; | 628 return true; |
| 647 case DISPLAY_CYCLE: | 629 case DISPLAY_CYCLE: |
| 648 if (DebugShortcutsEnabled()) | 630 internal::MultiDisplayManager::CycleDisplay(); |
| 649 internal::MultiDisplayManager::CycleDisplay(); | |
| 650 return true; | 631 return true; |
| 651 case DISPLAY_TOGGLE_SCALE: | 632 case DISPLAY_TOGGLE_SCALE: |
| 652 if (DebugShortcutsEnabled()) | 633 internal::MultiDisplayManager::ToggleDisplayScale(); |
| 653 internal::MultiDisplayManager::ToggleDisplayScale(); | |
| 654 return true; | 634 return true; |
| 655 case MAGNIFY_SCREEN_ZOOM_IN: | 635 case MAGNIFY_SCREEN_ZOOM_IN: |
| 656 return HandleMagnifyScreen(1); | 636 return HandleMagnifyScreen(1); |
| 657 case MAGNIFY_SCREEN_ZOOM_OUT: | 637 case MAGNIFY_SCREEN_ZOOM_OUT: |
| 658 return HandleMagnifyScreen(-1); | 638 return HandleMagnifyScreen(-1); |
| 659 #if !defined(NDEBUG) | 639 #if !defined(NDEBUG) |
| 660 case PRINT_LAYER_HIERARCHY: | 640 case PRINT_LAYER_HIERARCHY: |
| 661 return HandlePrintLayerHierarchy(); | 641 return HandlePrintLayerHierarchy(); |
| 662 case PRINT_VIEW_HIERARCHY: | 642 case PRINT_VIEW_HIERARCHY: |
| 663 return HandlePrintViewHierarchy(); | 643 return HandlePrintViewHierarchy(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 // There are two ways how found_index can be valid: a.) the nth item was | 714 // There are two ways how found_index can be valid: a.) the nth item was |
| 735 // found (which is true when indexes_left is -1) or b.) the last item was | 715 // found (which is true when indexes_left is -1) or b.) the last item was |
| 736 // requested (which is true when index was passed in as a negative number). | 716 // requested (which is true when index was passed in as a negative number). |
| 737 if (found_index >= 0 && (indexes_left == -1 || window < 0) && | 717 if (found_index >= 0 && (indexes_left == -1 || window < 0) && |
| 738 items[found_index].status == ash::STATUS_RUNNING) { | 718 items[found_index].status == ash::STATUS_RUNNING) { |
| 739 // Then set this one as active. | 719 // Then set this one as active. |
| 740 Shell::GetInstance()->launcher()->ActivateLauncherItem(found_index); | 720 Shell::GetInstance()->launcher()->ActivateLauncherItem(found_index); |
| 741 } | 721 } |
| 742 } | 722 } |
| 743 | 723 |
| 724 void AcceleratorController::RegisterAccelerators( |
| 725 const AcceleratorData accelerators[], |
| 726 size_t accelerators_length) { |
| 727 for (size_t i = 0; i < accelerators_length; ++i) { |
| 728 ui::Accelerator accelerator(accelerators[i].keycode, |
| 729 accelerators[i].modifiers); |
| 730 accelerator.set_type(accelerators[i].trigger_on_press ? |
| 731 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED); |
| 732 Register(accelerator, this); |
| 733 accelerators_.insert( |
| 734 std::make_pair(accelerator, accelerators[i].action)); |
| 735 } |
| 736 } |
| 737 |
| 744 bool AcceleratorController::CanHandleAccelerators() const { | 738 bool AcceleratorController::CanHandleAccelerators() const { |
| 745 return true; | 739 return true; |
| 746 } | 740 } |
| 747 | 741 |
| 748 } // namespace ash | 742 } // namespace ash |
| OLD | NEW |