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 "ash/caps_lock_delegate.h" | 7 #include "ash/caps_lock_delegate.h" |
8 #include "ash/ime_control_delegate.h" | 8 #include "ash/ime_control_delegate.h" |
9 #include "ash/launcher/launcher.h" | 9 #include "ash/launcher/launcher.h" |
10 #include "ash/launcher/launcher_model.h" | 10 #include "ash/launcher/launcher_model.h" |
11 #include "ash/screenshot_delegate.h" | 11 #include "ash/screenshot_delegate.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/shell_delegate.h" | 13 #include "ash/shell_delegate.h" |
14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
15 #include "ash/system/brightness/brightness_control_delegate.h" | 15 #include "ash/system/brightness/brightness_control_delegate.h" |
16 #include "ash/volume_control_delegate.h" | 16 #include "ash/volume_control_delegate.h" |
17 #include "ash/wm/window_cycle_controller.h" | 17 #include "ash/wm/window_cycle_controller.h" |
18 #include "ash/wm/window_util.h" | 18 #include "ash/wm/window_util.h" |
| 19 #include "ui/aura/client/activation_client.h" |
19 #include "ui/aura/event.h" | 20 #include "ui/aura/event.h" |
20 #include "ui/aura/root_window.h" | 21 #include "ui/aura/root_window.h" |
21 #include "ui/base/accelerators/accelerator.h" | 22 #include "ui/base/accelerators/accelerator.h" |
22 #include "ui/base/accelerators/accelerator_manager.h" | 23 #include "ui/base/accelerators/accelerator_manager.h" |
23 #include "ui/gfx/compositor/debug_utils.h" | 24 #include "ui/gfx/compositor/debug_utils.h" |
24 #include "ui/gfx/compositor/layer_animation_sequence.h" | 25 #include "ui/gfx/compositor/layer_animation_sequence.h" |
25 #include "ui/gfx/compositor/layer_animator.h" | 26 #include "ui/gfx/compositor/layer_animator.h" |
26 #include "ui/gfx/compositor/screen_rotation.h" | 27 #include "ui/gfx/compositor/screen_rotation.h" |
27 | 28 |
28 namespace { | 29 namespace { |
(...skipping 16 matching lines...) Expand all Loading... |
45 #if defined(OS_CHROMEOS) | 46 #if defined(OS_CHROMEOS) |
46 LOCK_SCREEN, | 47 LOCK_SCREEN, |
47 #endif | 48 #endif |
48 #if !defined(NDEBUG) | 49 #if !defined(NDEBUG) |
49 PRINT_LAYER_HIERARCHY, | 50 PRINT_LAYER_HIERARCHY, |
50 PRINT_WINDOW_HIERARCHY, | 51 PRINT_WINDOW_HIERARCHY, |
51 ROTATE_SCREEN, | 52 ROTATE_SCREEN, |
52 TOGGLE_DESKTOP_BACKGROUND_MODE, | 53 TOGGLE_DESKTOP_BACKGROUND_MODE, |
53 TOGGLE_ROOT_WINDOW_FULL_SCREEN, | 54 TOGGLE_ROOT_WINDOW_FULL_SCREEN, |
54 #endif | 55 #endif |
| 56 SELECT_WIN_0, |
| 57 SELECT_WIN_1, |
| 58 SELECT_WIN_2, |
| 59 SELECT_WIN_3, |
| 60 SELECT_WIN_4, |
| 61 SELECT_WIN_5, |
| 62 SELECT_WIN_6, |
| 63 SELECT_WIN_7, |
| 64 SELECT_WIN_8, |
55 }; | 65 }; |
56 | 66 |
57 // Accelerators handled by AcceleratorController. | 67 // Accelerators handled by AcceleratorController. |
58 const struct AcceleratorData { | 68 const struct AcceleratorData { |
59 ui::EventType type; | 69 ui::EventType type; |
60 ui::KeyboardCode keycode; | 70 ui::KeyboardCode keycode; |
61 bool shift; | 71 bool shift; |
62 bool ctrl; | 72 bool ctrl; |
63 bool alt; | 73 bool alt; |
64 AcceleratorAction action; | 74 AcceleratorAction action; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 VOLUME_MUTE }, | 122 VOLUME_MUTE }, |
113 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_VOLUME_MUTE, false, false, false, | 123 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_VOLUME_MUTE, false, false, false, |
114 VOLUME_MUTE }, | 124 VOLUME_MUTE }, |
115 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_F9, false, false, false, | 125 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_F9, false, false, false, |
116 VOLUME_DOWN }, | 126 VOLUME_DOWN }, |
117 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_VOLUME_DOWN, false, false, false, | 127 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_VOLUME_DOWN, false, false, false, |
118 VOLUME_DOWN }, | 128 VOLUME_DOWN }, |
119 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_F10, false, false, false, VOLUME_UP }, | 129 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_F10, false, false, false, VOLUME_UP }, |
120 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_VOLUME_UP, false, false, false, | 130 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_VOLUME_UP, false, false, false, |
121 VOLUME_UP }, | 131 VOLUME_UP }, |
| 132 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_1, false, false, true, |
| 133 SELECT_WIN_0 }, |
| 134 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_2, false, false, true, |
| 135 SELECT_WIN_1 }, |
| 136 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_3, false, false, true, |
| 137 SELECT_WIN_2 }, |
| 138 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_4, false, false, true, |
| 139 SELECT_WIN_3 }, |
| 140 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_5, false, false, true, |
| 141 SELECT_WIN_4 }, |
| 142 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_6, false, false, true, |
| 143 SELECT_WIN_5 }, |
| 144 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_7, false, false, true, |
| 145 SELECT_WIN_6 }, |
| 146 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_8, false, false, true, |
| 147 SELECT_WIN_7 }, |
| 148 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_9, false, false, true, |
| 149 SELECT_WIN_8 }, |
| 150 |
122 #if !defined(NDEBUG) | 151 #if !defined(NDEBUG) |
123 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_HOME, false, true, false, | 152 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_HOME, false, true, false, |
124 ROTATE_SCREEN }, | 153 ROTATE_SCREEN }, |
125 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_B, false, true, true, | 154 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_B, false, true, true, |
126 TOGGLE_DESKTOP_BACKGROUND_MODE }, | 155 TOGGLE_DESKTOP_BACKGROUND_MODE }, |
127 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_F11, false, true, false, | 156 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_F11, false, true, false, |
128 TOGGLE_ROOT_WINDOW_FULL_SCREEN }, | 157 TOGGLE_ROOT_WINDOW_FULL_SCREEN }, |
129 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_L, false, false, true, | 158 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_L, false, false, true, |
130 PRINT_LAYER_HIERARCHY }, | 159 PRINT_LAYER_HIERARCHY }, |
131 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_L, true, false, true, | 160 { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_L, true, false, true, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 338 } |
310 | 339 |
311 //////////////////////////////////////////////////////////////////////////////// | 340 //////////////////////////////////////////////////////////////////////////////// |
312 // AcceleratorController, ui::AcceleratorTarget implementation: | 341 // AcceleratorController, ui::AcceleratorTarget implementation: |
313 | 342 |
314 bool AcceleratorController::AcceleratorPressed( | 343 bool AcceleratorController::AcceleratorPressed( |
315 const ui::Accelerator& accelerator) { | 344 const ui::Accelerator& accelerator) { |
316 std::map<ui::Accelerator, int>::const_iterator it = | 345 std::map<ui::Accelerator, int>::const_iterator it = |
317 accelerators_.find(accelerator); | 346 accelerators_.find(accelerator); |
318 DCHECK(it != accelerators_.end()); | 347 DCHECK(it != accelerators_.end()); |
| 348 unsigned int window = 0; |
319 switch (static_cast<AcceleratorAction>(it->second)) { | 349 switch (static_cast<AcceleratorAction>(it->second)) { |
320 case CYCLE_BACKWARD: | 350 case CYCLE_BACKWARD: |
321 return HandleCycleWindow(WindowCycleController::BACKWARD, | 351 return HandleCycleWindow(WindowCycleController::BACKWARD, |
322 accelerator.IsAltDown()); | 352 accelerator.IsAltDown()); |
323 case CYCLE_FORWARD: | 353 case CYCLE_FORWARD: |
324 return HandleCycleWindow(WindowCycleController::FORWARD, | 354 return HandleCycleWindow(WindowCycleController::FORWARD, |
325 accelerator.IsAltDown()); | 355 accelerator.IsAltDown()); |
326 #if defined(OS_CHROMEOS) | 356 #if defined(OS_CHROMEOS) |
327 case LOCK_SCREEN: | 357 case LOCK_SCREEN: |
328 return HandleLock(); | 358 return HandleLock(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 return ime_control_delegate_->HandleNextIme(); | 402 return ime_control_delegate_->HandleNextIme(); |
373 break; | 403 break; |
374 case PREVIOUS_IME: | 404 case PREVIOUS_IME: |
375 if (ime_control_delegate_.get()) | 405 if (ime_control_delegate_.get()) |
376 return ime_control_delegate_->HandlePreviousIme(); | 406 return ime_control_delegate_->HandlePreviousIme(); |
377 break; | 407 break; |
378 case SWITCH_IME: | 408 case SWITCH_IME: |
379 if (ime_control_delegate_.get()) | 409 if (ime_control_delegate_.get()) |
380 return ime_control_delegate_->HandleSwitchIme(accelerator); | 410 return ime_control_delegate_->HandleSwitchIme(accelerator); |
381 break; | 411 break; |
| 412 case SELECT_WIN_8: |
| 413 window++; |
| 414 // Fallthrough. |
| 415 case SELECT_WIN_7: |
| 416 window++; |
| 417 // Fallthrough. |
| 418 case SELECT_WIN_6: |
| 419 window++; |
| 420 // Fallthrough. |
| 421 case SELECT_WIN_5: |
| 422 window++; |
| 423 // Fallthrough. |
| 424 case SELECT_WIN_4: |
| 425 window++; |
| 426 // Fallthrough. |
| 427 case SELECT_WIN_3: |
| 428 window++; |
| 429 // Fallthrough. |
| 430 case SELECT_WIN_2: |
| 431 window++; |
| 432 // Fallthrough. |
| 433 case SELECT_WIN_1: |
| 434 window++; |
| 435 // Fallthrough. |
| 436 case SELECT_WIN_0: |
| 437 SwitchToWindow(window); |
| 438 break; |
382 #if !defined(NDEBUG) | 439 #if !defined(NDEBUG) |
383 case ROTATE_SCREEN: | 440 case ROTATE_SCREEN: |
384 return HandleRotateScreen(); | 441 return HandleRotateScreen(); |
385 case TOGGLE_DESKTOP_BACKGROUND_MODE: | 442 case TOGGLE_DESKTOP_BACKGROUND_MODE: |
386 return HandleToggleDesktopBackgroundMode(); | 443 return HandleToggleDesktopBackgroundMode(); |
387 case TOGGLE_ROOT_WINDOW_FULL_SCREEN: | 444 case TOGGLE_ROOT_WINDOW_FULL_SCREEN: |
388 return HandleToggleRootWindowFullScreen(); | 445 return HandleToggleRootWindowFullScreen(); |
389 case PRINT_LAYER_HIERARCHY: | 446 case PRINT_LAYER_HIERARCHY: |
390 return HandlePrintLayerHierarchy(); | 447 return HandlePrintLayerHierarchy(); |
391 case PRINT_WINDOW_HIERARCHY: | 448 case PRINT_WINDOW_HIERARCHY: |
392 return HandlePrintWindowHierarchy(); | 449 return HandlePrintWindowHierarchy(); |
393 #endif | 450 #endif |
394 default: | 451 default: |
395 NOTREACHED() << "Unhandled action " << it->second; | 452 NOTREACHED() << "Unhandled action " << it->second; |
396 } | 453 } |
397 return false; | 454 return false; |
398 } | 455 } |
399 | 456 |
| 457 void AcceleratorController::SwitchToWindow(const unsigned int window) { |
| 458 const std::vector<aura::Window*>& windows = |
| 459 Shell::GetInstance()->delegate()->GetCycleWindowList( |
| 460 ShellDelegate::SOURCE_LAUNCHER, |
| 461 ShellDelegate::ORDER_LINEAR); |
| 462 if (window < windows.size()) { |
| 463 aura::client::ActivationClient* activation_client = |
| 464 aura::client::GetActivationClient(Shell::GetRootWindow()); |
| 465 aura::Window* window_to_activate = windows[window]; |
| 466 aura::Window* current_window = wm::GetActiveWindow(); |
| 467 if (window_to_activate != current_window) { |
| 468 bool maximized = wm::IsWindowMaximized(current_window); |
| 469 if (maximized) { |
| 470 wm::RestoreWindow(current_window); |
| 471 } |
| 472 activation_client->ActivateWindow(window_to_activate); |
| 473 if (maximized) { |
| 474 wm::MaximizeWindow(window_to_activate); |
| 475 } |
| 476 } |
| 477 } |
| 478 } |
| 479 |
400 bool AcceleratorController::CanHandleAccelerators() const { | 480 bool AcceleratorController::CanHandleAccelerators() const { |
401 return true; | 481 return true; |
402 } | 482 } |
403 | 483 |
404 } // namespace ash | 484 } // namespace ash |
OLD | NEW |