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

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: Minor style adjustment 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 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/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;
32
33 private:
34 DISALLOW_COPY_AND_ASSIGN(WindowCycleEventFilter);
35 };
36
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()->StopCycling();
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 this is the start of an alt-tab cycle through multiple windows,
77 // listen for the alt key being released to stop cycling.
78 if (!IsCycling())
79 StartCycling();
80
81 Step(direction);
82 }
83
84 void WindowCycleController::StartCycling() {
85 window_cycle_list_.reset(new WindowCycleList(ash::Shell::GetInstance()->
86 mru_window_tracker()->BuildMruWindowList()));
87 event_handler_.reset(new WindowCycleEventFilter());
88 Shell::GetInstance()->AddPreTargetHandler(event_handler_.get());
89 }
90
91 //////////////////////////////////////////////////////////////////////////////
92 // WindowCycleController, private:
93
94 void WindowCycleController::Step(Direction direction) {
95 DCHECK(window_cycle_list_.get());
96 window_cycle_list_->Step(direction);
97 }
98
99 void WindowCycleController::StopCycling() {
100 window_cycle_list_.reset();
101 // Remove our key event filter.
102 if (event_handler_) {
103 Shell::GetInstance()->RemovePreTargetHandler(event_handler_.get());
104 event_handler_.reset();
105 }
106 }
107
108 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698