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. ...@@ -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."> <message name="IDS_ASH_HOLDING_SPACE_PINNED_TITLE" desc="Title of the pinned files area in the holding space bubble.">
Pinned Pinned
</message> </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."> <message name="IDS_ASH_HOLDING_SPACE_DOWNLOADS_TITLE" desc="Title of the downloads area in the holding space bubble.">
Downloads Downloads
</message> </message>
......
0ad404e14ac69a7254a868558f7ca5c89489c141
\ No newline at end of file
...@@ -39,8 +39,8 @@ HoldingSpaceItemChipView::HoldingSpaceItemChipView( ...@@ -39,8 +39,8 @@ HoldingSpaceItemChipView::HoldingSpaceItemChipView(
label_->SetElideBehavior(gfx::ELIDE_MIDDLE); label_->SetElideBehavior(gfx::ELIDE_MIDDLE);
layout->SetFlexForView(label_, 1); layout->SetFlexForView(label_, 1);
TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::HOLDING_SPACE_TITLE); TrayPopupItemStyle(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL)
style.SetupLabel(label_); .SetupLabel(label_);
const auto* color_provider = AshColorProvider::Get(); const auto* color_provider = AshColorProvider::Get();
SetBackground(views::CreateRoundedRectBackground( SetBackground(views::CreateRoundedRectBackground(
......
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
namespace ash { namespace ash {
namespace { namespace {
// HoldingSpaceScrollView ------------------------------------------------------
class HoldingSpaceScrollView : public views::ScrollView, class HoldingSpaceScrollView : public views::ScrollView,
public views::ViewObserver { public views::ViewObserver {
public: public:
...@@ -44,6 +47,13 @@ class HoldingSpaceScrollView : public views::ScrollView, ...@@ -44,6 +47,13 @@ class HoldingSpaceScrollView : public views::ScrollView,
PreferredSizeChanged(); 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 { void OnViewIsDeleting(View* observed_view) override {
view_observer_.Remove(observed_view); view_observer_.Remove(observed_view);
} }
...@@ -51,8 +61,11 @@ class HoldingSpaceScrollView : public views::ScrollView, ...@@ -51,8 +61,11 @@ class HoldingSpaceScrollView : public views::ScrollView,
private: private:
ScopedObserver<views::View, views::ViewObserver> view_observer_{this}; ScopedObserver<views::View, views::ViewObserver> view_observer_{this};
}; };
} // namespace } // namespace
// PinnedFilesContainer --------------------------------------------------------
PinnedFilesContainer::PinnedFilesContainer( PinnedFilesContainer::PinnedFilesContainer(
HoldingSpaceItemViewDelegate* delegate) HoldingSpaceItemViewDelegate* delegate)
: delegate_(delegate) { : delegate_(delegate) {
...@@ -64,19 +77,33 @@ PinnedFilesContainer::PinnedFilesContainer( ...@@ -64,19 +77,33 @@ PinnedFilesContainer::PinnedFilesContainer(
auto* title_label = AddChildView(std::make_unique<views::Label>( auto* title_label = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_PINNED_TITLE))); l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_PINNED_TITLE)));
TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::HOLDING_SPACE_TITLE, title_label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
true /* use_unified_theme */);
style.SetupLabel(title_label);
title_label->SetPaintToLayer(); title_label->SetPaintToLayer();
title_label->layer()->SetFillsBoundsOpaquely(false); title_label->layer()->SetFillsBoundsOpaquely(false);
auto* scroller = AddChildView(std::make_unique<HoldingSpaceScrollView>()); TrayPopupItemStyle(TrayPopupItemStyle::FontStyle::SUB_HEADER)
scroller->SetBackgroundColor(base::nullopt); .SetupLabel(title_label);
scroller->SetDrawOverflowIndicator(false);
scroller->ClipHeightTo(0, INT_MAX); 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_ = auto* scroll_view = AddChildView(std::make_unique<HoldingSpaceScrollView>());
scroller->SetContents(std::make_unique<HoldingSpaceItemChipsContainer>()); 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()) if (HoldingSpaceController::Get()->model())
OnHoldingSpaceModelAttached(HoldingSpaceController::Get()->model()); OnHoldingSpaceModelAttached(HoldingSpaceController::Get()->model());
...@@ -84,6 +111,28 @@ PinnedFilesContainer::PinnedFilesContainer( ...@@ -84,6 +111,28 @@ PinnedFilesContainer::PinnedFilesContainer(
PinnedFilesContainer::~PinnedFilesContainer() = default; 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( void PinnedFilesContainer::AddHoldingSpaceItemView(
const HoldingSpaceItem* item) { const HoldingSpaceItem* item) {
DCHECK(!base::Contains(views_by_item_id_, item->id())); DCHECK(!base::Contains(views_by_item_id_, item->id()));
......
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
#include "ash/system/holding_space/holding_space_item_views_container.h" #include "ash/system/holding_space/holding_space_item_views_container.h"
namespace views {
class Label;
} // namespace views
namespace ash { namespace ash {
class HoldingSpaceItemChipsContainer; class HoldingSpaceItemChipsContainer;
...@@ -23,6 +27,8 @@ class PinnedFilesContainer : public HoldingSpaceItemViewsContainer { ...@@ -23,6 +27,8 @@ class PinnedFilesContainer : public HoldingSpaceItemViewsContainer {
~PinnedFilesContainer() override; ~PinnedFilesContainer() override;
// HoldingSpaceItemViewsContainer: // HoldingSpaceItemViewsContainer:
void ChildVisibilityChanged(views::View* child) override;
void ViewHierarchyChanged(const views::ViewHierarchyChangedDetails&) override;
void AddHoldingSpaceItemView(const HoldingSpaceItem* item) override; void AddHoldingSpaceItemView(const HoldingSpaceItem* item) override;
void RemoveAllHoldingSpaceItemViews() override; void RemoveAllHoldingSpaceItemViews() override;
void RemoveHoldingSpaceItemView(const HoldingSpaceItem* item) override; void RemoveHoldingSpaceItemView(const HoldingSpaceItem* item) override;
...@@ -30,6 +36,7 @@ class PinnedFilesContainer : public HoldingSpaceItemViewsContainer { ...@@ -30,6 +36,7 @@ class PinnedFilesContainer : public HoldingSpaceItemViewsContainer {
private: private:
HoldingSpaceItemViewDelegate* const delegate_; HoldingSpaceItemViewDelegate* const delegate_;
views::Label* empty_prompt_label_ = nullptr;
HoldingSpaceItemChipsContainer* item_chips_container_ = nullptr; HoldingSpaceItemChipsContainer* item_chips_container_ = nullptr;
std::map<std::string, views::View*> views_by_item_id_; std::map<std::string, views::View*> views_by_item_id_;
......
...@@ -34,17 +34,18 @@ RecentFilesContainer::RecentFilesContainer( ...@@ -34,17 +34,18 @@ RecentFilesContainer::RecentFilesContainer(
views::BoxLayout::Orientation::kVertical, kHoldingSpaceContainerPadding, views::BoxLayout::Orientation::kVertical, kHoldingSpaceContainerPadding,
kHoldingSpaceContainerChildSpacing)); kHoldingSpaceContainerChildSpacing));
auto setup_layered_child = [](views::View* child) { auto setup_label = [](views::Label* label) {
child->SetPaintToLayer(); TrayPopupItemStyle(TrayPopupItemStyle::FontStyle::SUB_HEADER)
child->layer()->SetFillsBoundsOpaquely(false); .SetupLabel(label);
label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
label->SetPaintToLayer();
label->layer()->SetFillsBoundsOpaquely(false);
}; };
auto* screenshots_label = AddChildView(std::make_unique<views::Label>( auto* screenshots_label = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_SCREENSHOTS_TITLE))); l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_SCREENSHOTS_TITLE)));
setup_layered_child(screenshots_label); setup_label(screenshots_label);
TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::HOLDING_SPACE_TITLE,
true /* use_unified_theme */);
style.SetupLabel(screenshots_label);
screenshots_container_ = AddChildView(std::make_unique<views::View>()); screenshots_container_ = AddChildView(std::make_unique<views::View>());
screenshots_container_ screenshots_container_
...@@ -57,8 +58,7 @@ RecentFilesContainer::RecentFilesContainer( ...@@ -57,8 +58,7 @@ RecentFilesContainer::RecentFilesContainer(
auto* downloads_label = AddChildView(std::make_unique<views::Label>( auto* downloads_label = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_DOWNLOADS_TITLE))); l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_DOWNLOADS_TITLE)));
setup_layered_child(downloads_label); setup_label(downloads_label);
style.SetupLabel(downloads_label);
downloads_container_ = downloads_container_ =
AddChildView(std::make_unique<HoldingSpaceItemChipsContainer>()); AddChildView(std::make_unique<HoldingSpaceItemChipsContainer>());
......
...@@ -116,11 +116,6 @@ void TrayPopupItemStyle::SetupLabel(views::Label* label) const { ...@@ -116,11 +116,6 @@ void TrayPopupItemStyle::SetupLabel(views::Label* label) const {
label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL, label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL,
gfx::Font::Weight::NORMAL)); gfx::Font::Weight::NORMAL));
break; 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 { ...@@ -49,8 +49,6 @@ class TrayPopupItemStyle {
CLICKABLE_SYSTEM_INFO, CLICKABLE_SYSTEM_INFO,
// Sub text within a row (e.g. user name in user row). // Sub text within a row (e.g. user name in user row).
CAPTION, CAPTION,
// Labels in holding space bubble
HOLDING_SPACE_TITLE,
}; };
static constexpr double kInactiveIconAlpha = 0.54; static constexpr double kInactiveIconAlpha = 0.54;
......
...@@ -43,6 +43,11 @@ HoldingSpaceKeyedService::HoldingSpaceKeyedService(Profile* profile, ...@@ -43,6 +43,11 @@ HoldingSpaceKeyedService::HoldingSpaceKeyedService(Profile* profile,
account_id_(account_id), account_id_(account_id),
holding_space_client_(profile), holding_space_client_(profile),
thumbnail_loader_(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 // Model restoration is a multi-step process, currently consisting of a
// restoration from persistence followed by a restoration of downloads. Once // restoration from persistence followed by a restoration of downloads. Once
// all steps have indicated completion, `OnModelFullyRestored()` is invoked. // 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