Chromium Code Reviews| 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 void AcceleratorController::Init() { | 343 void AcceleratorController::Init() { |
| 344 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { | 344 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { |
| 345 actions_allowed_at_login_screen_.insert( | 345 actions_allowed_at_login_screen_.insert( |
| 346 kActionsAllowedAtLoginOrLockScreen[i]); | 346 kActionsAllowedAtLoginOrLockScreen[i]); |
| 347 actions_allowed_at_lock_screen_.insert( | 347 actions_allowed_at_lock_screen_.insert( |
| 348 kActionsAllowedAtLoginOrLockScreen[i]); | 348 kActionsAllowedAtLoginOrLockScreen[i]); |
| 349 } | 349 } |
| 350 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) { | 350 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) { |
| 351 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); | 351 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); |
| 352 } | 352 } |
| 353 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) { | |
| 354 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]); | |
| 355 } | |
| 353 for (size_t i = 0; i < kReservedActionsLength; ++i) { | 356 for (size_t i = 0; i < kReservedActionsLength; ++i) { |
| 354 reserved_actions_.insert(kReservedActions[i]); | 357 reserved_actions_.insert(kReservedActions[i]); |
| 355 } | 358 } |
| 356 | 359 |
| 357 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); | 360 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); |
| 358 | 361 |
| 359 if (DebugShortcutsEnabled()) | 362 if (DebugShortcutsEnabled()) |
| 360 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); | 363 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); |
| 361 } | 364 } |
| 362 | 365 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 } | 406 } |
| 404 | 407 |
| 405 bool AcceleratorController::PerformAction(int action, | 408 bool AcceleratorController::PerformAction(int action, |
| 406 const ui::Accelerator& accelerator) { | 409 const ui::Accelerator& accelerator) { |
| 407 ash::Shell* shell = ash::Shell::GetInstance(); | 410 ash::Shell* shell = ash::Shell::GetInstance(); |
| 408 bool at_login_screen = false; | 411 bool at_login_screen = false; |
| 409 #if defined(OS_CHROMEOS) | 412 #if defined(OS_CHROMEOS) |
| 410 at_login_screen = shell->delegate() && !shell->delegate()->IsSessionStarted(); | 413 at_login_screen = shell->delegate() && !shell->delegate()->IsSessionStarted(); |
| 411 #endif | 414 #endif |
| 412 bool at_lock_screen = shell->IsScreenLocked(); | 415 bool at_lock_screen = shell->IsScreenLocked(); |
| 416 bool at_modal_window = shell->IsModalWindowOpen(); | |
| 413 | 417 |
| 414 if (at_login_screen && | 418 if (at_login_screen && |
| 415 actions_allowed_at_login_screen_.find(action) == | 419 actions_allowed_at_login_screen_.find(action) == |
| 416 actions_allowed_at_login_screen_.end()) { | 420 actions_allowed_at_login_screen_.end()) { |
| 417 return false; | 421 return false; |
| 418 } | 422 } |
| 419 if (at_lock_screen && | 423 if (at_lock_screen && |
| 420 actions_allowed_at_lock_screen_.find(action) == | 424 actions_allowed_at_lock_screen_.find(action) == |
| 421 actions_allowed_at_lock_screen_.end()) { | 425 actions_allowed_at_lock_screen_.end()) { |
| 422 return false; | 426 return false; |
| 423 } | 427 } |
| 428 if (at_modal_window && | |
| 429 actions_allowed_at_modal_window_.find(action) == | |
| 430 actions_allowed_at_modal_window_.end()) { | |
| 431 // Note: we return true. This indicates the shortcut is handled | |
| 432 // and will not be passed to the modal window. This is important | |
| 433 // for things Alt+Tab that would cause an undesired effect in | |
|
Daniel Erat
2012/09/30 01:24:47
nit: s/things/things like/
sschmitz
2012/10/15 23:50:34
Done.
| |
| 434 // the modal window by cycling through its window elements. | |
| 435 return true; | |
| 436 } | |
| 424 const ui::KeyboardCode key_code = accelerator.key_code(); | 437 const ui::KeyboardCode key_code = accelerator.key_code(); |
| 425 | 438 |
| 426 const ui::AcceleratorManagerContext& context = | 439 const ui::AcceleratorManagerContext& context = |
| 427 accelerator_manager_->GetContext(); | 440 accelerator_manager_->GetContext(); |
| 428 const ui::EventType last_event_type = context.GetLastEventType(); | 441 const ui::EventType last_event_type = context.GetLastEventType(); |
| 429 | 442 |
| 430 // You *MUST* return true when some action is performed. Otherwise, this | 443 // You *MUST* return true when some action is performed. Otherwise, this |
| 431 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent | 444 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent |
| 432 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. | 445 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. |
| 433 switch (action) { | 446 switch (action) { |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 accelerators_.insert( | 842 accelerators_.insert( |
| 830 std::make_pair(accelerator, accelerators[i].action)); | 843 std::make_pair(accelerator, accelerators[i].action)); |
| 831 } | 844 } |
| 832 } | 845 } |
| 833 | 846 |
| 834 bool AcceleratorController::CanHandleAccelerators() const { | 847 bool AcceleratorController::CanHandleAccelerators() const { |
| 835 return true; | 848 return true; |
| 836 } | 849 } |
| 837 | 850 |
| 838 } // namespace ash | 851 } // namespace ash |
| OLD | NEW |