| 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/wm/mru_window_tracker.h" | 9 #include "ash/common/wm/mru_window_tracker.h" |
| 10 #include "ash/common/wm/window_cycle_event_filter.h" | 10 #include "ash/common/wm/window_cycle_event_filter.h" |
| 11 #include "ash/common/wm/window_cycle_list.h" | 11 #include "ash/common/wm/window_cycle_list.h" |
| 12 #include "ash/common/wm/window_state.h" |
| 12 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 13 #include "ash/common/wm_window.h" | 14 #include "ash/common/wm_window.h" |
| 14 #include "ash/public/cpp/shell_window_ids.h" | 15 #include "ash/public/cpp/shell_window_ids.h" |
| 15 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 16 | 17 |
| 17 namespace ash { | 18 namespace ash { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Returns the most recently active window from the |window_list| or nullptr | 22 // Returns the most recently active window from the |window_list| or nullptr |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 | 48 |
| 48 if (!IsCycling()) | 49 if (!IsCycling()) |
| 49 StartCycling(); | 50 StartCycling(); |
| 50 | 51 |
| 51 Step(direction); | 52 Step(direction); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void WindowCycleController::StartCycling() { | 55 void WindowCycleController::StartCycling() { |
| 55 MruWindowTracker::WindowList window_list = | 56 MruWindowTracker::WindowList window_list = |
| 56 WmShell::Get()->mru_window_tracker()->BuildMruWindowList(); | 57 WmShell::Get()->mru_window_tracker()->BuildMruWindowList(); |
| 57 // Exclude the AppList window, which will hide as soon as cycling starts | 58 // Exclude windows: |
| 58 // anyway. It doesn't make sense to count it as a "switchable" window, yet | 59 // - non user positionable windows, such as extension popups. |
| 59 // a lot of code relies on the MRU list returning the app window. If we | 60 // - windows being dragged |
| 60 // don't manually remove it, the window cycling UI won't crash or misbehave, | 61 // - the AppList window, which will hide as soon as cycling starts |
| 61 // but there will be a flicker as the target window changes. | 62 // anyway. It doesn't make sense to count it as a "switchable" window, yet |
| 63 // a lot of code relies on the MRU list returning the app window. If we |
| 64 // don't manually remove it, the window cycling UI won't crash or misbehave, |
| 65 // but there will be a flicker as the target window changes. Also exclude |
| 66 // unselectable windows such as extension popups. |
| 67 auto window_is_ineligible = [](WmWindow* window) { |
| 68 wm::WindowState* state = window->GetWindowState(); |
| 69 return !state->IsUserPositionable() || state->is_dragged() || |
| 70 window->GetRootWindow() |
| 71 ->GetChildByShellWindowId(kShellWindowId_AppListContainer) |
| 72 ->Contains(window); |
| 73 }; |
| 62 window_list.erase(std::remove_if(window_list.begin(), window_list.end(), | 74 window_list.erase(std::remove_if(window_list.begin(), window_list.end(), |
| 63 [](WmWindow* window) { | 75 window_is_ineligible), |
| 64 return window->GetRootWindow() | |
| 65 ->GetChildByShellWindowId( | |
| 66 kShellWindowId_AppListContainer) | |
| 67 ->Contains(window); | |
| 68 }), | |
| 69 window_list.end()); | 76 window_list.end()); |
| 70 | 77 |
| 71 active_window_before_window_cycle_ = GetActiveWindow(window_list); | 78 active_window_before_window_cycle_ = GetActiveWindow(window_list); |
| 72 | 79 |
| 73 window_cycle_list_.reset(new WindowCycleList(window_list)); | 80 window_cycle_list_.reset(new WindowCycleList(window_list)); |
| 74 event_filter_ = WmShell::Get()->CreateWindowCycleEventFilter(); | 81 event_filter_ = WmShell::Get()->CreateWindowCycleEventFilter(); |
| 75 cycle_start_time_ = base::Time::Now(); | 82 cycle_start_time_ = base::Time::Now(); |
| 76 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_CYCLE); | 83 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_CYCLE); |
| 77 UMA_HISTOGRAM_COUNTS_100("Ash.WindowCycleController.Items", | 84 UMA_HISTOGRAM_COUNTS_100("Ash.WindowCycleController.Items", |
| 78 window_list.size()); | 85 window_list.size()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 117 |
| 111 if (active_window_after_window_cycle != nullptr && | 118 if (active_window_after_window_cycle != nullptr && |
| 112 active_window_before_window_cycle_ != active_window_after_window_cycle) { | 119 active_window_before_window_cycle_ != active_window_after_window_cycle) { |
| 113 WmShell::Get()->RecordTaskSwitchMetric( | 120 WmShell::Get()->RecordTaskSwitchMetric( |
| 114 TaskSwitchSource::WINDOW_CYCLE_CONTROLLER); | 121 TaskSwitchSource::WINDOW_CYCLE_CONTROLLER); |
| 115 } | 122 } |
| 116 active_window_before_window_cycle_ = nullptr; | 123 active_window_before_window_cycle_ = nullptr; |
| 117 } | 124 } |
| 118 | 125 |
| 119 } // namespace ash | 126 } // namespace ash |
| OLD | NEW |