OLD | NEW |
(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 "ash/session/session_state_delegate.h" |
| 8 #include "ash/shell.h" |
| 9 #include "ash/wm/mru_window_tracker.h" |
| 10 #include "ash/wm/window_cycle_list.h" |
| 11 #include "ui/events/event.h" |
| 12 #include "ui/events/event_handler.h" |
| 13 |
| 14 namespace ash { |
| 15 |
| 16 namespace { |
| 17 |
| 18 // Filter to watch for the termination of a keyboard gesture to cycle through |
| 19 // multiple windows. |
| 20 class WindowCycleEventFilter : public ui::EventHandler { |
| 21 public: |
| 22 WindowCycleEventFilter(); |
| 23 virtual ~WindowCycleEventFilter(); |
| 24 |
| 25 // Overridden from ui::EventHandler: |
| 26 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| 27 |
| 28 private: |
| 29 DISALLOW_COPY_AND_ASSIGN(WindowCycleEventFilter); |
| 30 }; |
| 31 |
| 32 WindowCycleEventFilter::WindowCycleEventFilter() { |
| 33 Shell::GetInstance()->AddPreTargetHandler(this); |
| 34 } |
| 35 |
| 36 WindowCycleEventFilter::~WindowCycleEventFilter() { |
| 37 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 38 } |
| 39 |
| 40 void WindowCycleEventFilter::OnKeyEvent(ui::KeyEvent* event) { |
| 41 // Views uses VKEY_MENU for both left and right Alt keys. |
| 42 if (event->key_code() == ui::VKEY_MENU && |
| 43 event->type() == ui::ET_KEY_RELEASED) { |
| 44 Shell::GetInstance()->window_cycle_controller()->StopCycling(); |
| 45 // Warning: |this| will be deleted from here on. |
| 46 } |
| 47 } |
| 48 |
| 49 } // namespace |
| 50 |
| 51 ////////////////////////////////////////////////////////////////////////////// |
| 52 // WindowCycleController, public: |
| 53 |
| 54 WindowCycleController::WindowCycleController() { |
| 55 } |
| 56 |
| 57 WindowCycleController::~WindowCycleController() { |
| 58 } |
| 59 |
| 60 // static |
| 61 bool WindowCycleController::CanCycle() { |
| 62 // Don't allow window cycling if the screen is locked or a modal dialog is |
| 63 // open. |
| 64 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && |
| 65 !Shell::GetInstance()->IsSystemModalWindowOpen(); |
| 66 } |
| 67 |
| 68 void WindowCycleController::HandleCycleWindow(Direction direction) { |
| 69 if (!CanCycle()) |
| 70 return; |
| 71 |
| 72 if (!IsCycling()) |
| 73 StartCycling(); |
| 74 |
| 75 Step(direction); |
| 76 } |
| 77 |
| 78 void WindowCycleController::StartCycling() { |
| 79 window_cycle_list_.reset(new WindowCycleList(ash::Shell::GetInstance()-> |
| 80 mru_window_tracker()->BuildMruWindowList())); |
| 81 event_handler_.reset(new WindowCycleEventFilter()); |
| 82 } |
| 83 |
| 84 ////////////////////////////////////////////////////////////////////////////// |
| 85 // WindowCycleController, private: |
| 86 |
| 87 void WindowCycleController::Step(Direction direction) { |
| 88 DCHECK(window_cycle_list_.get()); |
| 89 window_cycle_list_->Step(direction); |
| 90 } |
| 91 |
| 92 void WindowCycleController::StopCycling() { |
| 93 window_cycle_list_.reset(); |
| 94 // Remove our key event filter. |
| 95 event_handler_.reset(); |
| 96 } |
| 97 |
| 98 } // namespace ash |
OLD | NEW |