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

Implement empty state of holding space recent files container.

Screenshots should only be visible if we have screenshot items.
Downloads should only be visible if we have download items.
Recent files should only be visible if we screenshots and/or downloads.

Bug: 1131253
Change-Id: I1bf70b6312c46cf5f7dbc616c5e33e7af0ad2740
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2434468
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarAhmed Mehfooz <amehfooz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812493}
parent 57eb4260
......@@ -25,7 +25,8 @@ constexpr int kHoldingSpaceChipsPerRow = 2;
constexpr int kHoldingSpaceColumnSpacing = 8;
constexpr int kHoldingSpaceColumnWidth = 160;
constexpr int kHoldingSpaceCornerRadius = 8;
constexpr int kHoldingSpaceDownloadsChevronIconSize = 16;
constexpr int kHoldingSpaceDownloadsChevronIconSize = 20;
constexpr int kHoldingSpaceDownloadsHeaderSpacing = 8;
constexpr int kHoldingSpacePinIconSize = 20;
constexpr int kHoldingSpaceRowSpacing = 8;
constexpr gfx::Insets kHoldingSpaceScreenshotPadding(8);
......@@ -33,7 +34,7 @@ constexpr int kHoldingSpaceScreenshotSpacing = 8;
constexpr gfx::Size kHoldingSpaceScreenshotSize(104, 80);
constexpr gfx::Insets kHoldingSpaceScreenshotsContainerPadding(8, 0);
constexpr float kHoldingSpaceSelectedOverlayOpacity = 0.24f;
constexpr int kHoldingSpaceTrayIconMainAxisMargin = 6;
constexpr int kHoldingSpaceTrayMainAxisMargin = 6;
// Context menu commands.
enum HoldingSpaceCommandId {
......
......@@ -24,6 +24,8 @@ HoldingSpaceItemChipView::HoldingSpaceItemChipView(
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal,
gfx::Insets(kHoldingSpaceChipPadding), kHoldingSpaceChipChildSpacing));
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
SetPreferredSize(gfx::Size(kHoldingSpaceChipWidth, kHoldingSpaceChipHeight));
......
......@@ -19,6 +19,11 @@ void HoldingSpaceItemViewsContainer::ChildPreferredSizeChanged(
PreferredSizeChanged();
}
void HoldingSpaceItemViewsContainer::ChildVisibilityChanged(
views::View* child) {
PreferredSizeChanged();
}
void HoldingSpaceItemViewsContainer::OnHoldingSpaceModelAttached(
HoldingSpaceModel* model) {
model_observer_.Add(model);
......
......@@ -34,6 +34,7 @@ class HoldingSpaceItemViewsContainer : public views::View,
// views::View:
void ChildPreferredSizeChanged(views::View* child) override;
void ChildVisibilityChanged(views::View* child) override;
// HoldingSpaceControllerObserver:
void OnHoldingSpaceModelAttached(HoldingSpaceModel* model) override;
......
......@@ -33,7 +33,7 @@ HoldingSpaceTray::HoldingSpaceTray(Shelf* shelf) : TrayBackgroundView(shelf) {
icon_->SetImage(CreateVectorIcon(kHoldingSpaceIcon,
ShelfConfig::Get()->shelf_icon_color()));
tray_container()->SetMargin(kHoldingSpaceTrayIconMainAxisMargin, 0);
tray_container()->SetMargin(kHoldingSpaceTrayMainAxisMargin, 0);
}
HoldingSpaceTray::~HoldingSpaceTray() = default;
......
......@@ -66,11 +66,11 @@ void SetupViewLayer(views::View* view) {
layer->SetIsFastRoundedCorner(true);
}
// HoldingSpaceBubbleContainerView ---------------------------------------------
// HoldingSpaceBubbleContainer -------------------------------------------------
class HoldingSpaceBubbleContainerView : public views::View {
class HoldingSpaceBubbleContainer : public views::View {
public:
HoldingSpaceBubbleContainerView() {
HoldingSpaceBubbleContainer() {
layout_ = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(),
kHoldingSpaceContainerSpacing));
......@@ -80,11 +80,16 @@ class HoldingSpaceBubbleContainerView : public views::View {
layout_->SetFlexForView(child, flex);
}
private:
// views::View:
void ChildPreferredSizeChanged(views::View* child) override {
PreferredSizeChanged();
}
private:
void ChildVisibilityChanged(views::View* child) override {
PreferredSizeChanged();
}
views::BoxLayout* layout_ = nullptr;
};
......@@ -112,22 +117,19 @@ HoldingSpaceTrayBubble::HoldingSpaceTrayBubble(
// Create and customize bubble view.
TrayBubbleView* bubble_view = new TrayBubbleView(init_params);
bubble_view->SetMaxHeight(CalculateMaxHeight());
HoldingSpaceBubbleContainerView* bubble_container_view =
bubble_view->AddChildView(
std::make_unique<HoldingSpaceBubbleContainerView>());
HoldingSpaceBubbleContainer* bubble_container = bubble_view->AddChildView(
std::make_unique<HoldingSpaceBubbleContainer>());
// Add pinned files container.
pinned_files_container_ = bubble_container_view->AddChildView(
pinned_files_container_ = bubble_container->AddChildView(
std::make_unique<PinnedFilesContainer>(&delegate_));
bubble_container_view->SetFlexForChild(pinned_files_container_, 1);
bubble_container->SetFlexForChild(pinned_files_container_, 1);
SetupViewLayer(pinned_files_container_);
// Add recent files container.
recent_files_container_ = bubble_container_view->AddChildView(
recent_files_container_ = bubble_container->AddChildView(
std::make_unique<RecentFilesContainer>(&delegate_));
SetupViewLayer(recent_files_container_);
......@@ -174,17 +176,19 @@ views::Widget* HoldingSpaceTrayBubble::GetBubbleWidget() {
}
int HoldingSpaceTrayBubble::CalculateMaxHeight() const {
WorkAreaInsets* work_area = WorkAreaInsets::ForWindow(
const WorkAreaInsets* work_area = WorkAreaInsets::ForWindow(
holding_space_tray_->shelf()->GetWindow()->GetRootWindow());
int bottom = holding_space_tray_->shelf()->IsHorizontalAlignment()
? holding_space_tray_->shelf()->GetShelfBoundsInScreen().y()
: work_area->user_work_area_bounds().bottom();
int free_space_height_above_anchor =
const int bottom =
holding_space_tray_->shelf()->IsHorizontalAlignment()
? holding_space_tray_->shelf()->GetShelfBoundsInScreen().y()
: work_area->user_work_area_bounds().bottom();
const int free_space_height_above_anchor =
bottom - work_area->user_work_area_bounds().y();
const gfx::Insets insets = GetTrayBubbleInsets();
int bubble_vertical_margin = insets.top() + insets.bottom();
const int bubble_vertical_margin = insets.top() + insets.bottom();
return free_space_height_above_anchor - bubble_vertical_margin;
}
......
......@@ -113,10 +113,6 @@ 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.
......
......@@ -27,7 +27,6 @@ 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;
......
......@@ -10,6 +10,7 @@
#include "ash/public/cpp/holding_space/holding_space_constants.h"
#include "ash/public/cpp/holding_space/holding_space_controller.h"
#include "ash/public/cpp/holding_space/holding_space_item.h"
#include "ash/public/cpp/holding_space/holding_space_metrics.h"
#include "ash/public/cpp/holding_space/holding_space_model.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
......@@ -33,34 +34,34 @@
#include "ui/views/view_class_properties.h"
namespace ash {
namespace {
// Helpers ---------------------------------------------------------------------
// Sets up the specified `label`.
void SetupLabel(views::Label* label) {
TrayPopupItemStyle(TrayPopupItemStyle::FontStyle::SUB_HEADER)
.SetupLabel(label);
label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
}
// DownloadsHeader--------------------------------------------------------------
class DownloadsHeader : public views::Button {
public:
explicit DownloadsHeader() {
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal));
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
// Accessiblity
GetViewAccessibility().OverrideName(
SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_DOWNLOADS_TITLE));
GetViewAccessibility().OverrideRole(ax::mojom::Role::kButton);
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets(),
kHoldingSpaceDownloadsHeaderSpacing));
auto* label = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_DOWNLOADS_TITLE)));
SetupLabel(label);
layout->SetFlexForView(label, 1);
SetupLabel(label);
auto* chevron = AddChildView(std::make_unique<views::ImageView>());
chevron->EnableCanvasFlippingForRTLUI(true);
......@@ -70,46 +71,57 @@ class DownloadsHeader : public views::Button {
chevron->SetImage(CreateVectorIcon(
kChevronRightIcon, kHoldingSpaceDownloadsChevronIconSize, icon_color));
set_callback(base::BindRepeating(&DownloadsHeader::OpenDownloadsFolder,
set_callback(base::BindRepeating(&DownloadsHeader::OnPressed,
base::Unretained(this)));
}
private:
void OpenDownloadsFolder() {
void OnPressed() {
holding_space_metrics::RecordDownloadsAction(
holding_space_metrics::DownloadsAction::kClick);
HoldingSpaceController::Get()->client()->OpenDownloads(base::DoNothing());
}
};
} // namespace
// RecentFilesContainer --------------------------------------------------------
RecentFilesContainer::RecentFilesContainer(
HoldingSpaceItemViewDelegate* delegate)
: delegate_(delegate) {
SetID(kHoldingSpaceRecentFilesContainerId);
SetVisible(false);
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, kHoldingSpaceContainerPadding,
kHoldingSpaceContainerChildSpacing));
auto* screenshots_label = AddChildView(std::make_unique<views::Label>(
screenshots_label_ = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_SCREENSHOTS_TITLE)));
SetupLabel(screenshots_label);
screenshots_label->SetPaintToLayer();
screenshots_label->layer()->SetFillsBoundsOpaquely(false);
screenshots_label_->SetPaintToLayer();
screenshots_label_->layer()->SetFillsBoundsOpaquely(false);
screenshots_label_->SetVisible(false);
SetupLabel(screenshots_label_);
screenshots_container_ = AddChildView(std::make_unique<views::View>());
screenshots_container_->SetVisible(false);
screenshots_container_
->SetLayoutManager(std::make_unique<views::FlexLayout>())
->SetOrientation(views::LayoutOrientation::kHorizontal)
.SetInteriorMargin(kHoldingSpaceScreenshotsContainerPadding)
.SetDefault(views::kMarginsKey,
gfx::Insets(/*top=*/0, /*left=*/0, /*bottom=*/0,
/*right=*/kHoldingSpaceScreenshotSpacing));
AddChildView(std::make_unique<DownloadsHeader>());
downloads_header_ = AddChildView(std::make_unique<DownloadsHeader>());
downloads_header_->SetPaintToLayer();
downloads_header_->layer()->SetFillsBoundsOpaquely(false);
downloads_header_->SetVisible(false);
downloads_container_ =
AddChildView(std::make_unique<HoldingSpaceItemChipsContainer>());
downloads_container_->SetVisible(false);
if (HoldingSpaceController::Get()->model())
OnHoldingSpaceModelAttached(HoldingSpaceController::Get()->model());
......@@ -117,6 +129,26 @@ RecentFilesContainer::RecentFilesContainer(
RecentFilesContainer::~RecentFilesContainer() = default;
void RecentFilesContainer::ChildVisibilityChanged(views::View* child) {
// The recent files container should be visible iff it has visible children.
bool visible = false;
for (const views::View* c : children())
visible |= c->GetVisible();
if (visible != GetVisible())
SetVisible(visible);
HoldingSpaceItemViewsContainer::ChildVisibilityChanged(child);
}
void RecentFilesContainer::ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) {
if (details.parent == screenshots_container_)
OnScreenshotsContainerViewHierarchyChanged(details);
else if (details.parent == downloads_container_)
OnDownloadsContainerViewHierarchyChanged(details);
}
void RecentFilesContainer::AddHoldingSpaceItemView(
const HoldingSpaceItem* item) {
if (item->type() == HoldingSpaceItem::Type::kScreenshot)
......@@ -237,4 +269,22 @@ void RecentFilesContainer::RemoveHoldingSpaceDownloadView(
}
}
void RecentFilesContainer::OnScreenshotsContainerViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) {
// Update screenshots visibility when becoming empty or non-empty.
if (screenshots_container_->children().size() == 1u) {
screenshots_label_->SetVisible(details.is_add);
screenshots_container_->SetVisible(details.is_add);
}
}
void RecentFilesContainer::OnDownloadsContainerViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) {
// Update downloads visibility when becoming empty or non-empty.
if (downloads_container_->children().size() == 1u) {
downloads_header_->SetVisible(details.is_add);
downloads_container_->SetVisible(details.is_add);
}
}
} // namespace ash
\ No newline at end of file
......@@ -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 RecentFilesContainer : public HoldingSpaceItemViewsContainer {
~RecentFilesContainer() 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;
......@@ -32,10 +38,17 @@ class RecentFilesContainer : public HoldingSpaceItemViewsContainer {
void RemoveHoldingSpaceScreenshotView(const HoldingSpaceItem* item);
void AddHoldingSpaceDownloadView(const HoldingSpaceItem* item);
void RemoveHoldingSpaceDownloadView(const HoldingSpaceItem* item);
void OnScreenshotsContainerViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details);
void OnDownloadsContainerViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details);
HoldingSpaceItemViewDelegate* const delegate_;
views::View* screenshots_container_ = nullptr;
views::Label* screenshots_label_ = nullptr;
HoldingSpaceItemChipsContainer* downloads_container_ = nullptr;
views::View* downloads_header_ = nullptr;
std::map<std::string, views::View*> views_by_item_id_;
};
......
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