| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/common/wm/window_cycle_controller.h" | 5 #include "ash/common/wm/window_cycle_controller.h" |
| 6 | 6 |
| 7 #include "ash/common/metrics/task_switch_source.h" | 7 #include "ash/common/metrics/task_switch_source.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shell_window_ids.h" | |
| 10 #include "ash/common/wm/mru_window_tracker.h" | 9 #include "ash/common/wm/mru_window_tracker.h" |
| 11 #include "ash/common/wm/window_cycle_event_filter.h" | 10 #include "ash/common/wm/window_cycle_event_filter.h" |
| 12 #include "ash/common/wm/window_cycle_list.h" | 11 #include "ash/common/wm/window_cycle_list.h" |
| 13 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 14 #include "ash/common/wm_window.h" | |
| 15 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 16 | 14 |
| 17 namespace ash { | 15 namespace ash { |
| 18 | 16 |
| 19 namespace { | 17 namespace { |
| 20 | 18 |
| 21 // Returns the most recently active window from the |window_list| or nullptr | 19 // Returns the most recently active window from the |window_list| or nullptr |
| 22 // if the list is empty. | 20 // if the list is empty. |
| 23 WmWindow* GetActiveWindow(const MruWindowTracker::WindowList& window_list) { | 21 WmWindow* GetActiveWindow(const MruWindowTracker::WindowList& window_list) { |
| 24 return window_list.empty() ? nullptr : window_list[0]; | 22 return window_list.empty() ? nullptr : window_list[0]; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 47 | 45 |
| 48 if (!IsCycling()) | 46 if (!IsCycling()) |
| 49 StartCycling(); | 47 StartCycling(); |
| 50 | 48 |
| 51 Step(direction); | 49 Step(direction); |
| 52 } | 50 } |
| 53 | 51 |
| 54 void WindowCycleController::StartCycling() { | 52 void WindowCycleController::StartCycling() { |
| 55 MruWindowTracker::WindowList window_list = | 53 MruWindowTracker::WindowList window_list = |
| 56 WmShell::Get()->mru_window_tracker()->BuildMruWindowList(); | 54 WmShell::Get()->mru_window_tracker()->BuildMruWindowList(); |
| 57 // Exclude the AppList window, which will hide as soon as cycling starts | |
| 58 // anyway. It doesn't make sense to count it as a "switchable" window, yet | |
| 59 // a lot of code relies on the MRU list returning the app window. If we | |
| 60 // don't manually remove it, the window cycling UI won't crash or misbehave, | |
| 61 // but there will be a flicker as the target window changes. | |
| 62 window_list.erase(std::remove_if(window_list.begin(), window_list.end(), | |
| 63 [](WmWindow* window) { | |
| 64 return window->GetRootWindow() | |
| 65 ->GetChildByShellWindowId( | |
| 66 kShellWindowId_AppListContainer) | |
| 67 ->Contains(window); | |
| 68 }), | |
| 69 window_list.end()); | |
| 70 | 55 |
| 71 active_window_before_window_cycle_ = GetActiveWindow(window_list); | 56 active_window_before_window_cycle_ = GetActiveWindow(window_list); |
| 72 | 57 |
| 73 window_cycle_list_.reset(new WindowCycleList(window_list)); | 58 window_cycle_list_.reset(new WindowCycleList(window_list)); |
| 74 event_filter_ = WmShell::Get()->CreateWindowCycleEventFilter(); | 59 event_filter_ = WmShell::Get()->CreateWindowCycleEventFilter(); |
| 75 cycle_start_time_ = base::Time::Now(); | 60 cycle_start_time_ = base::Time::Now(); |
| 76 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_CYCLE); | 61 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_CYCLE); |
| 77 UMA_HISTOGRAM_COUNTS_100("Ash.WindowCycleController.Items", | 62 UMA_HISTOGRAM_COUNTS_100("Ash.WindowCycleController.Items", |
| 78 window_list.size()); | 63 window_list.size()); |
| 79 } | 64 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 101 | 86 |
| 102 if (active_window_after_window_cycle != nullptr && | 87 if (active_window_after_window_cycle != nullptr && |
| 103 active_window_before_window_cycle_ != active_window_after_window_cycle) { | 88 active_window_before_window_cycle_ != active_window_after_window_cycle) { |
| 104 WmShell::Get()->RecordTaskSwitchMetric( | 89 WmShell::Get()->RecordTaskSwitchMetric( |
| 105 TaskSwitchSource::WINDOW_CYCLE_CONTROLLER); | 90 TaskSwitchSource::WINDOW_CYCLE_CONTROLLER); |
| 106 } | 91 } |
| 107 active_window_before_window_cycle_ = nullptr; | 92 active_window_before_window_cycle_ = nullptr; |
| 108 } | 93 } |
| 109 | 94 |
| 110 } // namespace ash | 95 } // namespace ash |
| OLD | NEW |