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

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

Issue 22778002: Revert 216874 - Use overview mode for alt-tab cycling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 4 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/wm/window_selector_controller.h ('k') | ash/wm/window_selector_unittest.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/wm/window_selector_controller.h" 5 #include "ash/wm/window_selector_controller.h"
6 6
7 #include "ash/session_state_delegate.h" 7 #include "ash/session_state_delegate.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/wm/mru_window_tracker.h" 9 #include "ash/wm/mru_window_tracker.h"
10 #include "ash/wm/window_selector.h" 10 #include "ash/wm/window_selector.h"
11 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
12 #include "ui/base/events/event.h"
13 #include "ui/base/events/event_handler.h"
14 12
15 namespace ash { 13 namespace ash {
16 14
17 namespace {
18
19 // Filter to watch for the termination of a keyboard gesture to cycle through
20 // multiple windows.
21 class WindowSelectorEventFilter : public ui::EventHandler {
22 public:
23 WindowSelectorEventFilter();
24 virtual ~WindowSelectorEventFilter();
25
26 // Overridden from ui::EventHandler:
27 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
28
29 private:
30 DISALLOW_COPY_AND_ASSIGN(WindowSelectorEventFilter);
31 };
32
33 // Watch for all keyboard events by filtering the root window.
34 WindowSelectorEventFilter::WindowSelectorEventFilter() {
35 Shell::GetInstance()->AddPreTargetHandler(this);
36 }
37
38 WindowSelectorEventFilter::~WindowSelectorEventFilter() {
39 Shell::GetInstance()->RemovePreTargetHandler(this);
40 }
41
42 void WindowSelectorEventFilter::OnKeyEvent(ui::KeyEvent* event) {
43 // Views uses VKEY_MENU for both left and right Alt keys.
44 if (event->key_code() == ui::VKEY_MENU &&
45 event->type() == ui::ET_KEY_RELEASED) {
46 Shell::GetInstance()->window_selector_controller()->AltKeyReleased();
47 // Warning: |this| will be deleted from here on.
48 }
49 }
50
51 } // namespace
52
53 WindowSelectorController::WindowSelectorController() { 15 WindowSelectorController::WindowSelectorController() {
54 } 16 }
55 17
56 WindowSelectorController::~WindowSelectorController() { 18 WindowSelectorController::~WindowSelectorController() {
57 } 19 }
58 20
59 // static 21 // static
60 bool WindowSelectorController::CanSelect() { 22 bool WindowSelectorController::CanSelect() {
61 // Don't allow a window overview if the screen is locked or a modal dialog is 23 // Don't allow a window overview if the screen is locked or a modal dialog is
62 // open. 24 // open.
63 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && 25 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
64 !Shell::GetInstance()->IsSystemModalWindowOpen(); 26 !Shell::GetInstance()->IsSystemModalWindowOpen();
65 } 27 }
66 28
67 void WindowSelectorController::ToggleOverview() { 29 void WindowSelectorController::ToggleOverview() {
68 if (window_selector_.get()) { 30 if (window_selector_.get()) {
69 window_selector_.reset(); 31 window_selector_.reset();
70 } else { 32 } else {
71 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> 33 std::vector<aura::Window*> windows = ash::Shell::GetInstance()->
72 mru_window_tracker()->BuildMruWindowList(); 34 mru_window_tracker()->BuildMruWindowList();
73 // Don't enter overview mode with no windows. 35 // Don't enter overview mode with no windows.
74 if (windows.empty()) 36 if (windows.empty())
75 return; 37 return;
76 38
77 // Deactivating the window will hide popup windows like the omnibar or 39 // Deactivating the window will hide popup windows like the omnibar or
78 // open menus. 40 // open menus.
79 aura::Window* active_window = wm::GetActiveWindow(); 41 aura::Window* active_window = wm::GetActiveWindow();
80 if (active_window) 42 if (active_window)
81 wm::DeactivateWindow(active_window); 43 wm::DeactivateWindow(active_window);
82 window_selector_.reset( 44 window_selector_.reset(new WindowSelector(windows, this));
83 new WindowSelector(windows, WindowSelector::OVERVIEW, this));
84 } 45 }
85 } 46 }
86 47
87 void WindowSelectorController::HandleCycleWindow(
88 WindowSelector::Direction direction) {
89 if (!CanSelect())
90 return;
91
92 if (!IsSelecting()) {
93 event_handler_.reset(new WindowSelectorEventFilter());
94 std::vector<aura::Window*> windows = ash::Shell::GetInstance()->
95 mru_window_tracker()->BuildMruWindowList();
96 window_selector_.reset(
97 new WindowSelector(windows, WindowSelector::CYCLE, this));
98 window_selector_->Step(direction);
99 } else if (window_selector_->mode() == WindowSelector::CYCLE) {
100 window_selector_->Step(direction);
101 }
102 }
103
104 void WindowSelectorController::AltKeyReleased() {
105 event_handler_.reset();
106 window_selector_->SelectWindow();
107 }
108
109 bool WindowSelectorController::IsSelecting() { 48 bool WindowSelectorController::IsSelecting() {
110 return window_selector_.get() != NULL; 49 return window_selector_.get() != NULL;
111 } 50 }
112 51
113 void WindowSelectorController::OnWindowSelected(aura::Window* window) { 52 void WindowSelectorController::OnWindowSelected(aura::Window* window) {
114 window_selector_.reset(); 53 window_selector_.reset();
115 wm::ActivateWindow(window); 54 wm::ActivateWindow(window);
116 } 55 }
117 56
118 void WindowSelectorController::OnSelectionCanceled() { 57 void WindowSelectorController::OnSelectionCanceled() {
119 window_selector_.reset(); 58 window_selector_.reset();
120 } 59 }
121 60
122 } // namespace ash 61 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_selector_controller.h ('k') | ash/wm/window_selector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698