Commit 864c1901 authored by David Black's avatar David Black Committed by Commit Bot

Wire up pref to hide/show previews in holding space.

Bug: 1142572
Change-Id: I67ca2b66c9a10d68e0952bd46ef3cae8ae8865bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2528638Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#825972}
parent a1a21b01
...@@ -36,7 +36,6 @@ constexpr int kHoldingSpaceScreenCaptureSpacing = 8; ...@@ -36,7 +36,6 @@ constexpr int kHoldingSpaceScreenCaptureSpacing = 8;
constexpr gfx::Size kHoldingSpaceScreenCaptureSize(104, 80); 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 kHoldingSpaceTrayIconMaxVisiblePreviews = 3; constexpr int kHoldingSpaceTrayIconMaxVisiblePreviews = 3;
constexpr int kHoldingSpaceTrayIconSize = 20; constexpr int kHoldingSpaceTrayIconSize = 20;
...@@ -54,6 +53,7 @@ enum HoldingSpaceCommandId { ...@@ -54,6 +53,7 @@ enum HoldingSpaceCommandId {
// View IDs. // View IDs.
constexpr int kHoldingSpacePinnedFilesContainerId = 1; constexpr int kHoldingSpacePinnedFilesContainerId = 1;
constexpr int kHoldingSpaceRecentFilesContainerId = 2; constexpr int kHoldingSpaceRecentFilesContainerId = 2;
constexpr int kHoldingSpaceTrayIconId = 3;
// The maximum allowed age for files restored into the holding space model. // The maximum allowed age for files restored into the holding space model.
// Note that this is not enforced for pinned items. // Note that this is not enforced for pinned items.
......
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
#include "ash/public/cpp/holding_space/holding_space_prefs.h" #include "ash/public/cpp/holding_space/holding_space_prefs.h"
#include "ash/public/cpp/ash_features.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/util/values/values_util.h" #include "base/util/values/values_util.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
...@@ -14,6 +16,9 @@ namespace holding_space_prefs { ...@@ -14,6 +16,9 @@ namespace holding_space_prefs {
namespace { namespace {
// Boolean preference storing if holding space previews are enabled.
constexpr char kPreviewsEnabled[] = "ash.holding_space.previews_enabled";
// Time preference storing when holding space first became available. // Time preference storing when holding space first became available.
constexpr char kTimeOfFirstAvailability[] = constexpr char kTimeOfFirstAvailability[] =
"ash.holding_space.time_of_first_availability"; "ash.holding_space.time_of_first_availability";
...@@ -27,11 +32,27 @@ constexpr char kTimeOfFirstPin[] = "ash.holding_space.time_of_first_pin"; ...@@ -27,11 +32,27 @@ constexpr char kTimeOfFirstPin[] = "ash.holding_space.time_of_first_pin";
} // namespace } // namespace
void RegisterProfilePrefs(PrefRegistrySimple* registry) { void RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(
kPreviewsEnabled,
features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled());
registry->RegisterTimePref(kTimeOfFirstAvailability, base::Time::UnixEpoch()); registry->RegisterTimePref(kTimeOfFirstAvailability, base::Time::UnixEpoch());
registry->RegisterTimePref(kTimeOfFirstEntry, base::Time::UnixEpoch()); registry->RegisterTimePref(kTimeOfFirstEntry, base::Time::UnixEpoch());
registry->RegisterTimePref(kTimeOfFirstPin, base::Time::UnixEpoch()); registry->RegisterTimePref(kTimeOfFirstPin, base::Time::UnixEpoch());
} }
void AddPreviewsEnabledChangedCallback(PrefChangeRegistrar* registrar,
base::RepeatingClosure callback) {
registrar->Add(kPreviewsEnabled, std::move(callback));
}
bool IsPreviewsEnabled(PrefService* prefs) {
return prefs->GetBoolean(kPreviewsEnabled);
}
void SetPreviewsEnabled(PrefService* prefs, bool enabled) {
prefs->SetBoolean(kPreviewsEnabled, enabled);
}
base::Optional<base::Time> GetTimeOfFirstAvailability(PrefService* prefs) { base::Optional<base::Time> GetTimeOfFirstAvailability(PrefService* prefs) {
auto* pref = prefs->FindPreference(kTimeOfFirstAvailability); auto* pref = prefs->FindPreference(kTimeOfFirstAvailability);
return pref->IsDefaultValue() ? base::nullopt return pref->IsDefaultValue() ? base::nullopt
......
...@@ -6,8 +6,10 @@ ...@@ -6,8 +6,10 @@
#define ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_PREFS_H_ #define ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_PREFS_H_
#include "ash/public/cpp/ash_public_export.h" #include "ash/public/cpp/ash_public_export.h"
#include "base/callback_forward.h"
#include "base/optional.h" #include "base/optional.h"
class PrefChangeRegistrar;
class PrefRegistrySimple; class PrefRegistrySimple;
class PrefService; class PrefService;
...@@ -21,6 +23,17 @@ namespace holding_space_prefs { ...@@ -21,6 +23,17 @@ namespace holding_space_prefs {
// Registers holding space profile preferences to `registry`. // Registers holding space profile preferences to `registry`.
ASH_PUBLIC_EXPORT void RegisterProfilePrefs(PrefRegistrySimple* registry); ASH_PUBLIC_EXPORT void RegisterProfilePrefs(PrefRegistrySimple* registry);
// Adds `callback` to `registrar` to be invoked on changes to previews enabled.
ASH_PUBLIC_EXPORT void AddPreviewsEnabledChangedCallback(
PrefChangeRegistrar* registrar,
base::RepeatingClosure callback);
// Returns whether previews are enabled.
ASH_PUBLIC_EXPORT bool IsPreviewsEnabled(PrefService* prefs);
// Sets whether previews are `enabled`.
ASH_PUBLIC_EXPORT void SetPreviewsEnabled(PrefService* prefs, bool enabled);
// Returns the time when holding space first became available. Note that if the // Returns the time when holding space first became available. Note that if the
// time of first availability is unmarked, `base::nullopt` is returned. // time of first availability is unmarked, `base::nullopt` is returned.
ASH_PUBLIC_EXPORT base::Optional<base::Time> GetTimeOfFirstAvailability( ASH_PUBLIC_EXPORT base::Optional<base::Time> GetTimeOfFirstAvailability(
......
...@@ -61,6 +61,9 @@ class ASH_EXPORT HoldingSpaceTestApi { ...@@ -61,6 +61,9 @@ class ASH_EXPORT HoldingSpaceTestApi {
// Returns the holding space tray in the shelf. // Returns the holding space tray in the shelf.
views::View* GetTray(); views::View* GetTray();
// Returns the holding space tray icon in the shelf.
views::View* GetTrayIcon();
// Returns whether the pinned files container is shown. // Returns whether the pinned files container is shown.
bool PinnedFilesContainerShown() const; bool PinnedFilesContainerShown() const;
......
...@@ -130,6 +130,10 @@ views::View* HoldingSpaceTestApi::GetTray() { ...@@ -130,6 +130,10 @@ views::View* HoldingSpaceTestApi::GetTray() {
return holding_space_tray_; return holding_space_tray_;
} }
views::View* HoldingSpaceTestApi::GetTrayIcon() {
return holding_space_tray_->GetViewByID(kHoldingSpaceTrayIconId);
}
bool HoldingSpaceTestApi::PinnedFilesContainerShown() const { bool HoldingSpaceTestApi::PinnedFilesContainerShown() const {
if (!holding_space_tray_->GetBubbleView()) if (!holding_space_tray_->GetBubbleView())
return false; return false;
......
...@@ -30,11 +30,6 @@ namespace { ...@@ -30,11 +30,6 @@ namespace {
// Helpers --------------------------------------------------------------------- // Helpers ---------------------------------------------------------------------
// TODO(crbug.com/1142572): Read state from prefs.
bool IsShowingPreviews() {
return features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled();
}
// Returns whether the holding space model contains any finalized items. // Returns whether the holding space model contains any finalized items.
bool ModelContainsFinalizedItems(HoldingSpaceModel* model) { bool ModelContainsFinalizedItems(HoldingSpaceModel* model) {
for (const auto& item : model->items()) { for (const auto& item : model->items()) {
...@@ -59,7 +54,6 @@ HoldingSpaceTray::HoldingSpaceTray(Shelf* shelf) : TrayBackgroundView(shelf) { ...@@ -59,7 +54,6 @@ HoldingSpaceTray::HoldingSpaceTray(Shelf* shelf) : TrayBackgroundView(shelf) {
// Icon. // Icon.
icon_ = tray_container()->AddChildView( icon_ = tray_container()->AddChildView(
std::make_unique<HoldingSpaceTrayIcon>(shelf)); std::make_unique<HoldingSpaceTrayIcon>(shelf));
tray_container()->SetMargin(icon_->GetPreferredMainAxisMargin(), 0);
} }
HoldingSpaceTray::~HoldingSpaceTray() = default; HoldingSpaceTray::~HoldingSpaceTray() = default;
...@@ -206,10 +200,21 @@ void HoldingSpaceTray::OnHoldingSpaceItemFinalized( ...@@ -206,10 +200,21 @@ void HoldingSpaceTray::OnHoldingSpaceItemFinalized(
UpdateVisibility(); UpdateVisibility();
} }
// TODO(crbug.com/1142572): Implement.
void HoldingSpaceTray::ExecuteCommand(int command_id, int event_flags) { void HoldingSpaceTray::ExecuteCommand(int command_id, int event_flags) {
DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled()); DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled());
NOTIMPLEMENTED(); switch (command_id) {
case HoldingSpaceCommandId::kHidePreviews:
holding_space_prefs::SetPreviewsEnabled(
Shell::Get()->session_controller()->GetActivePrefService(), false);
break;
case HoldingSpaceCommandId::kShowPreviews:
holding_space_prefs::SetPreviewsEnabled(
Shell::Get()->session_controller()->GetActivePrefService(), true);
break;
default:
NOTREACHED();
break;
}
} }
void HoldingSpaceTray::ShowContextMenuForViewImpl( void HoldingSpaceTray::ShowContextMenuForViewImpl(
...@@ -220,7 +225,10 @@ void HoldingSpaceTray::ShowContextMenuForViewImpl( ...@@ -220,7 +225,10 @@ void HoldingSpaceTray::ShowContextMenuForViewImpl(
context_menu_model_ = std::make_unique<ui::SimpleMenuModel>(this); context_menu_model_ = std::make_unique<ui::SimpleMenuModel>(this);
if (IsShowingPreviews()) { const bool previews_enabled = holding_space_prefs::IsPreviewsEnabled(
Shell::Get()->session_controller()->GetActivePrefService());
if (previews_enabled) {
context_menu_model_->AddItemWithIcon( context_menu_model_->AddItemWithIcon(
HoldingSpaceCommandId::kHidePreviews, HoldingSpaceCommandId::kHidePreviews,
l10n_util::GetStringUTF16( l10n_util::GetStringUTF16(
......
...@@ -7,14 +7,17 @@ ...@@ -7,14 +7,17 @@
#include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/ash_features.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_item.h" #include "ash/public/cpp/holding_space/holding_space_item.h"
#include "ash/public/cpp/holding_space/holding_space_prefs.h"
#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/shelf_config.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "ash/session/session_controller_impl.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_preview.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"
#include "components/prefs/pref_change_registrar.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
...@@ -23,23 +26,34 @@ ...@@ -23,23 +26,34 @@
namespace ash { namespace ash {
namespace {
// Helpers ---------------------------------------------------------------------
// Returns whether previews are enabled.
bool IsPreviewsEnabled() {
auto* prefs = Shell::Get()->session_controller()->GetActivePrefService();
return features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled() &&
prefs && holding_space_prefs::IsPreviewsEnabled(prefs);
}
} // namespace
// HoldingSpaceTrayIcon --------------------------------------------------------
HoldingSpaceTrayIcon::HoldingSpaceTrayIcon(Shelf* shelf) : shelf_(shelf) { HoldingSpaceTrayIcon::HoldingSpaceTrayIcon(Shelf* shelf) : shelf_(shelf) {
SetID(kHoldingSpaceTrayIconId);
InitLayout(); InitLayout();
if (features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled()) { if (features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled()) {
controller_observer_.Add(HoldingSpaceController::Get()); controller_observer_.Add(HoldingSpaceController::Get());
shell_observer_.Add(Shell::Get()); shell_observer_.Add(Shell::Get());
session_observer_.Add(Shell::Get()->session_controller());
} }
} }
HoldingSpaceTrayIcon::~HoldingSpaceTrayIcon() = default; HoldingSpaceTrayIcon::~HoldingSpaceTrayIcon() = default;
int HoldingSpaceTrayIcon::GetPreferredMainAxisMargin() const {
return features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled()
? 0
: kHoldingSpaceTrayIconMainAxisMargin;
}
void HoldingSpaceTrayIcon::OnLocaleChanged() { void HoldingSpaceTrayIcon::OnLocaleChanged() {
TooltipTextChanged(); TooltipTextChanged();
} }
...@@ -49,10 +63,19 @@ base::string16 HoldingSpaceTrayIcon::GetTooltipText( ...@@ -49,10 +63,19 @@ base::string16 HoldingSpaceTrayIcon::GetTooltipText(
return l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_TITLE); return l10n_util::GetStringUTF16(IDS_ASH_HOLDING_SPACE_TITLE);
} }
int HoldingSpaceTrayIcon::GetHeightForWidth(int width) const {
// The parent for this view (`TrayContainer`) uses a `BoxLayout` for its
// `LayoutManager`. When the shelf orientation is vertical, the `BoxLayout`
// will also have vertical orientation and will invoke `GetHeightForWidth()`
// instead of `GetPreferredSize()` when determining preferred size.
return GetPreferredSize().height();
}
void HoldingSpaceTrayIcon::InitLayout() { void HoldingSpaceTrayIcon::InitLayout() {
if (features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled()) { SetLayoutManager(std::make_unique<views::FillLayout>());
SetPreferredSize(gfx::Size(kTrayItemSize, kTrayItemSize)); SetPreferredSize(gfx::Size(kTrayItemSize, kTrayItemSize));
if (features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled()) {
// As holding space items are added to the model, child layers will be added // As holding space items are added to the model, child layers will be added
// to `this` view's layer to represent them. // to `this` view's layer to represent them.
SetPaintToLayer(); SetPaintToLayer();
...@@ -60,18 +83,8 @@ void HoldingSpaceTrayIcon::InitLayout() { ...@@ -60,18 +83,8 @@ void HoldingSpaceTrayIcon::InitLayout() {
return; return;
} }
SetLayoutManager(std::make_unique<views::FillLayout>()); // Force hide previews to initialize view state.
HidePreviews(/*force=*/true);
// Image.
auto* image_view = AddChildView(std::make_unique<views::ImageView>());
image_view->SetImage(
gfx::CreateVectorIcon(kHoldingSpaceIcon, kHoldingSpaceTrayIconSize,
ShelfConfig::Get()->shelf_icon_color()));
// Disallow events on `image_view` so that tooltips will be retrieved from
// `this`. Moving forward, `image_view` will not exist as we transition to a
// more content forward tray icon.
image_view->SetCanProcessEventsWithinSubtree(false);
} }
void HoldingSpaceTrayIcon::OnHoldingSpaceModelAttached( void HoldingSpaceTrayIcon::OnHoldingSpaceModelAttached(
...@@ -96,6 +109,9 @@ void HoldingSpaceTrayIcon::OnHoldingSpaceItemAdded( ...@@ -96,6 +109,9 @@ void HoldingSpaceTrayIcon::OnHoldingSpaceItemAdded(
const HoldingSpaceItem* item) { const HoldingSpaceItem* item) {
DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled()); DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled());
if (!previews_enabled_)
return;
if (!item->IsFinalized()) if (!item->IsFinalized())
return; return;
...@@ -113,6 +129,9 @@ void HoldingSpaceTrayIcon::OnHoldingSpaceItemRemoved( ...@@ -113,6 +129,9 @@ void HoldingSpaceTrayIcon::OnHoldingSpaceItemRemoved(
const HoldingSpaceItem* item) { const HoldingSpaceItem* item) {
DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled()); DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled());
if (!previews_enabled_)
return;
if (!item->IsFinalized()) if (!item->IsFinalized())
return; return;
...@@ -144,6 +163,9 @@ void HoldingSpaceTrayIcon::OnHoldingSpaceItemFinalized( ...@@ -144,6 +163,9 @@ void HoldingSpaceTrayIcon::OnHoldingSpaceItemFinalized(
const HoldingSpaceItem* item) { const HoldingSpaceItem* item) {
DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled()); DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled());
if (!previews_enabled_)
return;
if (previews_.empty()) { if (previews_.empty()) {
OnHoldingSpaceItemAdded(item); OnHoldingSpaceItemAdded(item);
return; return;
...@@ -175,6 +197,9 @@ void HoldingSpaceTrayIcon::OnShelfAlignmentChanged( ...@@ -175,6 +197,9 @@ void HoldingSpaceTrayIcon::OnShelfAlignmentChanged(
ShelfAlignment old_alignment) { ShelfAlignment old_alignment) {
DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled()); DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled());
if (!previews_enabled_)
return;
removed_previews_.clear(); removed_previews_.clear();
for (const auto& preview : previews_) for (const auto& preview : previews_)
...@@ -183,7 +208,28 @@ void HoldingSpaceTrayIcon::OnShelfAlignmentChanged( ...@@ -183,7 +208,28 @@ void HoldingSpaceTrayIcon::OnShelfAlignmentChanged(
UpdatePreferredSize(); UpdatePreferredSize();
} }
void HoldingSpaceTrayIcon::OnActiveUserPrefServiceChanged(PrefService* prefs) {
DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled());
pref_change_registrar_ = std::make_unique<PrefChangeRegistrar>();
pref_change_registrar_->Init(prefs);
// NOTE: The callback being bound is scoped to `pref_change_registrar_` which
// is owned by `this` so it is safe to bind with an unretained raw pointer.
holding_space_prefs::AddPreviewsEnabledChangedCallback(
pref_change_registrar_.get(),
base::BindRepeating(&HoldingSpaceTrayIcon::UpdatePreviewsEnabled,
base::Unretained(this)));
UpdatePreviewsEnabled();
}
void HoldingSpaceTrayIcon::UpdatePreferredSize() { void HoldingSpaceTrayIcon::UpdatePreferredSize() {
if (!previews_enabled_) {
SetPreferredSize(gfx::Size(kTrayItemSize, kTrayItemSize));
return;
}
const int num_visible_previews = const int num_visible_previews =
std::min(kHoldingSpaceTrayIconMaxVisiblePreviews, std::min(kHoldingSpaceTrayIconMaxVisiblePreviews,
static_cast<int>(previews_.size())); static_cast<int>(previews_.size()));
...@@ -200,6 +246,54 @@ void HoldingSpaceTrayIcon::UpdatePreferredSize() { ...@@ -200,6 +246,54 @@ void HoldingSpaceTrayIcon::UpdatePreferredSize() {
SetPreferredSize(preferred_size); SetPreferredSize(preferred_size);
} }
void HoldingSpaceTrayIcon::UpdatePreviewsEnabled() {
DCHECK(features::IsTemporaryHoldingSpaceContentForwardEntryPointEnabled());
const bool previews_enabled = IsPreviewsEnabled();
if (previews_enabled_ == previews_enabled)
return;
if (previews_enabled)
ShowPreviews();
else
HidePreviews();
}
void HoldingSpaceTrayIcon::ShowPreviews() {
if (previews_enabled_)
return;
previews_enabled_ = true;
RemoveAllChildViews(/*delete_children=*/true);
if (HoldingSpaceController::Get()->model()) {
for (const auto& item : HoldingSpaceController::Get()->model()->items())
OnHoldingSpaceItemAdded(item.get());
}
}
void HoldingSpaceTrayIcon::HidePreviews(bool force) {
if (!previews_enabled_ && !force)
return;
previews_enabled_ = false;
previews_.clear();
removed_previews_.clear();
// Image.
// NOTE: Events are disallowed on the `image_view` subtree so that tooltips
// will be retrieved from `this` instead.
auto* image_view = AddChildView(std::make_unique<views::ImageView>());
image_view->SetCanProcessEventsWithinSubtree(false);
image_view->SetImage(
gfx::CreateVectorIcon(kHoldingSpaceIcon, kHoldingSpaceTrayIconSize,
ShelfConfig::Get()->shelf_icon_color()));
UpdatePreferredSize();
}
void HoldingSpaceTrayIcon::OnHoldingSpaceTrayIconPreviewAnimatedOut( void HoldingSpaceTrayIcon::OnHoldingSpaceTrayIconPreviewAnimatedOut(
HoldingSpaceTrayIconPreview* preview) { HoldingSpaceTrayIconPreview* preview) {
base::EraseIf(removed_previews_, base::MatchesUniquePtr(preview)); base::EraseIf(removed_previews_, base::MatchesUniquePtr(preview));
......
...@@ -13,12 +13,16 @@ ...@@ -13,12 +13,16 @@
#include "ash/public/cpp/holding_space/holding_space_controller_observer.h" #include "ash/public/cpp/holding_space/holding_space_controller_observer.h"
#include "ash/public/cpp/holding_space/holding_space_model.h" #include "ash/public/cpp/holding_space/holding_space_model.h"
#include "ash/public/cpp/holding_space/holding_space_model_observer.h" #include "ash/public/cpp/holding_space/holding_space_model_observer.h"
#include "ash/public/cpp/session/session_controller.h"
#include "ash/public/cpp/session/session_observer.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/shell_observer.h" #include "ash/shell_observer.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "ui/views/metadata/metadata_header_macros.h" #include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/view.h" #include "ui/views/view.h"
class PrefChangeRegistrar;
namespace ash { namespace ash {
class HoldingSpaceTrayIconPreview; class HoldingSpaceTrayIconPreview;
...@@ -29,7 +33,8 @@ class Shelf; ...@@ -29,7 +33,8 @@ class Shelf;
class ASH_EXPORT HoldingSpaceTrayIcon : public views::View, class ASH_EXPORT HoldingSpaceTrayIcon : public views::View,
public HoldingSpaceControllerObserver, public HoldingSpaceControllerObserver,
public HoldingSpaceModelObserver, public HoldingSpaceModelObserver,
public ShellObserver { public ShellObserver,
public SessionObserver {
public: public:
METADATA_HEADER(HoldingSpaceTrayIcon); METADATA_HEADER(HoldingSpaceTrayIcon);
...@@ -38,9 +43,6 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View, ...@@ -38,9 +43,6 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View,
HoldingSpaceTrayIcon& operator=(const HoldingSpaceTrayIcon&) = delete; HoldingSpaceTrayIcon& operator=(const HoldingSpaceTrayIcon&) = delete;
~HoldingSpaceTrayIcon() override; ~HoldingSpaceTrayIcon() override;
// Returns the preferred main axis margin for this view.
int GetPreferredMainAxisMargin() const;
// Invoked when the system locale has changed. // Invoked when the system locale has changed.
void OnLocaleChanged(); void OnLocaleChanged();
...@@ -50,6 +52,7 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View, ...@@ -50,6 +52,7 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View,
private: private:
// views::View: // views::View:
base::string16 GetTooltipText(const gfx::Point& point) const override; base::string16 GetTooltipText(const gfx::Point& point) const override;
int GetHeightForWidth(int width) const override;
// HoldingSpaceControllerObserver: // HoldingSpaceControllerObserver:
void OnHoldingSpaceModelAttached(HoldingSpaceModel* model) override; void OnHoldingSpaceModelAttached(HoldingSpaceModel* model) override;
...@@ -64,8 +67,15 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View, ...@@ -64,8 +67,15 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View,
void OnShelfAlignmentChanged(aura::Window* root_window, void OnShelfAlignmentChanged(aura::Window* root_window,
ShelfAlignment old_alignment) override; ShelfAlignment old_alignment) override;
// SessionController:
void OnActiveUserPrefServiceChanged(PrefService* prefs) override;
void InitLayout(); void InitLayout();
void UpdatePreferredSize(); void UpdatePreferredSize();
void UpdatePreviewsEnabled();
void ShowPreviews();
void HidePreviews(bool force = false);
// Invoked when the specified preview has completed animating out. At this // Invoked when the specified preview has completed animating out. At this
// point it is owned by `removed_previews_` and should be destroyed. // point it is owned by `removed_previews_` and should be destroyed.
...@@ -74,6 +84,11 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View, ...@@ -74,6 +84,11 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View,
// The shelf associated with this holding space tray icon. // The shelf associated with this holding space tray icon.
Shelf* const shelf_; Shelf* const shelf_;
// Whether previews are currently enabled. Note that if the content forward
// entry point feature is disabled, this will always be false. Otherwise,
// previews can be enabled/disabled by the user at runtime.
bool previews_enabled_ = false;
// A preview 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, previews are added to `previews_` where they // space item. Upon creation, previews are added to `previews_` where they
// are owned until being animated out. Upon being animated out, previews are // are owned until being animated out. Upon being animated out, previews are
...@@ -82,6 +97,12 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View, ...@@ -82,6 +97,12 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View,
std::vector<std::unique_ptr<HoldingSpaceTrayIconPreview>> previews_; std::vector<std::unique_ptr<HoldingSpaceTrayIconPreview>> previews_;
std::vector<std::unique_ptr<HoldingSpaceTrayIconPreview>> removed_previews_; std::vector<std::unique_ptr<HoldingSpaceTrayIconPreview>> removed_previews_;
// When the holding space content forward entry point is enabled, the user
// can enable/disable previews. This registrar is associated with the active
// user pref service and notifies the holding space tray icon of changes to
// the user's preference.
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
ScopedObserver<HoldingSpaceController, HoldingSpaceControllerObserver> ScopedObserver<HoldingSpaceController, HoldingSpaceControllerObserver>
controller_observer_{this}; controller_observer_{this};
ScopedObserver<HoldingSpaceModel, HoldingSpaceModelObserver> model_observer_{ ScopedObserver<HoldingSpaceModel, HoldingSpaceModelObserver> model_observer_{
...@@ -91,6 +112,7 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View, ...@@ -91,6 +112,7 @@ class ASH_EXPORT HoldingSpaceTrayIcon : public views::View,
&Shell::AddShellObserver, &Shell::AddShellObserver,
&Shell::RemoveShellObserver> &Shell::RemoveShellObserver>
shell_observer_{this}; shell_observer_{this};
ScopedObserver<SessionController, SessionObserver> session_observer_{this};
}; };
} // namespace ash } // namespace ash
......
...@@ -205,6 +205,10 @@ std::vector<views::View*> HoldingSpaceBrowserTestBase::GetScreenCaptureViews() { ...@@ -205,6 +205,10 @@ std::vector<views::View*> HoldingSpaceBrowserTestBase::GetScreenCaptureViews() {
return test_api_->GetScreenCaptureViews(); return test_api_->GetScreenCaptureViews();
} }
views::View* HoldingSpaceBrowserTestBase::GetTrayIcon() {
return test_api_->GetTrayIcon();
}
void HoldingSpaceBrowserTestBase::RequestAndAwaitLockScreen() { void HoldingSpaceBrowserTestBase::RequestAndAwaitLockScreen() {
if (session_manager::SessionManager::Get()->IsScreenLocked()) if (session_manager::SessionManager::Get()->IsScreenLocked())
return; return;
......
...@@ -85,6 +85,9 @@ class HoldingSpaceBrowserTestBase : public InProcessBrowserTest { ...@@ -85,6 +85,9 @@ class HoldingSpaceBrowserTestBase : public InProcessBrowserTest {
// If holding space UI is not visible, an empty collection is returned. // If holding space UI is not visible, an empty collection is returned.
std::vector<views::View*> GetScreenCaptureViews(); std::vector<views::View*> GetScreenCaptureViews();
// Returns the holding space tray icon in the shelf.
views::View* GetTrayIcon();
// Requests lock screen, waiting to return until session state is locked. // Requests lock screen, waiting to return until session state is locked.
void RequestAndAwaitLockScreen(); void RequestAndAwaitLockScreen();
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/events/test/event_generator.h" #include "ui/events/test/event_generator.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
...@@ -70,6 +71,14 @@ void PressAndReleaseKey(ui::KeyboardCode key_code, int flags = ui::EF_NONE) { ...@@ -70,6 +71,14 @@ void PressAndReleaseKey(ui::KeyboardCode key_code, int flags = ui::EF_NONE) {
event_generator.ReleaseKey(key_code, flags); event_generator.ReleaseKey(key_code, flags);
} }
// Performs a right click on `view`.
void RightClick(const views::View* view) {
auto* root_window = view->GetWidget()->GetNativeWindow()->GetRootWindow();
ui::test::EventGenerator event_generator(root_window);
event_generator.MoveMouseTo(view->GetBoundsInScreen().CenterPoint());
event_generator.ClickRightButton();
}
// Mocks ----------------------------------------------------------------------- // Mocks -----------------------------------------------------------------------
class MockActivationChangeObserver : public wm::ActivationChangeObserver { class MockActivationChangeObserver : public wm::ActivationChangeObserver {
...@@ -277,6 +286,84 @@ IN_PROC_BROWSER_TEST_F(HoldingSpaceUiBrowserTest, OpenItem) { ...@@ -277,6 +286,84 @@ IN_PROC_BROWSER_TEST_F(HoldingSpaceUiBrowserTest, OpenItem) {
} }
} }
// Base class for holding space UI browser tests that test previews.
class HoldingSpaceUiPreviewsBrowserTest : public HoldingSpaceUiBrowserTest {
public:
HoldingSpaceUiPreviewsBrowserTest() {
scoped_feature_list_.InitAndEnableFeatureWithParameters(
features::kTemporaryHoldingSpace,
/*field_trial_params=*/{
{"content-forward-entry-point-enabled", "true"}});
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// Verifies that previews can be toggled via context menu.
IN_PROC_BROWSER_TEST_F(HoldingSpaceUiPreviewsBrowserTest, TogglePreviews) {
ASSERT_TRUE(IsShowingInShelf());
auto* tray_icon = GetTrayIcon();
ASSERT_TRUE(tray_icon);
ASSERT_TRUE(tray_icon->layer());
// Initially the tray icon should be empty.
EXPECT_EQ(0u, tray_icon->children().size());
EXPECT_EQ(0u, tray_icon->layer()->children().size());
// After pinning a file, we should have a single preview in the tray icon.
AddPinnedFile();
EXPECT_EQ(0u, tray_icon->children().size());
EXPECT_EQ(1u, tray_icon->layer()->children().size());
EXPECT_EQ(gfx::Size(32, 32), tray_icon->size());
// After downloading a file, we should have two previews in the tray icon.
AddDownloadFile();
EXPECT_EQ(0u, tray_icon->children().size());
EXPECT_EQ(2u, tray_icon->layer()->children().size());
EXPECT_EQ(gfx::Size(48, 32), tray_icon->size());
// After taking a screenshot, we should have three previews in the tray icon.
AddScreenshotFile();
EXPECT_EQ(0u, tray_icon->children().size());
EXPECT_EQ(3u, tray_icon->layer()->children().size());
EXPECT_EQ(gfx::Size(64, 32), tray_icon->size());
// Right click the tray icon, and expect a context menu to be shown which will
// allow the user to hide previews.
RightClick(tray_icon);
ASSERT_TRUE(views::MenuController::GetActiveInstance());
// Use the keyboard to select the context menu item to hide previews. Doing so
// should dismiss the context menu.
PressAndReleaseKey(ui::KeyboardCode::VKEY_DOWN);
PressAndReleaseKey(ui::KeyboardCode::VKEY_RETURN);
EXPECT_FALSE(views::MenuController::GetActiveInstance());
// The tray icon should now contain no previews, but have a single child which
// contains the static image to show when previews are disabled.
EXPECT_EQ(1u, tray_icon->children().size());
EXPECT_EQ(0u, tray_icon->layer()->children().size());
EXPECT_EQ(gfx::Size(32, 32), tray_icon->size());
// Right click the tray icon, and expect a context menu to be shown which will
// allow the user to show previews.
RightClick(tray_icon);
ASSERT_TRUE(views::MenuController::GetActiveInstance());
// Use the keyboard to select the context menu item to show previews. Doing so
// should dismiss the context menu.
PressAndReleaseKey(ui::KeyboardCode::VKEY_DOWN);
PressAndReleaseKey(ui::KeyboardCode::VKEY_RETURN);
EXPECT_FALSE(views::MenuController::GetActiveInstance());
// The tray icon should once again show three previews.
EXPECT_EQ(0u, tray_icon->children().size());
EXPECT_EQ(3u, tray_icon->layer()->children().size());
EXPECT_EQ(gfx::Size(64, 32), tray_icon->size());
}
// Base class for holding space UI browser tests that take screenshots. // Base class for holding space UI browser tests that take screenshots.
// Parameterized by whether or not `features::CaptureMode` is enabled. // Parameterized by whether or not `features::CaptureMode` is enabled.
class HoldingSpaceUiScreenshotBrowserTest class HoldingSpaceUiScreenshotBrowserTest
......
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