| 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/common/metrics/task_switch_source.h" | |
| 8 #include "ash/common/session/session_state_delegate.h" | |
| 9 #include "ash/common/wm/mru_window_tracker.h" | |
| 10 #include "ash/common/wm/window_cycle_event_filter.h" | |
| 11 #include "ash/common/wm_shell.h" | |
| 12 #include "ash/shell.h" | |
| 13 #include "ash/wm/window_cycle_list.h" | |
| 14 #include "base/metrics/histogram.h" | |
| 15 | |
| 16 namespace ash { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 // Returns the most recently active window from the |window_list| or nullptr | |
| 21 // if the list is empty. | |
| 22 WmWindow* GetActiveWindow(const MruWindowTracker::WindowList& window_list) { | |
| 23 return window_list.empty() ? nullptr : window_list[0]; | |
| 24 } | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 ////////////////////////////////////////////////////////////////////////////// | |
| 29 // WindowCycleController, public: | |
| 30 | |
| 31 WindowCycleController::WindowCycleController() {} | |
| 32 | |
| 33 WindowCycleController::~WindowCycleController() {} | |
| 34 | |
| 35 // static | |
| 36 bool WindowCycleController::CanCycle() { | |
| 37 // Prevent window cycling if the screen is locked or a modal dialog is open. | |
| 38 WmShell* wm_shell = WmShell::Get(); | |
| 39 return !wm_shell->GetSessionStateDelegate()->IsScreenLocked() && | |
| 40 !wm_shell->IsSystemModalWindowOpen() && !wm_shell->IsPinned(); | |
| 41 } | |
| 42 | |
| 43 void WindowCycleController::HandleCycleWindow(Direction direction) { | |
| 44 if (!CanCycle()) | |
| 45 return; | |
| 46 | |
| 47 if (!IsCycling()) | |
| 48 StartCycling(); | |
| 49 | |
| 50 Step(direction); | |
| 51 } | |
| 52 | |
| 53 void WindowCycleController::StartCycling() { | |
| 54 MruWindowTracker::WindowList window_list = | |
| 55 WmShell::Get()->mru_window_tracker()->BuildMruWindowList(); | |
| 56 | |
| 57 active_window_before_window_cycle_ = GetActiveWindow(window_list); | |
| 58 | |
| 59 window_cycle_list_.reset(new WindowCycleList(window_list)); | |
| 60 event_filter_ = WmShell::Get()->CreateWindowCycleEventFilter(); | |
| 61 cycle_start_time_ = base::Time::Now(); | |
| 62 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_CYCLE); | |
| 63 UMA_HISTOGRAM_COUNTS_100("Ash.WindowCycleController.Items", | |
| 64 window_list.size()); | |
| 65 } | |
| 66 | |
| 67 ////////////////////////////////////////////////////////////////////////////// | |
| 68 // WindowCycleController, private: | |
| 69 | |
| 70 void WindowCycleController::Step(Direction direction) { | |
| 71 DCHECK(window_cycle_list_.get()); | |
| 72 window_cycle_list_->Step(direction); | |
| 73 } | |
| 74 | |
| 75 void WindowCycleController::StopCycling() { | |
| 76 UMA_HISTOGRAM_COUNTS_100("Ash.WindowCycleController.SelectionDepth", | |
| 77 window_cycle_list_->current_index() + 1); | |
| 78 window_cycle_list_.reset(); | |
| 79 | |
| 80 WmWindow* active_window_after_window_cycle = GetActiveWindow( | |
| 81 WmShell::Get()->mru_window_tracker()->BuildMruWindowList()); | |
| 82 | |
| 83 // Remove our key event filter. | |
| 84 event_filter_.reset(); | |
| 85 UMA_HISTOGRAM_MEDIUM_TIMES("Ash.WindowCycleController.CycleTime", | |
| 86 base::Time::Now() - cycle_start_time_); | |
| 87 | |
| 88 if (active_window_after_window_cycle != nullptr && | |
| 89 active_window_before_window_cycle_ != active_window_after_window_cycle) { | |
| 90 WmShell::Get()->RecordTaskSwitchMetric( | |
| 91 TaskSwitchSource::WINDOW_CYCLE_CONTROLLER); | |
| 92 } | |
| 93 active_window_before_window_cycle_ = nullptr; | |
| 94 } | |
| 95 | |
| 96 } // namespace ash | |
| OLD | NEW |