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

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

Issue 2147013003: Mark POWER key as system key so that it won't be passed to regular apps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl format Created 4 years, 5 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
« no previous file with comments | « ash/accelerators/accelerator_delegate.h ('k') | ui/wm/core/accelerator_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_delegate.h" 5 #include "ash/accelerators/accelerator_delegate.h"
6 6
7 #include "ash/accelerators/accelerator_controller.h" 7 #include "ash/accelerators/accelerator_controller.h"
8 #include "ash/common/wm/window_state.h" 8 #include "ash/common/wm/window_state.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/window_state_aura.h" 10 #include "ash/wm/window_state_aura.h"
11 #include "ui/base/accelerators/accelerator.h" 11 #include "ui/base/accelerators/accelerator.h"
12 #include "ui/events/event.h" 12 #include "ui/events/event.h"
13 #include "ui/wm/core/window_util.h" 13 #include "ui/wm/core/window_util.h"
14 14
15 namespace ash { 15 namespace ash {
16 16
17 namespace {
18
19 // Returns true if |key_code| is a key usually handled directly by the shell.
20 bool IsSystemKey(ui::KeyboardCode key_code) {
21 #if defined(OS_CHROMEOS)
22 switch (key_code) {
23 case ui::VKEY_MEDIA_LAUNCH_APP2: // Fullscreen button.
24 case ui::VKEY_MEDIA_LAUNCH_APP1: // Overview button.
25 case ui::VKEY_BRIGHTNESS_DOWN:
26 case ui::VKEY_BRIGHTNESS_UP:
27 case ui::VKEY_KBD_BRIGHTNESS_DOWN:
28 case ui::VKEY_KBD_BRIGHTNESS_UP:
29 case ui::VKEY_VOLUME_MUTE:
30 case ui::VKEY_VOLUME_DOWN:
31 case ui::VKEY_VOLUME_UP:
32 case ui::VKEY_POWER:
33 return true;
34 default:
35 return false;
36 }
37 #endif // defined(OS_CHROMEOS)
38 return false;
39 }
40
41 } // namespace
42
17 AcceleratorDelegate::AcceleratorDelegate() {} 43 AcceleratorDelegate::AcceleratorDelegate() {}
18 AcceleratorDelegate::~AcceleratorDelegate() {} 44 AcceleratorDelegate::~AcceleratorDelegate() {}
19 45
20 bool AcceleratorDelegate::ProcessAccelerator(const ui::KeyEvent& key_event, 46 bool AcceleratorDelegate::ProcessAccelerator(
21 const ui::Accelerator& accelerator, 47 const ui::KeyEvent& key_event,
22 KeyType key_type) { 48 const ui::Accelerator& accelerator) {
23 // Special hardware keys like brightness and volume are handled in 49 // Special hardware keys like brightness and volume are handled in
24 // special way. However, some windows can override this behavior 50 // special way. However, some windows can override this behavior
25 // (e.g. Chrome v1 apps by default and Chrome v2 apps with 51 // (e.g. Chrome v1 apps by default and Chrome v2 apps with
26 // permission) by setting a window property. 52 // permission) by setting a window property.
27 if (key_type == KEY_TYPE_SYSTEM && !CanConsumeSystemKeys(key_event)) { 53 if (IsSystemKey(key_event.key_code()) && !CanConsumeSystemKeys(key_event)) {
28 // System keys are always consumed regardless of whether they trigger an 54 // System keys are always consumed regardless of whether they trigger an
29 // accelerator to prevent windows from seeing unexpected key up events. 55 // accelerator to prevent windows from seeing unexpected key up events.
30 Shell::GetInstance()->accelerator_controller()->Process(accelerator); 56 Shell::GetInstance()->accelerator_controller()->Process(accelerator);
31 return true; 57 return true;
32 } 58 }
33 if (!ShouldProcessAcceleratorNow(key_event, accelerator)) 59 if (!ShouldProcessAcceleratorNow(key_event, accelerator))
34 return false; 60 return false;
35 return Shell::GetInstance()->accelerator_controller()->Process(accelerator); 61 return Shell::GetInstance()->accelerator_controller()->Process(accelerator);
36 } 62 }
37 63
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 106
81 // Handle preferred accelerators (such as ALT-TAB) before sending 107 // Handle preferred accelerators (such as ALT-TAB) before sending
82 // to the target. 108 // to the target.
83 if (shell->accelerator_controller()->IsPreferred(accelerator)) 109 if (shell->accelerator_controller()->IsPreferred(accelerator))
84 return true; 110 return true;
85 111
86 return shell->GetAppListTargetVisibility(); 112 return shell->GetAppListTargetVisibility();
87 } 113 }
88 114
89 } // namespace ash 115 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_delegate.h ('k') | ui/wm/core/accelerator_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698