saved_desks: Remain in the saved desk library when empty.
This changes the saved desk library so that we don't automatically transition out of the UI when the last saved desk is deleted. When this happens, a label is shown in the middle of the screen to indicate that there are, in fact, no saved desks. This CL re-uses the round label that the overview grid uses when there are no windows to show. The view class was previously stashed away in the .cc file of RoundedLabelWidget. We don't need the widget, just the view, so this CL also moves the view class out to its own file. Bug: 1310311 Change-Id: I1a2d99266ffabd7b30dcde21e83e53b605f5d571 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3653322 Reviewed-by: Yongshun Liu <yongshun@chromium.org> Reviewed-by: Sammie Quon <sammiequon@chromium.org> Commit-Queue: Daniel Andersson <dandersson@chromium.org> Cr-Commit-Position: refs/heads/main@{#1006645}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
bb73fea47e
commit
a68b69ae0e
@ -1958,6 +1958,8 @@ component("ash") {
|
||||
"wm/overview/overview_wallpaper_controller.h",
|
||||
"wm/overview/overview_window_drag_controller.cc",
|
||||
"wm/overview/overview_window_drag_controller.h",
|
||||
"wm/overview/rounded_label.cc",
|
||||
"wm/overview/rounded_label.h",
|
||||
"wm/overview/rounded_label_widget.cc",
|
||||
"wm/overview/rounded_label_widget.h",
|
||||
"wm/overview/scoped_overview_animation_settings.cc",
|
||||
|
@ -1901,6 +1901,12 @@ This file contains the strings for ash.
|
||||
<message name="IDS_ASH_DESKS_TEMPLATES_LIBRARY_SAVE_AND_RECALL_GRID_LABEL" desc="The label visible above the save and recall items in the saved desk library.">
|
||||
Saved for later
|
||||
</message>
|
||||
<message name="IDS_ASH_DESKS_TEMPLATES_LIBRARY_NO_TEMPLATES_OR_DESKS_LABEL" desc="The text that shows in the saved desk library when there are no saved desks or templates.">
|
||||
No saved desks or templates
|
||||
</message>
|
||||
<message name="IDS_ASH_DESKS_TEMPLATES_LIBRARY_NO_DESKS_LABEL" desc="The text that shows in the saved desk library when there are no saved desks.">
|
||||
No saved desks
|
||||
</message>
|
||||
|
||||
<!-- Virtual Desks -->
|
||||
<message name="IDS_ASH_DESKS_NEW_DESK_BUTTON" desc="The label of the new virtual desk (a.k.a. workspaces) button.">
|
||||
|
@ -0,0 +1 @@
|
||||
9851b83070260b7e9da863feb2e539ab2005f4ae
|
1
ash/ash_strings_grd/IDS_ASH_DESKS_TEMPLATES_LIBRARY_NO_TEMPLATES_OR_DESKS_LABEL.png.sha1
Normal file
1
ash/ash_strings_grd/IDS_ASH_DESKS_TEMPLATES_LIBRARY_NO_TEMPLATES_OR_DESKS_LABEL.png.sha1
Normal file
@ -0,0 +1 @@
|
||||
64e4304e1cc16ee69747ac0752aadc2804f127f8
|
@ -20,6 +20,7 @@
|
||||
#include "ash/wm/desks/templates/saved_desk_name_view.h"
|
||||
#include "ash/wm/desks/templates/saved_desk_util.h"
|
||||
#include "ash/wm/overview/overview_controller.h"
|
||||
#include "ash/wm/overview/rounded_label.h"
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/aura/window_targeter.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
@ -42,10 +43,15 @@ constexpr int kGridLabelFontSize = 16;
|
||||
// Grids use landscape mode if the available width is greater or equal to this.
|
||||
constexpr int kLandscapeMinWidth = 756;
|
||||
|
||||
// Label dimensions.
|
||||
// Section label dimensions.
|
||||
constexpr gfx::Size kLabelSizeLandscape = {708, 24};
|
||||
constexpr gfx::Size kLabelSizePortrait = {464, 24};
|
||||
|
||||
// "No items" label dimensions.
|
||||
constexpr gfx::Size kNoItemsLabelPadding = {16, 8};
|
||||
constexpr int kNoItemsLabelCornerRadius = 16;
|
||||
constexpr int kNoItemsLabelHeight = 32;
|
||||
|
||||
// Between child spacing of Library page scroll content view.
|
||||
constexpr int kLibraryPageScrollContentsBetweenChildSpacingDp = 32;
|
||||
|
||||
@ -260,6 +266,16 @@ SavedDeskLibraryView::SavedDeskLibraryView() {
|
||||
IDS_ASH_PERSISTENT_DESKS_BAR_CONTEXT_MENU_FEEDBACK),
|
||||
PillButton::Type::kIcon, &kPersistentDesksBarFeedbackIcon));
|
||||
|
||||
no_items_label_ =
|
||||
scroll_contents->AddChildView(std::make_unique<RoundedLabel>(
|
||||
kNoItemsLabelPadding.width(), kNoItemsLabelPadding.height(),
|
||||
kNoItemsLabelCornerRadius, kNoItemsLabelHeight,
|
||||
l10n_util::GetStringUTF16(
|
||||
saved_desk_util::AreDesksTemplatesEnabled()
|
||||
? IDS_ASH_DESKS_TEMPLATES_LIBRARY_NO_TEMPLATES_OR_DESKS_LABEL
|
||||
: IDS_ASH_DESKS_TEMPLATES_LIBRARY_NO_DESKS_LABEL)));
|
||||
no_items_label_->SetVisible(false);
|
||||
|
||||
scroll_view_->SetContents(std::move(scroll_contents));
|
||||
}
|
||||
|
||||
@ -426,6 +442,8 @@ void SavedDeskLibraryView::Layout() {
|
||||
: SavedDeskGridView::LayoutMode::PORTRAIT);
|
||||
}
|
||||
|
||||
size_t total_saved_desks = 0;
|
||||
|
||||
DCHECK_EQ(grid_views_.size(), grid_labels_.size());
|
||||
for (size_t i = 0; i != grid_views_.size(); ++i) {
|
||||
// Make the grid label invisible if the corresponding grid view is
|
||||
@ -433,8 +451,13 @@ void SavedDeskLibraryView::Layout() {
|
||||
grid_labels_[i]->SetVisible(!grid_views_[i]->grid_items().empty());
|
||||
grid_labels_[i]->SetPreferredSize(landscape ? kLabelSizeLandscape
|
||||
: kLabelSizePortrait);
|
||||
|
||||
total_saved_desks += grid_views_[i]->grid_items().size();
|
||||
}
|
||||
|
||||
feedback_button_->SetVisible(total_saved_desks != 0);
|
||||
no_items_label_->SetVisible(total_saved_desks == 0);
|
||||
|
||||
scroll_view_->SetBoundsRect({0, 0, width(), height()});
|
||||
scroll_view_gradient_helper_->UpdateGradientZone();
|
||||
}
|
||||
|
@ -113,6 +113,9 @@ class SavedDeskLibraryView : public views::View, public aura::WindowObserver {
|
||||
// TODO(crbug.com/1289880): Remove this button when it is no longer needed.
|
||||
PillButton* feedback_button_ = nullptr;
|
||||
|
||||
// Label that shows up when the library has no items.
|
||||
views::Label* no_items_label_ = nullptr;
|
||||
|
||||
// Handles mouse/touch events on saved desk library widget.
|
||||
std::unique_ptr<SavedDeskLibraryEventHandler> event_handler_;
|
||||
};
|
||||
|
@ -56,6 +56,8 @@ SavedDeskPresenter::SavedDeskPresenter(OverviewSession* overview_session)
|
||||
auto* desk_model = GetDeskModel();
|
||||
desk_model_observation_.Observe(desk_model);
|
||||
GetAllEntries(base::GUID(), Shell::GetPrimaryRootWindow());
|
||||
|
||||
should_show_templates_ui_ = GetEntryCount() > 0;
|
||||
}
|
||||
|
||||
SavedDeskPresenter::~SavedDeskPresenter() = default;
|
||||
@ -85,20 +87,34 @@ size_t SavedDeskPresenter::GetMaxSaveAndRecallDeskEntryCount() const {
|
||||
}
|
||||
|
||||
void SavedDeskPresenter::UpdateDesksTemplatesUI() {
|
||||
// The save as desk template button is hidden in tablet mode. The desks
|
||||
// templates button on the desk bar view and the desks templates grid are
|
||||
// hidden in tablet mode and if there no templates to view.
|
||||
// This function:
|
||||
// 1. Figures out whether the library button should be shown in the desk bar.
|
||||
// 2. Hides the library if necessary.
|
||||
// 3. Triggers save desk buttons in the overview overgrid to update.
|
||||
//
|
||||
// The library and the library button is always hidden if we enter tablet
|
||||
// mode. If not in tablet mode, the library button is visible if there are
|
||||
// saved desks in the model, *or* we are already showing the library.
|
||||
const bool in_tablet_mode =
|
||||
Shell::Get()->tablet_mode_controller()->InTabletMode();
|
||||
should_show_templates_ui_ = !in_tablet_mode && GetEntryCount() > 0u;
|
||||
|
||||
const bool has_saved_desks = GetEntryCount() > 0u;
|
||||
|
||||
for (auto& overview_grid : overview_session_->grid_list()) {
|
||||
if (!should_show_templates_ui_ &&
|
||||
overview_grid->IsShowingDesksTemplatesGrid()) {
|
||||
// When deleting, it is possible to delete the last template. In this
|
||||
// case, close the template grid and go back to overview.
|
||||
const bool is_showing_library =
|
||||
overview_grid->IsShowingDesksTemplatesGrid();
|
||||
|
||||
if (in_tablet_mode && is_showing_library) {
|
||||
// This happens when entering tablet mode while the library is visible.
|
||||
overview_grid->HideDesksTemplatesGrid(/*exit_overview=*/false);
|
||||
}
|
||||
|
||||
// The functions below reach into this class to determine whether the
|
||||
// buttons should be shown or not. If we are already showing saved desk
|
||||
// library, they should not go away (unless we're in tablet mode).
|
||||
should_show_templates_ui_ =
|
||||
!in_tablet_mode && (is_showing_library || has_saved_desks);
|
||||
|
||||
if (DesksBarView* desks_bar_view =
|
||||
const_cast<DesksBarView*>(overview_grid->desks_bar_view())) {
|
||||
desks_bar_view->UpdateDesksTemplatesButtonVisibility();
|
||||
|
@ -57,9 +57,14 @@ class SavedDeskLibraryViewTestApi {
|
||||
SavedDeskLibraryViewTestApi& operator=(SavedDeskLibraryViewTestApi&) = delete;
|
||||
~SavedDeskLibraryViewTestApi() = default;
|
||||
|
||||
void WaitForAnimationDone();
|
||||
const views::ScrollView* scroll_view() { return library_view_->scroll_view_; }
|
||||
|
||||
const views::Label* no_items_label() {
|
||||
return library_view_->no_items_label_;
|
||||
}
|
||||
|
||||
void WaitForAnimationDone();
|
||||
|
||||
private:
|
||||
SavedDeskLibraryView* library_view_;
|
||||
};
|
||||
|
@ -547,10 +547,8 @@ TEST_F(SavedDeskTest, NoWindowsLabelOnTemplateGridShow) {
|
||||
EXPECT_FALSE(grid_list[1]->no_windows_widget());
|
||||
}
|
||||
|
||||
// Tests that the no windows widget is shown when the last desk template is
|
||||
// deleted, forcing it out of desk template grid and return to overview mode
|
||||
// onto a desk grid with no windows
|
||||
TEST_F(SavedDeskTest, NoWindowsLabelOnReturnToEmptyOverviewDesk) {
|
||||
// Tests that we stay in the saved desk library when deleting the last entry.
|
||||
TEST_F(SavedDeskTest, NoItemsLabelOnDeletingLastSavedDesk) {
|
||||
UpdateDisplay("800x600,800x600");
|
||||
// Create a test window.
|
||||
auto test_window = CreateAppWindow();
|
||||
@ -567,16 +565,27 @@ TEST_F(SavedDeskTest, NoWindowsLabelOnReturnToEmptyOverviewDesk) {
|
||||
WaitForDesksTemplatesUI();
|
||||
EXPECT_TRUE(GetOverviewGridList()[0]->no_windows_widget());
|
||||
|
||||
// Open the desk templates grid. The no windows widget should now be hidden.
|
||||
// Open the desk templates grid. The no windows widget should now be hidden
|
||||
// and the no items label in the library UI should also not be visible.
|
||||
ShowDesksTemplatesGrids();
|
||||
EXPECT_FALSE(GetOverviewGridList()[0]->no_windows_widget());
|
||||
EXPECT_FALSE(SavedDeskLibraryViewTestApi(
|
||||
GetOverviewGridList()[0]->GetSavedDeskLibraryView())
|
||||
.no_items_label()
|
||||
->GetVisible());
|
||||
|
||||
// Delete the one and only template, which should hide the templates grid but
|
||||
// remain in overview. Check that the no windows widget is now back.
|
||||
OpenOverviewAndShowTemplatesGrid();
|
||||
DeleteTemplate(entries[0]->uuid(), /*expected_current_item_count=*/1);
|
||||
|
||||
ASSERT_TRUE(InOverviewSession());
|
||||
EXPECT_TRUE(GetOverviewGridList()[0]->no_windows_widget());
|
||||
// We should be in the saved desk UI and the no items label should now be
|
||||
// visible.
|
||||
EXPECT_TRUE(SavedDeskLibraryViewTestApi(
|
||||
GetOverviewGridList()[0]->GetSavedDeskLibraryView())
|
||||
.no_items_label()
|
||||
->GetVisible());
|
||||
}
|
||||
|
||||
// Tests that the "App does not support split-screen" label is hidden when the
|
||||
@ -853,15 +862,6 @@ TEST_F(SavedDeskTest, DeleteTemplate) {
|
||||
// Delete the template with `uuid_2`.
|
||||
DeleteTemplate(uuid_2, /*expected_current_item_count=*/1);
|
||||
EXPECT_EQ(0ul, desk_model()->GetEntryCount());
|
||||
|
||||
// After all templates have been deleted, check to ensure we have exited the
|
||||
// Desks Templates Grid on all displays. Also check to make sure the hidden
|
||||
// windows and the save template button are shown again.
|
||||
EXPECT_EQ(1.0f, test_window->layer()->opacity());
|
||||
for (auto& overview_grid : GetOverviewGridList())
|
||||
EXPECT_FALSE(overview_grid->IsShowingDesksTemplatesGrid());
|
||||
EXPECT_TRUE(GetOverviewGridForRoot(Shell::GetPrimaryRootWindow())
|
||||
->IsSaveDeskAsTemplateButtonVisible());
|
||||
}
|
||||
|
||||
// Tests that the save desk button container is aligned with the first
|
||||
@ -950,13 +950,18 @@ TEST_F(SavedDeskTest, SaveDeskButtonsEnabledDisabled) {
|
||||
ASSERT_EQ(saved_desk_presenter->GetMaxDeskTemplateEntryCount(),
|
||||
saved_desk_presenter->GetDeskTemplateEntryCount());
|
||||
|
||||
// Verify that the button is re-enabled after we delete all entries and exit
|
||||
// the templates grid.
|
||||
// Verify that the button is re-enabled after we delete all entries.
|
||||
std::vector<const DeskTemplate*> entries = GetAllEntries();
|
||||
for (size_t i = entries.size(); i > 0; i--) {
|
||||
DeleteTemplate(/*uuid=*/entries[i - 1]->uuid(),
|
||||
/*expected_current_item_count=*/i);
|
||||
}
|
||||
EXPECT_TRUE(GetOverviewGridList()[0]->IsShowingDesksTemplatesGrid());
|
||||
|
||||
// Leave and re-enter overview.
|
||||
ToggleOverview();
|
||||
ToggleOverview();
|
||||
|
||||
EXPECT_FALSE(GetOverviewGridList()[0]->IsShowingDesksTemplatesGrid());
|
||||
EXPECT_EQ(views::Button::STATE_NORMAL,
|
||||
GetSaveDeskAsTemplateButtonForRoot(root_window)->GetState());
|
||||
@ -989,13 +994,18 @@ TEST_F(SavedDeskTest, SaveDeskButtonsEnabledDisabled) {
|
||||
ASSERT_EQ(saved_desk_presenter->GetMaxSaveAndRecallDeskEntryCount(),
|
||||
saved_desk_presenter->GetSaveAndRecallDeskEntryCount());
|
||||
|
||||
// Verify that the button is re-enabled after we delete all entries and exit
|
||||
// the templates grid.
|
||||
// Verify that the button is re-enabled after we delete all entries.
|
||||
std::vector<const DeskTemplate*> entries = GetAllEntries();
|
||||
for (size_t i = entries.size(); i > 0; i--) {
|
||||
DeleteTemplate(/*uuid=*/entries[i - 1]->uuid(),
|
||||
/*expected_current_item_count=*/i);
|
||||
}
|
||||
EXPECT_TRUE(GetOverviewGridList()[0]->IsShowingDesksTemplatesGrid());
|
||||
|
||||
// Leave and re-enter overview.
|
||||
ToggleOverview();
|
||||
ToggleOverview();
|
||||
|
||||
EXPECT_FALSE(GetOverviewGridList()[0]->IsShowingDesksTemplatesGrid());
|
||||
EXPECT_EQ(views::Button::STATE_NORMAL,
|
||||
GetSaveDeskForLaterButtonForRoot(root_window)->GetState());
|
||||
@ -1703,9 +1713,9 @@ TEST_F(SavedDeskTest, ClamshellToTabletMode) {
|
||||
GetOverviewGridForRoot(root)->IsSaveDeskAsTemplateButtonVisible());
|
||||
}
|
||||
|
||||
// Tests that the desks templates grid gets hidden when transitioning to tablet
|
||||
// Tests that the saved desk library gets hidden when transitioning to tablet
|
||||
// mode.
|
||||
TEST_F(SavedDeskTest, ShowingTemplatesGridToTabletMode) {
|
||||
TEST_F(SavedDeskTest, ShowingSavedDeskLibraryToTabletMode) {
|
||||
// Create a window and add a test entry. Otherwise the templates UI wouldn't
|
||||
// show up.
|
||||
auto test_window_1 = CreateAppWindow();
|
||||
@ -1835,10 +1845,9 @@ TEST_F(SavedDeskTest, TabbingInvisibleTemplatesButton) {
|
||||
EXPECT_NE(button, GetHighlightedView());
|
||||
}
|
||||
|
||||
// Tests that the desks bar returns to zero state if the second-to-last desk is
|
||||
// deleted while viewing the templates grid. Also verifies that the zero state
|
||||
// buttons are visible. Regression test for https://crbug.com/1264989.
|
||||
TEST_F(SavedDeskTest, DesksBarReturnsToZeroState) {
|
||||
// Tests that the desks bar does not return to zero state if the second-to-last
|
||||
// desk is deleted while viewing the templates grid.
|
||||
TEST_F(SavedDeskTest, DesksBarDoesNotReturnToZeroState) {
|
||||
DesksController::Get()->NewDesk(DesksCreationRemovalSource::kKeyboard);
|
||||
const base::GUID uuid = base::GUID::GenerateRandomV4();
|
||||
AddEntry(uuid, "template", base::Time::Now(), DeskTemplateType::kTemplate);
|
||||
@ -1862,17 +1871,17 @@ TEST_F(SavedDeskTest, DesksBarReturnsToZeroState) {
|
||||
EXPECT_TRUE(expanded_templates_button->GetVisible());
|
||||
EXPECT_FALSE(desks_bar_view->IsZeroState());
|
||||
|
||||
// Delete the one and only template, which should hide the templates grid.
|
||||
// Delete the one and only template, we should remain in the desk library.
|
||||
DeleteTemplate(uuid, /*expected_current_item_count=*/1);
|
||||
EXPECT_FALSE(GetOverviewSession()
|
||||
->GetGridWithRootWindow(root_window)
|
||||
->saved_desk_library_widget()
|
||||
->IsVisible());
|
||||
EXPECT_TRUE(GetOverviewSession()
|
||||
->GetGridWithRootWindow(root_window)
|
||||
->saved_desk_library_widget()
|
||||
->IsVisible());
|
||||
|
||||
// Test that we are now in zero state.
|
||||
// Test that we are not in zero state.
|
||||
auto* zero_new_desk_button = desks_bar_view->zero_state_new_desk_button();
|
||||
EXPECT_TRUE(zero_new_desk_button->GetVisible());
|
||||
EXPECT_TRUE(desks_bar_view->IsZeroState());
|
||||
EXPECT_FALSE(zero_new_desk_button->GetVisible());
|
||||
EXPECT_FALSE(desks_bar_view->IsZeroState());
|
||||
}
|
||||
|
||||
// Tests that the unsupported apps dialog is shown when a user attempts to save
|
||||
@ -2125,9 +2134,10 @@ TEST_F(SavedDeskTest, HideAndShowTemplatesGridWithoutLeavingOverview) {
|
||||
GetOverviewGridList().front()->GetSavedDeskLibraryView();
|
||||
ASSERT_TRUE(library_view);
|
||||
|
||||
// The library has two grids, two labels and one feedback button.
|
||||
// The library has two grids, two section labels, one feedback button and one
|
||||
// "no items" label.
|
||||
SavedDeskLibraryViewTestApi test_api(library_view);
|
||||
ASSERT_EQ(5ul, test_api.scroll_view()->contents()->children().size());
|
||||
ASSERT_EQ(6ul, test_api.scroll_view()->contents()->children().size());
|
||||
|
||||
// Click on the grid item to launch the template.
|
||||
ClickOnView(GetItemViewFromTemplatesGrid(/*grid_item_index=*/0));
|
||||
@ -2137,41 +2147,7 @@ TEST_F(SavedDeskTest, HideAndShowTemplatesGridWithoutLeavingOverview) {
|
||||
// Go back to the library view and verify that we have the same amount of
|
||||
// expected children.
|
||||
ShowDesksTemplatesGrids();
|
||||
ASSERT_EQ(5ul, test_api.scroll_view()->contents()->children().size());
|
||||
}
|
||||
|
||||
// Tests that if we open the desks templates grid a second time during an
|
||||
// overview session, we can still see the template items. Opening a second time
|
||||
// can be done after deleting all the templates from the first open. Regression
|
||||
// test for https://crbug.com/1275179.
|
||||
TEST_F(SavedDeskTest, TemplatesAreVisibleAfterSecondSave) {
|
||||
// One window is needed to save a template.
|
||||
auto window = CreateAppWindow();
|
||||
|
||||
// Open overview and save a template.
|
||||
OpenOverviewAndSaveTemplate(Shell::Get()->GetPrimaryRootWindow());
|
||||
std::vector<const DeskTemplate*> entries = GetAllEntries();
|
||||
ASSERT_EQ(1ul, entries.size());
|
||||
|
||||
// Delete the one and only template, which should hide the templates grid but
|
||||
// remain in overview.
|
||||
DeleteTemplate(entries[0]->uuid(), /*expected_current_item_count=*/1);
|
||||
ASSERT_TRUE(InOverviewSession());
|
||||
|
||||
// Open overview and save a template again.
|
||||
OpenOverviewAndSaveTemplate(Shell::Get()->GetPrimaryRootWindow());
|
||||
|
||||
OverviewGrid* overview_grid = GetOverviewGridList()[0].get();
|
||||
SavedDeskLibraryView* library_view = overview_grid->GetSavedDeskLibraryView();
|
||||
ASSERT_TRUE(library_view);
|
||||
|
||||
const std::vector<SavedDeskItemView*> grid_items =
|
||||
GetItemViewsFromDeskLibrary(library_view);
|
||||
ASSERT_EQ(1ul, grid_items.size());
|
||||
|
||||
// Tests that bounds of the views are not empty.
|
||||
EXPECT_FALSE(library_view->bounds().IsEmpty());
|
||||
EXPECT_FALSE(grid_items[0]->bounds().IsEmpty());
|
||||
ASSERT_EQ(6ul, test_api.scroll_view()->contents()->children().size());
|
||||
}
|
||||
|
||||
// Tests that the desks templates are organized in alphabetical order.
|
||||
@ -2734,11 +2710,12 @@ TEST_F(SavedDeskTest, ItemsDoNotOverlapShelf) {
|
||||
SavedDeskLibraryView* library_view =
|
||||
GetOverviewGridList().front()->GetSavedDeskLibraryView();
|
||||
|
||||
// The library has two grids, two labels and one feedback button.
|
||||
// The library has two grids, two section labels, one feedback button and one
|
||||
// "no items" label.
|
||||
SavedDeskLibraryViewTestApi test_api(library_view);
|
||||
views::View::Views library_child_views =
|
||||
test_api.scroll_view()->contents()->children();
|
||||
ASSERT_EQ(5ul, library_child_views.size());
|
||||
ASSERT_EQ(6ul, library_child_views.size());
|
||||
|
||||
const gfx::Rect shelf_bounds =
|
||||
GetPrimaryShelf()->shelf_widget()->GetWindowBoundsInScreen();
|
||||
@ -2791,10 +2768,6 @@ TEST_F(SavedDeskTest, DeleteTemplateRecordsMetric) {
|
||||
DeleteTemplate(uuid_1, /*expected_current_item_count=*/1);
|
||||
EXPECT_EQ(0ul, desk_model()->GetEntryCount());
|
||||
|
||||
// There is only one desk to delete in this test so we should have
|
||||
// exited the overview.
|
||||
EXPECT_EQ(1.0f, test_window->layer()->opacity());
|
||||
|
||||
// Verifies that the template with `uuid_1`, doesn't exist anymore.
|
||||
DeleteTemplate(uuid_1, /*expected_current_item_count=*/0,
|
||||
/*expect_template_exists=*/false);
|
||||
|
68
ash/wm/overview/rounded_label.cc
Normal file
68
ash/wm/overview/rounded_label.cc
Normal file
@ -0,0 +1,68 @@
|
||||
// Copyright 2022 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 "ash/wm/overview/rounded_label.h"
|
||||
|
||||
#include "ash/constants/ash_features.h"
|
||||
#include "ash/public/cpp/style/color_provider.h"
|
||||
#include "ui/compositor/layer.h"
|
||||
#include "ui/views/background.h"
|
||||
#include "ui/views/border.h"
|
||||
#include "ui/views/highlight_border.h"
|
||||
|
||||
namespace ash {
|
||||
|
||||
RoundedLabel::RoundedLabel(int horizontal_padding,
|
||||
int vertical_padding,
|
||||
int rounding_dp,
|
||||
int preferred_height,
|
||||
const std::u16string& text)
|
||||
: views::Label(text, views::style::CONTEXT_LABEL),
|
||||
rounding_dp_(rounding_dp),
|
||||
preferred_height_(preferred_height) {
|
||||
SetBorder(views::CreateEmptyBorder(
|
||||
gfx::Insets::VH(vertical_padding, horizontal_padding)));
|
||||
|
||||
SetBackground(views::CreateSolidBackground(SK_ColorTRANSPARENT));
|
||||
SetHorizontalAlignment(gfx::ALIGN_CENTER);
|
||||
SetPaintToLayer();
|
||||
layer()->SetFillsBoundsOpaquely(false);
|
||||
layer()->SetBackgroundBlur(ColorProvider::kBackgroundBlurSigma);
|
||||
const gfx::RoundedCornersF radii(rounding_dp);
|
||||
layer()->SetRoundedCornerRadius(radii);
|
||||
layer()->SetIsFastRoundedCorner(true);
|
||||
}
|
||||
|
||||
RoundedLabel::~RoundedLabel() = default;
|
||||
|
||||
gfx::Size RoundedLabel::CalculatePreferredSize() const {
|
||||
return gfx::Size(views::Label::CalculatePreferredSize().width(),
|
||||
preferred_height_);
|
||||
}
|
||||
|
||||
int RoundedLabel::GetHeightForWidth(int width) const {
|
||||
return preferred_height_;
|
||||
}
|
||||
|
||||
void RoundedLabel::OnThemeChanged() {
|
||||
views::Label::OnThemeChanged();
|
||||
auto* color_provider = ColorProvider::Get();
|
||||
const SkColor background_color = color_provider->GetBaseLayerColor(
|
||||
ColorProvider::BaseLayerType::kTransparent80);
|
||||
background()->SetNativeControlColor(background_color);
|
||||
SetBackgroundColor(background_color);
|
||||
SetEnabledColor(color_provider->GetContentLayerColor(
|
||||
ColorProvider::ContentLayerType::kTextColorPrimary));
|
||||
}
|
||||
|
||||
void RoundedLabel::OnPaintBorder(gfx::Canvas* canvas) {
|
||||
if (features::IsDarkLightModeEnabled()) {
|
||||
views::HighlightBorder::PaintBorderToCanvas(
|
||||
canvas, *this, GetLocalBounds(), gfx::RoundedCornersF(rounding_dp_),
|
||||
views::HighlightBorder::Type::kHighlightBorder2,
|
||||
/*use_light_colors=*/false);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ash
|
37
ash/wm/overview/rounded_label.h
Normal file
37
ash/wm/overview/rounded_label.h
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright 2022 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 ASH_WM_OVERVIEW_ROUNDED_LABEL_H_
|
||||
#define ASH_WM_OVERVIEW_ROUNDED_LABEL_H_
|
||||
|
||||
#include "ui/views/controls/label.h"
|
||||
|
||||
namespace ash {
|
||||
|
||||
// A rounded background with a label containing text we want to display.
|
||||
class RoundedLabel : public views::Label {
|
||||
public:
|
||||
RoundedLabel(int horizontal_padding,
|
||||
int vertical_padding,
|
||||
int rounding_dp,
|
||||
int preferred_height,
|
||||
const std::u16string& text);
|
||||
RoundedLabel(const RoundedLabel&) = delete;
|
||||
RoundedLabel& operator=(const RoundedLabel&) = delete;
|
||||
~RoundedLabel() override;
|
||||
|
||||
private:
|
||||
// views::Label:
|
||||
gfx::Size CalculatePreferredSize() const override;
|
||||
int GetHeightForWidth(int width) const override;
|
||||
void OnThemeChanged() override;
|
||||
void OnPaintBorder(gfx::Canvas* canvas) override;
|
||||
|
||||
const int rounding_dp_;
|
||||
const int preferred_height_;
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
||||
#endif // ASH_WM_OVERVIEW_ROUNDED_LABEL_H_
|
@ -6,85 +6,15 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ash/constants/ash_features.h"
|
||||
#include "ash/public/cpp/style/color_provider.h"
|
||||
#include "ash/public/cpp/window_properties.h"
|
||||
#include "ash/wm/overview/rounded_label.h"
|
||||
#include "ash/wm/overview/scoped_overview_animation_settings.h"
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/compositor/layer.h"
|
||||
#include "ui/display/screen.h"
|
||||
#include "ui/views/background.h"
|
||||
#include "ui/views/border.h"
|
||||
#include "ui/views/controls/label.h"
|
||||
#include "ui/views/highlight_border.h"
|
||||
|
||||
namespace ash {
|
||||
|
||||
namespace {
|
||||
|
||||
// The contents of RoundedLabelWidget. It is a rounded background with a label
|
||||
// containing text we want to display.
|
||||
class RoundedLabelView : public views::Label {
|
||||
public:
|
||||
RoundedLabelView(int horizontal_padding,
|
||||
int vertical_padding,
|
||||
int rounding_dp,
|
||||
int preferred_height,
|
||||
int message_id)
|
||||
: views::Label(l10n_util::GetStringUTF16(message_id),
|
||||
views::style::CONTEXT_LABEL),
|
||||
rounding_dp_(rounding_dp),
|
||||
preferred_height_(preferred_height) {
|
||||
SetBorder(views::CreateEmptyBorder(
|
||||
gfx::Insets::VH(vertical_padding, horizontal_padding)));
|
||||
|
||||
SetBackground(views::CreateSolidBackground(SK_ColorTRANSPARENT));
|
||||
SetHorizontalAlignment(gfx::ALIGN_CENTER);
|
||||
SetPaintToLayer();
|
||||
layer()->SetFillsBoundsOpaquely(false);
|
||||
layer()->SetBackgroundBlur(ColorProvider::kBackgroundBlurSigma);
|
||||
const gfx::RoundedCornersF radii(rounding_dp);
|
||||
layer()->SetRoundedCornerRadius(radii);
|
||||
layer()->SetIsFastRoundedCorner(true);
|
||||
}
|
||||
RoundedLabelView(const RoundedLabelView&) = delete;
|
||||
RoundedLabelView& operator=(const RoundedLabelView&) = delete;
|
||||
~RoundedLabelView() override = default;
|
||||
|
||||
// views::Label:
|
||||
gfx::Size CalculatePreferredSize() const override {
|
||||
return gfx::Size(views::Label::CalculatePreferredSize().width(),
|
||||
preferred_height_);
|
||||
}
|
||||
|
||||
void OnThemeChanged() override {
|
||||
views::Label::OnThemeChanged();
|
||||
auto* color_provider = ColorProvider::Get();
|
||||
const SkColor background_color = color_provider->GetBaseLayerColor(
|
||||
ColorProvider::BaseLayerType::kTransparent80);
|
||||
background()->SetNativeControlColor(background_color);
|
||||
SetBackgroundColor(background_color);
|
||||
SetEnabledColor(color_provider->GetContentLayerColor(
|
||||
ColorProvider::ContentLayerType::kTextColorPrimary));
|
||||
}
|
||||
|
||||
void OnPaintBorder(gfx::Canvas* canvas) override {
|
||||
if (features::IsDarkLightModeEnabled()) {
|
||||
views::HighlightBorder::PaintBorderToCanvas(
|
||||
canvas, *this, GetLocalBounds(), gfx::RoundedCornersF(rounding_dp_),
|
||||
views::HighlightBorder::Type::kHighlightBorder2,
|
||||
/*use_light_colors=*/false);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const int rounding_dp_;
|
||||
const int preferred_height_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
RoundedLabelWidget::InitParams::InitParams() = default;
|
||||
|
||||
RoundedLabelWidget::InitParams::InitParams(InitParams&& other) = default;
|
||||
@ -111,16 +41,15 @@ void RoundedLabelWidget::Init(InitParams params) {
|
||||
}
|
||||
views::Widget::Init(std::move(widget_params));
|
||||
|
||||
SetContentsView(std::make_unique<RoundedLabelView>(
|
||||
SetContentsView(std::make_unique<RoundedLabel>(
|
||||
params.horizontal_padding, params.vertical_padding, params.rounding_dp,
|
||||
params.preferred_height, params.message_id));
|
||||
params.preferred_height, l10n_util::GetStringUTF16(params.message_id)));
|
||||
Show();
|
||||
}
|
||||
|
||||
gfx::Rect RoundedLabelWidget::GetBoundsCenteredIn(const gfx::Rect& bounds) {
|
||||
DCHECK(GetContentsView());
|
||||
RoundedLabelView* contents_view =
|
||||
static_cast<RoundedLabelView*>(GetContentsView());
|
||||
views::View* contents_view = GetContentsView();
|
||||
DCHECK(contents_view);
|
||||
gfx::Rect widget_bounds = bounds;
|
||||
widget_bounds.ClampToCenteredSize(contents_view->GetPreferredSize());
|
||||
return widget_bounds;
|
||||
|
Reference in New Issue
Block a user