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