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

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: impl. of review comments 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } 364 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i)
365 for (size_t i = 0; i < kReservedActionsLength; ++i) { 365 actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]);
366 for (size_t i = 0; i < kReservedActionsLength; ++i)
366 reserved_actions_.insert(kReservedActions[i]); 367 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
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
426 if (at_login_screen && 424 if (at_login_screen &&
427 actions_allowed_at_login_screen_.find(action) == 425 actions_allowed_at_login_screen_.find(action) ==
428 actions_allowed_at_login_screen_.end()) { 426 actions_allowed_at_login_screen_.end()) {
429 return false; 427 return false;
430 } 428 }
431 if (at_lock_screen && 429 if (shell->IsScreenLocked() &&
432 actions_allowed_at_lock_screen_.find(action) == 430 actions_allowed_at_lock_screen_.find(action) ==
433 actions_allowed_at_lock_screen_.end()) { 431 actions_allowed_at_lock_screen_.end()) {
434 return false; 432 return false;
435 } 433 }
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 }
436 const ui::KeyboardCode key_code = accelerator.key_code(); 443 const ui::KeyboardCode key_code = accelerator.key_code();
437 444
438 const ui::AcceleratorManagerContext& context = 445 const ui::AcceleratorManagerContext& context =
439 accelerator_manager_->GetContext(); 446 accelerator_manager_->GetContext();
440 const ui::EventType last_event_type = context.GetLastEventType(); 447 const ui::EventType last_event_type = context.GetLastEventType();
441 448
442 // You *MUST* return true when some action is performed. Otherwise, this 449 // You *MUST* return true when some action is performed. Otherwise, this
443 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent 450 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent
444 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. 451 // and BrowserView::HandleKeyboardEvent, for a single accelerator press.
445 switch (action) { 452 switch (action) {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 accelerators_.insert( 889 accelerators_.insert(
883 std::make_pair(accelerator, accelerators[i].action)); 890 std::make_pair(accelerator, accelerators[i].action));
884 } 891 }
885 } 892 }
886 893
887 bool AcceleratorController::CanHandleAccelerators() const { 894 bool AcceleratorController::CanHandleAccelerators() const {
888 return true; 895 return true;
889 } 896 }
890 897
891 } // namespace ash 898 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_controller.h ('k') | ash/accelerators/accelerator_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698