Commit 9903da3f authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

Remove function to sort windows by z-index, which is no longer used.

The function is no longer used since occlusion tracking is done
by aura::WindowOcclusionTracker.

Bug: 973682
Change-Id: I1bee51d47547f1e91f375c0f591dbd27664155de
Reviewed-on: https://chromium-review.googlesource.com/996299Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548400}
parent 1e1a0e30
......@@ -1875,7 +1875,6 @@ split_static_library("ui") {
"ash/session_controller_client.h",
"ash/session_util.cc",
"ash/session_util.h",
"ash/sort_windows_by_z_index.cc",
"ash/system_tray_client.cc",
"ash/system_tray_client.h",
"ash/tab_scrubber.cc",
......@@ -1899,7 +1898,6 @@ split_static_library("ui") {
"settings_window_manager_chromeos.cc",
"settings_window_manager_chromeos.h",
"settings_window_manager_observer_chromeos.h",
"sort_windows_by_z_index.h",
"views/apps/app_info_dialog/arc_app_info_links_panel.cc",
"views/apps/app_info_dialog/arc_app_info_links_panel.h",
"views/apps/chrome_native_app_window_views_aura_ash.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/sort_windows_by_z_index.h"
#include <memory>
#include <utility>
#include "ash/shell.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/containers/flat_set.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tracker.h"
namespace ui {
namespace {
// Append windows in |windows| that are descendant of |root_window| to
// |sorted_windows| in z-order, from topmost to bottommost.
void AppendDescendantsSortedByZIndex(
const aura::Window* root_window,
const base::flat_set<aura::Window*>& windows,
std::vector<aura::Window*>* sorted_windows) {
const aura::Window::Windows& children = root_window->children();
for (auto it = children.rbegin(); it != children.rend(); ++it) {
aura::Window* window = *it;
if (base::ContainsKey(windows, window)) {
sorted_windows->push_back(window);
// Skip children of |window| since a window in |windows| is not expected
// to be the parent of another window in |windows|.
} else {
AppendDescendantsSortedByZIndex(window, windows, sorted_windows);
}
}
}
void DoSortWindowsByZIndex(std::unique_ptr<aura::WindowTracker> window_tracker,
SortWindowsByZIndexCallback callback) {
const base::flat_set<aura::Window*> windows(window_tracker->windows(),
base::KEEP_FIRST_OF_DUPES);
std::vector<aura::Window*> sorted_windows;
for (aura::Window* root_window : ash::Shell::GetAllRootWindows())
AppendDescendantsSortedByZIndex(root_window, windows, &sorted_windows);
DCHECK_EQ(windows.size(), sorted_windows.size());
std::move(callback).Run(sorted_windows);
}
} // namespace
void SortWindowsByZIndex(const std::vector<aura::Window*>& windows,
SortWindowsByZIndexCallback callback) {
auto window_tracker = std::make_unique<aura::WindowTracker>();
for (aura::Window* window : windows)
window_tracker->Add(window);
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&DoSortWindowsByZIndex, std::move(window_tracker),
std::move(callback)));
}
} // namespace ui
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_SORT_WINDOWS_BY_Z_INDEX_H_
#define CHROME_BROWSER_UI_SORT_WINDOWS_BY_Z_INDEX_H_
#include <vector>
#include "base/callback_forward.h"
#include "ui/gfx/native_widget_types.h"
namespace ui {
using SortWindowsByZIndexCallback =
base::OnceCallback<void(std::vector<gfx::NativeWindow>)>;
// Returns a list with the windows in |windows| sorted by z-index, from topmost
// to bottommost, via an asynchronous call to |callback| on the current
// sequence. Windows from |windows| that have been deleted by the time
// |callback| runs won't be part of the sorted list.
//
// TODO(fdoray): Implement this on all platforms. https://crbug.com/731145
void SortWindowsByZIndex(const std::vector<gfx::NativeWindow>& windows,
SortWindowsByZIndexCallback callback);
} // namespace ui
#endif // CHROME_BROWSER_UI_SORT_WINDOWS_BY_Z_INDEX_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/sort_windows_by_z_index.h"
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/callback.h"
#include "base/containers/flat_set.h"
#include "base/run_loop.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h"
using SortWindowsByZIndexBrowserTest = InProcessBrowserTest;
IN_PROC_BROWSER_TEST_F(SortWindowsByZIndexBrowserTest, SortWindowsByZIndex) {
Browser* browser1 = BrowserList::GetInstance()->GetLastActive();
chrome::NewWindow(browser1);
Browser* browser2 = BrowserList::GetInstance()->GetLastActive();
EXPECT_NE(browser1, browser2);
chrome::NewWindow(browser1);
Browser* browser3 = BrowserList::GetInstance()->GetLastActive();
EXPECT_NE(browser1, browser3);
EXPECT_NE(browser2, browser3);
chrome::NewWindow(browser1);
Browser* browser4 = BrowserList::GetInstance()->GetLastActive();
EXPECT_NE(browser1, browser4);
EXPECT_NE(browser2, browser4);
EXPECT_NE(browser3, browser4);
gfx::NativeWindow window1 = browser1->window()->GetNativeWindow();
gfx::NativeWindow window2 = browser2->window()->GetNativeWindow();
gfx::NativeWindow window3 = browser3->window()->GetNativeWindow();
gfx::NativeWindow window4 = browser4->window()->GetNativeWindow();
std::vector<gfx::NativeWindow> expected_sorted_windows{window4, window3,
window2, window1};
bool callback_did_run = false;
ui::SortWindowsByZIndex(
{window1, window3, window2, window4},
base::BindOnce(
[](std::vector<gfx::NativeWindow> expected_sorted_windows,
bool* callback_did_run,
std::vector<gfx::NativeWindow> sorted_windows) {
EXPECT_EQ(expected_sorted_windows, sorted_windows);
*callback_did_run = true;
},
std::move(expected_sorted_windows),
base::Unretained(&callback_did_run)));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(callback_did_run);
}
......@@ -1685,7 +1685,6 @@ test("browser_tests") {
"../browser/ui/ash/tablet_mode_page_behavior_browsertest.cc",
"../browser/ui/ash/time_to_first_present_recorder_browsertest.cc",
"../browser/ui/ash/volume_controller_browsertest.cc",
"../browser/ui/sort_windows_by_z_index_browsertest.cc",
"../browser/ui/views/apps/chrome_native_app_window_views_aura_ash_browsertest.cc",
"../browser/ui/views/arc_app_dialog_view_browsertest.cc",
"../browser/ui/views/frame/browser_frame_ash_browsertest.cc",
......
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