OLD | NEW |
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/common/accelerators/accelerator_router.h" | 5 #include "ash/common/accelerators/accelerator_router.h" |
6 | 6 |
7 #include "ash/common/accelerators/accelerator_controller.h" | 7 #include "ash/common/accelerators/accelerator_controller.h" |
8 #include "ash/common/wm/window_state.h" | 8 #include "ash/common/wm/window_state.h" |
9 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
10 #include "ash/common/wm_window.h" | 10 #include "ash/common/wm_window.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 DCHECK(target); | 50 DCHECK(target); |
51 RecordSearchKeyStats(accelerator); | 51 RecordSearchKeyStats(accelerator); |
52 // Special hardware keys like brightness and volume are handled in | 52 // Special hardware keys like brightness and volume are handled in |
53 // special way. However, some windows can override this behavior | 53 // special way. However, some windows can override this behavior |
54 // (e.g. Chrome v1 apps by default and Chrome v2 apps with | 54 // (e.g. Chrome v1 apps by default and Chrome v2 apps with |
55 // permission) by setting a window property. | 55 // permission) by setting a window property. |
56 if (IsSystemKey(key_event.key_code()) && | 56 if (IsSystemKey(key_event.key_code()) && |
57 !CanConsumeSystemKeys(target, key_event)) { | 57 !CanConsumeSystemKeys(target, key_event)) { |
58 // System keys are always consumed regardless of whether they trigger an | 58 // System keys are always consumed regardless of whether they trigger an |
59 // accelerator to prevent windows from seeing unexpected key up events. | 59 // accelerator to prevent windows from seeing unexpected key up events. |
60 WmShell::Get()->accelerator_controller()->Process(accelerator); | 60 Shell::Get()->accelerator_controller()->Process(accelerator); |
61 return true; | 61 return true; |
62 } | 62 } |
63 if (!ShouldProcessAcceleratorNow(target, key_event, accelerator)) | 63 if (!ShouldProcessAcceleratorNow(target, key_event, accelerator)) |
64 return false; | 64 return false; |
65 return WmShell::Get()->accelerator_controller()->Process(accelerator); | 65 return Shell::Get()->accelerator_controller()->Process(accelerator); |
66 } | 66 } |
67 | 67 |
68 void AcceleratorRouter::RecordSearchKeyStats( | 68 void AcceleratorRouter::RecordSearchKeyStats( |
69 const ui::Accelerator& accelerator) { | 69 const ui::Accelerator& accelerator) { |
70 if (accelerator.IsCmdDown()) { | 70 if (accelerator.IsCmdDown()) { |
71 if (search_key_state_ == RELEASED) { | 71 if (search_key_state_ == RELEASED) { |
72 search_key_state_ = PRESSED; | 72 search_key_state_ = PRESSED; |
73 search_key_pressed_timestamp_ = base::TimeTicks::Now(); | 73 search_key_pressed_timestamp_ = base::TimeTicks::Now(); |
74 } | 74 } |
75 | 75 |
(...skipping 25 matching lines...) Expand all Loading... |
101 DCHECK(target); | 101 DCHECK(target); |
102 // On ChromeOS, If the accelerator is Search+<key(s)> then it must never be | 102 // On ChromeOS, If the accelerator is Search+<key(s)> then it must never be |
103 // intercepted by apps or windows. | 103 // intercepted by apps or windows. |
104 if (accelerator.IsCmdDown()) | 104 if (accelerator.IsCmdDown()) |
105 return true; | 105 return true; |
106 | 106 |
107 if (base::ContainsValue(WmShell::Get()->GetAllRootWindows(), target)) | 107 if (base::ContainsValue(WmShell::Get()->GetAllRootWindows(), target)) |
108 return true; | 108 return true; |
109 | 109 |
110 AcceleratorController* accelerator_controller = | 110 AcceleratorController* accelerator_controller = |
111 WmShell::Get()->accelerator_controller(); | 111 Shell::Get()->accelerator_controller(); |
112 | 112 |
113 // Reserved accelerators (such as Power button) always have a prority. | 113 // Reserved accelerators (such as Power button) always have a prority. |
114 if (accelerator_controller->IsReserved(accelerator)) | 114 if (accelerator_controller->IsReserved(accelerator)) |
115 return true; | 115 return true; |
116 | 116 |
117 // A full screen window has a right to handle all key events including the | 117 // A full screen window has a right to handle all key events including the |
118 // reserved ones. | 118 // reserved ones. |
119 WmWindow* top_level = target->GetToplevelWindowForFocus(); | 119 WmWindow* top_level = target->GetToplevelWindowForFocus(); |
120 if (top_level && top_level->GetWindowState()->IsFullscreen()) { | 120 if (top_level && top_level->GetWindowState()->IsFullscreen()) { |
121 // On ChromeOS, fullscreen windows are either browser or apps, which | 121 // On ChromeOS, fullscreen windows are either browser or apps, which |
122 // send key events to a web content first, then will process keys | 122 // send key events to a web content first, then will process keys |
123 // if the web content didn't consume them. | 123 // if the web content didn't consume them. |
124 return false; | 124 return false; |
125 } | 125 } |
126 | 126 |
127 // Handle preferred accelerators (such as ALT-TAB) before sending | 127 // Handle preferred accelerators (such as ALT-TAB) before sending |
128 // to the target. | 128 // to the target. |
129 if (accelerator_controller->IsPreferred(accelerator)) | 129 if (accelerator_controller->IsPreferred(accelerator)) |
130 return true; | 130 return true; |
131 | 131 |
132 return Shell::Get()->GetAppListTargetVisibility(); | 132 return Shell::Get()->GetAppListTargetVisibility(); |
133 } | 133 } |
134 | 134 |
135 } // namespace ash | 135 } // namespace ash |
OLD | NEW |