Commit 58fc8914 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Dynamically adjust feature pod button hover size

This CL does two things:
* It decreases height of feature pod hover when the pod doesn't have
  sub-label. (https://crbug.com/858942)
* It increases width of the hover when it doesn't have enough space to
  show detailed view arrow. Previously, it hid the arrow in such case.
  In order to do that, it increased the width of feature pod button by
  28px because we symmetrically increase the hover width.
  The arrow and the spacing takes 14px in total.

Screenshot(before): http://screen/5bzdLf3rGQn
Screenshot(after): http://screen/48Jr2f39Kp7

TEST=manual
BUG=858942,858913

Change-Id: If1db17c0fa932188b36b02979374253f5cde084d
Reviewed-on: https://chromium-review.googlesource.com/1124199
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572480}
parent 31fb6ead
...@@ -167,15 +167,16 @@ constexpr int kUnifiedSystemInfoSpacing = 8; ...@@ -167,15 +167,16 @@ constexpr int kUnifiedSystemInfoSpacing = 8;
// Constants used in FeaturePodsView of UnifiedSystemTray. // Constants used in FeaturePodsView of UnifiedSystemTray.
constexpr gfx::Size kUnifiedFeaturePodIconSize(48, 48); constexpr gfx::Size kUnifiedFeaturePodIconSize(48, 48);
constexpr gfx::Size kUnifiedFeaturePodSize(84, 88); constexpr gfx::Size kUnifiedFeaturePodSize(112, 88);
constexpr gfx::Size kUnifiedFeaturePodCollapsedSize(48, 48); constexpr gfx::Size kUnifiedFeaturePodCollapsedSize(48, 48);
constexpr gfx::Insets kUnifiedFeaturePodIconPadding(4); constexpr gfx::Insets kUnifiedFeaturePodIconPadding(4);
constexpr gfx::Insets kUnifiedFeaturePodHoverPadding(2); constexpr gfx::Insets kUnifiedFeaturePodHoverPadding(2);
constexpr int kUnifiedFeaturePodLabelWidth = 80;
constexpr int kUnifiedFeaturePodSpacing = 6; constexpr int kUnifiedFeaturePodSpacing = 6;
constexpr int kUnifiedFeaturePodHoverRadius = 4; constexpr int kUnifiedFeaturePodHoverRadius = 4;
constexpr int kUnifiedFeaturePodVerticalPadding = 28; constexpr int kUnifiedFeaturePodVerticalPadding = 28;
constexpr int kUnifiedFeaturePodHorizontalSidePadding = 26; constexpr int kUnifiedFeaturePodHorizontalSidePadding = 12;
constexpr int kUnifiedFeaturePodHorizontalMiddlePadding = 28; constexpr int kUnifiedFeaturePodHorizontalMiddlePadding = 0;
constexpr int kUnifiedFeaturePodCollapsedVerticalPadding = 16; constexpr int kUnifiedFeaturePodCollapsedVerticalPadding = 16;
constexpr int kUnifiedFeaturePodCollapsedHorizontalPadding = 24; constexpr int kUnifiedFeaturePodCollapsedHorizontalPadding = 24;
constexpr int kUnifiedFeaturePodArrowSpacing = 4; constexpr int kUnifiedFeaturePodArrowSpacing = 4;
......
...@@ -29,6 +29,7 @@ namespace { ...@@ -29,6 +29,7 @@ namespace {
void ConfigureFeaturePodLabel(views::Label* label) { void ConfigureFeaturePodLabel(views::Label* label) {
label->SetAutoColorReadabilityEnabled(false); label->SetAutoColorReadabilityEnabled(false);
label->SetSubpixelRenderingEnabled(false); label->SetSubpixelRenderingEnabled(false);
label->set_can_process_events_within_subtree(false);
} }
} // namespace } // namespace
...@@ -105,6 +106,7 @@ FeaturePodLabelButton::FeaturePodLabelButton(views::ButtonListener* listener) ...@@ -105,6 +106,7 @@ FeaturePodLabelButton::FeaturePodLabelButton(views::ButtonListener* listener)
ConfigureFeaturePodLabel(sub_label_); ConfigureFeaturePodLabel(sub_label_);
label_->SetEnabledColor(kUnifiedMenuTextColor); label_->SetEnabledColor(kUnifiedMenuTextColor);
sub_label_->SetEnabledColor(kUnifiedMenuSecondaryTextColor); sub_label_->SetEnabledColor(kUnifiedMenuSecondaryTextColor);
sub_label_->SetVisible(false);
detailed_view_arrow_->set_can_process_events_within_subtree(false); detailed_view_arrow_->set_can_process_events_within_subtree(false);
detailed_view_arrow_->SetImage( detailed_view_arrow_->SetImage(
...@@ -141,10 +143,24 @@ void FeaturePodLabelButton::Layout() { ...@@ -141,10 +143,24 @@ void FeaturePodLabelButton::Layout() {
} }
gfx::Size FeaturePodLabelButton::CalculatePreferredSize() const { gfx::Size FeaturePodLabelButton::CalculatePreferredSize() const {
return gfx::Size(kUnifiedFeaturePodSize.width(), // Minimum width of the button
label_->GetPreferredSize().height() + int width = kUnifiedFeaturePodLabelWidth + GetInsets().width();
sub_label_->GetPreferredSize().height() + if (detailed_view_arrow_->visible()) {
GetInsets().height()); const int label_width = std::min(kUnifiedFeaturePodLabelWidth,
label_->GetPreferredSize().width());
// Symmetrically increase the width to accommodate the arrow
const int extra_space_for_arrow =
2 * (kUnifiedFeaturePodArrowSpacing +
detailed_view_arrow_->GetPreferredSize().width());
width = std::max(width,
label_width + extra_space_for_arrow + GetInsets().width());
}
int height = label_->GetPreferredSize().height() + GetInsets().height();
if (sub_label_->visible())
height += sub_label_->GetPreferredSize().height();
return gfx::Size(width, height);
} }
std::unique_ptr<views::InkDrop> FeaturePodLabelButton::CreateInkDrop() { std::unique_ptr<views::InkDrop> FeaturePodLabelButton::CreateInkDrop() {
...@@ -174,24 +190,20 @@ std::unique_ptr<views::InkDropMask> FeaturePodLabelButton::CreateInkDropMask() ...@@ -174,24 +190,20 @@ std::unique_ptr<views::InkDropMask> FeaturePodLabelButton::CreateInkDropMask()
void FeaturePodLabelButton::SetLabel(const base::string16& label) { void FeaturePodLabelButton::SetLabel(const base::string16& label) {
label_->SetText(label); label_->SetText(label);
UpdateDetailedViewArrow();
SetTooltipTextFromLabels(); SetTooltipTextFromLabels();
Layout(); InvalidateLayout();
SchedulePaint();
} }
void FeaturePodLabelButton::SetSubLabel(const base::string16& sub_label) { void FeaturePodLabelButton::SetSubLabel(const base::string16& sub_label) {
sub_label_->SetText(sub_label); sub_label_->SetText(sub_label);
sub_label_->SetVisible(true);
SetTooltipTextFromLabels(); SetTooltipTextFromLabels();
Layout(); InvalidateLayout();
SchedulePaint();
} }
void FeaturePodLabelButton::ShowDetailedViewArrow() { void FeaturePodLabelButton::ShowDetailedViewArrow() {
show_detailed_view_arrow_ = true; detailed_view_arrow_->SetVisible(true);
UpdateDetailedViewArrow(); InvalidateLayout();
Layout();
SchedulePaint();
} }
void FeaturePodLabelButton::SetTooltipTextFromLabels() { void FeaturePodLabelButton::SetTooltipTextFromLabels() {
...@@ -203,23 +215,13 @@ void FeaturePodLabelButton::SetTooltipTextFromLabels() { ...@@ -203,23 +215,13 @@ void FeaturePodLabelButton::SetTooltipTextFromLabels() {
void FeaturePodLabelButton::LayoutInCenter(views::View* child, int y) { void FeaturePodLabelButton::LayoutInCenter(views::View* child, int y) {
gfx::Rect contents_bounds = GetContentsBounds(); gfx::Rect contents_bounds = GetContentsBounds();
gfx::Size preferred_size = child->GetPreferredSize(); gfx::Size preferred_size = child->GetPreferredSize();
int child_width = std::min(contents_bounds.width(), preferred_size.width()); int child_width =
std::min(kUnifiedFeaturePodLabelWidth, preferred_size.width());
child->SetBounds( child->SetBounds(
contents_bounds.x() + (contents_bounds.width() - child_width) / 2, y, contents_bounds.x() + (contents_bounds.width() - child_width) / 2, y,
child_width, preferred_size.height()); child_width, preferred_size.height());
} }
void FeaturePodLabelButton::UpdateDetailedViewArrow() {
// If the feature pod button has a detailed view, and the label row has enough
// space to show the arrow, set the arrow visible.
detailed_view_arrow_->SetVisible(
show_detailed_view_arrow_ &&
label_->GetPreferredSize().width() +
detailed_view_arrow_->GetPreferredSize().width() +
kUnifiedFeaturePodArrowSpacing <=
GetPreferredSize().width() - GetInsets().width());
}
FeaturePodButton::FeaturePodButton(FeaturePodControllerBase* controller) FeaturePodButton::FeaturePodButton(FeaturePodControllerBase* controller)
: controller_(controller), : controller_(controller),
icon_button_(new FeaturePodIconButton(this)), icon_button_(new FeaturePodIconButton(this)),
...@@ -232,8 +234,6 @@ FeaturePodButton::FeaturePodButton(FeaturePodControllerBase* controller) ...@@ -232,8 +234,6 @@ FeaturePodButton::FeaturePodButton(FeaturePodControllerBase* controller)
AddChildView(icon_button_); AddChildView(icon_button_);
AddChildView(label_button_); AddChildView(label_button_);
layout->SetFlexForView(label_button_, 1);
SetPaintToLayer(); SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false); layer()->SetFillsBoundsOpaquely(false);
} }
...@@ -248,14 +248,20 @@ void FeaturePodButton::SetVectorIcon(const gfx::VectorIcon& icon) { ...@@ -248,14 +248,20 @@ void FeaturePodButton::SetVectorIcon(const gfx::VectorIcon& icon) {
void FeaturePodButton::SetLabel(const base::string16& label) { void FeaturePodButton::SetLabel(const base::string16& label) {
icon_button_->SetTooltipText(label); icon_button_->SetTooltipText(label);
label_button_->SetLabel(label); label_button_->SetLabel(label);
Layout();
label_button_->SchedulePaint();
} }
void FeaturePodButton::SetSubLabel(const base::string16& sub_label) { void FeaturePodButton::SetSubLabel(const base::string16& sub_label) {
label_button_->SetSubLabel(sub_label); label_button_->SetSubLabel(sub_label);
Layout();
label_button_->SchedulePaint();
} }
void FeaturePodButton::ShowDetailedViewArrow() { void FeaturePodButton::ShowDetailedViewArrow() {
label_button_->ShowDetailedViewArrow(); label_button_->ShowDetailedViewArrow();
Layout();
label_button_->SchedulePaint();
} }
void FeaturePodButton::SetToggled(bool toggled) { void FeaturePodButton::SetToggled(bool toggled) {
......
...@@ -78,16 +78,11 @@ class FeaturePodLabelButton : public views::Button { ...@@ -78,16 +78,11 @@ class FeaturePodLabelButton : public views::Button {
// Layout |child| in horizontal center with its vertical origin set to |y|. // Layout |child| in horizontal center with its vertical origin set to |y|.
void LayoutInCenter(views::View* child, int y); void LayoutInCenter(views::View* child, int y);
// Hide detailed view arrow if there's no space for it.
void UpdateDetailedViewArrow();
// Owned by views hierarchy. // Owned by views hierarchy.
views::Label* const label_; views::Label* const label_;
views::Label* const sub_label_; views::Label* const sub_label_;
views::ImageView* const detailed_view_arrow_; views::ImageView* const detailed_view_arrow_;
bool show_detailed_view_arrow_ = false;
DISALLOW_COPY_AND_ASSIGN(FeaturePodLabelButton); DISALLOW_COPY_AND_ASSIGN(FeaturePodLabelButton);
}; };
......
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