Commit f022327d authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Implement collapsed state in UnifiedSystemTray

According to UX spec, UnifiedSystemTray supports collapsed state.

This CL
* Adds SetExpanded to FeaturePodButton. If false, it hides labels.
* Adds SetExpanded to FeaturePodsContainerView. If false, it uses layout
  that places all the buttons horizontally.
  Buttons exceed the limit will be hidden in the collapsed state.
  To support this behavior, FeaturePodButton::SetExpandedByContainer is
  also added.
* Adds SetExpanded to UnifiedSystemTrayView and puts all sliders to
  |sliders_container_|, so that it can be easily hidden when collapsed.
* Adds FeaturePodsContainerViewTest unit tests.

Screencast: http://go/scrcast/NTk3Mzg1NzQwMzkyODU3NnxhZTNmMDI2ZS1kNA

UnifiedSystemTray design doc: go/cros-qs-restyling

TEST=FeaturePodsContainerViewTest
BUG=819942

Change-Id: Ic7b7bcf56f1405b9eb0babab8f041f5a83d361f2
Reviewed-on: https://chromium-review.googlesource.com/964031Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544988}
parent c966e00e
...@@ -1595,6 +1595,7 @@ test("ash_unittests") { ...@@ -1595,6 +1595,7 @@ test("ash_unittests") {
"system/tray_caps_lock_unittest.cc", "system/tray_caps_lock_unittest.cc",
"system/tray_tracing_unittest.cc", "system/tray_tracing_unittest.cc",
"system/unified/accessibility_feature_pod_controller_unittest.cc", "system/unified/accessibility_feature_pod_controller_unittest.cc",
"system/unified/feature_pods_container_view_unittest.cc",
"system/unified/top_shortcuts_view_unittest.cc", "system/unified/top_shortcuts_view_unittest.cc",
"system/unified/unified_system_info_view_unittest.cc", "system/unified/unified_system_info_view_unittest.cc",
"system/update/tray_update_unittest.cc", "system/update/tray_update_unittest.cc",
......
...@@ -153,10 +153,14 @@ constexpr int kUnifiedSystemInfoSpacing = 8; ...@@ -153,10 +153,14 @@ constexpr int kUnifiedSystemInfoSpacing = 8;
// Constants used in FeaturePodsView of UnifiedSystemTray. // Constants used in FeaturePodsView of UnifiedSystemTray.
constexpr int kUnifiedFeaturePodIconSize = 48; constexpr int kUnifiedFeaturePodIconSize = 48;
constexpr gfx::Size kUnifiedFeaturePodSize(80, 88); constexpr gfx::Size kUnifiedFeaturePodSize(80, 88);
constexpr gfx::Size kUnifiedFeaturePodCollapsedSize(48, 48);
constexpr int kUnifiedFeaturePodVerticalPadding = 28; constexpr int kUnifiedFeaturePodVerticalPadding = 28;
constexpr int kUnifiedFeaturePodHorizontalSidePadding = 28; constexpr int kUnifiedFeaturePodHorizontalSidePadding = 28;
constexpr int kUnifiedFeaturePodHorizontalMiddlePadding = 32; constexpr int kUnifiedFeaturePodHorizontalMiddlePadding = 32;
constexpr int kUnifiedFeaturePodCollapsedVerticalPadding = 16;
constexpr int kUnifiedFeaturePodCollapsedHorizontalPadding = 24;
constexpr int kUnifiedFeaturePodItemsInRow = 3; constexpr int kUnifiedFeaturePodItemsInRow = 3;
constexpr int kUnifiedFeaturePodMaxItemsInCollapsed = 5;
} // namespace ash } // namespace ash
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/paint_recorder.h" #include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/skbitmap_operations.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h" #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_highlight.h" #include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h" #include "ui/views/animation/ink_drop_impl.h"
...@@ -64,9 +66,7 @@ void CollapseButtonInkDropMask::OnPaintLayer(const ui::PaintContext& context) { ...@@ -64,9 +66,7 @@ void CollapseButtonInkDropMask::OnPaintLayer(const ui::PaintContext& context) {
CollapseButton::CollapseButton(views::ButtonListener* listener) CollapseButton::CollapseButton(views::ButtonListener* listener)
: ImageButton(listener) { : ImageButton(listener) {
SetImage(views::Button::STATE_NORMAL, UpdateIcon(true /* expanded */);
gfx::CreateVectorIcon(kNotificationCenterCollapseIcon,
kCollapseIconSize, kUnifiedMenuIconColor));
SetImageAlignment(HorizontalAlignment::ALIGN_CENTER, SetImageAlignment(HorizontalAlignment::ALIGN_CENTER,
VerticalAlignment::ALIGN_BOTTOM); VerticalAlignment::ALIGN_BOTTOM);
SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_COLLAPSE)); SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_COLLAPSE));
...@@ -78,6 +78,16 @@ CollapseButton::CollapseButton(views::ButtonListener* listener) ...@@ -78,6 +78,16 @@ CollapseButton::CollapseButton(views::ButtonListener* listener)
CollapseButton::~CollapseButton() = default; CollapseButton::~CollapseButton() = default;
void CollapseButton::UpdateIcon(bool expanded) {
gfx::ImageSkia icon =
gfx::CreateVectorIcon(kNotificationCenterCollapseIcon, kCollapseIconSize,
kUnifiedMenuIconColor);
if (!expanded)
icon = gfx::ImageSkiaOperations::CreateRotatedImage(
icon, SkBitmapOperations::ROTATION_180_CW);
SetImage(views::Button::STATE_NORMAL, icon);
}
gfx::Size CollapseButton::CalculatePreferredSize() const { gfx::Size CollapseButton::CalculatePreferredSize() const {
return gfx::Size(kTrayItemSize, kTrayItemSize * 3 / 2); return gfx::Size(kTrayItemSize, kTrayItemSize * 3 / 2);
} }
......
...@@ -18,6 +18,9 @@ class CollapseButton : public views::ImageButton { ...@@ -18,6 +18,9 @@ class CollapseButton : public views::ImageButton {
CollapseButton(views::ButtonListener* listener); CollapseButton(views::ButtonListener* listener);
~CollapseButton() override; ~CollapseButton() override;
// Change the icon for the |expanded| state.
void UpdateIcon(bool expanded);
// views::ImageButton: // views::ImageButton:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
int GetHeightForWidth(int width) const override; int GetHeightForWidth(int width) const override;
......
...@@ -133,6 +133,21 @@ void FeaturePodButton::SetToggled(bool toggled) { ...@@ -133,6 +133,21 @@ void FeaturePodButton::SetToggled(bool toggled) {
icon_button_->SetToggled(toggled); icon_button_->SetToggled(toggled);
} }
void FeaturePodButton::SetExpanded(bool expanded) {
label_->SetVisible(expanded);
if (sub_label_)
sub_label_->SetVisible(expanded);
}
void FeaturePodButton::SetVisibleByContainer(bool visible) {
View::SetVisible(visible);
}
void FeaturePodButton::SetVisible(bool visible) {
visible_preferred_ = visible;
View::SetVisible(visible);
}
void FeaturePodButton::ButtonPressed(views::Button* sender, void FeaturePodButton::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
controller_->OnPressed(); controller_->OnPressed();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef ASH_SYSTEM_UNIFIED_FEATURE_POD_BUTTON_H_ #ifndef ASH_SYSTEM_UNIFIED_FEATURE_POD_BUTTON_H_
#define ASH_SYSTEM_UNIFIED_FEATURE_POD_BUTTON_H_ #define ASH_SYSTEM_UNIFIED_FEATURE_POD_BUTTON_H_
#include "ash/ash_export.h"
#include "ui/gfx/vector_icon_types.h" #include "ui/gfx/vector_icon_types.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -48,7 +49,8 @@ class FeaturePodIconButton : public views::ImageButton { ...@@ -48,7 +49,8 @@ class FeaturePodIconButton : public views::ImageButton {
// vertically. They are also togglable and the background color indicates the // vertically. They are also togglable and the background color indicates the
// current state. // current state.
// See the comment in FeaturePodsView for detail. // See the comment in FeaturePodsView for detail.
class FeaturePodButton : public views::View, public views::ButtonListener { class ASH_EXPORT FeaturePodButton : public views::View,
public views::ButtonListener {
public: public:
explicit FeaturePodButton(FeaturePodControllerBase* controller); explicit FeaturePodButton(FeaturePodControllerBase* controller);
~FeaturePodButton() override; ~FeaturePodButton() override;
...@@ -65,11 +67,22 @@ class FeaturePodButton : public views::View, public views::ButtonListener { ...@@ -65,11 +67,22 @@ class FeaturePodButton : public views::View, public views::ButtonListener {
// Change the toggled state. If toggled, the background color of the circle // Change the toggled state. If toggled, the background color of the circle
// will change. // will change.
void SetToggled(bool toggled); void SetToggled(bool toggled);
bool IsToggled() const { return icon_button_->toggled(); }
// Change the expanded state. If not expanded, the labels are not shown.
void SetExpanded(bool expanded);
// Only called by the container. Same as SetVisible but doesn't change
// |visible_preferred_| flag.
void SetVisibleByContainer(bool visible);
// views::View:
void SetVisible(bool visible) override;
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
bool IsToggled() const { return icon_button_->toggled(); } bool visible_preferred() { return visible_preferred_; }
protected: protected:
FeaturePodIconButton* icon_button() const { return icon_button_; } FeaturePodIconButton* icon_button() const { return icon_button_; }
...@@ -83,6 +96,13 @@ class FeaturePodButton : public views::View, public views::ButtonListener { ...@@ -83,6 +96,13 @@ class FeaturePodButton : public views::View, public views::ButtonListener {
views::Label* const label_; views::Label* const label_;
views::Label* sub_label_ = nullptr; views::Label* sub_label_ = nullptr;
// If true, it is preferred by the FeaturePodController that the view is
// visible. Usually, this should match visible(), but in case that the
// container does not have enough space, it might not match.
// In such case, the preferred visibility is reflected after the container is
// expanded.
bool visible_preferred_ = true;
DISALLOW_COPY_AND_ASSIGN(FeaturePodButton); DISALLOW_COPY_AND_ASSIGN(FeaturePodButton);
}; };
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ash/system/unified/feature_pods_container_view.h" #include "ash/system/unified/feature_pods_container_view.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/feature_pod_button.h"
namespace ash { namespace ash {
...@@ -13,27 +14,55 @@ FeaturePodsContainerView::FeaturePodsContainerView() {} ...@@ -13,27 +14,55 @@ FeaturePodsContainerView::FeaturePodsContainerView() {}
FeaturePodsContainerView::~FeaturePodsContainerView() = default; FeaturePodsContainerView::~FeaturePodsContainerView() = default;
gfx::Size FeaturePodsContainerView::CalculatePreferredSize() const { gfx::Size FeaturePodsContainerView::CalculatePreferredSize() const {
int visible_count = 0; if (!expanded_) {
for (int i = 0; i < child_count(); ++i) { return gfx::Size(kTrayMenuWidth,
if (child_at(i)->visible()) 2 * kUnifiedFeaturePodCollapsedVerticalPadding +
++visible_count; kUnifiedFeaturePodCollapsedSize.height());
} }
int visible_count = CountVisibleChildren();
// floor(visible_count / kUnifiedFeaturePodItemsInRow) // floor(visible_count / kUnifiedFeaturePodItemsInRow)
int number_of_lines = (visible_count + kUnifiedFeaturePodItemsInRow - 1) / int number_of_lines = (visible_count + kUnifiedFeaturePodItemsInRow - 1) /
kUnifiedFeaturePodItemsInRow; kUnifiedFeaturePodItemsInRow;
return gfx::Size(0, kUnifiedFeaturePodVerticalPadding + return gfx::Size(kTrayMenuWidth, kUnifiedFeaturePodVerticalPadding +
(kUnifiedFeaturePodVerticalPadding + (kUnifiedFeaturePodVerticalPadding +
kUnifiedFeaturePodSize.height()) * kUnifiedFeaturePodSize.height()) *
number_of_lines); number_of_lines);
}
void FeaturePodsContainerView::SetExpanded(bool expanded) {
if (expanded_ == expanded)
return;
expanded_ = expanded;
for (int i = 0; i < child_count(); ++i) {
auto* child = static_cast<FeaturePodButton*>(child_at(i));
child->SetExpanded(expanded);
}
UpdateChildVisibility();
PreferredSizeChanged();
} }
void FeaturePodsContainerView::ChildVisibilityChanged(View* child) { void FeaturePodsContainerView::ChildVisibilityChanged(View* child) {
// ChildVisibilityChanged can change child visibility in
// UpdateChildVisibility(), so we have to prevent this.
if (changing_visibility_)
return;
UpdateChildVisibility();
Layout(); Layout();
SchedulePaint(); SchedulePaint();
} }
void FeaturePodsContainerView::Layout() { void FeaturePodsContainerView::Layout() {
if (expanded_)
LayoutExpanded();
else
LayoutCollapsed();
}
void FeaturePodsContainerView::LayoutExpanded() {
DCHECK(expanded_);
int x = kUnifiedFeaturePodHorizontalSidePadding; int x = kUnifiedFeaturePodHorizontalSidePadding;
int y = kUnifiedFeaturePodVerticalPadding; int y = kUnifiedFeaturePodVerticalPadding;
int visible_count = 0; int visible_count = 0;
...@@ -62,4 +91,62 @@ void FeaturePodsContainerView::Layout() { ...@@ -62,4 +91,62 @@ void FeaturePodsContainerView::Layout() {
} }
} }
void FeaturePodsContainerView::LayoutCollapsed() {
DCHECK(!expanded_);
int visible_count = CountVisibleChildren();
DCHECK(visible_count > 0 &&
visible_count <= kUnifiedFeaturePodMaxItemsInCollapsed);
int contents_width =
visible_count * kUnifiedFeaturePodCollapsedSize.width() +
(visible_count - 1) * kUnifiedFeaturePodCollapsedHorizontalPadding;
int side_padding = (width() - contents_width) / 2;
DCHECK(side_padding > 0);
int x = side_padding;
for (int i = 0; i < child_count(); ++i) {
views::View* child = child_at(i);
if (!child->visible())
continue;
child->SetBounds(x, kUnifiedFeaturePodCollapsedVerticalPadding,
kUnifiedFeaturePodCollapsedSize.width(),
kUnifiedFeaturePodCollapsedSize.height());
x += kUnifiedFeaturePodCollapsedSize.width() +
kUnifiedFeaturePodCollapsedHorizontalPadding;
}
DCHECK(x - kUnifiedFeaturePodCollapsedHorizontalPadding + side_padding ==
kTrayMenuWidth);
}
int FeaturePodsContainerView::CountVisibleChildren() const {
int visible_count = 0;
for (int i = 0; i < child_count(); ++i) {
if (child_at(i)->visible())
++visible_count;
}
return visible_count;
}
void FeaturePodsContainerView::UpdateChildVisibility() {
DCHECK(!changing_visibility_);
changing_visibility_ = true;
int visible_count = 0;
for (int i = 0; i < child_count(); ++i) {
auto* child = static_cast<FeaturePodButton*>(child_at(i));
child->SetVisibleByContainer(
child->visible_preferred() &&
(expanded_ || visible_count < kUnifiedFeaturePodMaxItemsInCollapsed));
if (child->visible())
++visible_count;
}
changing_visibility_ = false;
}
} // namespace ash } // namespace ash
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef ASH_SYSTEM_UNIFIED_FEATURE_PODS_CONTAINER_VIEW_H_ #ifndef ASH_SYSTEM_UNIFIED_FEATURE_PODS_CONTAINER_VIEW_H_
#define ASH_SYSTEM_UNIFIED_FEATURE_PODS_CONTAINER_VIEW_H_ #define ASH_SYSTEM_UNIFIED_FEATURE_PODS_CONTAINER_VIEW_H_
#include "ash/ash_export.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace ash { namespace ash {
...@@ -14,17 +15,31 @@ namespace ash { ...@@ -14,17 +15,31 @@ namespace ash {
// as 3x2. FeaturePodButtons implements these individual buttons. // as 3x2. FeaturePodButtons implements these individual buttons.
// The container will also implement collapsed state where all the buttons are // The container will also implement collapsed state where all the buttons are
// horizontally placed. // horizontally placed.
class FeaturePodsContainerView : public views::View { class ASH_EXPORT FeaturePodsContainerView : public views::View {
public: public:
FeaturePodsContainerView(); FeaturePodsContainerView();
~FeaturePodsContainerView() override; ~FeaturePodsContainerView() override;
// Change the expanded state. If collapsed, all the buttons are horizontally
// placed.
void SetExpanded(bool expanded);
// Overridden views::View: // Overridden views::View:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
void ChildVisibilityChanged(View* child) override; void ChildVisibilityChanged(View* child) override;
void Layout() override; void Layout() override;
private: private:
void LayoutExpanded();
void LayoutCollapsed();
void UpdateChildVisibility();
int CountVisibleChildren() const;
bool expanded_ = true;
bool changing_visibility_ = false;
DISALLOW_COPY_AND_ASSIGN(FeaturePodsContainerView); DISALLOW_COPY_AND_ASSIGN(FeaturePodsContainerView);
}; };
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/unified/feature_pods_container_view.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/feature_pod_button.h"
#include "ash/system/unified/feature_pod_controller_base.h"
#include "ash/test/ash_test_base.h"
#include "ui/views/view_observer.h"
namespace ash {
class FeaturePodsContainerViewTest : public AshTestBase,
public FeaturePodControllerBase,
public views::ViewObserver {
public:
FeaturePodsContainerViewTest() = default;
~FeaturePodsContainerViewTest() override = default;
// AshTestBase:
void SetUp() override {
AshTestBase::SetUp();
container_ = std::make_unique<FeaturePodsContainerView>();
container_->AddObserver(this);
}
// FeaturePodControllerBase:
FeaturePodButton* CreateButton() override { return nullptr; }
void OnPressed() override {}
// views::ViewObserver:
void OnViewPreferredSizeChanged(views::View* observed_view) override {
container_->SetBoundsRect(gfx::Rect(container_->GetPreferredSize()));
container_->Layout();
}
protected:
void AddButtons(int count) {
for (int i = 0; i < count; ++i) {
buttons_.push_back(new FeaturePodButton(this));
container()->AddChildView(buttons_.back());
}
OnViewPreferredSizeChanged(container());
}
FeaturePodsContainerView* container() { return container_.get(); }
std::vector<FeaturePodButton*> buttons_;
private:
std::unique_ptr<FeaturePodsContainerView> container_;
DISALLOW_COPY_AND_ASSIGN(FeaturePodsContainerViewTest);
};
TEST_F(FeaturePodsContainerViewTest, ExpandedAndCollapsed) {
const int kNumberOfAddedButtons = kUnifiedFeaturePodItemsInRow * 3;
EXPECT_LT(kUnifiedFeaturePodMaxItemsInCollapsed, kNumberOfAddedButtons);
AddButtons(kNumberOfAddedButtons);
// In expanded state, buttons are laid out in plane.
EXPECT_LT(buttons_[0]->x(), buttons_[1]->x());
EXPECT_EQ(buttons_[0]->y(), buttons_[1]->y());
// If the row exceeds kUnifiedFeaturePodItemsInRow, the next button is placed
// right under the first button.
EXPECT_EQ(buttons_[0]->x(), buttons_[kUnifiedFeaturePodItemsInRow]->x());
EXPECT_LT(buttons_[0]->y(), buttons_[kUnifiedFeaturePodItemsInRow]->y());
// All buttons are visible.
for (auto* button : buttons_)
EXPECT_TRUE(button->visible());
container()->SetExpanded(false);
// In collapsed state, all buttons are laid out horizontally.
for (int i = 1; i < kUnifiedFeaturePodMaxItemsInCollapsed; ++i)
EXPECT_EQ(buttons_[0]->y(), buttons_[i]->y());
// Buttons exceed kUnifiedFeaturePodMaxItemsInCollapsed are invisible.
for (int i = 0; i < kNumberOfAddedButtons; ++i) {
EXPECT_EQ(i < kUnifiedFeaturePodMaxItemsInCollapsed,
buttons_[i]->visible());
}
}
TEST_F(FeaturePodsContainerViewTest, HiddenButtonRemainsHidden) {
AddButtons(kUnifiedFeaturePodMaxItemsInCollapsed);
// The button is invisible in expanded state.
buttons_.front()->SetVisible(false);
container()->SetExpanded(false);
EXPECT_FALSE(buttons_.front()->visible());
container()->SetExpanded(true);
EXPECT_FALSE(buttons_.front()->visible());
}
TEST_F(FeaturePodsContainerViewTest, BecomeVisibleInCollapsed) {
AddButtons(kUnifiedFeaturePodMaxItemsInCollapsed);
// The button is invisible in expanded state.
buttons_.back()->SetVisible(false);
container()->SetExpanded(false);
// The button becomes visible in collapsed state.
buttons_.back()->SetVisible(true);
// As the container still has remaining space, the button will be visible.
EXPECT_TRUE(buttons_.back()->visible());
}
TEST_F(FeaturePodsContainerViewTest, StillHiddenInCollapsed) {
AddButtons(kUnifiedFeaturePodMaxItemsInCollapsed + 1);
// The button is invisible in expanded state.
buttons_.back()->SetVisible(false);
container()->SetExpanded(false);
// The button becomes visible in collapsed state.
buttons_.back()->SetVisible(true);
// As the container doesn't have remaining space, the button won't be visible.
EXPECT_FALSE(buttons_.back()->visible());
container()->SetExpanded(true);
// The button becomes visible in expanded state.
EXPECT_TRUE(buttons_.back()->visible());
}
TEST_F(FeaturePodsContainerViewTest, DifferentButtonBecomeVisibleInCollapsed) {
AddButtons(kUnifiedFeaturePodMaxItemsInCollapsed + 1);
container()->SetExpanded(false);
// The last button is not visible as it doesn't have enough space.
EXPECT_FALSE(buttons_.back()->visible());
// The first button becomes invisible.
buttons_.front()->SetVisible(false);
// The last button now has the space for it.
EXPECT_TRUE(buttons_.back()->visible());
}
} // namespace ash
...@@ -96,6 +96,10 @@ TopShortcutsView::TopShortcutsView(UnifiedSystemTrayController* controller) ...@@ -96,6 +96,10 @@ TopShortcutsView::TopShortcutsView(UnifiedSystemTrayController* controller)
TopShortcutsView::~TopShortcutsView() = default; TopShortcutsView::~TopShortcutsView() = default;
void TopShortcutsView::SetExpanded(bool expanded) {
collapse_button_->UpdateIcon(expanded);
}
void TopShortcutsView::ButtonPressed(views::Button* sender, void TopShortcutsView::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
if (sender == sign_out_button_) if (sender == sign_out_button_)
......
...@@ -24,6 +24,9 @@ class ASH_EXPORT TopShortcutsView : public views::View, ...@@ -24,6 +24,9 @@ class ASH_EXPORT TopShortcutsView : public views::View,
explicit TopShortcutsView(UnifiedSystemTrayController* controller); explicit TopShortcutsView(UnifiedSystemTrayController* controller);
~TopShortcutsView() override; ~TopShortcutsView() override;
// Change the expanded state. CollapseButton icon will change.
void SetExpanded(bool expanded);
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
......
...@@ -3,14 +3,13 @@ ...@@ -3,14 +3,13 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "ash/system/unified/top_shortcuts_view.h" #include "ash/system/unified/top_shortcuts_view.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/session/test_session_controller_client.h" #include "ash/session/test_session_controller_client.h"
#include "ash/system/unified/collapse_button.h" #include "ash/system/unified/collapse_button.h"
#include "ash/system/unified/sign_out_button.h" #include "ash/system/unified/sign_out_button.h"
#include "ash/system/unified/top_shortcut_button.h" #include "ash/system/unified/top_shortcut_button.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "base/command_line.h"
using views::Button; using views::Button;
......
...@@ -78,7 +78,8 @@ void UnifiedSystemTrayController::HandlePowerAction() { ...@@ -78,7 +78,8 @@ void UnifiedSystemTrayController::HandlePowerAction() {
} }
void UnifiedSystemTrayController::ToggleExpanded() { void UnifiedSystemTrayController::ToggleExpanded() {
// TODO(tetsui): Implement. expanded_ = !expanded_;
unified_view_->SetExpanded(expanded_);
} }
void UnifiedSystemTrayController::ShowNetworkDetailedView() { void UnifiedSystemTrayController::ShowNetworkDetailedView() {
......
...@@ -85,6 +85,8 @@ class ASH_EXPORT UnifiedSystemTrayController { ...@@ -85,6 +85,8 @@ class ASH_EXPORT UnifiedSystemTrayController {
std::unique_ptr<UnifiedBrightnessSliderController> std::unique_ptr<UnifiedBrightnessSliderController>
brightness_slider_controller_; brightness_slider_controller_;
bool expanded_ = true;
DISALLOW_COPY_AND_ASSIGN(UnifiedSystemTrayController); DISALLOW_COPY_AND_ASSIGN(UnifiedSystemTrayController);
}; };
......
...@@ -18,7 +18,9 @@ namespace ash { ...@@ -18,7 +18,9 @@ namespace ash {
UnifiedSystemTrayView::UnifiedSystemTrayView( UnifiedSystemTrayView::UnifiedSystemTrayView(
UnifiedSystemTrayController* controller) UnifiedSystemTrayController* controller)
: controller_(controller), : controller_(controller),
top_shortcuts_view_(new TopShortcutsView(controller_)),
feature_pods_container_(new FeaturePodsContainerView()), feature_pods_container_(new FeaturePodsContainerView()),
sliders_container_(new views::View),
system_info_view_(new UnifiedSystemInfoView()) { system_info_view_(new UnifiedSystemInfoView()) {
DCHECK(controller_); DCHECK(controller_);
...@@ -32,8 +34,12 @@ UnifiedSystemTrayView::UnifiedSystemTrayView( ...@@ -32,8 +34,12 @@ UnifiedSystemTrayView::UnifiedSystemTrayView(
SetPaintToLayer(); SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false); layer()->SetFillsBoundsOpaquely(false);
AddChildView(new TopShortcutsView(controller_)); sliders_container_->SetLayoutManager(
std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical));
AddChildView(top_shortcuts_view_);
AddChildView(feature_pods_container_); AddChildView(feature_pods_container_);
AddChildView(sliders_container_);
AddChildView(system_info_view_); AddChildView(system_info_view_);
} }
...@@ -44,7 +50,14 @@ void UnifiedSystemTrayView::AddFeaturePodButton(FeaturePodButton* button) { ...@@ -44,7 +50,14 @@ void UnifiedSystemTrayView::AddFeaturePodButton(FeaturePodButton* button) {
} }
void UnifiedSystemTrayView::AddSliderView(views::View* slider_view) { void UnifiedSystemTrayView::AddSliderView(views::View* slider_view) {
AddChildViewAt(slider_view, GetIndexOf(system_info_view_)); sliders_container_->AddChildView(slider_view);
}
void UnifiedSystemTrayView::SetExpanded(bool expanded) {
top_shortcuts_view_->SetExpanded(expanded);
feature_pods_container_->SetExpanded(expanded);
sliders_container_->SetVisible(expanded);
PreferredSizeChanged();
} }
} // namespace ash } // namespace ash
...@@ -11,6 +11,7 @@ namespace ash { ...@@ -11,6 +11,7 @@ namespace ash {
class FeaturePodButton; class FeaturePodButton;
class FeaturePodsContainerView; class FeaturePodsContainerView;
class TopShortcutsView;
class UnifiedSystemInfoView; class UnifiedSystemInfoView;
class UnifiedSystemTrayController; class UnifiedSystemTrayController;
...@@ -26,12 +27,17 @@ class UnifiedSystemTrayView : public views::View { ...@@ -26,12 +27,17 @@ class UnifiedSystemTrayView : public views::View {
// Add slider view. // Add slider view.
void AddSliderView(views::View* slider_view); void AddSliderView(views::View* slider_view);
// Change the expanded state.
void SetExpanded(bool expanded);
private: private:
// Unowned. // Unowned.
UnifiedSystemTrayController* controller_; UnifiedSystemTrayController* controller_;
// Owned by views hierarchy. // Owned by views hierarchy.
TopShortcutsView* top_shortcuts_view_;
FeaturePodsContainerView* feature_pods_container_; FeaturePodsContainerView* feature_pods_container_;
views::View* sliders_container_;
UnifiedSystemInfoView* system_info_view_; UnifiedSystemInfoView* system_info_view_;
DISALLOW_COPY_AND_ASSIGN(UnifiedSystemTrayView); 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