| 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/overview/window_selector_controller.h" | 5 #include "ash/wm/overview/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/overview/window_selector.h" | 10 #include "ash/wm/overview/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. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 79 new WindowSelector(windows, WindowSelector::OVERVIEW, this)); | 41 new WindowSelector(windows, WindowSelector::OVERVIEW, this)); |
| 80 } | 42 } |
| 81 } | 43 } |
| 82 | 44 |
| 83 void WindowSelectorController::HandleCycleWindow( | 45 void WindowSelectorController::HandleCycleWindow( |
| 84 WindowSelector::Direction direction) { | 46 WindowSelector::Direction direction) { |
| 85 if (!CanSelect()) | 47 if (!CanSelect()) |
| 86 return; | 48 return; |
| 87 | 49 |
| 88 if (!IsSelecting()) { | 50 if (!IsSelecting()) { |
| 89 event_handler_.reset(new WindowSelectorEventFilter()); | |
| 90 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> | 51 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> |
| 91 mru_window_tracker()->BuildMruWindowList(); | 52 mru_window_tracker()->BuildMruWindowList(); |
| 92 // Removing focus will hide popup windows like the omnibar or open menus. | 53 // Removing focus will hide popup windows like the omnibar or open menus. |
| 93 window_selector_.reset( | 54 window_selector_.reset( |
| 94 new WindowSelector(windows, WindowSelector::CYCLE, this)); | 55 new WindowSelector(windows, WindowSelector::CYCLE, this)); |
| 95 window_selector_->Step(direction); | 56 window_selector_->Step(direction); |
| 96 } else if (window_selector_->mode() == WindowSelector::CYCLE) { | 57 } else if (window_selector_->mode() == WindowSelector::CYCLE) { |
| 97 window_selector_->Step(direction); | 58 window_selector_->Step(direction); |
| 98 } | 59 } |
| 99 } | 60 } |
| 100 | 61 |
| 101 void WindowSelectorController::AltKeyReleased() { | |
| 102 event_handler_.reset(); | |
| 103 window_selector_->SelectWindow(); | |
| 104 } | |
| 105 | |
| 106 bool WindowSelectorController::IsSelecting() { | 62 bool WindowSelectorController::IsSelecting() { |
| 107 return window_selector_.get() != NULL; | 63 return window_selector_.get() != NULL; |
| 108 } | 64 } |
| 109 | 65 |
| 110 void WindowSelectorController::OnWindowSelected(aura::Window* window) { | 66 void WindowSelectorController::OnWindowSelected(aura::Window* window) { |
| 111 window_selector_.reset(); | 67 window_selector_.reset(); |
| 112 wm::ActivateWindow(window); | 68 wm::ActivateWindow(window); |
| 113 } | 69 } |
| 114 | 70 |
| 115 void WindowSelectorController::OnSelectionCanceled() { | 71 void WindowSelectorController::OnSelectionCanceled() { |
| 116 window_selector_.reset(); | 72 window_selector_.reset(); |
| 117 } | 73 } |
| 118 | 74 |
| 119 } // namespace ash | 75 } // namespace ash |
| OLD | NEW |