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

Side by Side Diff: ash/wm/window_cycle_controller.cc

Issue 260883005: Separated alt-tab window cycle from overview mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
(Empty)
1 // Copyright (c) 2012 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/wm/window_cycle_controller.h"
6
7 #include <algorithm>
8
9 #include "ash/session/session_state_delegate.h"
10 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h"
12 #include "ash/wm/mru_window_tracker.h"
13 #include "ash/wm/window_cycle_list.h"
14 #include "ash/wm/window_util.h"
15 #include "ash/wm/workspace_controller.h"
16 #include "ui/events/event.h"
17 #include "ui/events/event_handler.h"
18
19 namespace ash {
20
21 namespace {
22
23 // Filter to watch for the termination of a keyboard gesture to cycle through
24 // multiple windows.
25 class WindowCycleEventFilter : public ui::EventHandler {
26 public:
27 WindowCycleEventFilter();
28 virtual ~WindowCycleEventFilter();
29
30 // Overridden from ui::EventHandler:
31 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
tdanderson 2014/05/01 18:51:39 newline after 31
Nina 2014/05/01 20:41:16 Done.
32 private:
33 DISALLOW_COPY_AND_ASSIGN(WindowCycleEventFilter);
34 };
35
36 // Watch for all keyboard events by filtering the root window.
37 WindowCycleEventFilter::WindowCycleEventFilter() {
38 }
39
40 WindowCycleEventFilter::~WindowCycleEventFilter() {
41 }
42
43 void WindowCycleEventFilter::OnKeyEvent(ui::KeyEvent* event) {
44 // Views uses VKEY_MENU for both left and right Alt keys.
45 if (event->key_code() == ui::VKEY_MENU &&
46 event->type() == ui::ET_KEY_RELEASED) {
47 Shell::GetInstance()->window_cycle_controller()->AltKeyReleased();
48 // Warning: |this| will be deleted from here on.
49 }
50 }
51
52 } // namespace
53
54
55 // WindowCycleController, public:
56
57 WindowCycleController::WindowCycleController() {
58 }
59
60 WindowCycleController::~WindowCycleController() {
61 StopCycling();
62 }
63
64 // static
65 bool WindowCycleController::CanCycle() {
66 // Don't allow window cycling if the screen is locked or a modal dialog is
67 // open.
68 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
69 !Shell::GetInstance()->IsSystemModalWindowOpen();
70 }
71
72 void WindowCycleController::HandleCycleWindow(Direction direction) {
73 if (!CanCycle())
74 return;
75
76 if (!IsCycling()) {
77 // This is the start of an alt-tab cycle through multiple windows, so
78 // listen for the alt key being released to stop cycling.
79 StartCycling();
80 Step(direction);
tdanderson 2014/05/01 18:51:39 Can you factor out the call to Step(direction) her
Nina 2014/05/01 20:41:16 Done.
81 InstallEventFilter();
82 } else {
83 // We're in the middle of an alt-tab cycle, just step forward.
tdanderson 2014/05/01 18:51:39 "forward" -> |direction| is not necessarily FORWAR
Nina 2014/05/01 20:41:16 Done.
84 Step(direction);
85 }
86 }
87
88 void WindowCycleController::HandleLinearCycleWindow() {
89 if (!CanCycle() || IsCycling())
90 return;
91
92 // Use the reversed list of windows to prevent a 2-cycle of the most recent
93 // windows occurring.
94 WindowCycleList cycle_list(MruWindowTracker::BuildWindowList(true));
95 cycle_list.Step(WindowCycleList::FORWARD);
96 }
97
98 void WindowCycleController::AltKeyReleased() {
99 StopCycling();
100 }
101
102 //////////////////////////////////////////////////////////////////////////////
103 // WindowCycleController, private:
104
105 void WindowCycleController::StartCycling() {
106 windows_.reset(new WindowCycleList(ash::Shell::GetInstance()->
107 mru_window_tracker()->BuildMruWindowList()));
108 }
109
110 void WindowCycleController::Step(Direction direction) {
111 DCHECK(windows_.get());
112 windows_->Step(direction == FORWARD ? WindowCycleList::FORWARD :
113 WindowCycleList::BACKWARD);
114 }
115
116 void WindowCycleController::StopCycling() {
117 windows_.reset();
118 // Remove our key event filter.
119 if (event_handler_) {
120 Shell::GetInstance()->RemovePreTargetHandler(event_handler_.get());
121 event_handler_.reset();
122 }
123 }
124
125 void WindowCycleController::InstallEventFilter() {
tdanderson 2014/05/01 18:51:39 I don't think this needs to be its own helper. I'd
Nina 2014/05/01 20:41:16 Done.
126 event_handler_.reset(new WindowCycleEventFilter());
127 Shell::GetInstance()->AddPreTargetHandler(event_handler_.get());
128 }
129
130 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698