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

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: fixed condition 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
« 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/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 == KEY_TYPE_SYSTEM && !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 (!ShouldProcessAcceleratorNow(key_event, accelerator))
oshima 2014/05/30 23:50:28 FYI: The rest of code has to be run for both OTHER
44 return false;
45 return Shell::GetInstance()->accelerator_controller()->Process(accelerator);
46 }
47
30 // Uses the top level window so if the target is a web contents window the 48 // 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. 49 // containing parent window will be checked for the property.
32 bool AcceleratorDelegate::CanConsumeSystemKeys(const ui::KeyEvent& event) { 50 bool AcceleratorDelegate::CanConsumeSystemKeys(const ui::KeyEvent& event) {
33 aura::Window* target = static_cast<aura::Window*>(event.target()); 51 aura::Window* target = static_cast<aura::Window*>(event.target());
34 if (!target) // Can be NULL in tests. 52 if (!target) // Can be NULL in tests.
35 return false; 53 return false;
oshima 2014/05/30 23:50:28 And this was still necessary for test. I'll try to
36 aura::Window* top_level = ::wm::GetToplevelWindow(target); 54 aura::Window* top_level = ::wm::GetToplevelWindow(target);
37 return top_level && wm::GetWindowState(top_level)->can_consume_system_keys(); 55 return top_level && wm::GetWindowState(top_level)->can_consume_system_keys();
38 } 56 }
39 57
40 // Returns true if the |accelerator| should be processed now, inside Ash's env 58 // Returns true if the |accelerator| should be processed now, inside Ash's env
41 // event filter. 59 // event filter.
42 bool AcceleratorDelegate::ShouldProcessAcceleratorNow( 60 bool AcceleratorDelegate::ShouldProcessAcceleratorNow(
43 const ui::KeyEvent& event, 61 const ui::KeyEvent& event,
44 const ui::Accelerator& accelerator) { 62 const ui::Accelerator& accelerator) {
45 aura::Window* target = static_cast<aura::Window*>(event.target()); 63 aura::Window* target = static_cast<aura::Window*>(event.target());
46 if (!target) 64 if (!target)
47 return true; 65 return true;
48 66
49 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 67 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
50 if (std::find(root_windows.begin(), root_windows.end(), target) != 68 if (std::find(root_windows.begin(), root_windows.end(), target) !=
51 root_windows.end()) 69 root_windows.end())
52 return true; 70 return true;
53 71
54 // A full screen window should be able to handle all key events including the 72 // A full screen window should be able to handle all key events including the
55 // reserved ones. 73 // reserved ones.
56 if (wm::GetWindowState(target)->IsFullscreen()) { 74 aura::Window* top_level = ::wm::GetToplevelWindow(target);
75
76 if (top_level && wm::GetWindowState(top_level)->IsFullscreen()) {
57 // TODO(yusukes): On Chrome OS, only browser and flash windows can be full 77 // 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. 78 // screen. Launching an app in "open full-screen" mode is not supported yet.
59 // That makes the IsWindowFullscreen() check above almost meaningless 79 // That makes the IsWindowFullscreen() check above almost meaningless
60 // because a browser and flash window do handle Ash accelerators anyway 80 // because a browser and flash window do handle Ash accelerators anyway
61 // before they're passed to a page or flash content. 81 // before they're passed to a page or flash content.
62 return false; 82 return false;
63 } 83 }
64 84
65 if (Shell::GetInstance()->GetAppListTargetVisibility()) 85 if (Shell::GetInstance()->GetAppListTargetVisibility())
66 return true; 86 return true;
67 87
68 // Unless |target| is in the full screen state, handle reserved accelerators 88 // Unless |target| is in the full screen state, handle reserved accelerators
69 // such as Alt+Tab now. 89 // such as Alt+Tab now.
70 return Shell::GetInstance()->accelerator_controller()->IsReservedAccelerator( 90 return Shell::GetInstance()->accelerator_controller()->IsReservedAccelerator(
71 accelerator); 91 accelerator);
72 } 92 }
73 93
74 bool AcceleratorDelegate::ProcessAccelerator(
75 const ui::Accelerator& accelerator) {
76 return Shell::GetInstance()->accelerator_controller()->Process(accelerator);
77 }
78
79 } // namespace ash 94 } // 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