Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: ash/accelerators/accelerator_controller.cc

Issue 10977088: Fix for Ash shortcuts unexpectedly working in system model dialog (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: adding unit tests Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } 364 }
365 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) {
Daniel Erat 2012/10/16 03:03:50 nit: not your fault, but i won't object if you wan
sschmitz 2012/10/16 18:18:23 Done.
366 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]);
367 }
365 for (size_t i = 0; i < kReservedActionsLength; ++i) { 368 for (size_t i = 0; i < kReservedActionsLength; ++i) {
366 reserved_actions_.insert(kReservedActions[i]); 369 reserved_actions_.insert(kReservedActions[i]);
367 } 370 }
368 371
369 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); 372 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength);
370 373
371 if (DebugShortcutsEnabled()) 374 if (DebugShortcutsEnabled())
372 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); 375 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength);
373 } 376 }
374 377
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 418 }
416 419
417 bool AcceleratorController::PerformAction(int action, 420 bool AcceleratorController::PerformAction(int action,
418 const ui::Accelerator& accelerator) { 421 const ui::Accelerator& accelerator) {
419 ash::Shell* shell = ash::Shell::GetInstance(); 422 ash::Shell* shell = ash::Shell::GetInstance();
420 bool at_login_screen = false; 423 bool at_login_screen = false;
421 #if defined(OS_CHROMEOS) 424 #if defined(OS_CHROMEOS)
422 at_login_screen = shell->delegate() && !shell->delegate()->IsSessionStarted(); 425 at_login_screen = shell->delegate() && !shell->delegate()->IsSessionStarted();
423 #endif 426 #endif
424 bool at_lock_screen = shell->IsScreenLocked(); 427 bool at_lock_screen = shell->IsScreenLocked();
428 bool at_modal_window = shell->IsModalWindowOpen();
Daniel Erat 2012/10/16 03:03:50 nit: i don't think that there's any reason to crea
sschmitz 2012/10/16 18:18:23 Done.
425 429
426 if (at_login_screen && 430 if (at_login_screen &&
427 actions_allowed_at_login_screen_.find(action) == 431 actions_allowed_at_login_screen_.find(action) ==
428 actions_allowed_at_login_screen_.end()) { 432 actions_allowed_at_login_screen_.end()) {
429 return false; 433 return false;
430 } 434 }
431 if (at_lock_screen && 435 if (at_lock_screen &&
432 actions_allowed_at_lock_screen_.find(action) == 436 actions_allowed_at_lock_screen_.find(action) ==
433 actions_allowed_at_lock_screen_.end()) { 437 actions_allowed_at_lock_screen_.end()) {
434 return false; 438 return false;
435 } 439 }
440 if (at_modal_window &&
441 actions_allowed_at_modal_window_.find(action) ==
442 actions_allowed_at_modal_window_.end()) {
443 // Note: we return true. This indicates the shortcut is handled
444 // and will not be passed to the modal window. This is important
445 // for things like Alt+Tab that would cause an undesired effect
446 // in the modal window by cycling through its window elements.
447 return true;
448 }
436 const ui::KeyboardCode key_code = accelerator.key_code(); 449 const ui::KeyboardCode key_code = accelerator.key_code();
437 450
438 const ui::AcceleratorManagerContext& context = 451 const ui::AcceleratorManagerContext& context =
439 accelerator_manager_->GetContext(); 452 accelerator_manager_->GetContext();
440 const ui::EventType last_event_type = context.GetLastEventType(); 453 const ui::EventType last_event_type = context.GetLastEventType();
441 454
442 // You *MUST* return true when some action is performed. Otherwise, this 455 // You *MUST* return true when some action is performed. Otherwise, this
443 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent 456 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent
444 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. 457 // and BrowserView::HandleKeyboardEvent, for a single accelerator press.
445 switch (action) { 458 switch (action) {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 accelerators_.insert( 895 accelerators_.insert(
883 std::make_pair(accelerator, accelerators[i].action)); 896 std::make_pair(accelerator, accelerators[i].action));
884 } 897 }
885 } 898 }
886 899
887 bool AcceleratorController::CanHandleAccelerators() const { 900 bool AcceleratorController::CanHandleAccelerators() const {
888 return true; 901 return true;
889 } 902 }
890 903
891 } // namespace ash 904 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698