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

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

Issue 307533007: Move common accelerator code from ash to ui/wm/core (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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/accelerators/accelerator_delegate.h"
6
7 #include "ash/accelerators/accelerator_controller.h"
8 #include "ash/shell.h"
9 #include "ash/wm/window_state.h"
10 #include "ui/base/accelerators/accelerator.h"
11 #include "ui/events/event.h"
12 #include "ui/wm/core/window_util.h"
13
14 namespace ash {
15 namespace {} // namespace
16
17 AcceleratorDelegate::AcceleratorDelegate() {
18 }
19 AcceleratorDelegate::~AcceleratorDelegate() {
20 }
21
22 void AcceleratorDelegate::PreProcessAccelerator(
23 const ui::Accelerator& accelerator) {
24 // Fill out context object so AcceleratorController will know what
25 // was the previous accelerator or if the current accelerator is repeated.
26 Shell::GetInstance()->accelerator_controller()->context()->UpdateContext(
27 accelerator);
28 }
29
30 // 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.
32 bool AcceleratorDelegate::CanConsumeSystemKeys(const ui::KeyEvent& event) {
33 aura::Window* target = static_cast<aura::Window*>(event.target());
34 if (!target) // Can be NULL in tests.
35 return false;
36 aura::Window* top_level = ::wm::GetToplevelWindow(target);
37 return top_level && wm::GetWindowState(top_level)->can_consume_system_keys();
38 }
39
40 // Returns true if the |accelerator| should be processed now, inside Ash's env
41 // event filter.
42 bool AcceleratorDelegate::ShouldProcessAcceleratorNow(
43 const ui::KeyEvent& event,
44 const ui::Accelerator& accelerator) {
45 aura::Window* target = static_cast<aura::Window*>(event.target());
46 if (!target)
47 return true;
48
49 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
50 if (std::find(root_windows.begin(), root_windows.end(), target) !=
51 root_windows.end())
52 return true;
53
54 // A full screen window should be able to handle all key events including the
55 // reserved ones.
56 if (wm::GetWindowState(target)->IsFullscreen()) {
57 // 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.
59 // That makes the IsWindowFullscreen() check above almost meaningless
60 // because a browser and flash window do handle Ash accelerators anyway
61 // before they're passed to a page or flash content.
62 return false;
63 }
64
65 if (Shell::GetInstance()->GetAppListTargetVisibility())
66 return true;
67
68 // Unless |target| is in the full screen state, handle reserved accelerators
69 // such as Alt+Tab now.
70 return Shell::GetInstance()->accelerator_controller()->IsReservedAccelerator(
71 accelerator);
72 }
73
74 bool AcceleratorDelegate::ProcessAccelerator(
75 const ui::Accelerator& accelerator) {
76 return Shell::GetInstance()->accelerator_controller()->Process(accelerator);
77 }
78
79 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698