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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 AcceleratorController::~AcceleratorController() { | 352 AcceleratorController::~AcceleratorController() { |
353 } | 353 } |
354 | 354 |
355 void AcceleratorController::Init() { | 355 void AcceleratorController::Init() { |
356 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { | 356 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { |
357 actions_allowed_at_login_screen_.insert( | 357 actions_allowed_at_login_screen_.insert( |
358 kActionsAllowedAtLoginOrLockScreen[i]); | 358 kActionsAllowedAtLoginOrLockScreen[i]); |
359 actions_allowed_at_lock_screen_.insert( | 359 actions_allowed_at_lock_screen_.insert( |
360 kActionsAllowedAtLoginOrLockScreen[i]); | 360 kActionsAllowedAtLoginOrLockScreen[i]); |
361 } | 361 } |
362 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) | 362 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) { |
363 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); | 363 actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]); |
364 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) | 364 } |
365 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]); | 365 for (size_t i = 0; i < kReservedActionsLength; ++i) { |
366 for (size_t i = 0; i < kReservedActionsLength; ++i) | |
367 reserved_actions_.insert(kReservedActions[i]); | 366 reserved_actions_.insert(kReservedActions[i]); |
| 367 } |
368 | 368 |
369 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); | 369 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); |
370 | 370 |
371 if (DebugShortcutsEnabled()) | 371 if (DebugShortcutsEnabled()) |
372 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); | 372 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); |
373 } | 373 } |
374 | 374 |
375 void AcceleratorController::Register(const ui::Accelerator& accelerator, | 375 void AcceleratorController::Register(const ui::Accelerator& accelerator, |
376 ui::AcceleratorTarget* target) { | 376 ui::AcceleratorTarget* target) { |
377 accelerator_manager_->Register(accelerator, | 377 accelerator_manager_->Register(accelerator, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 return reserved_actions_.find(iter->second) != reserved_actions_.end(); | 414 return reserved_actions_.find(iter->second) != reserved_actions_.end(); |
415 } | 415 } |
416 | 416 |
417 bool AcceleratorController::PerformAction(int action, | 417 bool AcceleratorController::PerformAction(int action, |
418 const ui::Accelerator& accelerator) { | 418 const ui::Accelerator& accelerator) { |
419 ash::Shell* shell = ash::Shell::GetInstance(); | 419 ash::Shell* shell = ash::Shell::GetInstance(); |
420 bool at_login_screen = false; | 420 bool at_login_screen = false; |
421 #if defined(OS_CHROMEOS) | 421 #if defined(OS_CHROMEOS) |
422 at_login_screen = shell->delegate() && !shell->delegate()->IsSessionStarted(); | 422 at_login_screen = shell->delegate() && !shell->delegate()->IsSessionStarted(); |
423 #endif | 423 #endif |
| 424 bool at_lock_screen = shell->IsScreenLocked(); |
| 425 |
424 if (at_login_screen && | 426 if (at_login_screen && |
425 actions_allowed_at_login_screen_.find(action) == | 427 actions_allowed_at_login_screen_.find(action) == |
426 actions_allowed_at_login_screen_.end()) { | 428 actions_allowed_at_login_screen_.end()) { |
427 return false; | 429 return false; |
428 } | 430 } |
429 if (shell->IsScreenLocked() && | 431 if (at_lock_screen && |
430 actions_allowed_at_lock_screen_.find(action) == | 432 actions_allowed_at_lock_screen_.find(action) == |
431 actions_allowed_at_lock_screen_.end()) { | 433 actions_allowed_at_lock_screen_.end()) { |
432 return false; | 434 return false; |
433 } | 435 } |
434 if (shell->IsModalWindowOpen() && | |
435 actions_allowed_at_modal_window_.find(action) == | |
436 actions_allowed_at_modal_window_.end()) { | |
437 // Note: we return true. This indicates the shortcut is handled | |
438 // and will not be passed to the modal window. This is important | |
439 // for things like Alt+Tab that would cause an undesired effect | |
440 // in the modal window by cycling through its window elements. | |
441 return true; | |
442 } | |
443 const ui::KeyboardCode key_code = accelerator.key_code(); | 436 const ui::KeyboardCode key_code = accelerator.key_code(); |
444 | 437 |
445 const ui::AcceleratorManagerContext& context = | 438 const ui::AcceleratorManagerContext& context = |
446 accelerator_manager_->GetContext(); | 439 accelerator_manager_->GetContext(); |
447 const ui::EventType last_event_type = context.GetLastEventType(); | 440 const ui::EventType last_event_type = context.GetLastEventType(); |
448 | 441 |
449 // You *MUST* return true when some action is performed. Otherwise, this | 442 // You *MUST* return true when some action is performed. Otherwise, this |
450 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent | 443 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent |
451 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. | 444 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. |
452 switch (action) { | 445 switch (action) { |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 accelerators_.insert( | 884 accelerators_.insert( |
892 std::make_pair(accelerator, accelerators[i].action)); | 885 std::make_pair(accelerator, accelerators[i].action)); |
893 } | 886 } |
894 } | 887 } |
895 | 888 |
896 bool AcceleratorController::CanHandleAccelerators() const { | 889 bool AcceleratorController::CanHandleAccelerators() const { |
897 return true; | 890 return true; |
898 } | 891 } |
899 | 892 |
900 } // namespace ash | 893 } // namespace ash |
OLD | NEW |