Commit 3f3ea92c authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Embed old detailed views to UnifiedSystemTray.

This CL embeds old SystemTray's detailed views to UnifiedSystemTray.
Although this is temporary, this feature is important to start
early dogfooding, and requested multiple times from PM.
When we launch the feature, SystemTray instance is completely removed,
so this temporary hack will not work. Before launch, we're going to
replace all of them with our own implementation of detailed views.

TEST=manual
BUG=835733

Change-Id: Ic94f3ffa1976e3812f6bf200b64f1ec03878715c
Reviewed-on: https://chromium-review.googlesource.com/1023354Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553435}
parent 3c0ca2e3
......@@ -280,8 +280,10 @@ void TrayDetailsView::CreateTitleRow(int string_id) {
tri_view_ = TrayPopupUtils::CreateDefaultRowView();
back_button_ = CreateBackButton();
tri_view_->AddView(TriView::Container::START, back_button_);
if (!features::IsSystemTrayUnifiedEnabled()) {
back_button_ = CreateBackButton();
tri_view_->AddView(TriView::Container::START, back_button_);
}
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
auto* label = TrayPopupUtils::CreateDefaultLabel();
......
......@@ -56,7 +56,10 @@ UnifiedSystemTrayController::UnifiedSystemTrayController(
animation_->SetTweenType(gfx::Tween::EASE_IN_OUT);
}
UnifiedSystemTrayController::~UnifiedSystemTrayController() = default;
UnifiedSystemTrayController::~UnifiedSystemTrayController() {
if (detailed_view_item_)
detailed_view_item_->OnDetailedViewDestroyed();
}
UnifiedSystemTrayView* UnifiedSystemTrayController::CreateView() {
DCHECK(!unified_view_);
......@@ -192,12 +195,10 @@ void UnifiedSystemTrayController::AddFeaturePodItem(
void UnifiedSystemTrayController::ShowSystemTrayDetailedView(
SystemTrayItem* system_tray_item) {
// Initially create default view to set |default_bubble_height_|.
system_tray_->ShowDefaultView(BubbleCreationType::BUBBLE_CREATE_NEW,
true /* show_by_click */);
system_tray_->ShowDetailedView(system_tray_item,
0 /* close_delay_in_seconds */,
BubbleCreationType::BUBBLE_USE_EXISTING);
LoginStatus login_status = Shell::Get()->session_controller()->login_status();
unified_view_->SetDetailedView(
system_tray_item->CreateDetailedView(login_status));
detailed_view_item_ = system_tray_item;
}
void UnifiedSystemTrayController::UpdateExpandedAmount() {
......
......@@ -108,6 +108,17 @@ class ASH_EXPORT UnifiedSystemTrayController : public gfx::AnimationDelegate {
// Unowned. Owned by Views hierarchy.
UnifiedSystemTrayView* unified_view_ = nullptr;
// Reference to the SystemTrayItem of the currently shown detailed view.
// Unowned.
// We have to call SystemTrayItem::OnDetailedViewDestoryed() on bubble close,
// because typically each SystemTrayItem observes a model and it calls
// Update() method of each detailed view.
// To remove this, detailed views should observe models directly so that
// UnifiedSystemTrayController can instantiate them directly.
// TODO(tetsui): Remove this hack when we implement our own detailed views of
// UnifiedSystemTray.
SystemTrayItem* detailed_view_item_ = nullptr;
// Controllers of feature pod buttons. Owned by this.
std::vector<std::unique_ptr<FeaturePodControllerBase>>
feature_pod_controllers_;
......
......@@ -31,6 +31,21 @@ std::unique_ptr<views::Background> CreateUnifiedBackground() {
kUnifiedTrayCornerRadius));
}
class DetailedViewContainer : public views::View {
public:
DetailedViewContainer() = default;
~DetailedViewContainer() override = default;
void Layout() override {
for (int i = 0; i < child_count(); ++i)
child_at(i)->SetBoundsRect(GetContentsBounds());
views::View::Layout();
}
private:
DISALLOW_COPY_AND_ASSIGN(DetailedViewContainer);
};
} // namespace
UnifiedSlidersContainerView::UnifiedSlidersContainerView(
......@@ -89,7 +104,9 @@ UnifiedSystemTrayView::UnifiedSystemTrayView(
top_shortcuts_view_(new TopShortcutsView(controller_)),
feature_pods_container_(new FeaturePodsContainerView(initially_expanded)),
sliders_container_(new UnifiedSlidersContainerView(initially_expanded)),
system_info_view_(new UnifiedSystemInfoView()) {
system_info_view_(new UnifiedSystemInfoView()),
system_tray_container_(new views::View()),
detailed_view_container_(new DetailedViewContainer()) {
DCHECK(controller_);
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
......@@ -103,16 +120,18 @@ UnifiedSystemTrayView::UnifiedSystemTrayView(
AddChildView(message_center_view_);
layout->SetFlexForView(message_center_view_, 1);
auto* system_tray_container = new views::View;
system_tray_container->SetLayoutManager(
system_tray_container_->SetLayoutManager(
std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical));
system_tray_container->SetBackground(CreateUnifiedBackground());
AddChildView(system_tray_container);
system_tray_container_->SetBackground(CreateUnifiedBackground());
AddChildView(system_tray_container_);
system_tray_container_->AddChildView(top_shortcuts_view_);
system_tray_container_->AddChildView(feature_pods_container_);
system_tray_container_->AddChildView(sliders_container_);
system_tray_container_->AddChildView(system_info_view_);
system_tray_container->AddChildView(top_shortcuts_view_);
system_tray_container->AddChildView(feature_pods_container_);
system_tray_container->AddChildView(sliders_container_);
system_tray_container->AddChildView(system_info_view_);
detailed_view_container_->SetVisible(false);
AddChildView(detailed_view_container_);
}
UnifiedSystemTrayView::~UnifiedSystemTrayView() = default;
......@@ -131,6 +150,18 @@ void UnifiedSystemTrayView::AddSliderView(views::View* slider_view) {
sliders_container_->AddChildView(slider_view);
}
void UnifiedSystemTrayView::SetDetailedView(views::View* detailed_view) {
auto system_tray_size = system_tray_container_->GetPreferredSize();
system_tray_container_->SetVisible(false);
detailed_view_container_->RemoveAllChildViews(true /* delete_children */);
detailed_view_container_->AddChildView(detailed_view);
detailed_view_container_->SetPreferredSize(system_tray_size);
detailed_view_container_->SetVisible(true);
detailed_view->InvalidateLayout();
Layout();
}
void UnifiedSystemTrayView::SetExpandedAmount(double expanded_amount) {
DCHECK(0.0 <= expanded_amount && expanded_amount <= 1.0);
if (expanded_amount == 1.0 || expanded_amount == 0.0)
......
......@@ -57,6 +57,9 @@ class UnifiedSystemTrayView : public views::View {
// Add slider view.
void AddSliderView(views::View* slider_view);
// Hide the main view and show the given |detailed_view|.
void SetDetailedView(views::View* detailed_view);
// Change the expanded state. 0.0 if collapsed, and 1.0 if expanded.
// Otherwise, it shows intermediate state.
void SetExpandedAmount(double expanded_amount);
......@@ -75,6 +78,8 @@ class UnifiedSystemTrayView : public views::View {
FeaturePodsContainerView* feature_pods_container_;
UnifiedSlidersContainerView* sliders_container_;
UnifiedSystemInfoView* system_info_view_;
views::View* system_tray_container_;
views::View* detailed_view_container_;
DISALLOW_COPY_AND_ASSIGN(UnifiedSystemTrayView);
};
......
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