Skip to content

Commit

Permalink
desk_templates: Add num_(incognito|unsupported)_windows to overview_g…
Browse files Browse the repository at this point in the history
…rid.

This is part of the work to determine unsupported window types to
display them to users (e.g. Save Template Button tooltip text).

Test: added
Bug: 1286466
Change-Id: I2f95b38caa76f7e36e9e26cfffb63a08c8d88d95
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3465430
Reviewed-by: Sammie Quon <sammiequon@chromium.org>
Commit-Queue: Sophie Wen <sophiewen@google.com>
Cr-Commit-Position: refs/heads/main@{#972289}
  • Loading branch information
Sophie Wen authored and Chromium LUCI CQ committed Feb 17, 2022
1 parent 03af733 commit 2a39353
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ash/wm/desks/templates/desks_templates_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,31 @@ TEST_F(DesksTemplatesTest, AddRemoveSupportedWindows) {
EXPECT_EQ(0, desk_1->num_supported_windows());
}

// Tests that adding and removing unsupported windows is counted correctly.
TEST_F(DesksTemplatesTest, AddRemoveUnsupportedWindows) {
auto window1 = CreateTestWindow();
auto window2 = CreateTestWindow();

ToggleOverview();
EXPECT_TRUE(InOverviewSession());

EXPECT_EQ(0, GetOverviewGridList()[0]->num_incognito_windows());
EXPECT_EQ(2, GetOverviewGridList()[0]->num_unsupported_windows());

window1.reset();

// Expect `num_unsupported_windows_` to be 0.
EXPECT_EQ(0, GetOverviewGridList()[0]->num_incognito_windows());
EXPECT_EQ(1, GetOverviewGridList()[0]->num_unsupported_windows());

window2.reset();

// Re-open overview because all the windows closing caused it to close too.
ToggleOverview();
EXPECT_EQ(0, GetOverviewGridList()[0]->num_incognito_windows());
EXPECT_EQ(0, GetOverviewGridList()[0]->num_unsupported_windows());
}

// Tests the mouse and touch hover behavior on the template item view.
TEST_F(DesksTemplatesTest, HoverOnTemplateItemView) {
auto test_window = CreateAppWindow();
Expand Down
34 changes: 34 additions & 0 deletions ash/wm/overview/overview_grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "base/numerics/safe_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/ui/base/window_properties.h"
#include "components/app_restore/full_restore_utils.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/compositor_observer.h"
Expand Down Expand Up @@ -445,6 +446,8 @@ OverviewGrid::OverviewGrid(aura::Window* root_window,
window->layer()->GetAnimator()->StopAnimating();
window_list_.push_back(
std::make_unique<OverviewItem>(window, overview_session_, this));

UpdateNumIncognitoUnsupportedWindows(window, /*increment*/true);
}
}

Expand Down Expand Up @@ -643,6 +646,8 @@ void OverviewGrid::AddItem(aura::Window* window,
DCHECK(!GetOverviewItemContaining(window));
DCHECK_LE(index, window_list_.size());

UpdateNumIncognitoUnsupportedWindows(window, /*increment*/true);

window_list_.insert(
window_list_.begin() + index,
std::make_unique<OverviewItem>(window, overview_session_, this));
Expand Down Expand Up @@ -706,6 +711,9 @@ void OverviewGrid::RemoveItem(OverviewItem* overview_item,
base::MatchesUniquePtr(overview_item));
DCHECK(iter != window_list_.rend());

UpdateNumIncognitoUnsupportedWindows(overview_item->GetWindow(),
/*increment*/false);

// This can also be called when shutting down |this|, at which the item will
// be cleaning up and its associated view may be nullptr. |overview_item|
// needs to still be in |window_list_| so we can compute what the deleted
Expand Down Expand Up @@ -2403,6 +2411,32 @@ void OverviewGrid::OnSaveDeskAsTemplateButtonFadedOut() {
save_desk_as_template_widget_->Hide();
}

void OverviewGrid::UpdateNumIncognitoUnsupportedWindows(aura::Window* window,
bool increment) {
if (!desks_templates_util::AreDesksTemplatesEnabled())
return;

// Count apps without full restore in `num_unsupported_windows_`. This is to
// ensure Save Template behavior, which will disable the button if
// num_unsupported_windows_ == window_list.size().
// TODO(crbug.com/1297710): Separate apps without Full Restore app id from
// unsupported apps so that they are not labeled as "Linux" apps in text.
const bool has_restore_id =
wm::GetTransientParent(window) &&
(Shell::Get()
->desks_controller()
->disable_app_id_check_for_desk_templates() ||
!full_restore::GetAppId(window).empty());
int addend = increment ? 1 : -1;
if (!ash::DeskTemplate::IsAppTypeSupported(window) || !has_restore_id)
num_unsupported_windows_ += addend;
else if (Shell::Get()->desks_templates_delegate()->IsIncognitoWindow(window))
num_incognito_windows_ += addend;

DCHECK_GE(num_unsupported_windows_, 0);
DCHECK_GE(num_incognito_windows_, 0);
}

int OverviewGrid::GetDesksBarHeight() const {
const bool should_show_zero_state_desks_bar =
desks_bar_view_ ? desks_bar_view_->IsZeroState()
Expand Down
17 changes: 17 additions & 0 deletions ash/wm/overview/overview_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver,
return save_desk_as_template_widget_.get();
}

int num_incognito_windows() const { return num_incognito_windows_; }

int num_unsupported_windows() const { return num_unsupported_windows_; }

private:
class TargetWindowObserver;
friend class DesksTemplatesTest;
Expand Down Expand Up @@ -519,6 +523,11 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver,
// out is completed.
void OnSaveDeskAsTemplateButtonFadedOut();

// Either increment or decrement `num_incognito_windows_` and
// `num_unsupported_windows`.
void UpdateNumIncognitoUnsupportedWindows(aura::Window* window,
bool increment);

// Returns the height of `desks_bar_view_`.
int GetDesksBarHeight() const;

Expand Down Expand Up @@ -608,6 +617,14 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver,
// pressed.
std::unique_ptr<views::Widget> save_desk_as_template_widget_;

// The number of incognito windows in this grid. Used by Desk Templates to
// identify the unsupported window type to the user.
int num_incognito_windows_ = 0;

// The number of unsupported windows in this grid. Used by Desk Templates to
// identify the unsupported window type to the user.
int num_unsupported_windows_ = 0;

base::WeakPtrFactory<OverviewGrid> weak_ptr_factory_{this};
};

Expand Down

0 comments on commit 2a39353

Please sign in to comment.