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

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

Issue 2170753005: Moves AcceleratorController from Shell to WmShell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include 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
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/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/shell.h" 10 #include "ash/shell.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 bool AcceleratorDelegate::ProcessAccelerator( 47 bool AcceleratorDelegate::ProcessAccelerator(
48 const ui::KeyEvent& key_event, 48 const ui::KeyEvent& key_event,
49 const ui::Accelerator& accelerator) { 49 const ui::Accelerator& accelerator) {
50 // Special hardware keys like brightness and volume are handled in 50 // Special hardware keys like brightness and volume are handled in
51 // special way. However, some windows can override this behavior 51 // special way. However, some windows can override this behavior
52 // (e.g. Chrome v1 apps by default and Chrome v2 apps with 52 // (e.g. Chrome v1 apps by default and Chrome v2 apps with
53 // permission) by setting a window property. 53 // permission) by setting a window property.
54 if (IsSystemKey(key_event.key_code()) && !CanConsumeSystemKeys(key_event)) { 54 if (IsSystemKey(key_event.key_code()) && !CanConsumeSystemKeys(key_event)) {
55 // System keys are always consumed regardless of whether they trigger an 55 // System keys are always consumed regardless of whether they trigger an
56 // accelerator to prevent windows from seeing unexpected key up events. 56 // accelerator to prevent windows from seeing unexpected key up events.
57 Shell::GetInstance()->accelerator_controller()->Process(accelerator); 57 WmShell::Get()->accelerator_controller()->Process(accelerator);
58 return true; 58 return true;
59 } 59 }
60 if (!ShouldProcessAcceleratorNow(key_event, accelerator)) 60 if (!ShouldProcessAcceleratorNow(key_event, accelerator))
61 return false; 61 return false;
62 return Shell::GetInstance()->accelerator_controller()->Process(accelerator); 62 return WmShell::Get()->accelerator_controller()->Process(accelerator);
63 } 63 }
64 64
65 // Uses the top level window so if the target is a web contents window the 65 // Uses the top level window so if the target is a web contents window the
66 // containing parent window will be checked for the property. 66 // containing parent window will be checked for the property.
67 bool AcceleratorDelegate::CanConsumeSystemKeys(const ui::KeyEvent& event) { 67 bool AcceleratorDelegate::CanConsumeSystemKeys(const ui::KeyEvent& event) {
68 aura::Window* target = static_cast<aura::Window*>(event.target()); 68 aura::Window* target = static_cast<aura::Window*>(event.target());
69 DCHECK(target); 69 DCHECK(target);
70 aura::Window* top_level = ::wm::GetToplevelWindow(target); 70 aura::Window* top_level = ::wm::GetToplevelWindow(target);
71 return top_level && wm::GetWindowState(top_level)->can_consume_system_keys(); 71 return top_level && wm::GetWindowState(top_level)->can_consume_system_keys();
72 } 72 }
(...skipping 10 matching lines...) Expand all
83 83
84 aura::Window* target = static_cast<aura::Window*>(event.target()); 84 aura::Window* target = static_cast<aura::Window*>(event.target());
85 DCHECK(target); 85 DCHECK(target);
86 86
87 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 87 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
88 if (std::find(root_windows.begin(), root_windows.end(), target) != 88 if (std::find(root_windows.begin(), root_windows.end(), target) !=
89 root_windows.end()) 89 root_windows.end())
90 return true; 90 return true;
91 91
92 aura::Window* top_level = ::wm::GetToplevelWindow(target); 92 aura::Window* top_level = ::wm::GetToplevelWindow(target);
93 Shell* shell = Shell::GetInstance(); 93 AcceleratorController* accelerator_controller =
94 WmShell::Get()->accelerator_controller();
94 95
95 // Reserved accelerators (such as Power button) always have a prority. 96 // Reserved accelerators (such as Power button) always have a prority.
96 if (shell->accelerator_controller()->IsReserved(accelerator)) 97 if (accelerator_controller->IsReserved(accelerator))
97 return true; 98 return true;
98 99
99 // A full screen window has a right to handle all key events including the 100 // A full screen window has a right to handle all key events including the
100 // reserved ones. 101 // reserved ones.
101 if (top_level && wm::GetWindowState(top_level)->IsFullscreen()) { 102 if (top_level && wm::GetWindowState(top_level)->IsFullscreen()) {
102 // On ChromeOS, fullscreen windows are either browser or apps, which 103 // On ChromeOS, fullscreen windows are either browser or apps, which
103 // send key events to a web content first, then will process keys 104 // send key events to a web content first, then will process keys
104 // if the web content didn't consume them. 105 // if the web content didn't consume them.
105 return false; 106 return false;
106 } 107 }
107 108
108 // Handle preferred accelerators (such as ALT-TAB) before sending 109 // Handle preferred accelerators (such as ALT-TAB) before sending
109 // to the target. 110 // to the target.
110 if (shell->accelerator_controller()->IsPreferred(accelerator)) 111 if (accelerator_controller->IsPreferred(accelerator))
111 return true; 112 return true;
112 113
113 return WmShell::Get()->GetAppListTargetVisibility(); 114 return WmShell::Get()->GetAppListTargetVisibility();
114 } 115 }
115 116
116 } // namespace ash 117 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_controller_unittest.cc ('k') | ash/accelerators/focus_manager_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698