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

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

Issue 22667003: Reland "216874 - Use overview mode for alt-tab cycling." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix use after free in event handling. 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"
12 14
13 namespace ash { 15 namespace ash {
14 16
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
15 WindowSelectorController::WindowSelectorController() { 53 WindowSelectorController::WindowSelectorController() {
16 } 54 }
17 55
18 WindowSelectorController::~WindowSelectorController() { 56 WindowSelectorController::~WindowSelectorController() {
19 } 57 }
20 58
21 // static 59 // static
22 bool WindowSelectorController::CanSelect() { 60 bool WindowSelectorController::CanSelect() {
23 // Don't allow a window overview if the screen is locked or a modal dialog is 61 // Don't allow a window overview if the screen is locked or a modal dialog is
24 // open. 62 // open.
25 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && 63 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
26 !Shell::GetInstance()->IsSystemModalWindowOpen(); 64 !Shell::GetInstance()->IsSystemModalWindowOpen();
27 } 65 }
28 66
29 void WindowSelectorController::ToggleOverview() { 67 void WindowSelectorController::ToggleOverview() {
30 if (window_selector_.get()) { 68 if (window_selector_.get()) {
31 window_selector_.reset(); 69 window_selector_.reset();
32 } else { 70 } else {
33 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> 71 std::vector<aura::Window*> windows = ash::Shell::GetInstance()->
34 mru_window_tracker()->BuildMruWindowList(); 72 mru_window_tracker()->BuildMruWindowList();
35 // Don't enter overview mode with no windows. 73 // Don't enter overview mode with no windows.
36 if (windows.empty()) 74 if (windows.empty())
37 return; 75 return;
38 76
39 // Deactivating the window will hide popup windows like the omnibar or 77 // Deactivating the window will hide popup windows like the omnibar or
40 // open menus. 78 // open menus.
41 aura::Window* active_window = wm::GetActiveWindow(); 79 aura::Window* active_window = wm::GetActiveWindow();
42 if (active_window) 80 if (active_window)
43 wm::DeactivateWindow(active_window); 81 wm::DeactivateWindow(active_window);
44 window_selector_.reset(new WindowSelector(windows, this)); 82 window_selector_.reset(
83 new WindowSelector(windows, WindowSelector::OVERVIEW, this));
45 } 84 }
46 } 85 }
47 86
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
48 bool WindowSelectorController::IsSelecting() { 109 bool WindowSelectorController::IsSelecting() {
49 return window_selector_.get() != NULL; 110 return window_selector_.get() != NULL;
50 } 111 }
51 112
52 void WindowSelectorController::OnWindowSelected(aura::Window* window) { 113 void WindowSelectorController::OnWindowSelected(aura::Window* window) {
53 window_selector_.reset(); 114 window_selector_.reset();
54 wm::ActivateWindow(window); 115 wm::ActivateWindow(window);
55 } 116 }
56 117
57 void WindowSelectorController::OnSelectionCanceled() { 118 void WindowSelectorController::OnSelectionCanceled() {
58 window_selector_.reset(); 119 window_selector_.reset();
59 } 120 }
60 121
61 } // namespace ash 122 } // 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