| 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/accelerators/accelerator_router.h" | 5 #include "ash/accelerators/accelerator_router.h" |
| 6 | 6 |
| 7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_port.h" | 9 #include "ash/shell_port.h" |
| 10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
| 11 #include "ash/wm_window.h" | |
| 12 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "ui/aura/window.h" |
| 14 #include "ui/base/accelerators/accelerator.h" | 14 #include "ui/base/accelerators/accelerator.h" |
| 15 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 16 #include "ui/wm/core/window_util.h" |
| 16 | 17 |
| 17 namespace ash { | 18 namespace ash { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Returns true if |key_code| is a key usually handled directly by the shell. | 22 // Returns true if |key_code| is a key usually handled directly by the shell. |
| 22 bool IsSystemKey(ui::KeyboardCode key_code) { | 23 bool IsSystemKey(ui::KeyboardCode key_code) { |
| 23 switch (key_code) { | 24 switch (key_code) { |
| 24 case ui::VKEY_MEDIA_LAUNCH_APP2: // Fullscreen button. | 25 case ui::VKEY_MEDIA_LAUNCH_APP2: // Fullscreen button. |
| 25 case ui::VKEY_MEDIA_LAUNCH_APP1: // Overview button. | 26 case ui::VKEY_MEDIA_LAUNCH_APP1: // Overview button. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 return false; | 37 return false; |
| 37 } | 38 } |
| 38 } | 39 } |
| 39 | 40 |
| 40 } // namespace | 41 } // namespace |
| 41 | 42 |
| 42 AcceleratorRouter::AcceleratorRouter() {} | 43 AcceleratorRouter::AcceleratorRouter() {} |
| 43 | 44 |
| 44 AcceleratorRouter::~AcceleratorRouter() {} | 45 AcceleratorRouter::~AcceleratorRouter() {} |
| 45 | 46 |
| 46 bool AcceleratorRouter::ProcessAccelerator(WmWindow* target, | 47 bool AcceleratorRouter::ProcessAccelerator(aura::Window* target, |
| 47 const ui::KeyEvent& key_event, | 48 const ui::KeyEvent& key_event, |
| 48 const ui::Accelerator& accelerator) { | 49 const ui::Accelerator& accelerator) { |
| 49 // Callers should never supply null. | 50 // Callers should never supply null. |
| 50 DCHECK(target); | 51 DCHECK(target); |
| 51 RecordSearchKeyStats(accelerator); | 52 RecordSearchKeyStats(accelerator); |
| 52 // Special hardware keys like brightness and volume are handled in | 53 // Special hardware keys like brightness and volume are handled in |
| 53 // special way. However, some windows can override this behavior | 54 // special way. However, some windows can override this behavior |
| 54 // (e.g. Chrome v1 apps by default and Chrome v2 apps with | 55 // (e.g. Chrome v1 apps by default and Chrome v2 apps with |
| 55 // permission) by setting a window property. | 56 // permission) by setting a window property. |
| 56 if (IsSystemKey(key_event.key_code()) && | 57 if (IsSystemKey(key_event.key_code()) && |
| (...skipping 21 matching lines...) Expand all Loading... |
| 78 search_key_state_ = RECORDED; | 79 search_key_state_ = RECORDED; |
| 79 UMA_HISTOGRAM_TIMES( | 80 UMA_HISTOGRAM_TIMES( |
| 80 "Keyboard.Shortcuts.CrosSearchKeyDelay", | 81 "Keyboard.Shortcuts.CrosSearchKeyDelay", |
| 81 base::TimeTicks::Now() - search_key_pressed_timestamp_); | 82 base::TimeTicks::Now() - search_key_pressed_timestamp_); |
| 82 } | 83 } |
| 83 } else { | 84 } else { |
| 84 search_key_state_ = RELEASED; | 85 search_key_state_ = RELEASED; |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 bool AcceleratorRouter::CanConsumeSystemKeys(WmWindow* target, | 89 bool AcceleratorRouter::CanConsumeSystemKeys(aura::Window* target, |
| 89 const ui::KeyEvent& event) { | 90 const ui::KeyEvent& event) { |
| 90 // Uses the top level window so if the target is a web contents window the | 91 // Uses the top level window so if the target is a web contents window the |
| 91 // containing parent window will be checked for the property. | 92 // containing parent window will be checked for the property. |
| 92 WmWindow* top_level = target->GetToplevelWindowForFocus(); | 93 aura::Window* top_level = ::wm::GetToplevelWindow(target); |
| 93 return top_level && top_level->GetWindowState()->can_consume_system_keys(); | 94 return top_level && wm::GetWindowState(top_level)->can_consume_system_keys(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 bool AcceleratorRouter::ShouldProcessAcceleratorNow( | 97 bool AcceleratorRouter::ShouldProcessAcceleratorNow( |
| 97 WmWindow* target, | 98 aura::Window* target, |
| 98 const ui::KeyEvent& event, | 99 const ui::KeyEvent& event, |
| 99 const ui::Accelerator& accelerator) { | 100 const ui::Accelerator& accelerator) { |
| 100 // Callers should never supply null. | 101 // Callers should never supply null. |
| 101 DCHECK(target); | 102 DCHECK(target); |
| 102 // On ChromeOS, If the accelerator is Search+<key(s)> then it must never be | 103 // On ChromeOS, If the accelerator is Search+<key(s)> then it must never be |
| 103 // intercepted by apps or windows. | 104 // intercepted by apps or windows. |
| 104 if (accelerator.IsCmdDown()) | 105 if (accelerator.IsCmdDown()) |
| 105 return true; | 106 return true; |
| 106 | 107 |
| 107 if (base::ContainsValue(ShellPort::Get()->GetAllRootWindows(), target)) | 108 if (base::ContainsValue(Shell::GetAllRootWindows(), target)) |
| 108 return true; | 109 return true; |
| 109 | 110 |
| 110 AcceleratorController* accelerator_controller = | 111 AcceleratorController* accelerator_controller = |
| 111 Shell::Get()->accelerator_controller(); | 112 Shell::Get()->accelerator_controller(); |
| 112 | 113 |
| 113 // Reserved accelerators (such as Power button) always have a prority. | 114 // Reserved accelerators (such as Power button) always have a prority. |
| 114 if (accelerator_controller->IsReserved(accelerator)) | 115 if (accelerator_controller->IsReserved(accelerator)) |
| 115 return true; | 116 return true; |
| 116 | 117 |
| 117 // A full screen window has a right to handle all key events including the | 118 // A full screen window has a right to handle all key events including the |
| 118 // reserved ones. | 119 // reserved ones. |
| 119 WmWindow* top_level = target->GetToplevelWindowForFocus(); | 120 aura::Window* top_level = ::wm::GetToplevelWindow(target); |
| 120 if (top_level && top_level->GetWindowState()->IsFullscreen()) { | 121 if (top_level && wm::GetWindowState(top_level)->IsFullscreen()) { |
| 121 // On ChromeOS, fullscreen windows are either browser or apps, which | 122 // On ChromeOS, fullscreen windows are either browser or apps, which |
| 122 // send key events to a web content first, then will process keys | 123 // send key events to a web content first, then will process keys |
| 123 // if the web content didn't consume them. | 124 // if the web content didn't consume them. |
| 124 return false; | 125 return false; |
| 125 } | 126 } |
| 126 | 127 |
| 127 // Handle preferred accelerators (such as ALT-TAB) before sending | 128 // Handle preferred accelerators (such as ALT-TAB) before sending |
| 128 // to the target. | 129 // to the target. |
| 129 if (accelerator_controller->IsPreferred(accelerator)) | 130 if (accelerator_controller->IsPreferred(accelerator)) |
| 130 return true; | 131 return true; |
| 131 | 132 |
| 132 return Shell::Get()->GetAppListTargetVisibility(); | 133 return Shell::Get()->GetAppListTargetVisibility(); |
| 133 } | 134 } |
| 134 | 135 |
| 135 } // namespace ash | 136 } // namespace ash |
| OLD | NEW |