Commit 6b034bdc authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

Add all desks containers

This CL adds the remaining desks containers in preparation for
using them in the next CL.
This CL also makes sure that the correct container IDs list is
used based on whether the Virtual Desks feature is enabled or not.

BUG=866622
TEST=ash_unittests are passing.

Change-Id: I5919b362b484a2eab13d4d6243bdbdc9c10ef442
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1568766Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarMitsuru Oshima (Slow 4/22-26) <oshima@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652850}
parent 7b929f17
......@@ -4,14 +4,20 @@
#include "ash/public/cpp/shell_window_ids.h"
#include <array>
#include "ash/public/cpp/ash_features.h"
#include "base/stl_util.h"
namespace ash {
// NOTE: this list is ordered by activation order. That is, windows in
// containers appearing earlier in the list are activated before windows in
// containers appearing later in the list.
const int32_t kActivatableShellWindowIds[] = {
namespace {
// TODO(afakhry): Consolidate the below lists when we launch Virtual Desks.
// List of IDs of the containers whose windows are actiavated *before* windows
// in the desks containers.
constexpr std::array<int, 10> kPreDesksActivatableContainersIds = {
kShellWindowId_OverlayContainer,
kShellWindowId_LockSystemModalContainer,
kShellWindowId_AccessibilityPanelContainer,
......@@ -22,7 +28,11 @@ const int32_t kActivatableShellWindowIds[] = {
kShellWindowId_SystemModalContainer,
kShellWindowId_AlwaysOnTopContainer,
kShellWindowId_AppListContainer,
kShellWindowId_DefaultContainerDeprecated,
};
// List of IDs of the containers whose windows are actiavated *after* windows in
// the desks containers.
constexpr std::array<int, 5> kPostDesksActivatableContainersIds = {
kShellWindowId_HomeScreenContainer,
// Launcher and status are intentionally checked after other containers
......@@ -34,15 +44,28 @@ const int32_t kActivatableShellWindowIds[] = {
kShellWindowId_StatusContainer,
};
const size_t kNumActivatableShellWindowIds =
base::size(kActivatableShellWindowIds);
} // namespace
bool IsActivatableShellWindowId(int32_t id) {
for (size_t i = 0; i < kNumActivatableShellWindowIds; i++) {
if (id == kActivatableShellWindowIds[i])
return true;
std::vector<int> GetActivatableShellWindowIds() {
std::vector<int> ids(kPreDesksActivatableContainersIds.begin(),
kPreDesksActivatableContainersIds.end());
// Add the desks containers IDs. Can't use desks_util since we're in
// ash/public here.
ids.emplace_back(kShellWindowId_DefaultContainerDeprecated);
if (features::IsVirtualDesksEnabled()) {
ids.emplace_back(kShellWindowId_DeskContainerB);
ids.emplace_back(kShellWindowId_DeskContainerC);
ids.emplace_back(kShellWindowId_DeskContainerD);
}
return false;
ids.insert(ids.end(), kPostDesksActivatableContainersIds.begin(),
kPostDesksActivatableContainersIds.end());
return ids;
}
bool IsActivatableShellWindowId(int id) {
return base::ContainsValue(GetActivatableShellWindowIds(), id);
}
} // namespace ash
......@@ -5,8 +5,7 @@
#ifndef ASH_PUBLIC_CPP_SHELL_WINDOW_IDS_H_
#define ASH_PUBLIC_CPP_SHELL_WINDOW_IDS_H_
#include <stddef.h>
#include <stdint.h>
#include <vector>
#include "ash/public/cpp/ash_public_export.h"
......@@ -49,11 +48,18 @@ enum ShellWindowId {
kShellWindowId_WallpaperContainer,
// The containers for standard top-level windows per active desks.
// Note: Do not use this container directly. Use
// `desks_util::GetActiveDeskContainerId()` instead.
// * Notes:
// - There are no direct mapping between `kShellWindowId_DeskContainerA` and
// Desk 1, or `kShellWindowId_DeskContainerB` and Desk 2. The containers
// are reused as desks are created and deleted.
// - **DO NOT** use these container IDs directly, instead use
// `desks_util::GetActiveDeskContainerId()`.
// TODO(afakhry): Rename this container, unexpose it, and add the rest of the
// containers.
kShellWindowId_DefaultContainerDeprecated,
kShellWindowId_DeskContainerB,
kShellWindowId_DeskContainerC,
kShellWindowId_DeskContainerD,
// The container for top-level windows with the 'always-on-top' flag set.
kShellWindowId_AlwaysOnTopContainer,
......@@ -168,57 +174,22 @@ enum NonContainerWindowId {
kShellWindowId_PhantomWindow = kShellWindowId_MaxContainer + 1
};
// A list of all the above valid container IDs. Add any new ID to this list.
// This list is needed to validate we have no duplicate IDs.
const int32_t kAllShellContainerIds[] = {
kShellWindowId_ScreenRotationContainer,
kShellWindowId_NonLockScreenContainersContainer,
kShellWindowId_LockScreenContainersContainer,
kShellWindowId_LockScreenRelatedContainersContainer,
kShellWindowId_UnparentedControlContainer,
kShellWindowId_WallpaperContainer,
kShellWindowId_VirtualKeyboardContainer,
kShellWindowId_DefaultContainerDeprecated,
kShellWindowId_AlwaysOnTopContainer,
kShellWindowId_AppListContainer,
kShellWindowId_HomeScreenContainer,
kShellWindowId_ArcImeWindowParentContainer,
kShellWindowId_ArcVirtualKeyboardContainer,
kShellWindowId_ShelfContainer,
kShellWindowId_ShelfBubbleContainer,
kShellWindowId_SystemModalContainer,
kShellWindowId_LockScreenWallpaperContainer,
kShellWindowId_LockScreenContainer,
kShellWindowId_LockActionHandlerContainer,
kShellWindowId_LockSystemModalContainer,
kShellWindowId_StatusContainer,
kShellWindowId_ImeWindowParentContainer,
kShellWindowId_MenuContainer,
kShellWindowId_DragImageAndTooltipContainer,
kShellWindowId_PowerMenuContainer,
kShellWindowId_SettingBubbleContainer,
kShellWindowId_AccessibilityPanelContainer,
kShellWindowId_AutoclickContainer,
kShellWindowId_OverlayContainer,
kShellWindowId_DockedMagnifierContainer,
kShellWindowId_MouseCursorContainer,
kShellWindowId_AlwaysOnTopWallpaperContainer,
kShellWindowId_PowerButtonAnimationContainer,
};
// A list of system modal container IDs. The order of the list is important that
// the more restrictive container appears before the less restrictive ones.
const int32_t kSystemModalContainerIds[] = {
constexpr int kSystemModalContainerIds[] = {
kShellWindowId_LockSystemModalContainer,
kShellWindowId_SystemModalContainer};
// These are the list of container ids of containers which may contain windows
// that need to be activated.
ASH_PUBLIC_EXPORT extern const int32_t kActivatableShellWindowIds[];
ASH_PUBLIC_EXPORT extern const size_t kNumActivatableShellWindowIds;
// Returns the list of container ids of containers which may contain windows
// that need to be activated. this list is ordered by the activation order; that
// is, windows in containers appearing earlier in the list are activated before
// windows in containers appearing later in the list. This list is used by
// AshFocusRules to determine which container to start the search from when
// looking for the next activatable window.
ASH_PUBLIC_EXPORT std::vector<int> GetActivatableShellWindowIds();
// Returns true if |id| is in |kActivatableShellWindowIds|.
ASH_PUBLIC_EXPORT bool IsActivatableShellWindowId(int32_t id);
ASH_PUBLIC_EXPORT bool IsActivatableShellWindowId(int id);
} // namespace ash
......
......@@ -211,9 +211,7 @@ void ReparentWindow(aura::Window* window, aura::Window* new_parent) {
// Reparents the appropriate set of windows from |src| to |dst|.
void ReparentAllWindows(aura::Window* src, aura::Window* dst) {
// Set of windows to move.
const int kContainerIdsToMove[] = {
// TODO(afakhry): Add rest of desks containers.
kShellWindowId_DefaultContainerDeprecated,
constexpr int kContainerIdsToMove[] = {
kShellWindowId_AlwaysOnTopContainer,
kShellWindowId_PipContainer,
kShellWindowId_SystemModalContainer,
......@@ -222,18 +220,22 @@ void ReparentAllWindows(aura::Window* src, aura::Window* dst) {
kShellWindowId_OverlayContainer,
kShellWindowId_LockActionHandlerContainer,
};
const int kExtraContainerIdsToMoveInUnifiedMode[] = {
constexpr int kExtraContainerIdsToMoveInUnifiedMode[] = {
kShellWindowId_LockScreenContainer,
};
std::vector<int> container_ids(
kContainerIdsToMove,
kContainerIdsToMove + base::size(kContainerIdsToMove));
// The list of desks containers depends on whether the Virtual Desks feature
// is enabled or not.
std::vector<int> container_ids = desks_util::GetDesksContainersIds();
for (const int id : kContainerIdsToMove)
container_ids.emplace_back(id);
// Check the display mode as this is also necessary when trasitioning between
// mirror and unified mode.
if (Shell::Get()->display_manager()->current_default_multi_display_mode() ==
display::DisplayManager::UNIFIED) {
for (int id : kExtraContainerIdsToMoveInUnifiedMode)
container_ids.push_back(id);
for (const int id : kExtraContainerIdsToMoveInUnifiedMode)
container_ids.emplace_back(id);
}
for (int id : container_ids) {
......@@ -563,13 +565,14 @@ void RootWindowController::CloseChildWindows() {
return;
did_close_child_windows_ = true;
aura::Window* root = GetRootWindow();
// Notify the keyboard controller before closing child windows and shutting
// down associated layout managers.
Shell::Get()->ash_keyboard_controller()->OnRootWindowClosing(GetRootWindow());
Shell::Get()->ash_keyboard_controller()->OnRootWindowClosing(root);
shelf_->ShutdownShelfWidget();
aura::Window* root = GetRootWindow();
ClearWorkspaceControllers(root);
// Explicitly destroy top level windows. We do this because such windows may
......
......@@ -94,7 +94,7 @@ const char ShelfWindowWatcher::kDefaultShelfIdPrefix[] = "ShelfWindowWatcher";
void ShelfWindowWatcher::ContainerWindowObserver::OnWindowHierarchyChanged(
const HierarchyChangeParams& params) {
if (!params.old_parent && params.new_parent &&
desks_util::IsDeskContainerId(params.new_parent->id())) {
desks_util::IsDeskContainer(params.new_parent)) {
// A new window was created in one of the desks' containers. Note that the
// shelf is globally showing all apps from all active and inactive desks.
window_watcher_->OnUserWindowAdded(params.target);
......
......@@ -6,11 +6,13 @@
#include <algorithm>
#include <memory>
#include <queue>
#include <vector>
#include "ash/display/mouse_cursor_event_filter.h"
#include "ash/drag_drop/drag_drop_controller.h"
#include "ash/drag_drop/drag_drop_controller_test_api.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/scoped_root_window_for_new_windows.h"
......@@ -28,8 +30,10 @@
#include "ash/wm/desks/desks_util.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "base/containers/flat_set.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/account_id/account_id.h"
#include "components/prefs/testing_pref_service.h"
......@@ -72,18 +76,35 @@ aura::Window* GetAlwaysOnTopContainer() {
// Expect ALL the containers!
void ExpectAllContainers() {
aura::Window* root_window = Shell::GetPrimaryRootWindow();
// Validate no duplicate container IDs.
const size_t all_shell_container_ids_size = base::size(kAllShellContainerIds);
std::set<int32_t> container_ids;
for (size_t i = 0; i < all_shell_container_ids_size; ++i)
EXPECT_TRUE(container_ids.insert(kAllShellContainerIds[i]).second);
base::flat_set<int> container_ids;
std::queue<aura::Window*> window_queue;
window_queue.push(root_window);
while (!window_queue.empty()) {
aura::Window* current_window = window_queue.front();
window_queue.pop();
for (aura::Window* child : current_window->children())
window_queue.push(child);
const int id = current_window->id();
// Skip windows with no IDs.
if (id == aura::Window::kInitialId)
continue;
EXPECT_TRUE(container_ids.insert(id).second)
<< "Found duplicate ID: " << id
<< " at window: " << current_window->GetName();
}
aura::Window* root_window = Shell::GetPrimaryRootWindow();
EXPECT_TRUE(
Shell::GetContainer(root_window, kShellWindowId_WallpaperContainer));
// TODO(afakhry): Test rest of desks containers.
EXPECT_TRUE(Shell::GetContainer(root_window,
kShellWindowId_DefaultContainerDeprecated));
for (int desk_id : desks_util::GetDesksContainersIds())
EXPECT_TRUE(Shell::GetContainer(root_window, desk_id));
EXPECT_TRUE(
Shell::GetContainer(root_window, kShellWindowId_AlwaysOnTopContainer));
EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_ShelfContainer));
......@@ -677,4 +698,38 @@ TEST_F(ShellLoginTest, DragAndDropDisabledBeforeLogin) {
EXPECT_TRUE(drag_drop_controller_test_api.enabled());
}
// Defines a parameterized test fixture to validate that there are no duplicate
// containers IDs in both cases when the Virtual Desks feature is enabled or
// disabled.
class NoDuplicateShellContainerIdsTest
: public AshTestBase,
public ::testing::WithParamInterface<bool> {
public:
NoDuplicateShellContainerIdsTest() = default;
~NoDuplicateShellContainerIdsTest() override = default;
// AshTestBase:
void SetUp() override {
if (GetParam())
scoped_feature_list_.InitAndEnableFeature(features::kVirtualDesks);
else
scoped_feature_list_.InitAndDisableFeature(features::kVirtualDesks);
AshTestBase::SetUp();
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(NoDuplicateShellContainerIdsTest);
};
TEST_P(NoDuplicateShellContainerIdsTest, ValidateContainersIds) {
ExpectAllContainers();
}
INSTANTIATE_TEST_SUITE_P(,
NoDuplicateShellContainerIdsTest,
::testing::Values(false, true));
} // namespace ash
......@@ -12,6 +12,7 @@
#include "ash/wm/desks/desks_util.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/window_state.h"
#include "base/stl_util.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/events/event.h"
......@@ -42,7 +43,8 @@ bool BelongsToContainerWithId(const aura::Window* window, int container_id) {
////////////////////////////////////////////////////////////////////////////////
// AshFocusRules, public:
AshFocusRules::AshFocusRules() = default;
AshFocusRules::AshFocusRules()
: activatable_container_ids_(GetActivatableShellWindowIds()) {}
AshFocusRules::~AshFocusRules() = default;
......@@ -57,11 +59,12 @@ bool AshFocusRules::IsToplevelWindow(const aura::Window* window) const {
// The window must exist within a container that supports activation.
// The window cannot be blocked by a modal transient.
return IsActivatableShellWindowId(window->parent()->id());
return base::ContainsValue(activatable_container_ids_,
window->parent()->id());
}
bool AshFocusRules::SupportsChildActivation(const aura::Window* window) const {
return ash::IsActivatableShellWindowId(window->id());
return base::ContainsValue(activatable_container_ids_, window->id());
}
bool AshFocusRules::IsWindowConsideredVisibleForActivation(
......@@ -153,10 +156,10 @@ aura::Window* AshFocusRules::GetNextActivatableWindow(
aura::Window* root = starting_window->GetRootWindow();
if (!root)
root = Shell::GetRootWindowForNewWindows();
int container_count = static_cast<int>(kNumActivatableShellWindowIds);
int container_count = activatable_container_ids_.size();
for (int i = 0; i < container_count; i++) {
aura::Window* container =
Shell::GetContainer(root, kActivatableShellWindowIds[i]);
Shell::GetContainer(root, activatable_container_ids_[i]);
if (container && container->Contains(starting_window)) {
starting_container_index = i;
break;
......@@ -182,7 +185,7 @@ aura::Window* AshFocusRules::GetTopmostWindowToActivateForContainerIndex(
aura::Window* window = nullptr;
aura::Window* root = ignore ? ignore->GetRootWindow() : nullptr;
aura::Window::Windows containers = wm::GetContainersFromAllRootWindows(
kActivatableShellWindowIds[index], root);
activatable_container_ids_[index], root);
for (aura::Window* container : containers) {
window = GetTopmostWindowToActivateInContainer(container, ignore);
if (window)
......
......@@ -5,6 +5,8 @@
#ifndef ASH_WM_ASH_FOCUS_RULES_H_
#define ASH_WM_ASH_FOCUS_RULES_H_
#include <vector>
#include "ash/ash_export.h"
#include "base/macros.h"
#include "ui/wm/core/base_focus_rules.h"
......@@ -34,6 +36,10 @@ class ASH_EXPORT AshFocusRules : public ::wm::BaseFocusRules {
aura::Window* container,
aura::Window* ignore) const;
// List of container IDs in the order of actiavation. This list doesn't change
// for the lifetime of this object.
const std::vector<int> activatable_container_ids_;
DISALLOW_COPY_AND_ASSIGN(AshFocusRules);
};
......
......@@ -4,7 +4,10 @@
#include "ash/wm/desks/desks_util.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/wm/desks/desk.h"
#include "ash/wm/desks/desks_controller.h"
#include "ui/aura/window.h"
namespace ash {
......@@ -14,22 +17,37 @@ namespace desks_util {
namespace {
constexpr std::array<int, kMaxNumberOfDesks> kDesksContainersIds = {
// TODO(afakhry): Fill this.
kShellWindowId_DefaultContainerDeprecated,
kShellWindowId_DeskContainerB,
kShellWindowId_DeskContainerC,
kShellWindowId_DeskContainerD,
};
} // namespace
const std::array<int, kMaxNumberOfDesks>& GetDesksContainersIds() {
return kDesksContainersIds;
std::vector<int> GetDesksContainersIds() {
if (!features::IsVirtualDesksEnabled())
return std::vector<int>({kShellWindowId_DefaultContainerDeprecated});
return std::vector<int>(kDesksContainersIds.begin(),
kDesksContainersIds.end());
}
const char* GetDeskContainerName(int container_id) {
DCHECK(IsDeskContainerId(container_id));
switch (container_id) {
case kShellWindowId_DefaultContainerDeprecated:
return "Desk_Container_A";
// TODO(afakhry): Fill this.
case kShellWindowId_DeskContainerB:
return "Desk_Container_B";
case kShellWindowId_DeskContainerC:
return "Desk_Container_C";
case kShellWindowId_DeskContainerD:
return "Desk_Container_D";
default:
NOTREACHED();
......@@ -42,7 +60,7 @@ std::vector<aura::Window*> GetDesksContainers(aura::Window* root) {
DCHECK(root->IsRootWindow());
std::vector<aura::Window*> containers;
for (const auto& id : kDesksContainersIds) {
for (const auto& id : GetDesksContainersIds()) {
auto* container = root->GetChildById(id);
DCHECK(container);
containers.emplace_back(container);
......@@ -53,18 +71,18 @@ std::vector<aura::Window*> GetDesksContainers(aura::Window* root) {
bool IsDeskContainer(const aura::Window* container) {
DCHECK(container);
// TODO(afakhry): Add the rest of the desks containers.
return container->id() == kShellWindowId_DefaultContainerDeprecated;
return IsDeskContainerId(container->id());
}
bool IsDeskContainerId(int id) {
// TODO(afakhry): Add the rest of the desks containers.
return id == kShellWindowId_DefaultContainerDeprecated;
return id == kShellWindowId_DefaultContainerDeprecated ||
id == kShellWindowId_DeskContainerB ||
id == kShellWindowId_DeskContainerC ||
id == kShellWindowId_DeskContainerD;
}
int GetActiveDeskContainerId() {
// TODO(afakhry): Do proper checking when the other desks containers are
// added.
// TODO(afakhry): Return the correct ID based on the currently active app.
return kShellWindowId_DefaultContainerDeprecated;
}
......
......@@ -18,11 +18,9 @@ namespace ash {
namespace desks_util {
// TODO(afakhry): Fix the size of the array when you add the rest of the desks'
// containters.
constexpr size_t kMaxNumberOfDesks = 1;
constexpr size_t kMaxNumberOfDesks = 4;
ASH_EXPORT const std::array<int, kMaxNumberOfDesks>& GetDesksContainersIds();
ASH_EXPORT std::vector<int> GetDesksContainersIds();
ASH_EXPORT std::vector<aura::Window*> GetDesksContainers(aura::Window* root);
......
......@@ -106,9 +106,9 @@ MruWindowTracker::WindowList BuildWindowListInternal(
// |wm::kSwitchableWindowContainerIds[]| contains a list of the container
// IDs sorted such that the ID of the top-most container comes last. Hence,
// we iterate in reverse order so the top-most windows are added first.
for (int i = wm::kSwitchableWindowContainerIdsLength - 1; i >= 0; --i) {
aura::Window* container =
root->GetChildById(wm::kSwitchableWindowContainerIds[i]);
const auto switachable_containers =
wm::GetSwitchableContainersForRoot(root);
for (auto* container : base::Reversed(switachable_containers)) {
for (auto* child : base::Reversed(container->children())) {
// Only add windows that the predicate allows.
if (!can_include_window_predicate(child))
......
......@@ -203,9 +203,7 @@ void OverviewSession::Init(const WindowList& windows,
for (auto* root : root_windows) {
// Observed switchable containers for newly created windows on all root
// windows.
for (size_t i = 0; i < wm::kSwitchableWindowContainerIdsLength; ++i) {
aura::Window* container =
root->GetChildById(wm::kSwitchableWindowContainerIds[i]);
for (auto* container : wm::GetSwitchableContainersForRoot(root)) {
container->AddObserver(this);
observed_windows_.insert(container);
}
......@@ -756,13 +754,11 @@ void OverviewSession::OnWindowHierarchyChanged(
return;
}
for (size_t i = 0; i < wm::kSwitchableWindowContainerIdsLength; ++i) {
if (new_window->parent()->id() == wm::kSwitchableWindowContainerIds[i] &&
!::wm::GetTransientParent(new_window)) {
// The new window is in one of the switchable containers, abort overview.
CancelSelection();
return;
}
if (wm::IsSwitchableContainer(new_window->parent()) &&
!::wm::GetTransientParent(new_window)) {
// The new window is in one of the switchable containers, abort overview.
CancelSelection();
return;
}
}
......
......@@ -4,6 +4,9 @@
#include "ash/wm/switchable_windows.h"
#include <array>
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "base/stl_util.h"
#include "ui/aura/window.h"
......@@ -11,22 +14,59 @@
namespace ash {
namespace wm {
const int kSwitchableWindowContainerIds[] = {
namespace {
// TODO(afakhry): Consolidate the below lists when we launch Virtual Desks.
// The list of switchable containers IDs when the Virtual Desks feature is
// enabled.
constexpr std::array<int, 5> kSwitchableContainersWithDesks = {
kShellWindowId_DefaultContainerDeprecated,
kShellWindowId_DeskContainerB,
kShellWindowId_DeskContainerC,
kShellWindowId_DeskContainerD,
kShellWindowId_AlwaysOnTopContainer,
};
// The list of switchable containers IDs when the Virtual Desks feature is
// disabled.
constexpr std::array<int, 2> kSwitchableContainersNoDesks = {
kShellWindowId_DefaultContainerDeprecated,
kShellWindowId_AlwaysOnTopContainer};
kShellWindowId_AlwaysOnTopContainer,
};
std::vector<int> GetSwitchableContainersIds() {
if (!features::IsVirtualDesksEnabled()) {
return std::vector<int>(kSwitchableContainersNoDesks.begin(),
kSwitchableContainersNoDesks.end());
}
return std::vector<int>(kSwitchableContainersWithDesks.begin(),
kSwitchableContainersWithDesks.end());
}
const size_t kSwitchableWindowContainerIdsLength =
base::size(kSwitchableWindowContainerIds);
} // namespace
std::vector<aura::Window*> GetSwitchableContainersForRoot(aura::Window* root) {
DCHECK(root);
DCHECK(root->IsRootWindow());
std::vector<aura::Window*> containers;
for (const auto& id : GetSwitchableContainersIds()) {
auto* container = root->GetChildById(id);
DCHECK(container);
containers.emplace_back(container);
}
return containers;
}
// TODO(afakhry): Rename this to a better name.
bool IsSwitchableContainer(const aura::Window* window) {
if (!window)
return false;
const int shell_window_id = window->id();
for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) {
if (shell_window_id == kSwitchableWindowContainerIds[i])
return true;
}
return false;
return base::ContainsValue(GetSwitchableContainersIds(), shell_window_id);
}
} // namespace wm
......
......@@ -5,10 +5,9 @@
#ifndef ASH_WM_SWITCHABLE_WINDOWS_H_
#define ASH_WM_SWITCHABLE_WINDOWS_H_
#include <stddef.h>
#include <vector>
#include "ash/ash_export.h"
#include "base/macros.h"
namespace aura {
class Window;
......@@ -17,11 +16,8 @@ class Window;
namespace ash {
namespace wm {
// List of containers which contain windows that can be switched via Alt+Tab to.
ASH_EXPORT extern const int kSwitchableWindowContainerIds[];
// The number of elements in kSwitchableWindowContainerIds.
ASH_EXPORT extern const size_t kSwitchableWindowContainerIdsLength;
ASH_EXPORT std::vector<aura::Window*> GetSwitchableContainersForRoot(
aura::Window* root);
// Returns true if |window| is a container for windows which can be switched to.
ASH_EXPORT bool IsSwitchableContainer(const aura::Window* window);
......
......@@ -164,8 +164,8 @@ class TabletModeWindowManagerTest : public AshTestBase {
behavior |= params.can_resize ? ws::mojom::kResizeBehaviorCanResize : 0;
behavior |= params.can_maximize ? ws::mojom::kResizeBehaviorCanMaximize : 0;
window->SetProperty(aura::client::kResizeBehaviorKey, behavior);
aura::Window* container = Shell::GetContainer(
Shell::GetPrimaryRootWindow(), wm::kSwitchableWindowContainerIds[0]);
aura::Window* container =
wm::GetSwitchableContainersForRoot(Shell::GetPrimaryRootWindow())[0];
container->AddChild(window);
return window;
}
......
......@@ -168,8 +168,6 @@ std::unique_ptr<WindowResizer> CreateWindowResizer(
return nullptr;
window_state->CreateDragDetails(point_in_parent, window_component, source);
const int parent_shell_window_id =
window->parent() ? window->parent()->id() : -1;
// TODO(varkha): The chaining of window resizers causes some of the logic
// to be repeated and the logic flow difficult to control. With some windows
......@@ -181,10 +179,11 @@ std::unique_ptr<WindowResizer> CreateWindowResizer(
// layout manager that a drag has started or stopped. It may be possible to
// refactor and eliminate chaining.
std::unique_ptr<WindowResizer> window_resizer;
if (window->parent() &&
const auto* parent = window->parent();
if (parent &&
// TODO(afakhry): Maybe use switchable containers?
(desks_util::IsDeskContainerId(parent_shell_window_id) ||
parent_shell_window_id == kShellWindowId_AlwaysOnTopContainer)) {
(desks_util::IsDeskContainer(parent) ||
parent->id() == kShellWindowId_AlwaysOnTopContainer)) {
window_resizer.reset(WorkspaceWindowResizer::Create(
window_state, std::vector<aura::Window*>()));
} else {
......
......@@ -12,6 +12,7 @@ specific_include_rules = {
],
"desktop_media_list_ash\.cc": [
"+ash/shell.h",
"+ash/wm/desks/desks_util.h",
],
# TODO(mash): Fix. https://crbug.com/855147
"media_capture_devices_dispatcher\.cc": [
......
......@@ -6,6 +6,7 @@
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "ash/wm/desks/desks_util.h"
#include "base/bind.h"
#include "chrome/grit/generated_resources.h"
#include "media/base/video_util.h"
......@@ -108,15 +109,15 @@ void DesktopMediaListAsh::EnumerateSources(
CaptureThumbnail(screen_source.id, root_windows[i]);
} else {
constexpr int kContainersIds[] = {
ash::kShellWindowId_DefaultContainerDeprecated,
// TODO(afakhry): Add rest of desks containers.
ash::kShellWindowId_AlwaysOnTopContainer,
ash::kShellWindowId_PipContainer,
};
for (int id : kContainersIds)
EnumerateWindowsForRoot(sources, root_windows[i], id);
// The list of desks containers depends on whether the Virtual Desks
// feature is enabled or not.
for (int desk_id : ash::desks_util::GetDesksContainersIds())
EnumerateWindowsForRoot(sources, root_windows[i], desk_id);
EnumerateWindowsForRoot(sources, root_windows[i],
ash::kShellWindowId_AlwaysOnTopContainer);
EnumerateWindowsForRoot(sources, root_windows[i],
ash::kShellWindowId_PipContainer);
}
}
}
......
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