From 2d429e0e25efc2db3afd75ea31a41d42446c3338 Mon Sep 17 00:00:00 2001 From: Tetsui Ohkubo Date: Mon, 7 May 2018 04:49:43 +0000 Subject: [PATCH] Show UnifiedSystemTray button and hide old one. As described in the design doc, old SystemTray class is going to be replaced by UnifiedSystemTray class. Model variables of SystemTrayItems will be decoupled into SystemTrayModel, and tray icons will be implemented in UnifiedSystemTray by obseving the models. This is the initial CL to replace the old SystemTray button by new UnifiedSystemTray button. Old SystemTray still has unrelated logic e.g. notification generation, so at this point we still instantiate SystemTray and just set the visibility to false. When we finish refactoring to move all unrelated logic to outside SystemTray, we can stop instantiating it. Screenshot: http://screen/jVCtkJgKCXa Design doc: go/cros-qs-restyling TEST=manual BUG=836134 Change-Id: I89e708ad239fb93aee5993fd10ace7fdeaab6673 Reviewed-on: https://chromium-review.googlesource.com/1025495 Commit-Queue: Tetsui Ohkubo Reviewed-by: Steven Bennetts Cr-Commit-Position: refs/heads/master@{#556378} --- ash/system/status_area_widget.cc | 2 ++ ash/system/tray/system_tray.cc | 8 ++++++++ ash/system/tray/system_tray.h | 1 + ash/system/unified/unified_system_tray.cc | 20 +++++++++++--------- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ash/system/status_area_widget.cc b/ash/system/status_area_widget.cc index e7fba94cdad642..40084fec7f650d 100644 --- a/ash/system/status_area_widget.cc +++ b/ash/system/status_area_widget.cc @@ -189,6 +189,8 @@ void StatusAreaWidget::SetSystemTrayVisibility(bool visible) { TrayBackgroundView* StatusAreaWidget::GetSystemTrayAnchor() const { if (overview_button_tray_->visible()) return overview_button_tray_.get(); + if (unified_system_tray_) + return unified_system_tray_.get(); return system_tray_.get(); } diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc index f99187b94414a2..ad1a282484e42a 100644 --- a/ash/system/tray/system_tray.cc +++ b/ash/system/tray/system_tray.cc @@ -658,6 +658,14 @@ views::TrayBubbleView* SystemTray::GetBubbleView() { : nullptr; } +void SystemTray::SetVisible(bool visible) { + // TODO(tetsui): Port logic in SystemTrayItems that is unrelated to SystemTray + // UI, and stop instantiating SystemTray instead of hiding it when + // UnifiedSystemTray is enabled. + TrayBackgroundView::SetVisible(!features::IsSystemTrayUnifiedEnabled() && + visible); +} + void SystemTray::BubbleViewDestroyed() { if (system_bubble_) { system_bubble_->bubble()->BubbleViewDestroyed(); diff --git a/ash/system/tray/system_tray.h b/ash/system/tray/system_tray.h index b87067aacaefb0..8d0db5163cacc5 100644 --- a/ash/system/tray/system_tray.h +++ b/ash/system/tray/system_tray.h @@ -151,6 +151,7 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView, void CloseBubble() override; void ShowBubble(bool show_by_click) override; views::TrayBubbleView* GetBubbleView() override; + void SetVisible(bool visible) override; // views::TrayBubbleView::Delegate: void BubbleViewDestroyed() override; diff --git a/ash/system/unified/unified_system_tray.cc b/ash/system/unified/unified_system_tray.cc index 2e34352d58ac5c..e4e70dff8da537 100644 --- a/ash/system/unified/unified_system_tray.cc +++ b/ash/system/unified/unified_system_tray.cc @@ -4,8 +4,12 @@ #include "ash/system/unified/unified_system_tray.h" +#include "ash/shell.h" +#include "ash/system/date/date_view.h" +#include "ash/system/model/system_tray_model.h" #include "ash/system/status_area_widget.h" #include "ash/system/tray/system_tray.h" +#include "ash/system/tray/tray_container.h" #include "ash/system/unified/unified_system_tray_bubble.h" #include "ash/system/unified/unified_system_tray_model.h" #include "ash/system/web_notification/ash_popup_alignment_delegate.h" @@ -96,11 +100,11 @@ UnifiedSystemTray::UnifiedSystemTray(Shelf* shelf) : TrayBackgroundView(shelf), ui_delegate_(std::make_unique(this)), model_(std::make_unique()) { - // On the first step, features in the status area button are still provided by - // TrayViews in SystemTray. - // TODO(tetsui): Remove SystemTray from StatusAreaWidget and provide these - // features from UnifiedSystemTray. - SetVisible(false); + tray_container()->AddChildView( + new tray::TimeView(tray::TimeView::ClockLayout::HORIZONTAL_CLOCK, + Shell::Get()->system_tray_model()->clock())); + SetInkDropMode(InkDropMode::ON); + SetVisible(true); } UnifiedSystemTray::~UnifiedSystemTray() = default; @@ -140,14 +144,12 @@ void UnifiedSystemTray::ClickedOutsideBubble() {} void UnifiedSystemTray::ShowBubbleInternal(bool show_by_click) { bubble_ = std::make_unique(this, show_by_click); - // TODO(tetsui): Call its own SetIsActive. See the comment in the ctor. - shelf()->GetStatusAreaWidget()->system_tray()->SetIsActive(true); + SetIsActive(true); } void UnifiedSystemTray::HideBubbleInternal() { bubble_.reset(); - // TODO(tetsui): Call its own SetIsActive. See the comment in the ctor. - shelf()->GetStatusAreaWidget()->system_tray()->SetIsActive(false); + SetIsActive(false); } } // namespace ash