Chromium Code Reviews| 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 } | |
| 34 | |
| 35 WindowCycleEventFilter::~WindowCycleEventFilter() { | |
| 36 } | |
| 37 | |
| 38 void WindowCycleEventFilter::OnKeyEvent(ui::KeyEvent* event) { | |
| 39 // Views uses VKEY_MENU for both left and right Alt keys. | |
| 40 if (event->key_code() == ui::VKEY_MENU && | |
| 41 event->type() == ui::ET_KEY_RELEASED) { | |
| 42 Shell::GetInstance()->window_cycle_controller()->StopCycling(); | |
| 43 // Warning: |this| will be deleted from here on. | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 } // namespace | |
| 48 | |
| 49 // WindowCycleController, public: | |
| 50 | |
| 51 WindowCycleController::WindowCycleController() | |
| 52 : event_handler_(new WindowCycleEventFilter()) { | |
| 53 Shell::GetInstance()->AddPreTargetHandler(event_handler_.get()); | |
|
flackr
2014/05/07 16:03:45
I meant to move these to the WindowCycleEventFilte
| |
| 54 } | |
| 55 | |
| 56 WindowCycleController::~WindowCycleController() { | |
| 57 Shell::GetInstance()->RemovePreTargetHandler(event_handler_.get()); | |
| 58 event_handler_.reset(); | |
|
flackr
2014/05/07 16:03:45
This is not necessary, the scoped_ptr is destructe
| |
| 59 } | |
| 60 | |
| 61 // static | |
| 62 bool WindowCycleController::CanCycle() { | |
| 63 // Don't allow window cycling if the screen is locked or a modal dialog is | |
| 64 // open. | |
| 65 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && | |
| 66 !Shell::GetInstance()->IsSystemModalWindowOpen(); | |
| 67 } | |
| 68 | |
| 69 void WindowCycleController::HandleCycleWindow(Direction direction) { | |
| 70 if (!CanCycle()) | |
| 71 return; | |
| 72 | |
| 73 if (!IsCycling()) | |
| 74 StartCycling(); | |
| 75 | |
| 76 Step(direction); | |
| 77 } | |
| 78 | |
| 79 void WindowCycleController::StartCycling() { | |
| 80 window_cycle_list_.reset(new WindowCycleList( | |
| 81 ash::Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList())); | |
| 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 } | |
| 95 | |
| 96 } // namespace ash | |
| OLD | NEW |