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

Rename HoldingSpaceTrayIconItem to HoldingSpaceTrayIconPreview.

This will make our terminology consistent with UX terminology in the
spec and should hopefully clear up some amiguity/confusion that may
have arisen due to using the term "item" in a context not directly
referring to a holding space model item.

Bug: 1142572
Change-Id: I59adbeebbd83f95c1bf377c7941f8b149d6f4448
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523059
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824967}
parent 4ef013cc
......@@ -983,8 +983,8 @@ component("ash") {
"system/holding_space/holding_space_tray_bubble.h",
"system/holding_space/holding_space_tray_icon.cc",
"system/holding_space/holding_space_tray_icon.h",
"system/holding_space/holding_space_tray_icon_item.cc",
"system/holding_space/holding_space_tray_icon_item.h",
"system/holding_space/holding_space_tray_icon_preview.cc",
"system/holding_space/holding_space_tray_icon_preview.h",
"system/holding_space/pinned_files_container.cc",
"system/holding_space/pinned_files_container.h",
"system/holding_space/recent_files_container.cc",
......
......@@ -37,7 +37,7 @@ constexpr gfx::Size kHoldingSpaceScreenCaptureSize(104, 80);
constexpr gfx::Insets kHoldingSpaceScreenCapturesContainerPadding(8, 0);
constexpr float kHoldingSpaceSelectedOverlayOpacity = 0.24f;
constexpr int kHoldingSpaceTrayIconMainAxisMargin = 6;
constexpr int kHoldingSpaceTrayIconMaxVisibleItems = 3;
constexpr int kHoldingSpaceTrayIconMaxVisiblePreviews = 3;
constexpr int kHoldingSpaceTrayIconSize = 20;
// Context menu commands.
......
......@@ -11,7 +11,7 @@
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shelf/shelf.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/holding_space/holding_space_tray_icon_item.h"
#include "ash/system/holding_space/holding_space_tray_icon_preview.h"
#include "ash/system/tray/tray_constants.h"
#include "base/containers/unique_ptr_adapters.h"
#include "base/stl_util.h"
......@@ -99,11 +99,12 @@ void HoldingSpaceTrayIcon::OnHoldingSpaceItemAdded(
if (!item->IsFinalized())
return;
for (std::unique_ptr<HoldingSpaceTrayIconItem>& icon_item : icon_items_)
icon_item->AnimateShift();
for (std::unique_ptr<HoldingSpaceTrayIconPreview>& preview : previews_)
preview->AnimateShift();
icon_items_.push_back(std::make_unique<HoldingSpaceTrayIconItem>(this, item));
icon_items_.back()->AnimateIn(/*index=*/0u);
auto preview = std::make_unique<HoldingSpaceTrayIconPreview>(this, item);
previews_.push_back(std::move(preview));
previews_.back()->AnimateIn(/*index=*/0u);
UpdatePreferredSize();
}
......@@ -112,26 +113,26 @@ void HoldingSpaceTrayIcon::OnHoldingSpaceItemRemoved(
const HoldingSpaceItem* item) {
DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled());
size_t index = icon_items_.size();
for (size_t i = 0u; i < icon_items_.size(); ++i) {
if (icon_items_[i]->item() == item) {
size_t index = previews_.size();
for (size_t i = 0u; i < previews_.size(); ++i) {
if (previews_[i]->item() == item) {
index = i;
break;
}
}
DCHECK_LT(index, icon_items_.size());
DCHECK_LT(index, previews_.size());
removed_icon_items_.push_back(std::move(icon_items_[index]));
icon_items_.erase(icon_items_.begin() + index);
removed_previews_.push_back(std::move(previews_[index]));
previews_.erase(previews_.begin() + index);
for (int i = index - 1; i >= 0; --i)
icon_items_[i]->AnimateUnshift();
previews_[i]->AnimateUnshift();
removed_icon_items_.back()->AnimateOut(base::BindOnce(
&HoldingSpaceTrayIcon::OnHoldingSpaceTrayIconItemAnimatedOut,
removed_previews_.back()->AnimateOut(base::BindOnce(
&HoldingSpaceTrayIcon::OnHoldingSpaceTrayIconPreviewAnimatedOut,
base::Unretained(this),
base::Unretained(removed_icon_items_.back().get())));
base::Unretained(removed_previews_.back().get())));
UpdatePreferredSize();
}
......@@ -140,7 +141,7 @@ void HoldingSpaceTrayIcon::OnHoldingSpaceItemFinalized(
const HoldingSpaceItem* item) {
DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled());
if (icon_items_.empty()) {
if (previews_.empty()) {
OnHoldingSpaceItemAdded(item);
return;
}
......@@ -155,13 +156,13 @@ void HoldingSpaceTrayIcon::OnHoldingSpaceItemFinalized(
}
for (size_t i = 0; i < index; ++i)
icon_items_[i]->AnimateShift();
previews_[i]->AnimateShift();
auto icon_item = std::make_unique<HoldingSpaceTrayIconItem>(this, item);
icon_items_.insert(icon_items_.begin() + index, std::move(icon_item));
auto preview = std::make_unique<HoldingSpaceTrayIconPreview>(this, item);
previews_.insert(previews_.begin() + index, std::move(preview));
// NOTE: UI ordering is inverse of model ordering so take `index` from end.
icon_items_[index]->AnimateIn(icon_items_.size() - index - 1);
// NOTE: UI sort is inverse of model sort so take `index` from end.
previews_[index]->AnimateIn(previews_.size() - index - 1);
UpdatePreferredSize();
}
......@@ -171,21 +172,22 @@ void HoldingSpaceTrayIcon::OnShelfAlignmentChanged(
ShelfAlignment old_alignment) {
DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled());
removed_icon_items_.clear();
removed_previews_.clear();
for (const auto& icon_item : icon_items_)
icon_item->OnShelfAlignmentChanged(old_alignment, shelf_->alignment());
for (const auto& preview : previews_)
preview->OnShelfAlignmentChanged(old_alignment, shelf_->alignment());
UpdatePreferredSize();
}
void HoldingSpaceTrayIcon::UpdatePreferredSize() {
const int num_visible_items = std::min(kHoldingSpaceTrayIconMaxVisibleItems,
static_cast<int>(icon_items_.size()));
const int num_visible_previews =
std::min(kHoldingSpaceTrayIconMaxVisiblePreviews,
static_cast<int>(previews_.size()));
int primary_axis_size = kTrayItemSize;
if (num_visible_items > 1)
primary_axis_size += (num_visible_items - 1) * kTrayItemSize / 2;
if (num_visible_previews > 1)
primary_axis_size += (num_visible_previews - 1) * kTrayItemSize / 2;
gfx::Size preferred_size = shelf_->PrimaryAxisValue(
/*horizontal=*/gfx::Size(primary_axis_size, kTrayItemSize),
......@@ -195,9 +197,9 @@ void HoldingSpaceTrayIcon::UpdatePreferredSize() {
SetPreferredSize(preferred_size);
}
void HoldingSpaceTrayIcon::OnHoldingSpaceTrayIconItemAnimatedOut(
HoldingSpaceTrayIconItem* icon_item) {
base::EraseIf(removed_icon_items_, base::MatchesUniquePtr(icon_item));
void HoldingSpaceTrayIcon::OnHoldingSpaceTrayIconPreviewAnimatedOut(
HoldingSpaceTrayIconPreview* preview) {
base::EraseIf(removed_previews_, base::MatchesUniquePtr(preview));
}
BEGIN_METADATA(HoldingSpaceTrayIcon, views::View)
......
......@@ -21,7 +21,7 @@
namespace ash {
class HoldingSpaceTrayIconItem;
class HoldingSpaceTrayIconPreview;
class Shelf;
// TODO(crbug.com/1142572): Implement content forward icon w/ motion spec.
......@@ -67,20 +67,20 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View,
void InitLayout();
void UpdatePreferredSize();
// Invoked when the specified icon item has completed animated out. At this
// point it is owned by `removed_icon_items_` and should be destroyed.
void OnHoldingSpaceTrayIconItemAnimatedOut(HoldingSpaceTrayIconItem*);
// Invoked when the specified preview has completed animating out. At this
// point it is owned by `removed_previews_` and should be destroyed.
void OnHoldingSpaceTrayIconPreviewAnimatedOut(HoldingSpaceTrayIconPreview*);
// The shelf associated with this holding space tray icon.
Shelf* const shelf_;
// An icon item is added to the tray icon to visually represent each holding
// space item. Upon creation, icon items are added to `icon_items_` where they
// are owned until being animated out. Upon being animated out, icon items are
// moved to `removed_icon_items_` where they are owned until the out animation
// completes and are subsequently destroyed.
std::vector<std::unique_ptr<HoldingSpaceTrayIconItem>> icon_items_;
std::vector<std::unique_ptr<HoldingSpaceTrayIconItem>> removed_icon_items_;
// A preview is added to the tray icon to visually represent each holding
// space item. Upon creation, previews are added to `previews_` where they
// are owned until being animated out. Upon being animated out, previews are
// moved to `removed_previews_` where they are owned until the out animation
// completes and they are subsequently destroyed.
std::vector<std::unique_ptr<HoldingSpaceTrayIconPreview>> previews_;
std::vector<std::unique_ptr<HoldingSpaceTrayIconPreview>> removed_previews_;
ScopedObserver<HoldingSpaceController, HoldingSpaceControllerObserver>
controller_observer_{this};
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/holding_space/holding_space_tray_icon_item.h"
#include "ash/system/holding_space/holding_space_tray_icon_preview.h"
#include "ash/public/cpp/holding_space/holding_space_constants.h"
#include "ash/public/cpp/holding_space/holding_space_image.h"
......@@ -151,20 +151,21 @@ class ContentsImage : public gfx::ImageSkia {
} // namespace
// HoldingSpaceTrayIconItem ----------------------------------------------------
// HoldingSpaceTrayIconPreview -------------------------------------------------
HoldingSpaceTrayIconItem::HoldingSpaceTrayIconItem(HoldingSpaceTrayIcon* icon,
const HoldingSpaceItem* item)
HoldingSpaceTrayIconPreview::HoldingSpaceTrayIconPreview(
HoldingSpaceTrayIcon* icon,
const HoldingSpaceItem* item)
: icon_(icon), item_(item) {
contents_image_ = std::make_unique<ContentsImage>(
item_, base::BindRepeating(&HoldingSpaceTrayIconItem::InvalidateLayer,
item_, base::BindRepeating(&HoldingSpaceTrayIconPreview::InvalidateLayer,
base::Unretained(this)));
icon_observer_.Add(icon_);
}
HoldingSpaceTrayIconItem::~HoldingSpaceTrayIconItem() = default;
HoldingSpaceTrayIconPreview::~HoldingSpaceTrayIconPreview() = default;
void HoldingSpaceTrayIconItem::AnimateIn(size_t index) {
void HoldingSpaceTrayIconPreview::AnimateIn(size_t index) {
DCHECK(transform_.IsIdentity());
if (index > 0u) {
......@@ -196,7 +197,7 @@ void HoldingSpaceTrayIconItem::AnimateIn(size_t index) {
layer_->SetTransform(transform_);
}
void HoldingSpaceTrayIconItem::AnimateOut(
void HoldingSpaceTrayIconPreview::AnimateOut(
base::OnceClosure animate_out_closure) {
animate_out_closure_ = std::move(animate_out_closure);
......@@ -213,7 +214,7 @@ void HoldingSpaceTrayIconItem::AnimateOut(
layer_->SetVisible(false);
}
void HoldingSpaceTrayIconItem::AnimateShift() {
void HoldingSpaceTrayIconPreview::AnimateShift() {
gfx::Vector2dF translation(kTrayItemSize / 2, 0);
AdjustForShelfAlignmentAndTextDirection(&translation);
transform_.Translate(translation);
......@@ -233,7 +234,7 @@ void HoldingSpaceTrayIconItem::AnimateShift() {
}
}
void HoldingSpaceTrayIconItem::AnimateUnshift() {
void HoldingSpaceTrayIconPreview::AnimateUnshift() {
gfx::Vector2dF translation(-kTrayItemSize / 2, 0);
AdjustForShelfAlignmentAndTextDirection(&translation);
transform_.Translate(translation);
......@@ -263,7 +264,7 @@ void HoldingSpaceTrayIconItem::AnimateUnshift() {
layer_->SetOpacity(1.f);
}
void HoldingSpaceTrayIconItem::OnShelfAlignmentChanged(
void HoldingSpaceTrayIconPreview::OnShelfAlignmentChanged(
ShelfAlignment old_shelf_alignment,
ShelfAlignment new_shelf_alignment) {
// If shelf orientation has not changed, no action needs to be taken.
......@@ -307,7 +308,8 @@ void HoldingSpaceTrayIconItem::OnShelfAlignmentChanged(
}
// TODO(crbug.com/1142572): Support theming.
void HoldingSpaceTrayIconItem::OnPaintLayer(const ui::PaintContext& context) {
void HoldingSpaceTrayIconPreview::OnPaintLayer(
const ui::PaintContext& context) {
const gfx::Rect contents_bounds = GetContentsBounds();
ui::PaintRecorder recorder(context, gfx::Size(kTrayItemSize, kTrayItemSize));
......@@ -330,13 +332,13 @@ void HoldingSpaceTrayIconItem::OnPaintLayer(const ui::PaintContext& context) {
}
}
void HoldingSpaceTrayIconItem::OnDeviceScaleFactorChanged(
void HoldingSpaceTrayIconPreview::OnDeviceScaleFactorChanged(
float old_device_scale_factor,
float new_device_scale_factor) {
InvalidateLayer();
}
void HoldingSpaceTrayIconItem::OnImplicitAnimationsCompleted() {
void HoldingSpaceTrayIconPreview::OnImplicitAnimationsCompleted() {
if (layer_->visible())
return;
......@@ -348,18 +350,18 @@ void HoldingSpaceTrayIconItem::OnImplicitAnimationsCompleted() {
std::move(animate_out_closure_).Run();
}
void HoldingSpaceTrayIconItem::OnViewBoundsChanged(views::View* view) {
void HoldingSpaceTrayIconPreview::OnViewBoundsChanged(views::View* view) {
DCHECK_EQ(icon_, view);
if (layer_)
UpdateLayerBounds();
}
void HoldingSpaceTrayIconItem::OnViewIsDeleting(views::View* view) {
void HoldingSpaceTrayIconPreview::OnViewIsDeleting(views::View* view) {
DCHECK_EQ(icon_, view);
icon_observer_.Remove(icon_);
}
void HoldingSpaceTrayIconItem::CreateLayer() {
void HoldingSpaceTrayIconPreview::CreateLayer() {
DCHECK(!layer_);
layer_ = std::make_unique<ui::Layer>(ui::LAYER_TEXTURED);
layer_->SetFillsBoundsOpaquely(false);
......@@ -368,7 +370,7 @@ void HoldingSpaceTrayIconItem::CreateLayer() {
UpdateLayerBounds();
}
bool HoldingSpaceTrayIconItem::NeedsLayer() const {
bool HoldingSpaceTrayIconPreview::NeedsLayer() const {
// With horizontal shelf in RTL, `primary_axis_translation` is expected to be
// negative prior to taking its absolute value since it represents an offset
// relative to the parent layer's right bound.
......@@ -377,15 +379,15 @@ bool HoldingSpaceTrayIconItem::NeedsLayer() const {
/*horizontal=*/transform_.To2dTranslation().x(),
/*vertical=*/transform_.To2dTranslation().y()));
return primary_axis_translation <
kHoldingSpaceTrayIconMaxVisibleItems * kTrayItemSize / 2;
kHoldingSpaceTrayIconMaxVisiblePreviews * kTrayItemSize / 2;
}
void HoldingSpaceTrayIconItem::InvalidateLayer() {
void HoldingSpaceTrayIconPreview::InvalidateLayer() {
if (layer_)
layer_->SchedulePaint(gfx::Rect(layer_->size()));
}
void HoldingSpaceTrayIconItem::AdjustForShelfAlignmentAndTextDirection(
void HoldingSpaceTrayIconPreview::AdjustForShelfAlignmentAndTextDirection(
gfx::Vector2dF* vector_2df) {
if (!icon_->shelf()->IsHorizontalAlignment()) {
const float x = vector_2df->x();
......@@ -399,7 +401,7 @@ void HoldingSpaceTrayIconItem::AdjustForShelfAlignmentAndTextDirection(
vector_2df->Scale(-1.f);
}
void HoldingSpaceTrayIconItem::UpdateLayerBounds() {
void HoldingSpaceTrayIconPreview::UpdateLayerBounds() {
DCHECK(layer_);
// With a horizontal shelf in RTL, `layer_` is aligned with its parent layer's
// right bound and translated with a negative offset. In all other cases,
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_TRAY_ICON_ITEM_H_
#define ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_TRAY_ICON_ITEM_H_
#ifndef ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_TRAY_ICON_PREVIEW_H_
#define ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_TRAY_ICON_PREVIEW_H_
#include <memory>
#include <string>
......@@ -33,26 +33,27 @@ enum class ShelfAlignment;
// Class to visually represent a single holding space item within the holding
// space tray icon in the shelf. While determined to be within the icon's
// viewport, each instance will manage a layer for the holding space tray icon.
class ASH_EXPORT HoldingSpaceTrayIconItem
class ASH_EXPORT HoldingSpaceTrayIconPreview
: public ui::LayerDelegate,
public ui::ImplicitAnimationObserver,
public views::ViewObserver {
public:
HoldingSpaceTrayIconItem(HoldingSpaceTrayIcon*, const HoldingSpaceItem*);
HoldingSpaceTrayIconItem(const HoldingSpaceTrayIconItem&) = delete;
HoldingSpaceTrayIconItem& operator=(const HoldingSpaceTrayIconItem&) = delete;
~HoldingSpaceTrayIconItem() override;
HoldingSpaceTrayIconPreview(HoldingSpaceTrayIcon*, const HoldingSpaceItem*);
HoldingSpaceTrayIconPreview(const HoldingSpaceTrayIconPreview&) = delete;
HoldingSpaceTrayIconPreview& operator=(const HoldingSpaceTrayIconPreview&) =
delete;
~HoldingSpaceTrayIconPreview() override;
// Animates this item in at the specified `index`.
// Animates this preview in at the specified `index`.
void AnimateIn(size_t index);
// Animates this item out, invoking the specified closure on completion.
// Animates this preview out, invoking the specified closure on completion.
void AnimateOut(base::OnceClosure animate_out_closure);
// Animates a shift of this item.
// Animates a shift of this preview.
void AnimateShift();
// Animates an unshift of this item.
// Animates an unshift of this preview.
void AnimateUnshift();
// Invoked when the shelf associated with `icon_` has changed from
......@@ -60,7 +61,7 @@ class ASH_EXPORT HoldingSpaceTrayIconItem
void OnShelfAlignmentChanged(ShelfAlignment old_shelf_alignment,
ShelfAlignment new_shelf_alignment);
// Returns the holding space `item_` visually represented by this instance.
// Returns the holding space `item_` visually represented by this preview.
const HoldingSpaceItem* item() const { return item_; }
private:
......@@ -76,14 +77,15 @@ class ASH_EXPORT HoldingSpaceTrayIconItem
void OnViewBoundsChanged(views::View* observed_view) override;
void OnViewIsDeleting(views::View* observed_view) override;
// Creates the `layer_` for this item. Note that `layer_` may be created
// multiple times throughout this instance's lifetime as `layer_` will only
// Creates the `layer_` for this preview. Note that `layer_` may be created
// multiple times throughout this preview's lifetime as `layer_` will only
// exist while in the viewport for the holding space tray `icon_`.
void CreateLayer();
// Returns whether this item needs a layer for its current `transform_`. Since
// we only maintain `layer_` while it appears in the viewport for the holding
// space tray `icon_`, this is used to gate creation/deletion of `layer_`.
// Returns whether this preview needs a layer for its current `transform_`.
// Since we only maintain `layer_` while it appears in the viewport for the
// holding space tray `icon_`, this is used to gate creation/deletion of
// `layer_`.
bool NeedsLayer() const;
// Schedules repaint of `layer_`, no-oping if it doesn't exist.
......@@ -106,7 +108,7 @@ class ASH_EXPORT HoldingSpaceTrayIconItem
std::unique_ptr<gfx::ImageSkia> contents_image_;
// This is a proxy for `layer_`'s transform and represents the target
// position of this item. Because `layer_` only exists while in `icon_`'s
// position of this preview. Because `layer_` only exists while in `icon_`'s
// viewport, we need to manage transform ourselves and continue to update it
// even when `layer_` doesn't exist.
gfx::Transform transform_;
......@@ -117,17 +119,17 @@ class ASH_EXPORT HoldingSpaceTrayIconItem
std::unique_ptr<ui::Layer> layer_;
// Closure to invoke on completion of `AnimateOut()`. It is expected that this
// instance may be deleted during invocation.
// preview may be deleted during invocation.
base::OnceClosure animate_out_closure_;
// The `layer_` for this icon item is parented by `icon_`'s layer. It is
// The `layer_` for this preview is parented by `icon_`'s layer. It is
// necessary to observe and react to bounds changes in `icon_` to keep
// `layer_`'s bounds in sync.
ScopedObserver<views::View, views::ViewObserver> icon_observer_{this};
base::WeakPtrFactory<HoldingSpaceTrayIconItem> weak_factory_{this};
base::WeakPtrFactory<HoldingSpaceTrayIconPreview> weak_factory_{this};
};
} // namespace ash
#endif // ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_TRAY_ICON_ITEM_H_
#endif // ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_TRAY_ICON_PREVIEW_H_
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