OLD | NEW |
---|---|
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; | |
Daniel Erat
2013/08/09 20:54:35
nit: add a blank line after this one
flackr
2013/08/09 22:15:36
Done.
| |
28 private: | |
29 DISALLOW_COPY_AND_ASSIGN(WindowSelectorEventFilter); | |
30 }; | |
31 | |
32 // Watch for all keyboard events by filtering the root window. | |
33 WindowSelectorEventFilter::WindowSelectorEventFilter() { | |
34 Shell::GetInstance()->AddPreTargetHandler(this); | |
35 } | |
36 | |
37 WindowSelectorEventFilter::~WindowSelectorEventFilter() { | |
38 Shell::GetInstance()->RemovePreTargetHandler(this); | |
39 } | |
40 | |
41 void WindowSelectorEventFilter::OnKeyEvent(ui::KeyEvent* event) { | |
42 // Views uses VKEY_MENU for both left and right Alt keys. | |
43 if (event->key_code() == ui::VKEY_MENU && | |
44 event->type() == ui::ET_KEY_RELEASED) { | |
45 Shell::GetInstance()->window_selector_controller()->AltKeyReleased(); | |
46 // Warning: |this| will be deleted from here on. | |
47 } | |
48 } | |
49 | |
50 } // namespace | |
51 | |
15 WindowSelectorController::WindowSelectorController() { | 52 WindowSelectorController::WindowSelectorController() { |
16 } | 53 } |
17 | 54 |
18 WindowSelectorController::~WindowSelectorController() { | 55 WindowSelectorController::~WindowSelectorController() { |
19 } | 56 } |
20 | 57 |
21 // static | 58 // static |
22 bool WindowSelectorController::CanSelect() { | 59 bool WindowSelectorController::CanSelect() { |
23 // Don't allow a window overview if the screen is locked or a modal dialog is | 60 // Don't allow a window overview if the screen is locked or a modal dialog is |
24 // open. | 61 // open. |
25 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && | 62 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && |
26 !Shell::GetInstance()->IsSystemModalWindowOpen(); | 63 !Shell::GetInstance()->IsSystemModalWindowOpen(); |
27 } | 64 } |
28 | 65 |
29 void WindowSelectorController::ToggleOverview() { | 66 void WindowSelectorController::ToggleOverview() { |
30 if (window_selector_.get()) { | 67 if (window_selector_.get()) { |
31 window_selector_.reset(); | 68 window_selector_.reset(); |
32 } else { | 69 } else { |
33 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> | 70 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> |
34 mru_window_tracker()->BuildMruWindowList(); | 71 mru_window_tracker()->BuildMruWindowList(); |
35 // Don't enter overview mode with no windows. | 72 // Don't enter overview mode with no windows. |
36 if (windows.empty()) | 73 if (windows.empty()) |
37 return; | 74 return; |
38 | 75 |
39 // Deactivating the window will hide popup windows like the omnibar or | 76 // Deactivating the window will hide popup windows like the omnibar or |
40 // open menus. | 77 // open menus. |
41 aura::Window* active_window = wm::GetActiveWindow(); | 78 aura::Window* active_window = wm::GetActiveWindow(); |
42 if (active_window) | 79 if (active_window) |
43 wm::DeactivateWindow(active_window); | 80 wm::DeactivateWindow(active_window); |
44 window_selector_.reset(new WindowSelector(windows, this)); | 81 window_selector_.reset( |
82 new WindowSelector(windows, WindowSelector::OVERVIEW, this)); | |
45 } | 83 } |
46 } | 84 } |
47 | 85 |
86 void WindowSelectorController::HandleCycleWindow( | |
87 WindowSelector::Direction direction) { | |
88 if (!CanSelect()) | |
89 return; | |
90 | |
91 if (!IsSelecting()) { | |
92 event_handler_.reset(new WindowSelectorEventFilter()); | |
93 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> | |
94 mru_window_tracker()->BuildMruWindowList(); | |
95 window_selector_.reset( | |
96 new WindowSelector(windows, WindowSelector::CYCLE, this)); | |
97 window_selector_->Step(direction); | |
98 } else if (window_selector_->mode() == WindowSelector::CYCLE) { | |
99 window_selector_->Step(direction); | |
100 } | |
101 } | |
102 | |
103 void WindowSelectorController::AltKeyReleased() { | |
104 event_handler_.reset(); | |
105 window_selector_->SelectWindow(); | |
106 } | |
107 | |
48 bool WindowSelectorController::IsSelecting() { | 108 bool WindowSelectorController::IsSelecting() { |
49 return window_selector_.get() != NULL; | 109 return window_selector_.get() != NULL; |
50 } | 110 } |
51 | 111 |
52 void WindowSelectorController::OnWindowSelected(aura::Window* window) { | 112 void WindowSelectorController::OnWindowSelected(aura::Window* window) { |
53 window_selector_.reset(); | 113 window_selector_.reset(); |
54 wm::ActivateWindow(window); | 114 wm::ActivateWindow(window); |
55 } | 115 } |
56 | 116 |
57 void WindowSelectorController::OnSelectionCanceled() { | 117 void WindowSelectorController::OnSelectionCanceled() { |
58 window_selector_.reset(); | 118 window_selector_.reset(); |
59 } | 119 } |
60 | 120 |
61 } // namespace ash | 121 } // namespace ash |
OLD | NEW |