Commit e6167f51 authored by Ahmed Mehfooz's avatar Ahmed Mehfooz Committed by Commit Bot

Do not show holding space tray button if there are no items

Bug: 1138541
Change-Id: I3984809ea6144823145d70eaeb443c730563fb4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2473379
Commit-Queue: Ahmed Mehfooz <amehfooz@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarDavid Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#819952}
parent 9fb203e4
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ash/magnifier/docked_magnifier_controller_impl.h" #include "ash/magnifier/docked_magnifier_controller_impl.h"
#include "ash/media/media_controller_impl.h" #include "ash/media/media_controller_impl.h"
#include "ash/public/cpp/ash_pref_names.h" #include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/holding_space/holding_space_prefs.h"
#include "ash/shelf/contextual_tooltip.h" #include "ash/shelf/contextual_tooltip.h"
#include "ash/shelf/shelf_controller.h" #include "ash/shelf/shelf_controller.h"
#include "ash/style/ash_color_provider.h" #include "ash/style/ash_color_provider.h"
...@@ -61,6 +62,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) { ...@@ -61,6 +62,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) {
DockedMagnifierControllerImpl::RegisterProfilePrefs(registry); DockedMagnifierControllerImpl::RegisterProfilePrefs(registry);
GestureEducationNotificationController::RegisterProfilePrefs(registry, GestureEducationNotificationController::RegisterProfilePrefs(registry,
for_test); for_test);
holding_space_prefs::RegisterProfilePrefs(registry);
LoginScreenController::RegisterProfilePrefs(registry, for_test); LoginScreenController::RegisterProfilePrefs(registry, for_test);
LogoutButtonTray::RegisterProfilePrefs(registry); LogoutButtonTray::RegisterProfilePrefs(registry);
KeyboardControllerImpl::RegisterProfilePrefs(registry); KeyboardControllerImpl::RegisterProfilePrefs(registry);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#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/pref_registry/pref_registry_syncable.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
namespace ash { namespace ash {
...@@ -26,7 +26,7 @@ constexpr char kTimeOfFirstPin[] = "ash.holding_space.time_of_first_pin"; ...@@ -26,7 +26,7 @@ constexpr char kTimeOfFirstPin[] = "ash.holding_space.time_of_first_pin";
} // namespace } // namespace
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { void RegisterProfilePrefs(PrefRegistrySimple* registry) {
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());
......
...@@ -8,22 +8,18 @@ ...@@ -8,22 +8,18 @@
#include "ash/public/cpp/ash_public_export.h" #include "ash/public/cpp/ash_public_export.h"
#include "base/optional.h" #include "base/optional.h"
class PrefRegistrySimple;
class PrefService; class PrefService;
namespace base { namespace base {
class Time; class Time;
} // namespace base } // namespace base
namespace user_prefs {
class PrefRegistrySyncable;
} // namespace user_prefs
namespace ash { namespace ash {
namespace holding_space_prefs { namespace holding_space_prefs {
// Registers holding space profile preferences to `registry`. // Registers holding space profile preferences to `registry`.
ASH_PUBLIC_EXPORT void RegisterProfilePrefs( ASH_PUBLIC_EXPORT void RegisterProfilePrefs(PrefRegistrySimple* registry);
user_prefs::PrefRegistrySyncable* registry);
// 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.
......
...@@ -882,7 +882,7 @@ Shell::~Shell() { ...@@ -882,7 +882,7 @@ Shell::~Shell() {
// Destroys the MessageCenter singleton, so must happen late. // Destroys the MessageCenter singleton, so must happen late.
message_center_controller_.reset(); message_center_controller_.reset();
// HoldingSpaceController observes SessionController and must be // `HoldingSpaceController` observes `SessionController` and must be
// destructed before it. // destructed before it.
holding_space_controller_.reset(); holding_space_controller_.reset();
...@@ -1033,6 +1033,13 @@ void Shell::Init( ...@@ -1033,6 +1033,13 @@ void Shell::Init(
clipboard_history_controller_ = clipboard_history_controller_ =
std::make_unique<ClipboardHistoryControllerImpl>(); std::make_unique<ClipboardHistoryControllerImpl>();
} }
// `HoldingSpaceController` must be instantiated before the shelf.
if (features::IsTemporaryHoldingSpaceEnabled()) {
holding_space_controller_ = std::make_unique<HoldingSpaceController>(
std::make_unique<HoldingSpaceColorProviderImpl>());
}
shelf_config_ = std::make_unique<ShelfConfig>(); shelf_config_ = std::make_unique<ShelfConfig>();
shelf_controller_ = std::make_unique<ShelfController>(); shelf_controller_ = std::make_unique<ShelfController>();
...@@ -1259,11 +1266,6 @@ void Shell::Init( ...@@ -1259,11 +1266,6 @@ void Shell::Init(
std::make_unique<DisplayAlignmentController>(); std::make_unique<DisplayAlignmentController>();
} }
if (features::IsTemporaryHoldingSpaceEnabled()) {
holding_space_controller_ = std::make_unique<HoldingSpaceController>(
std::make_unique<HoldingSpaceColorProviderImpl>());
}
for (auto& observer : shell_observers_) for (auto& observer : shell_observers_)
observer.OnShellInitialized(); observer.OnShellInitialized();
......
...@@ -8,9 +8,11 @@ ...@@ -8,9 +8,11 @@
#include "ash/accessibility/accessibility_controller_impl.h" #include "ash/accessibility/accessibility_controller_impl.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_metrics.h" #include "ash/public/cpp/holding_space/holding_space_metrics.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/public/cpp/system_tray_client.h" #include "ash/public/cpp/system_tray_client.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/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
...@@ -26,6 +28,9 @@ ...@@ -26,6 +28,9 @@
namespace ash { namespace ash {
HoldingSpaceTray::HoldingSpaceTray(Shelf* shelf) : TrayBackgroundView(shelf) { HoldingSpaceTray::HoldingSpaceTray(Shelf* shelf) : TrayBackgroundView(shelf) {
controller_observer_.Add(HoldingSpaceController::Get());
SetVisible(false);
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
icon_ = tray_container()->AddChildView(std::make_unique<views::ImageView>()); icon_ = tray_container()->AddChildView(std::make_unique<views::ImageView>());
...@@ -58,8 +63,7 @@ void HoldingSpaceTray::AnchorUpdated() { ...@@ -58,8 +63,7 @@ void HoldingSpaceTray::AnchorUpdated() {
} }
void HoldingSpaceTray::UpdateAfterLoginStatusChange() { void HoldingSpaceTray::UpdateAfterLoginStatusChange() {
SetVisiblePreferred(shelf()->GetStatusAreaWidget()->login_status() == UpdateVisibility();
LoginStatus::USER);
} }
bool HoldingSpaceTray::PerformAction(const ui::Event& event) { bool HoldingSpaceTray::PerformAction(const ui::Event& event) {
...@@ -124,6 +128,28 @@ const char* HoldingSpaceTray::GetClassName() const { ...@@ -124,6 +128,28 @@ const char* HoldingSpaceTray::GetClassName() const {
return "HoldingSpaceTray"; return "HoldingSpaceTray";
} }
void HoldingSpaceTray::UpdateVisibility() {
HoldingSpaceModel* model = HoldingSpaceController::Get()->model();
bool logged_in =
shelf()->GetStatusAreaWidget()->login_status() == LoginStatus::USER;
if (!model || !logged_in) {
SetVisiblePreferred(false);
return;
}
PrefService* active_pref_service =
Shell::Get()->session_controller()->GetActivePrefService();
bool has_ever_pinned_item =
active_pref_service
? holding_space_prefs::GetTimeOfFirstPin(active_pref_service)
.has_value()
: false;
SetVisiblePreferred(!model->items().empty() || !has_ever_pinned_item);
}
base::string16 HoldingSpaceTray::GetAccessibleNameForBubble() { base::string16 HoldingSpaceTray::GetAccessibleNameForBubble() {
return GetAccessibleNameForTray(); return GetAccessibleNameForTray();
} }
...@@ -136,6 +162,24 @@ void HoldingSpaceTray::HideBubble(const TrayBubbleView* bubble_view) { ...@@ -136,6 +162,24 @@ void HoldingSpaceTray::HideBubble(const TrayBubbleView* bubble_view) {
CloseBubble(); CloseBubble();
} }
void HoldingSpaceTray::OnHoldingSpaceModelAttached(HoldingSpaceModel* model) {
model_observer_.Add(model);
UpdateVisibility();
}
void HoldingSpaceTray::OnHoldingSpaceModelDetached(HoldingSpaceModel* model) {
model_observer_.Remove(model);
UpdateVisibility();
}
void HoldingSpaceTray::OnHoldingSpaceItemAdded(const HoldingSpaceItem* item) {
UpdateVisibility();
}
void HoldingSpaceTray::OnHoldingSpaceItemRemoved(const HoldingSpaceItem* item) {
UpdateVisibility();
}
void HoldingSpaceTray::OnWidgetDragWillStart(views::Widget* widget) { void HoldingSpaceTray::OnWidgetDragWillStart(views::Widget* widget) {
// The holding space bubble should be closed while dragging holding space // The holding space bubble should be closed while dragging holding space
// items so as not to obstruct drop targets. Post the task to close the bubble // items so as not to obstruct drop targets. Post the task to close the bubble
......
...@@ -8,9 +8,14 @@ ...@@ -8,9 +8,14 @@
#include <memory> #include <memory>
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/public/cpp/holding_space/holding_space_controller.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_observer.h"
#include "ash/system/holding_space/holding_space_tray_bubble.h" #include "ash/system/holding_space/holding_space_tray_bubble.h"
#include "ash/system/tray/tray_background_view.h" #include "ash/system/tray/tray_background_view.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "ui/views/widget/widget_observer.h" #include "ui/views/widget/widget_observer.h"
namespace views { namespace views {
...@@ -22,6 +27,8 @@ namespace ash { ...@@ -22,6 +27,8 @@ namespace ash {
// This class also controls the lifetime for all of the tools available in the // This class also controls the lifetime for all of the tools available in the
// palette. HoldingSpaceTray has one instance per-display. // palette. HoldingSpaceTray has one instance per-display.
class ASH_EXPORT HoldingSpaceTray : public TrayBackgroundView, class ASH_EXPORT HoldingSpaceTray : public TrayBackgroundView,
public HoldingSpaceControllerObserver,
public HoldingSpaceModelObserver,
public views::WidgetObserver { public views::WidgetObserver {
public: public:
explicit HoldingSpaceTray(Shelf* shelf); explicit HoldingSpaceTray(Shelf* shelf);
...@@ -43,11 +50,21 @@ class ASH_EXPORT HoldingSpaceTray : public TrayBackgroundView, ...@@ -43,11 +50,21 @@ class ASH_EXPORT HoldingSpaceTray : public TrayBackgroundView,
const char* GetClassName() const override; const char* GetClassName() const override;
private: private:
void UpdateVisibility();
// TrayBubbleView::Delegate: // TrayBubbleView::Delegate:
base::string16 GetAccessibleNameForBubble() override; base::string16 GetAccessibleNameForBubble() override;
bool ShouldEnableExtraKeyboardAccessibility() override; bool ShouldEnableExtraKeyboardAccessibility() override;
void HideBubble(const TrayBubbleView* bubble_view) override; void HideBubble(const TrayBubbleView* bubble_view) override;
// HoldingSpaceControllerObserver:
void OnHoldingSpaceModelAttached(HoldingSpaceModel* model) override;
void OnHoldingSpaceModelDetached(HoldingSpaceModel* model) override;
// HoldingSpaceModelObserver:
void OnHoldingSpaceItemAdded(const HoldingSpaceItem* item) override;
void OnHoldingSpaceItemRemoved(const HoldingSpaceItem* item) override;
// views::WidgetObserver: // views::WidgetObserver:
void OnWidgetDragWillStart(views::Widget* widget) override; void OnWidgetDragWillStart(views::Widget* widget) override;
void OnWidgetDestroying(views::Widget* widget) override; void OnWidgetDestroying(views::Widget* widget) override;
...@@ -57,6 +74,11 @@ class ASH_EXPORT HoldingSpaceTray : public TrayBackgroundView, ...@@ -57,6 +74,11 @@ class ASH_EXPORT HoldingSpaceTray : public TrayBackgroundView,
// Weak pointer, will be parented by TrayContainer for its lifetime. // Weak pointer, will be parented by TrayContainer for its lifetime.
views::ImageView* icon_ = nullptr; views::ImageView* icon_ = nullptr;
ScopedObserver<HoldingSpaceController, HoldingSpaceControllerObserver>
controller_observer_{this};
ScopedObserver<HoldingSpaceModel, HoldingSpaceModelObserver> model_observer_{
this};
base::WeakPtrFactory<HoldingSpaceTray> weak_factory_{this}; base::WeakPtrFactory<HoldingSpaceTray> weak_factory_{this};
}; };
......
...@@ -72,13 +72,18 @@ HoldingSpaceKeyedService::HoldingSpaceKeyedService(Profile* profile, ...@@ -72,13 +72,18 @@ HoldingSpaceKeyedService::HoldingSpaceKeyedService(Profile* profile,
profile_manager_observer_.Add(profile_manager); profile_manager_observer_.Add(profile_manager);
} }
HoldingSpaceKeyedService::~HoldingSpaceKeyedService() = default; HoldingSpaceKeyedService::~HoldingSpaceKeyedService() {
if (HoldingSpaceController::Get()) {
// For BrowserWithTestWindowTest that releases profile and its keyed
// services before ash Shell.
HoldingSpaceController::Get()->RegisterClientAndModelForUser(
account_id_, /*client=*/nullptr, /*model=*/nullptr);
}
}
// static // static
void HoldingSpaceKeyedService::RegisterProfilePrefs( void HoldingSpaceKeyedService::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { user_prefs::PrefRegistrySyncable* registry) {
holding_space_prefs::RegisterProfilePrefs(registry);
// TODO(crbug.com/1131266): Move to `ash::holding_space_prefs`. // TODO(crbug.com/1131266): Move to `ash::holding_space_prefs`.
HoldingSpacePersistenceDelegate::RegisterProfilePrefs(registry); HoldingSpacePersistenceDelegate::RegisterProfilePrefs(registry);
} }
......
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