Commit ec950672 authored by David Black's avatar David Black Committed by Commit Bot

Implement empty state for holding space pinned files container.

Pinned files container should show a prompt to the user when empty,
otherwise the pinned files.

This CL also:
- Updates a few styles.
- Fixes a bug in which downloads were not restored due to the time of
  first enabling holding space not being stored to prefs.

Bug: 1131253
Change-Id: Ife26c626e633c4263fea80610b4948c7971ba09e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2434465
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarAhmed Mehfooz <amehfooz@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811426}
parent 8a94c67d
......@@ -976,6 +976,9 @@ This file contains the strings for ash.
<message name="IDS_ASH_HOLDING_SPACE_PINNED_TITLE" desc="Title of the pinned files area in the holding space bubble.">
Pinned
</message>
<message name="IDS_ASH_HOLDING_SPACE_PINNED_EMPTY_PROMPT" desc="Prompt shown in the pinned files area of the holding space bubble if the user has no pinned files.">
Quickly access your important files. Right-click or touch &amp; hold a file to pin it.
</message>
<message name="IDS_ASH_HOLDING_SPACE_DOWNLOADS_TITLE" desc="Title of the downloads area in the holding space bubble.">
Downloads
</message>
......
0ad404e14ac69a7254a868558f7ca5c89489c141
\ No newline at end of file
......@@ -39,8 +39,8 @@ HoldingSpaceItemChipView::HoldingSpaceItemChipView(
label_->SetElideBehavior(gfx::ELIDE_MIDDLE);
layout->SetFlexForView(label_, 1);
TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::HOLDING_SPACE_TITLE);
style.SetupLabel(label_);
TrayPopupItemStyle(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL)
.SetupLabel(label_);
const auto* color_provider = AshColorProvider::Get();
SetBackground(views::CreateRoundedRectBackground(
......
......@@ -28,6 +28,9 @@
namespace ash {
namespace {
// HoldingSpaceScrollView ------------------------------------------------------
class HoldingSpaceScrollView : public views::ScrollView,
public views::ViewObserver {
public:
......@@ -44,6 +47,13 @@ class HoldingSpaceScrollView : public views::ScrollView,
PreferredSizeChanged();
}
void OnViewVisibilityChanged(views::View* observed_view,
views::View* starting_view) override {
// Sync scroll view visibility with contents visibility.
if (GetVisible() != observed_view->GetVisible())
SetVisible(observed_view->GetVisible());
}
void OnViewIsDeleting(View* observed_view) override {
view_observer_.Remove(observed_view);
}
......@@ -51,8 +61,11 @@ class HoldingSpaceScrollView : public views::ScrollView,
private:
ScopedObserver<views::View, views::ViewObserver> view_observer_{this};
};
} // namespace
// PinnedFilesContainer --------------------------------------------------------
PinnedFilesContainer::PinnedFilesContainer(
HoldingSpaceItemViewDelegate* delegate)
: delegate_(delegate) {
......@@ -64,19 +77,33 @@ PinnedFilesContainer::PinnedFilesContainer(
auto* title_label = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_PINNED_TITLE)));
TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::HOLDING_SPACE_TITLE,
true /* use_unified_theme */);
style.SetupLabel(title_label);
title_label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
title_label->SetPaintToLayer();
title_label->layer()->SetFillsBoundsOpaquely(false);
auto* scroller = AddChildView(std::make_unique<HoldingSpaceScrollView>());
scroller->SetBackgroundColor(base::nullopt);
scroller->SetDrawOverflowIndicator(false);
scroller->ClipHeightTo(0, INT_MAX);
TrayPopupItemStyle(TrayPopupItemStyle::FontStyle::SUB_HEADER)
.SetupLabel(title_label);
empty_prompt_label_ = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_PINNED_EMPTY_PROMPT)));
empty_prompt_label_->SetHorizontalAlignment(
gfx::HorizontalAlignment::ALIGN_LEFT);
empty_prompt_label_->SetMultiLine(true);
empty_prompt_label_->SetPaintToLayer();
empty_prompt_label_->layer()->SetFillsBoundsOpaquely(false);
TrayPopupItemStyle(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL)
.SetupLabel(empty_prompt_label_);
item_chips_container_ =
scroller->SetContents(std::make_unique<HoldingSpaceItemChipsContainer>());
auto* scroll_view = AddChildView(std::make_unique<HoldingSpaceScrollView>());
scroll_view->SetBackgroundColor(base::nullopt);
scroll_view->SetDrawOverflowIndicator(false);
scroll_view->SetVisible(false);
scroll_view->ClipHeightTo(0, INT_MAX);
item_chips_container_ = scroll_view->SetContents(
std::make_unique<HoldingSpaceItemChipsContainer>());
item_chips_container_->SetVisible(false);
if (HoldingSpaceController::Get()->model())
OnHoldingSpaceModelAttached(HoldingSpaceController::Get()->model());
......@@ -84,6 +111,28 @@ PinnedFilesContainer::PinnedFilesContainer(
PinnedFilesContainer::~PinnedFilesContainer() = default;
void PinnedFilesContainer::ChildVisibilityChanged(views::View* child) {
PreferredSizeChanged();
}
void PinnedFilesContainer::ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) {
// We only care about `item_chips_container_` becoming empty and non-empty.
if (details.parent != item_chips_container_ ||
item_chips_container_->children().size() != 1u) {
return;
}
if (details.is_add) {
// `item_chips_container_` is becoming non-empty.
empty_prompt_label_->SetVisible(false);
item_chips_container_->SetVisible(true);
} else {
// `item_chips_container_` is becoming empty.
item_chips_container_->SetVisible(false);
empty_prompt_label_->SetVisible(true);
}
}
void PinnedFilesContainer::AddHoldingSpaceItemView(
const HoldingSpaceItem* item) {
DCHECK(!base::Contains(views_by_item_id_, item->id()));
......
......@@ -9,6 +9,10 @@
#include "ash/system/holding_space/holding_space_item_views_container.h"
namespace views {
class Label;
} // namespace views
namespace ash {
class HoldingSpaceItemChipsContainer;
......@@ -23,6 +27,8 @@ class PinnedFilesContainer : public HoldingSpaceItemViewsContainer {
~PinnedFilesContainer() override;
// HoldingSpaceItemViewsContainer:
void ChildVisibilityChanged(views::View* child) override;
void ViewHierarchyChanged(const views::ViewHierarchyChangedDetails&) override;
void AddHoldingSpaceItemView(const HoldingSpaceItem* item) override;
void RemoveAllHoldingSpaceItemViews() override;
void RemoveHoldingSpaceItemView(const HoldingSpaceItem* item) override;
......@@ -30,6 +36,7 @@ class PinnedFilesContainer : public HoldingSpaceItemViewsContainer {
private:
HoldingSpaceItemViewDelegate* const delegate_;
views::Label* empty_prompt_label_ = nullptr;
HoldingSpaceItemChipsContainer* item_chips_container_ = nullptr;
std::map<std::string, views::View*> views_by_item_id_;
......
......@@ -34,17 +34,18 @@ RecentFilesContainer::RecentFilesContainer(
views::BoxLayout::Orientation::kVertical, kHoldingSpaceContainerPadding,
kHoldingSpaceContainerChildSpacing));
auto setup_layered_child = [](views::View* child) {
child->SetPaintToLayer();
child->layer()->SetFillsBoundsOpaquely(false);
auto setup_label = [](views::Label* label) {
TrayPopupItemStyle(TrayPopupItemStyle::FontStyle::SUB_HEADER)
.SetupLabel(label);
label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
label->SetPaintToLayer();
label->layer()->SetFillsBoundsOpaquely(false);
};
auto* screenshots_label = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_SCREENSHOTS_TITLE)));
setup_layered_child(screenshots_label);
TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::HOLDING_SPACE_TITLE,
true /* use_unified_theme */);
style.SetupLabel(screenshots_label);
setup_label(screenshots_label);
screenshots_container_ = AddChildView(std::make_unique<views::View>());
screenshots_container_
......@@ -57,8 +58,7 @@ RecentFilesContainer::RecentFilesContainer(
auto* downloads_label = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_DOWNLOADS_TITLE)));
setup_layered_child(downloads_label);
style.SetupLabel(downloads_label);
setup_label(downloads_label);
downloads_container_ =
AddChildView(std::make_unique<HoldingSpaceItemChipsContainer>());
......
......@@ -116,11 +116,6 @@ void TrayPopupItemStyle::SetupLabel(views::Label* label) const {
label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL,
gfx::Font::Weight::NORMAL));
break;
case FontStyle::HOLDING_SPACE_TITLE:
label->SetFontList(base_font_list.Derive(3, gfx::Font::NORMAL,
gfx::Font::Weight::NORMAL));
label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
break;
}
}
......
......@@ -49,8 +49,6 @@ class TrayPopupItemStyle {
CLICKABLE_SYSTEM_INFO,
// Sub text within a row (e.g. user name in user row).
CAPTION,
// Labels in holding space bubble
HOLDING_SPACE_TITLE,
};
static constexpr double kInactiveIconAlpha = 0.54;
......
......@@ -43,6 +43,11 @@ HoldingSpaceKeyedService::HoldingSpaceKeyedService(Profile* profile,
account_id_(account_id),
holding_space_client_(profile),
thumbnail_loader_(profile) {
// If true, store this as the first time holding space has been enabled.
PrefService* const prefs = profile_->GetPrefs();
if (prefs->FindPreference(kPrefPathFirstEnabledTime)->IsDefaultValue())
prefs->SetTime(kPrefPathFirstEnabledTime, base::Time::Now());
// Model restoration is a multi-step process, currently consisting of a
// restoration from persistence followed by a restoration of downloads. Once
// all steps have indicated completion, `OnModelFullyRestored()` is invoked.
......
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