Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/aura_shell/shell_accelerator_controller.h" | 5 #include "ui/aura_shell/shell_accelerator_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "ui/aura/event.h" | 10 #include "ui/aura/event.h" |
| 9 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
| 12 #include "ui/aura_shell/launcher/launcher.h" | |
| 13 #include "ui/aura_shell/launcher/launcher_model.h" | |
| 10 #include "ui/aura_shell/shell.h" | 14 #include "ui/aura_shell/shell.h" |
| 15 #include "ui/aura_shell/shell_window_ids.h" | |
| 11 #include "ui/base/accelerators/accelerator.h" | 16 #include "ui/base/accelerators/accelerator.h" |
| 12 #include "ui/base/accelerators/accelerator_manager.h" | 17 #include "ui/base/accelerators/accelerator_manager.h" |
| 13 #include "ui/gfx/compositor/debug_utils.h" | 18 #include "ui/gfx/compositor/debug_utils.h" |
| 14 #include "ui/gfx/compositor/layer_animation_sequence.h" | 19 #include "ui/gfx/compositor/layer_animation_sequence.h" |
| 15 #include "ui/gfx/compositor/layer_animator.h" | 20 #include "ui/gfx/compositor/layer_animator.h" |
| 16 #include "ui/gfx/compositor/screen_rotation.h" | 21 #include "ui/gfx/compositor/screen_rotation.h" |
| 17 | 22 |
| 18 namespace { | 23 namespace { |
| 19 | 24 |
| 20 enum AcceleratorAction { | 25 enum AcceleratorAction { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 40 { ui::VKEY_TAB, false, false, true, CYCLE_FORWARD }, | 45 { ui::VKEY_TAB, false, false, true, CYCLE_FORWARD }, |
| 41 { ui::VKEY_F5, false, true, false, TAKE_SCREENSHOT }, | 46 { ui::VKEY_F5, false, true, false, TAKE_SCREENSHOT }, |
| 42 { ui::VKEY_PRINT, false, false, false, TAKE_SCREENSHOT }, | 47 { ui::VKEY_PRINT, false, false, false, TAKE_SCREENSHOT }, |
| 43 #if !defined(NDEBUG) | 48 #if !defined(NDEBUG) |
| 44 { ui::VKEY_HOME, false, true, false, ROTATE_SCREEN }, | 49 { ui::VKEY_HOME, false, true, false, ROTATE_SCREEN }, |
| 45 { ui::VKEY_F11, false, true, false, TOGGLE_ROOT_WINDOW_FULL_SCREEN }, | 50 { ui::VKEY_F11, false, true, false, TOGGLE_ROOT_WINDOW_FULL_SCREEN }, |
| 46 { ui::VKEY_L, false, false, true, PRINT_LAYER_HIERARCHY }, | 51 { ui::VKEY_L, false, false, true, PRINT_LAYER_HIERARCHY }, |
| 47 #endif | 52 #endif |
| 48 }; | 53 }; |
| 49 | 54 |
| 50 bool HandleCycleBackward() { | 55 // Returns true if the screen is locked. |
| 51 // TODO(mazda): http://crbug.com/105204 | 56 bool IsLocked() { |
|
Ben Goodger (Google)
2011/12/09 22:53:19
I wonder if we might want to make this a function
| |
| 52 NOTIMPLEMENTED(); | 57 const aura::Window* lock_screen_container = |
| 58 aura_shell::Shell::GetInstance()->GetContainer( | |
| 59 aura_shell::internal::kShellWindowId_LockScreenContainer); | |
| 60 const aura::Window::Windows& lock_screen_windows = | |
| 61 lock_screen_container->children(); | |
| 62 aura::Window::Windows::const_iterator lock_screen_it = | |
| 63 std::find_if(lock_screen_windows.begin(), lock_screen_windows.end(), | |
| 64 std::mem_fun(&aura::Window::IsVisible)); | |
| 65 if (lock_screen_it != lock_screen_windows.end()) | |
| 66 return true; | |
| 67 | |
| 68 aura::Window* lock_modal_container = | |
| 69 aura_shell::Shell::GetInstance()->GetContainer( | |
| 70 aura_shell::internal::kShellWindowId_LockModalContainer); | |
| 71 const aura::Window::Windows& lock_modal_windows = | |
| 72 lock_modal_container->children(); | |
| 73 aura::Window::Windows::const_iterator lock_modal_it = | |
| 74 std::find_if(lock_modal_windows.begin(), lock_modal_windows.end(), | |
| 75 std::mem_fun(&aura::Window::IsVisible)); | |
| 76 if (lock_modal_it != lock_modal_windows.end()) | |
| 77 return true; | |
| 78 | |
| 53 return false; | 79 return false; |
| 54 } | 80 } |
| 55 | 81 |
| 56 bool HandleCycleForward() { | 82 bool HandleCycleWindow(bool forward) { |
| 57 // TODO(mazda): http://crbug.com/105204 | 83 if (IsLocked()) |
| 58 NOTIMPLEMENTED(); | 84 return false; |
| 59 return false; | 85 |
| 86 // Use the same order of the windows in LauncherModel to cycle windows. | |
| 87 aura_shell::LauncherModel* model = | |
| 88 aura_shell::Shell::GetInstance()->launcher()->model(); | |
| 89 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); | |
| 90 aura::Window* active_window = root_window->active_window(); | |
| 91 if (!active_window) { | |
| 92 LOG(ERROR) << "No active window"; | |
| 93 return false; | |
| 94 } | |
| 95 int active_index = model->ItemIndexByWindow(active_window); | |
| 96 if (active_index < 0) { | |
| 97 VLOG(2) << "Active window not found in the launcher model"; | |
| 98 return false; | |
| 99 } | |
| 100 int next_index = (active_index + (forward ? 1 : -1) + model->item_count()) % | |
| 101 model->item_count(); | |
| 102 model->items()[next_index].window->Activate(); | |
| 103 return true; | |
| 60 } | 104 } |
| 61 | 105 |
| 62 bool HandleTakeScreenshot() { | 106 bool HandleTakeScreenshot() { |
| 63 // TODO(mazda): http://crbug.com/105198 | 107 // TODO(mazda): http://crbug.com/105198 |
| 64 NOTIMPLEMENTED(); | 108 NOTIMPLEMENTED(); |
| 65 return false; | 109 return false; |
| 66 } | 110 } |
| 67 | 111 |
| 68 #if !defined(NDEBUG) | 112 #if !defined(NDEBUG) |
| 69 // Rotates the screen. | 113 // Rotates the screen. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 //////////////////////////////////////////////////////////////////////////////// | 203 //////////////////////////////////////////////////////////////////////////////// |
| 160 // ShellAcceleratorController, ui::AcceleratorTarget implementation: | 204 // ShellAcceleratorController, ui::AcceleratorTarget implementation: |
| 161 | 205 |
| 162 bool ShellAcceleratorController::AcceleratorPressed( | 206 bool ShellAcceleratorController::AcceleratorPressed( |
| 163 const ui::Accelerator& accelerator) { | 207 const ui::Accelerator& accelerator) { |
| 164 std::map<ui::Accelerator, int>::const_iterator it = | 208 std::map<ui::Accelerator, int>::const_iterator it = |
| 165 accelerators_.find(accelerator); | 209 accelerators_.find(accelerator); |
| 166 DCHECK(it != accelerators_.end()); | 210 DCHECK(it != accelerators_.end()); |
| 167 switch (static_cast<AcceleratorAction>(it->second)) { | 211 switch (static_cast<AcceleratorAction>(it->second)) { |
| 168 case CYCLE_BACKWARD: | 212 case CYCLE_BACKWARD: |
| 169 return HandleCycleBackward(); | 213 return HandleCycleWindow(false); |
| 170 case CYCLE_FORWARD: | 214 case CYCLE_FORWARD: |
| 171 return HandleCycleForward(); | 215 return HandleCycleWindow(true); |
| 172 case TAKE_SCREENSHOT: | 216 case TAKE_SCREENSHOT: |
| 173 return HandleTakeScreenshot(); | 217 return HandleTakeScreenshot(); |
| 174 #if !defined(NDEBUG) | 218 #if !defined(NDEBUG) |
| 175 case ROTATE_SCREEN: | 219 case ROTATE_SCREEN: |
| 176 return HandleRotateScreen(); | 220 return HandleRotateScreen(); |
| 177 case TOGGLE_ROOT_WINDOW_FULL_SCREEN: | 221 case TOGGLE_ROOT_WINDOW_FULL_SCREEN: |
| 178 return HandleToggleRootWindowFullScreen(); | 222 return HandleToggleRootWindowFullScreen(); |
| 179 case PRINT_LAYER_HIERARCHY: | 223 case PRINT_LAYER_HIERARCHY: |
| 180 return HandlePrintLayerHierarchy(); | 224 return HandlePrintLayerHierarchy(); |
| 181 #endif | 225 #endif |
| 182 default: | 226 default: |
| 183 NOTREACHED() << "Unhandled action " << it->second;; | 227 NOTREACHED() << "Unhandled action " << it->second;; |
| 184 } | 228 } |
| 185 return false; | 229 return false; |
| 186 } | 230 } |
| 187 | 231 |
| 188 } // namespace aura_shell | 232 } // namespace aura_shell |
| OLD | NEW |