Commit 3eba5861 authored by Ahmed Mehfooz's avatar Ahmed Mehfooz Committed by Commit Bot

Make pinned files container scrollable

Limit the size of the pinned files container to make sure
it's always 8px below the top of the screen.

Bug: 1131268
Change-Id: I0533873d0039f1d1952e396724cebae10fc50200
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2427542
Commit-Queue: Ahmed Mehfooz <amehfooz@chromium.org>
Reviewed-by: default avatarDavid Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#811348}
parent 5db2d14d
...@@ -30,6 +30,7 @@ constexpr gfx::Insets kHoldingSpaceScreenshotPadding(8); ...@@ -30,6 +30,7 @@ constexpr gfx::Insets kHoldingSpaceScreenshotPadding(8);
constexpr int kHoldingSpaceScreenshotSpacing = 8; constexpr int kHoldingSpaceScreenshotSpacing = 8;
constexpr gfx::Size kHoldingSpaceScreenshotSize(104, 80); constexpr gfx::Size kHoldingSpaceScreenshotSize(104, 80);
constexpr gfx::Insets kHoldingSpaceScreenshotsContainerPadding(8, 0); constexpr gfx::Insets kHoldingSpaceScreenshotsContainerPadding(8, 0);
constexpr int kHoldingSpaceTrayIconMainAxisMargin = 6;
// Context menu commands. // Context menu commands.
enum HoldingSpaceCommandId { enum HoldingSpaceCommandId {
......
...@@ -24,11 +24,6 @@ ...@@ -24,11 +24,6 @@
namespace ash { namespace ash {
namespace {
// Padding for tray icon (dp; the button that shows the palette menu).
constexpr int kTrayIconMainAxisInset = 6;
} // namespace
HoldingSpaceTray::HoldingSpaceTray(Shelf* shelf) : TrayBackgroundView(shelf) { HoldingSpaceTray::HoldingSpaceTray(Shelf* shelf) : TrayBackgroundView(shelf) {
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
...@@ -37,7 +32,7 @@ HoldingSpaceTray::HoldingSpaceTray(Shelf* shelf) : TrayBackgroundView(shelf) { ...@@ -37,7 +32,7 @@ HoldingSpaceTray::HoldingSpaceTray(Shelf* shelf) : TrayBackgroundView(shelf) {
icon_->SetImage(CreateVectorIcon(kHoldingSpaceIcon, icon_->SetImage(CreateVectorIcon(kHoldingSpaceIcon,
ShelfConfig::Get()->shelf_icon_color())); ShelfConfig::Get()->shelf_icon_color()));
tray_container()->SetMargin(kTrayIconMainAxisInset, 0); tray_container()->SetMargin(kHoldingSpaceTrayIconMainAxisMargin, 0);
} }
HoldingSpaceTray::~HoldingSpaceTray() = default; HoldingSpaceTray::~HoldingSpaceTray() = default;
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
#include "ash/system/tray/tray_bubble_wrapper.h" #include "ash/system/tray/tray_bubble_wrapper.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_utils.h" #include "ash/system/tray/tray_utils.h"
#include "ui/views/controls/separator.h" #include "ash/wm/work_area_insets.h"
#include "ui/aura/window.h"
#include "ui/views/layout/box_layout.h"
namespace ash { namespace ash {
...@@ -29,11 +31,32 @@ void SetupViewLayer(views::View* view) { ...@@ -29,11 +31,32 @@ void SetupViewLayer(views::View* view) {
layer->SetFillsBoundsOpaquely(false); layer->SetFillsBoundsOpaquely(false);
layer->SetIsFastRoundedCorner(true); layer->SetIsFastRoundedCorner(true);
} }
class HoldingSpaceBubbleContainerView : public views::View {
public:
HoldingSpaceBubbleContainerView() {
layout_ = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(),
kHoldingSpaceContainerSpacing));
}
void SetFlexForChild(views::View* child, int flex) {
layout_->SetFlexForView(child, flex);
}
void ChildPreferredSizeChanged(views::View* child) override {
PreferredSizeChanged();
}
private:
views::BoxLayout* layout_ = nullptr;
};
} // namespace } // namespace
HoldingSpaceTrayBubble::HoldingSpaceTrayBubble( HoldingSpaceTrayBubble::HoldingSpaceTrayBubble(
HoldingSpaceTray* holding_space_tray, HoldingSpaceTray* holding_space_tray,
bool show_by_click) { bool show_by_click)
: holding_space_tray_(holding_space_tray) {
TrayBubbleView::InitParams init_params; TrayBubbleView::InitParams init_params;
init_params.delegate = holding_space_tray; init_params.delegate = holding_space_tray;
init_params.parent_window = holding_space_tray->GetBubbleWindowContainer(); init_params.parent_window = holding_space_tray->GetBubbleWindowContainer();
...@@ -50,18 +73,21 @@ HoldingSpaceTrayBubble::HoldingSpaceTrayBubble( ...@@ -50,18 +73,21 @@ HoldingSpaceTrayBubble::HoldingSpaceTrayBubble(
holding_space_tray->GetBubbleAnchorInsets()); holding_space_tray->GetBubbleAnchorInsets());
bubble_view->set_margins(GetSecondaryBubbleInsets()); bubble_view->set_margins(GetSecondaryBubbleInsets());
bubble_view->SetMaxHeight(CalculateMaxHeight());
HoldingSpaceBubbleContainerView* bubble_container_view =
bubble_view->AddChildView(
std::make_unique<HoldingSpaceBubbleContainerView>());
// Add pinned files container. // Add pinned files container.
pinned_files_container_ = bubble_view->AddChildView( pinned_files_container_ = bubble_container_view->AddChildView(
std::make_unique<PinnedFilesContainer>(&delegate_)); std::make_unique<PinnedFilesContainer>(&delegate_));
SetupViewLayer(pinned_files_container_); bubble_container_view->SetFlexForChild(pinned_files_container_, 1);
// Separator between the two containers, gives illusion of 2 separate bubbles. SetupViewLayer(pinned_files_container_);
auto* separator =
bubble_view->AddChildView(std::make_unique<views::Separator>());
separator->SetBorder(views::CreateEmptyBorder(
gfx::Insets(kHoldingSpaceContainerSpacing, 0, 0, 0)));
recent_files_container_ = bubble_view->AddChildView( // Add recent files container.
recent_files_container_ = bubble_container_view->AddChildView(
std::make_unique<RecentFilesContainer>(&delegate_)); std::make_unique<RecentFilesContainer>(&delegate_));
SetupViewLayer(recent_files_container_); SetupViewLayer(recent_files_container_);
...@@ -93,4 +119,20 @@ views::Widget* HoldingSpaceTrayBubble::GetBubbleWidget() { ...@@ -93,4 +119,20 @@ views::Widget* HoldingSpaceTrayBubble::GetBubbleWidget() {
return bubble_wrapper_->GetBubbleWidget(); return bubble_wrapper_->GetBubbleWidget();
} }
int HoldingSpaceTrayBubble::CalculateMaxHeight() const {
gfx::Rect anchor_bounds =
holding_space_tray_->GetBubbleAnchor()->GetBoundsInScreen();
int bottom = holding_space_tray_->shelf()->IsHorizontalAlignment()
? anchor_bounds.y() - kHoldingSpaceTrayIconMainAxisMargin
: anchor_bounds.bottom();
WorkAreaInsets* work_area = WorkAreaInsets::ForWindow(
holding_space_tray_->shelf()->GetWindow()->GetRootWindow());
int free_space_height_above_anchor =
bottom - work_area->user_work_area_bounds().y();
int bubble_vertical_margin = GetSecondaryBubbleInsets().bottom() * 2;
return free_space_height_above_anchor - bubble_vertical_margin;
}
} // namespace ash } // namespace ash
...@@ -31,6 +31,12 @@ class ASH_EXPORT HoldingSpaceTrayBubble { ...@@ -31,6 +31,12 @@ class ASH_EXPORT HoldingSpaceTrayBubble {
views::Widget* GetBubbleWidget(); views::Widget* GetBubbleWidget();
private: private:
// Return the maximum height available for the holding space bubble.
int CalculateMaxHeight() const;
// The owner of this class.
HoldingSpaceTray* const holding_space_tray_;
// The singleton delegate for `HoldingSpaceItemView`s that implements support // The singleton delegate for `HoldingSpaceItemView`s that implements support
// for context menu, drag-and-drop, and multiple selection. // for context menu, drag-and-drop, and multiple selection.
HoldingSpaceItemViewDelegate delegate_; HoldingSpaceItemViewDelegate delegate_;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ash/system/holding_space/pinned_files_container.h" #include "ash/system/holding_space/pinned_files_container.h"
#include <memory>
#include "ash/public/cpp/holding_space/holding_space_constants.h" #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_controller.h"
#include "ash/public/cpp/holding_space/holding_space_item.h" #include "ash/public/cpp/holding_space/holding_space_item.h"
...@@ -14,14 +16,43 @@ ...@@ -14,14 +16,43 @@
#include "ash/system/holding_space/holding_space_item_chips_container.h" #include "ash/system/holding_space/holding_space_item_chips_container.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_popup_item_style.h" #include "ash/system/tray/tray_popup_item_style.h"
#include "base/optional.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/separator.h" #include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/view_observer.h"
namespace ash { namespace ash {
namespace {
class HoldingSpaceScrollView : public views::ScrollView,
public views::ViewObserver {
public:
HoldingSpaceItemChipsContainer* SetContents(
std::unique_ptr<HoldingSpaceItemChipsContainer> view) {
HoldingSpaceItemChipsContainer* contents =
views::ScrollView::SetContents(std::move(view));
view_observer_.Add(contents);
return contents;
}
// views::ViewObserver:
void OnViewPreferredSizeChanged(View* observed_view) override {
PreferredSizeChanged();
}
void OnViewIsDeleting(View* observed_view) override {
view_observer_.Remove(observed_view);
}
private:
ScopedObserver<views::View, views::ViewObserver> view_observer_{this};
};
} // namespace
PinnedFilesContainer::PinnedFilesContainer( PinnedFilesContainer::PinnedFilesContainer(
HoldingSpaceItemViewDelegate* delegate) HoldingSpaceItemViewDelegate* delegate)
: delegate_(delegate) { : delegate_(delegate) {
...@@ -39,8 +70,13 @@ PinnedFilesContainer::PinnedFilesContainer( ...@@ -39,8 +70,13 @@ PinnedFilesContainer::PinnedFilesContainer(
title_label->SetPaintToLayer(); title_label->SetPaintToLayer();
title_label->layer()->SetFillsBoundsOpaquely(false); title_label->layer()->SetFillsBoundsOpaquely(false);
auto* scroller = AddChildView(std::make_unique<HoldingSpaceScrollView>());
scroller->SetBackgroundColor(base::nullopt);
scroller->SetDrawOverflowIndicator(false);
scroller->ClipHeightTo(0, INT_MAX);
item_chips_container_ = item_chips_container_ =
AddChildView(std::make_unique<HoldingSpaceItemChipsContainer>()); scroller->SetContents(std::make_unique<HoldingSpaceItemChipsContainer>());
if (HoldingSpaceController::Get()->model()) if (HoldingSpaceController::Get()->model())
OnHoldingSpaceModelAttached(HoldingSpaceController::Get()->model()); OnHoldingSpaceModelAttached(HoldingSpaceController::Get()->model());
......
...@@ -29,6 +29,7 @@ class PinnedFilesContainer : public HoldingSpaceItemViewsContainer { ...@@ -29,6 +29,7 @@ class PinnedFilesContainer : public HoldingSpaceItemViewsContainer {
private: private:
HoldingSpaceItemViewDelegate* const delegate_; HoldingSpaceItemViewDelegate* const delegate_;
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_;
......
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