Commit a8c7af16 authored by Tatsuhisa Yamaguchi's avatar Tatsuhisa Yamaguchi Committed by Commit Bot

Shrink gaps between top shortcut buttons.

- Expand/Collapse button should be in the fixed size.
- Secure minumum gap between Expand/Collapse and other buttons.
- Shring gap between other buttons when there's not enough space

Bug: 847100
Change-Id: I295126c63ed2702ca7e10906f6d4ca599485e904
Reviewed-on: https://chromium-review.googlesource.com/1078031
Commit-Queue: Tatsuhisa Yamaguchi <yamaguchi@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#563122}
parent 8405e18c
......@@ -174,6 +174,11 @@ constexpr int kUnifiedFeaturePodItemsInRow = 3;
constexpr int kUnifiedFeaturePodMaxItemsInCollapsed = 5;
constexpr int kUnifiedNotificationSeparatorThickness = 1;
// Gap between the buttons on the top shortcut row, other than the
// expand/collapse button.
constexpr int kUnifiedTopShortcutButtonDefaultSpacing = 16;
constexpr int kUnifiedTopShortcutButtonMinSpacing = 4;
} // namespace ash
#endif // ASH_SYSTEM_TRAY_TRAY_CONSTANTS_H_
......@@ -39,21 +39,97 @@ UserAvatarButton::UserAvatarButton(views::ButtonListener* listener)
AddChildView(CreateUserAvatarView(0 /* user_index */));
}
class TopShortcutButtonContainer : public views::View {
public:
TopShortcutButtonContainer();
~TopShortcutButtonContainer() override;
// views::View:
void Layout() override;
gfx::Size CalculatePreferredSize() const override;
private:
DISALLOW_COPY_AND_ASSIGN(TopShortcutButtonContainer);
};
// Buttons are equally spaced by the default value, but the gap will be
// narrowed evenly when the parent view is not large enough.
void TopShortcutButtonContainer::Layout() {
gfx::Rect child_area(GetContentsBounds());
int total_horizontal_size = 0;
int num_visible = 0;
for (int i = 0; i < child_count(); i++) {
const views::View* child = child_at(i);
if (!child->visible())
continue;
int child_horizontal_size = child->GetPreferredSize().width();
if (child_horizontal_size == 0)
continue;
total_horizontal_size += child_horizontal_size;
num_visible++;
}
int spacing = std::max(kUnifiedTopShortcutButtonMinSpacing,
std::min(kUnifiedTopShortcutButtonDefaultSpacing,
(child_area.width() - total_horizontal_size) /
(num_visible - 1)));
int horizontal_position = child_area.x();
for (int i = 0; i < child_count(); i++) {
views::View* child = child_at(i);
if (!child->visible())
continue;
gfx::Rect bounds(child_area);
bounds.set_x(horizontal_position);
bounds.set_width(child->GetPreferredSize().width());
child->SetBoundsRect(bounds);
horizontal_position += child->GetPreferredSize().width() + spacing;
}
}
gfx::Size TopShortcutButtonContainer::CalculatePreferredSize() const {
int total_horizontal_size = 0;
int max_height = 0;
int num_visible = 0;
for (int i = 0; i < child_count(); i++) {
const views::View* child = child_at(i);
if (!child->visible())
continue;
int child_horizontal_size = child->GetPreferredSize().width();
if (child_horizontal_size == 0)
continue;
total_horizontal_size += child_horizontal_size;
num_visible++;
max_height = std::max(child->GetPreferredSize().height(), max_height);
}
int width =
(num_visible == 0)
? 0
: total_horizontal_size +
(num_visible - 1) * kUnifiedTopShortcutButtonDefaultSpacing;
return gfx::Size(width, max_height);
}
TopShortcutButtonContainer::~TopShortcutButtonContainer() = default;
TopShortcutButtonContainer::TopShortcutButtonContainer() = default;
} // namespace
TopShortcutsView::TopShortcutsView(UnifiedSystemTrayController* controller)
: controller_(controller) {
: controller_(controller), container_(new TopShortcutButtonContainer()) {
DCHECK(controller_);
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::kHorizontal, kUnifiedTopShortcutPadding,
kUnifiedTopShortcutSpacing));
layout->set_cross_axis_alignment(views::BoxLayout::CROSS_AXIS_ALIGNMENT_END);
AddChildView(container_);
if (Shell::Get()->session_controller()->login_status() !=
LoginStatus::NOT_LOGGED_IN) {
user_avatar_button_ = new UserAvatarButton(this);
AddChildView(user_avatar_button_);
container_->AddChildView(user_avatar_button_);
}
// Show the buttons in this row as disabled if the user is at the login
......@@ -62,30 +138,28 @@ TopShortcutsView::TopShortcutsView(UnifiedSystemTrayController* controller)
const bool can_show_web_ui = TrayPopupUtils::CanOpenWebUISettings();
sign_out_button_ = new SignOutButton(this);
AddChildView(sign_out_button_);
container_->AddChildView(sign_out_button_);
lock_button_ = new TopShortcutButton(this, kSystemMenuLockIcon,
IDS_ASH_STATUS_TRAY_LOCK);
lock_button_->SetEnabled(can_show_web_ui &&
Shell::Get()->session_controller()->CanLockScreen());
AddChildView(lock_button_);
container_->AddChildView(lock_button_);
settings_button_ = new TopShortcutButton(this, kSystemMenuSettingsIcon,
IDS_ASH_STATUS_TRAY_SETTINGS);
settings_button_->SetEnabled(can_show_web_ui);
AddChildView(settings_button_);
container_->AddChildView(settings_button_);
bool reboot = Shell::Get()->shutdown_controller()->reboot_on_shutdown();
power_button_ = new TopShortcutButton(
this, kSystemMenuPowerIcon,
reboot ? IDS_ASH_STATUS_TRAY_REBOOT : IDS_ASH_STATUS_TRAY_SHUTDOWN);
AddChildView(power_button_);
container_->AddChildView(power_button_);
// |collapse_button_| should be right-aligned, so we need spacing between
// other buttons and |collapse_button_|.
views::View* spacing = new views::View;
AddChildView(spacing);
layout->SetFlexForView(spacing, 1);
// |collapse_button_| should be right-aligned, so we make the buttons
// container flex occupying all remaining space.
layout->SetFlexForView(container_, 1);
collapse_button_ = new CollapseButton(this);
AddChildView(collapse_button_);
......
......@@ -38,6 +38,7 @@ class ASH_EXPORT TopShortcutsView : public views::View,
// Owned by views hierarchy.
views::Button* user_avatar_button_ = nullptr;
SignOutButton* sign_out_button_ = nullptr;
views::View* const container_;
TopShortcutButton* lock_button_ = nullptr;
TopShortcutButton* settings_button_ = nullptr;
TopShortcutButton* power_button_ = nullptr;
......
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