| 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/wm/window_cycle_controller.h" | 5 #include "ash/wm/window_cycle_controller.h" |
| 6 | 6 |
| 7 #include "ash/metrics/task_switch_source.h" | 7 #include "ash/metrics/task_switch_source.h" |
| 8 #include "ash/public/cpp/shell_window_ids.h" | 8 #include "ash/public/cpp/shell_window_ids.h" |
| 9 #include "ash/session/session_controller.h" | 9 #include "ash/session/session_controller.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/shell_port.h" | 11 #include "ash/shell_port.h" |
| 12 #include "ash/wm/mru_window_tracker.h" | 12 #include "ash/wm/mru_window_tracker.h" |
| 13 #include "ash/wm/screen_pinning_controller.h" | 13 #include "ash/wm/screen_pinning_controller.h" |
| 14 #include "ash/wm/window_cycle_event_filter.h" | 14 #include "ash/wm/window_cycle_event_filter.h" |
| 15 #include "ash/wm/window_cycle_list.h" | 15 #include "ash/wm/window_cycle_list.h" |
| 16 #include "ash/wm/window_state.h" | 16 #include "ash/wm/window_state.h" |
| 17 #include "ash/wm/window_state_aura.h" |
| 17 #include "ash/wm_window.h" | 18 #include "ash/wm_window.h" |
| 18 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
| 19 | 20 |
| 20 namespace ash { | 21 namespace ash { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // Returns the most recently active window from the |window_list| or nullptr | 25 // Returns the most recently active window from the |window_list| or nullptr |
| 25 // if the list is empty. | 26 // if the list is empty. |
| 26 WmWindow* GetActiveWindow(const MruWindowTracker::WindowList& window_list) { | 27 aura::Window* GetActiveWindow(const WindowCycleList::WindowList& window_list) { |
| 27 return window_list.empty() ? nullptr : window_list[0]; | 28 return window_list.empty() ? nullptr : window_list[0]; |
| 28 } | 29 } |
| 29 | 30 |
| 30 } // namespace | 31 } // namespace |
| 31 | 32 |
| 32 ////////////////////////////////////////////////////////////////////////////// | 33 ////////////////////////////////////////////////////////////////////////////// |
| 33 // WindowCycleController, public: | 34 // WindowCycleController, public: |
| 34 | 35 |
| 35 WindowCycleController::WindowCycleController() {} | 36 WindowCycleController::WindowCycleController() {} |
| 36 | 37 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 if (!CanCycle()) | 49 if (!CanCycle()) |
| 49 return; | 50 return; |
| 50 | 51 |
| 51 if (!IsCycling()) | 52 if (!IsCycling()) |
| 52 StartCycling(); | 53 StartCycling(); |
| 53 | 54 |
| 54 Step(direction); | 55 Step(direction); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void WindowCycleController::StartCycling() { | 58 void WindowCycleController::StartCycling() { |
| 58 MruWindowTracker::WindowList window_list = | 59 WindowCycleList::WindowList window_list = WmWindow::ToAuraWindows( |
| 59 Shell::Get()->mru_window_tracker()->BuildMruWindowList(); | 60 Shell::Get()->mru_window_tracker()->BuildMruWindowList()); |
| 60 // Exclude windows: | 61 // Exclude windows: |
| 61 // - non user positionable windows, such as extension popups. | 62 // - non user positionable windows, such as extension popups. |
| 62 // - windows being dragged | 63 // - windows being dragged |
| 63 // - the AppList window, which will hide as soon as cycling starts | 64 // - the AppList window, which will hide as soon as cycling starts |
| 64 // anyway. It doesn't make sense to count it as a "switchable" window, yet | 65 // anyway. It doesn't make sense to count it as a "switchable" window, yet |
| 65 // a lot of code relies on the MRU list returning the app window. If we | 66 // a lot of code relies on the MRU list returning the app window. If we |
| 66 // don't manually remove it, the window cycling UI won't crash or misbehave, | 67 // don't manually remove it, the window cycling UI won't crash or misbehave, |
| 67 // but there will be a flicker as the target window changes. Also exclude | 68 // but there will be a flicker as the target window changes. Also exclude |
| 68 // unselectable windows such as extension popups. | 69 // unselectable windows such as extension popups. |
| 69 auto window_is_ineligible = [](WmWindow* window) { | 70 auto window_is_ineligible = [](aura::Window* window) { |
| 70 wm::WindowState* state = window->GetWindowState(); | 71 wm::WindowState* state = wm::GetWindowState(window); |
| 71 return !state->IsUserPositionable() || state->is_dragged() || | 72 return !state->IsUserPositionable() || state->is_dragged() || |
| 72 window->GetRootWindow() | 73 window->GetRootWindow() |
| 73 ->GetChildByShellWindowId(kShellWindowId_AppListContainer) | 74 ->GetChildById(kShellWindowId_AppListContainer) |
| 74 ->Contains(window); | 75 ->Contains(window); |
| 75 }; | 76 }; |
| 76 window_list.erase(std::remove_if(window_list.begin(), window_list.end(), | 77 window_list.erase(std::remove_if(window_list.begin(), window_list.end(), |
| 77 window_is_ineligible), | 78 window_is_ineligible), |
| 78 window_list.end()); | 79 window_list.end()); |
| 79 | 80 |
| 80 active_window_before_window_cycle_ = GetActiveWindow(window_list); | 81 active_window_before_window_cycle_ = GetActiveWindow(window_list); |
| 81 | 82 |
| 82 window_cycle_list_.reset(new WindowCycleList(window_list)); | 83 window_cycle_list_.reset(new WindowCycleList(window_list)); |
| 83 event_filter_ = ShellPort::Get()->CreateWindowCycleEventFilter(); | 84 event_filter_ = ShellPort::Get()->CreateWindowCycleEventFilter(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 102 void WindowCycleController::Step(Direction direction) { | 103 void WindowCycleController::Step(Direction direction) { |
| 103 DCHECK(window_cycle_list_.get()); | 104 DCHECK(window_cycle_list_.get()); |
| 104 window_cycle_list_->Step(direction); | 105 window_cycle_list_->Step(direction); |
| 105 } | 106 } |
| 106 | 107 |
| 107 void WindowCycleController::StopCycling() { | 108 void WindowCycleController::StopCycling() { |
| 108 UMA_HISTOGRAM_COUNTS_100("Ash.WindowCycleController.SelectionDepth", | 109 UMA_HISTOGRAM_COUNTS_100("Ash.WindowCycleController.SelectionDepth", |
| 109 window_cycle_list_->current_index() + 1); | 110 window_cycle_list_->current_index() + 1); |
| 110 window_cycle_list_.reset(); | 111 window_cycle_list_.reset(); |
| 111 | 112 |
| 112 WmWindow* active_window_after_window_cycle = | 113 aura::Window* active_window_after_window_cycle = |
| 113 GetActiveWindow(Shell::Get()->mru_window_tracker()->BuildMruWindowList()); | 114 GetActiveWindow(WmWindow::ToAuraWindows( |
| 115 Shell::Get()->mru_window_tracker()->BuildMruWindowList())); |
| 114 | 116 |
| 115 // Remove our key event filter. | 117 // Remove our key event filter. |
| 116 event_filter_.reset(); | 118 event_filter_.reset(); |
| 117 UMA_HISTOGRAM_MEDIUM_TIMES("Ash.WindowCycleController.CycleTime", | 119 UMA_HISTOGRAM_MEDIUM_TIMES("Ash.WindowCycleController.CycleTime", |
| 118 base::Time::Now() - cycle_start_time_); | 120 base::Time::Now() - cycle_start_time_); |
| 119 | 121 |
| 120 if (active_window_after_window_cycle != nullptr && | 122 if (active_window_after_window_cycle != nullptr && |
| 121 active_window_before_window_cycle_ != active_window_after_window_cycle) { | 123 active_window_before_window_cycle_ != active_window_after_window_cycle) { |
| 122 ShellPort::Get()->RecordTaskSwitchMetric( | 124 ShellPort::Get()->RecordTaskSwitchMetric( |
| 123 TaskSwitchSource::WINDOW_CYCLE_CONTROLLER); | 125 TaskSwitchSource::WINDOW_CYCLE_CONTROLLER); |
| 124 } | 126 } |
| 125 active_window_before_window_cycle_ = nullptr; | 127 active_window_before_window_cycle_ = nullptr; |
| 126 } | 128 } |
| 127 | 129 |
| 128 } // namespace ash | 130 } // namespace ash |
| OLD | NEW |