Commit 9eb4c3c1 authored by chinsenj's avatar chinsenj Committed by Chromium LUCI CQ

cros: Visible on all desks windows appear in all desks' preview views.

Currently visible on all desks windows only appear in the active desk's
view. They should appear on all desks' preview views.

This CL augments DeskPreviewView to mirror visible on all desks windows
as well.

Test: manual
Bug: 1163691
Change-Id: I763330edc2567aa6c96f9a418498207020cb5353
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2616326
Commit-Queue: Jeremy Chinsen <chinsenj@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842805}
parent 74e43623
......@@ -8,12 +8,19 @@
#include <utility>
#include "ash/multi_user/multi_user_window_manager_impl.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/shell.h"
#include "ash/wallpaper/wallpaper_base_view.h"
#include "ash/wm/desks/desk_mini_view.h"
#include "ash/wm/desks/desks_controller.h"
#include "ash/wm/desks/desks_util.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/window_state.h"
#include "ash/wm/wm_highlight_item_border.h"
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_tree_owner.h"
#include "ui/compositor/layer_type.h"
......@@ -63,6 +70,11 @@ struct LayerData {
// should always be visible (even for inactive desks) to be able to see their
// contents in the mini_views.
bool should_force_mirror_visible = false;
// If true, transformations will be cleared for this layer. This is used,
// for example, for visible on all desk windows to clear their overview
// transformation since they don't belong to inactive desks.
bool should_clear_transform = false;
};
// Returns true if |window| can be shown in the desk's preview according to its
......@@ -83,14 +95,51 @@ bool CanShowWindowForMultiProfile(aura::Window* window) {
return account_id == multi_user_window_manager->CurrentAccountId();
}
// Appends clones of all the visible on all desks windows' layers to
// |out_desk_container_children|. Should only be called if
// |visible_on_all_desks_windows| is not empty.
void AppendVisibleOnAllDesksWindowsToDeskLayer(
const base::flat_set<aura::Window*>& visible_on_all_desks_windows,
std::vector<ui::Layer*>* out_desk_container_children) {
DCHECK(!visible_on_all_desks_windows.empty());
auto mru_windows =
Shell::Get()->mru_window_tracker()->BuildMruWindowList(kAllDesks);
for (auto* window : visible_on_all_desks_windows) {
auto window_iter =
std::find(mru_windows.begin(), mru_windows.end(), window);
DCHECK(window_iter != mru_windows.end());
auto closest_window_below_iter = std::next(window_iter);
while (closest_window_below_iter != mru_windows.end() &&
!base::Contains(*out_desk_container_children,
(*closest_window_below_iter)->layer())) {
// Find the closest window to |window| in the MRU tracker whose layer also
// is in |out_desk_container_children|. This window will be used to
// determine the stacking order of the visible on all desks window in the
// preview view.
closest_window_below_iter = std::next(closest_window_below_iter);
}
auto insertion_point_iter =
closest_window_below_iter == mru_windows.end()
? out_desk_container_children->begin()
: std::next(std::find(out_desk_container_children->begin(),
out_desk_container_children->end(),
(*closest_window_below_iter)->layer()));
out_desk_container_children->insert(insertion_point_iter, window->layer());
}
}
// Recursively mirrors |source_layer| and its children and adds them as children
// of |parent|, taking into account the given |layers_data|.
// The transforms of the mirror layers of the direct children of
// |desk_container_layer| will be reset to identity.
void MirrorLayerTree(ui::Layer* desk_container_layer,
ui::Layer* source_layer,
// of |parent|, taking into account the given |layers_data|. If the layer data
// of |source_layer| has |should_clear_transform| set to true, the transforms of
// its mirror layers will be reset to identity.
void MirrorLayerTree(ui::Layer* source_layer,
ui::Layer* parent,
const base::flat_map<ui::Layer*, LayerData>& layers_data) {
const base::flat_map<ui::Layer*, LayerData>& layers_data,
const base::flat_set<aura::Window*>&
visible_on_all_desks_windows_to_mirror) {
const auto iter = layers_data.find(source_layer);
const LayerData layer_data =
iter == layers_data.end() ? LayerData{} : iter->second;
......@@ -100,8 +149,20 @@ void MirrorLayerTree(ui::Layer* desk_container_layer,
auto* mirror = source_layer->Mirror().release();
parent->Add(mirror);
for (auto* child : source_layer->children())
MirrorLayerTree(desk_container_layer, child, mirror, layers_data);
std::vector<ui::Layer*> children = source_layer->children();
if (!visible_on_all_desks_windows_to_mirror.empty()) {
// Windows that are visible on all desks should show up in each desk
// preview so for inactive desks, we need to append the layers of visible on
// all desks windows.
AppendVisibleOnAllDesksWindowsToDeskLayer(
visible_on_all_desks_windows_to_mirror, &children);
}
for (auto* child : children) {
// Visible on all desks windows only needed to be added to the subtree once
// so use an empty set for subsequent calls.
MirrorLayerTree(child, mirror, layers_data,
base::flat_set<aura::Window*>());
}
mirror->set_sync_bounds_with_source(true);
if (layer_data.should_force_mirror_visible) {
......@@ -110,10 +171,7 @@ void MirrorLayerTree(ui::Layer* desk_container_layer,
mirror->set_sync_visibility_with_source(false);
}
// Windows in overview mode are transformed into their positions in the grid,
// but we want to show a preview of the windows in their untransformed state
// outside of overview mode.
if (source_layer->parent() == desk_container_layer)
if (layer_data.should_clear_transform)
mirror->SetTransform(gfx::Transform());
}
......@@ -150,6 +208,15 @@ void GetLayersData(aura::Window* window,
if (window->GetProperty(kForceVisibleInMiniViewKey))
layer_data.should_force_mirror_visible = true;
// Visible on all desks windows aren't children of inactive desk's container
// so mark them explicitly to clear overview transforms. Additionally, windows
// in overview mode are transformed into their positions in the grid, but we
// want to show a preview of the windows in their untransformed state.
if (window->GetProperty(aura::client::kVisibleOnAllWorkspacesKey) ||
desks_util::IsDeskContainer(window->parent())) {
layer_data.should_clear_transform = true;
}
for (auto* child : window->children())
GetLayersData(child, out_layers_data);
}
......@@ -289,9 +356,22 @@ void DeskPreviewView::RecreateDeskContentsMirrorLayers() {
mirrored_content_root_layer->SetName("mirrored contents root layer");
base::flat_map<ui::Layer*, LayerData> layers_data;
GetLayersData(desk_container, &layers_data);
base::flat_set<aura::Window*> visible_on_all_desks_windows_to_mirror;
if (features::IsBentoEnabled() &&
!desks_util::IsActiveDeskContainer(desk_container)) {
// Since visible on all desks windows reside on the active desk, only mirror
// them in the layer tree if |this| is not the preview view for the active
// desk.
visible_on_all_desks_windows_to_mirror =
Shell::Get()->desks_controller()->visible_on_all_desks_windows();
for (auto* window : visible_on_all_desks_windows_to_mirror)
GetLayersData(window, &layers_data);
}
auto* desk_container_layer = desk_container->layer();
MirrorLayerTree(desk_container_layer, desk_container_layer,
mirrored_content_root_layer.get(), layers_data);
MirrorLayerTree(desk_container_layer, mirrored_content_root_layer.get(),
layers_data, visible_on_all_desks_windows_to_mirror);
// Add the root of the mirrored layer tree as a child of the
// |desk_mirrored_contents_view_|'s layer.
......
......@@ -546,6 +546,9 @@ bool DesksController::MoveWindowFromActiveDeskTo(
}
void DesksController::AddVisibleOnAllDesksWindow(aura::Window* window) {
if (!features::IsBentoEnabled())
return;
const bool added = visible_on_all_desks_windows_.emplace(window).second;
DCHECK(added);
}
......
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