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

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

Issue 308193002: Simplify AcceleratorDelegate interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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/shell.h" 8 #include "ash/shell.h"
9 #include "ash/wm/window_state.h" 9 #include "ash/wm/window_state.h"
10 #include "ui/base/accelerators/accelerator.h" 10 #include "ui/base/accelerators/accelerator.h"
11 #include "ui/events/event.h" 11 #include "ui/events/event.h"
12 #include "ui/wm/core/window_util.h" 12 #include "ui/wm/core/window_util.h"
13 13
14 namespace ash { 14 namespace ash {
15 namespace {} // namespace 15 namespace {} // namespace
16 16
17 AcceleratorDelegate::AcceleratorDelegate() { 17 AcceleratorDelegate::AcceleratorDelegate() {
18 } 18 }
19 AcceleratorDelegate::~AcceleratorDelegate() { 19 AcceleratorDelegate::~AcceleratorDelegate() {
20 } 20 }
21 21
22 void AcceleratorDelegate::PreProcessAccelerator( 22 void AcceleratorDelegate::PreProcessAccelerator(
23 const ui::Accelerator& accelerator) { 23 const ui::Accelerator& accelerator) {
24 // Fill out context object so AcceleratorController will know what 24 // Fill out context object so AcceleratorController will know what
25 // was the previous accelerator or if the current accelerator is repeated. 25 // was the previous accelerator or if the current accelerator is repeated.
26 Shell::GetInstance()->accelerator_controller()->context()->UpdateContext( 26 Shell::GetInstance()->accelerator_controller()->context()->UpdateContext(
27 accelerator); 27 accelerator);
28 } 28 }
29 29
30 bool AcceleratorDelegate::ProcessAccelerator(const ui::KeyEvent& key_event,
31 const ui::Accelerator& accelerator,
32 KeyType key_type) {
33 // Special hardware keys like brightness and volume are handled in
34 // special way. However, some windows can override this behavior
35 // (e.g. Chrome v1 apps by default and Chrome v2 apps with
36 // permission) by setting a window property.
37 if (key_type == SYSTEM_KEYS && !CanConsumeSystemKeys(key_event)) {
38 // System keys are always consumed regardless of whether they trigger an
39 // accelerator to prevent windows from seeing unexpected key up events.
40 Shell::GetInstance()->accelerator_controller()->Process(accelerator);
41 return true;
42 }
43 if (key_type == NORMAL_KEYS &&
44 !ShouldProcessAcceleratorNow(key_event, accelerator)) {
45 return false;
46 }
47 return Shell::GetInstance()->accelerator_controller()->Process(accelerator);
48 }
49
30 // Uses the top level window so if the target is a web contents window the 50 // Uses the top level window so if the target is a web contents window the
31 // containing parent window will be checked for the property. 51 // containing parent window will be checked for the property.
32 bool AcceleratorDelegate::CanConsumeSystemKeys(const ui::KeyEvent& event) { 52 bool AcceleratorDelegate::CanConsumeSystemKeys(const ui::KeyEvent& event) {
33 aura::Window* target = static_cast<aura::Window*>(event.target()); 53 aura::Window* target = static_cast<aura::Window*>(event.target());
34 if (!target) // Can be NULL in tests. 54 DCHECK(target);
35 return false;
36 aura::Window* top_level = ::wm::GetToplevelWindow(target); 55 aura::Window* top_level = ::wm::GetToplevelWindow(target);
37 return top_level && wm::GetWindowState(top_level)->can_consume_system_keys(); 56 return top_level && wm::GetWindowState(top_level)->can_consume_system_keys();
38 } 57 }
39 58
40 // Returns true if the |accelerator| should be processed now, inside Ash's env 59 // Returns true if the |accelerator| should be processed now, inside Ash's env
41 // event filter. 60 // event filter.
42 bool AcceleratorDelegate::ShouldProcessAcceleratorNow( 61 bool AcceleratorDelegate::ShouldProcessAcceleratorNow(
43 const ui::KeyEvent& event, 62 const ui::KeyEvent& event,
44 const ui::Accelerator& accelerator) { 63 const ui::Accelerator& accelerator) {
45 aura::Window* target = static_cast<aura::Window*>(event.target()); 64 aura::Window* target = static_cast<aura::Window*>(event.target());
46 if (!target) 65 DCHECK(target);
47 return true;
48
49 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 66 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
50 if (std::find(root_windows.begin(), root_windows.end(), target) != 67 if (std::find(root_windows.begin(), root_windows.end(), target) !=
51 root_windows.end()) 68 root_windows.end())
52 return true; 69 return true;
53 70
54 // A full screen window should be able to handle all key events including the 71 // A full screen window should be able to handle all key events including the
55 // reserved ones. 72 // reserved ones.
56 if (wm::GetWindowState(target)->IsFullscreen()) { 73 aura::Window* top_level = ::wm::GetToplevelWindow(target);
74
75 if (top_level && wm::GetWindowState(top_level)->IsFullscreen()) {
57 // TODO(yusukes): On Chrome OS, only browser and flash windows can be full 76 // TODO(yusukes): On Chrome OS, only browser and flash windows can be full
58 // screen. Launching an app in "open full-screen" mode is not supported yet. 77 // screen. Launching an app in "open full-screen" mode is not supported yet.
59 // That makes the IsWindowFullscreen() check above almost meaningless 78 // That makes the IsWindowFullscreen() check above almost meaningless
60 // because a browser and flash window do handle Ash accelerators anyway 79 // because a browser and flash window do handle Ash accelerators anyway
61 // before they're passed to a page or flash content. 80 // before they're passed to a page or flash content.
62 return false; 81 return false;
63 } 82 }
64 83
65 if (Shell::GetInstance()->GetAppListTargetVisibility()) 84 if (Shell::GetInstance()->GetAppListTargetVisibility())
66 return true; 85 return true;
67 86
68 // Unless |target| is in the full screen state, handle reserved accelerators 87 // Unless |target| is in the full screen state, handle reserved accelerators
69 // such as Alt+Tab now. 88 // such as Alt+Tab now.
70 return Shell::GetInstance()->accelerator_controller()->IsReservedAccelerator( 89 return Shell::GetInstance()->accelerator_controller()->IsReservedAccelerator(
71 accelerator); 90 accelerator);
72 } 91 }
73 92
74 bool AcceleratorDelegate::ProcessAccelerator(
75 const ui::Accelerator& accelerator) {
76 return Shell::GetInstance()->accelerator_controller()->Process(accelerator);
77 }
78
79 } // namespace ash 93 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698