Commit 89538929 authored by Robert Flack's avatar Robert Flack Committed by Commit Bot

Optimize removal of non-overview windows in WindowSelectorController

WindowSelectorController::ToggleOverview used to do 3 removal loops over the
active window list, one of which did a search through another window list for
each window. This reduces the runtime complexity (a single removal loop) and
makes the code easier to read (having fewer conditions).

Bug: None
Change-Id: I06ddf20b5ef3be57da4660de849bffeb4935683b
Reviewed-on: https://chromium-review.googlesource.com/934974Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Robert Flack <flackr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538869}
parent e7ba5e63
......@@ -218,7 +218,7 @@ views::Widget* CreateTextFilter(views::TextfieldController* controller,
} // namespace
// static
bool WindowSelector::IsSelectable(aura::Window* window) {
bool WindowSelector::IsSelectable(const aura::Window* window) {
return wm::GetWindowState(window)->IsUserPositionable();
}
......
......@@ -52,7 +52,7 @@ class ASH_EXPORT WindowSelector : public display::DisplayObserver,
public SplitViewController::Observer {
public:
// Returns true if the window can be selected in overview mode.
static bool IsSelectable(aura::Window* window);
static bool IsSelectable(const aura::Window* window);
enum Direction { LEFT, UP, RIGHT, DOWN };
......
......@@ -25,6 +25,38 @@
namespace ash {
namespace {
// Returns true if |window| should be hidden when entering overview.
bool ShouldHideWindowInOverview(const aura::Window* window) {
return !window->GetProperty(ash::kShowInOverviewKey);
}
// Returns true if |window| should be excluded from overview.
bool ShouldExcludeWindowFromOverview(const aura::Window* window) {
if (ShouldHideWindowInOverview(window))
return true;
// Other non-selectable windows will be ignored in overview.
if (!WindowSelector::IsSelectable(window))
return true;
// Remove the default snapped window from the window list. The default
// snapped window occupies one side of the screen, while the other windows
// occupy the other side of the screen in overview mode. The default snap
// position is the position where the window was first snapped. See
// |default_snap_position_| in SplitViewController for more detail.
if (Shell::Get()->IsSplitViewModeActive() &&
window ==
Shell::Get()->split_view_controller()->GetDefaultSnappedWindow()) {
return true;
}
return false;
}
} // namespace
WindowSelectorController::WindowSelectorController() = default;
WindowSelectorController::~WindowSelectorController() {
......@@ -64,48 +96,20 @@ bool WindowSelectorController::ToggleOverview() {
auto windows = Shell::Get()->mru_window_tracker()->BuildMruWindowList();
// System modal windows will be hidden in overview.
std::vector<aura::Window*> hide_windows;
for (auto* window : windows) {
if (!window->GetProperty(ash::kShowInOverviewKey))
hide_windows.push_back(window);
}
auto end = std::remove_if(
windows.begin(), windows.end(), [&hide_windows](aura::Window* window) {
return std::find(hide_windows.begin(), hide_windows.end(), window) !=
hide_windows.end();
});
windows.resize(end - windows.begin());
// Hidden windows will be removed by ShouldExcludeWindowFromOverview so we
// must copy them out first.
std::vector<aura::Window*> hide_windows(windows.size());
auto end = std::copy_if(windows.begin(), windows.end(),
hide_windows.begin(), ShouldHideWindowInOverview);
hide_windows.resize(end - hide_windows.begin());
// Other non-selectable windows will be ignored in overview.
end =
std::remove_if(windows.begin(), windows.end(),
std::not1(std::ptr_fun(&WindowSelector::IsSelectable)));
end = std::remove_if(windows.begin(), windows.end(),
ShouldExcludeWindowFromOverview);
windows.resize(end - windows.begin());
if (!Shell::Get()->IsSplitViewModeActive()) {
// Don't enter overview with no window if the split view mode is inactive.
if (!IsNewOverviewUi() && windows.empty())
return false;
} else {
// Don't enter overview with less than 1 window if the split view mode is
// active.
if (windows.size() <= 1)
return false;
// Remove the default snapped window from the window list. The default
// snapped window occupies one side of the screen, while the other windows
// occupy the other side of the screen in overview mode. The default snap
// position is the position where the window was first snapped. See
// |default_snap_position_| in SplitViewController for more detail.
aura::Window* default_snapped_window =
Shell::Get()->split_view_controller()->GetDefaultSnappedWindow();
auto iter =
std::find(windows.begin(), windows.end(), default_snapped_window);
DCHECK(iter != windows.end());
windows.erase(iter);
}
// Don't enter overview with no windows to select from.
if (!IsNewOverviewUi() && windows.empty())
return false;
Shell::Get()->NotifyOverviewModeStarting();
window_selector_.reset(new WindowSelector(this));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment