Commit 24c8b5c8 authored by pkasting's avatar pkasting Committed by Commit bot

When animating a content setting bubble smaller, hide the background later.

We were hiding when the label size reached 0.  That winds up hiding the
background when the icon has both the internal spacing and the trailing padding
adjacent to it before the background ends.  Instead, wait to hide the background
until the internal spacing portion of that is collapsed, so it's just
<leading padding><icon><trailing padding>.

This isn't very noticeable when the internal spacing is 2 px.  It will be more
noticeable when I later increase the spacing (which is how I saw this).

This allows moving label layout in IconLabelBubbleView() downward since we no
longer care about sizing the label to 0 early.  I think the code reads more
clearly that way.

BUG=none
TEST=none

Review URL: https://codereview.chromium.org/1830343003

Cr-Commit-Position: refs/heads/master@{#383922}
parent d8464b0b
...@@ -176,7 +176,8 @@ SkColor ContentSettingImageView::GetBorderColor() const { ...@@ -176,7 +176,8 @@ SkColor ContentSettingImageView::GetBorderColor() const {
} }
bool ContentSettingImageView::ShouldShowBackground() const { bool ContentSettingImageView::ShouldShowBackground() const {
return (!IsShrinking() || label()->width() > 0) && return (!IsShrinking() ||
(width() >= MinimumWidthForImageWithBackgroundShown())) &&
(slide_animator_.is_animating() || pause_animation_); (slide_animator_.is_animating() || pause_animation_);
} }
......
...@@ -119,21 +119,7 @@ gfx::Size IconLabelBubbleView::GetPreferredSize() const { ...@@ -119,21 +119,7 @@ gfx::Size IconLabelBubbleView::GetPreferredSize() const {
} }
void IconLabelBubbleView::Layout() { void IconLabelBubbleView::Layout() {
// Compute the label bounds. The label gets whatever size is left over after // Compute the image bounds. In non-MD, the leading padding depends on
// accounting for the preferred image width and padding amounts. Note that if
// the label has zero size it doesn't actually matter what we compute its X
// value to be, since it won't be visible, so the X value can be "wrong"
// compared to where the right edge of the image is computed to be below.
// This means doing this layout doesn't doesn't depend on any of the layout
// below. That layout, however, may need for this layout to have already
// happened, since the value of ShouldShowBackground() we read below may
// depend on whether the label has nonzero size. Therefore, we do this first.
const int label_x = GetOuterPadding(true) + GetImageAndPaddingWidth();
const int label_width =
std::max(0, width() - label_x - GetOuterPadding(false));
label_->SetBounds(label_x, 0, label_width, height());
// Now compute the image bounds. In non-MD, the leading padding depends on
// whether this is an extension icon, since extension icons and // whether this is an extension icon, since extension icons and
// Chrome-provided icons are different sizes. In MD, these sizes are the // Chrome-provided icons are different sizes. In MD, these sizes are the
// same, so it's not necessary to handle the two types differently. // same, so it's not necessary to handle the two types differently.
...@@ -166,6 +152,15 @@ void IconLabelBubbleView::Layout() { ...@@ -166,6 +152,15 @@ void IconLabelBubbleView::Layout() {
std::min(image_preferred_width, std::min(image_preferred_width,
std::max(0, width() - image_x - bubble_trailing_padding)); std::max(0, width() - image_x - bubble_trailing_padding));
image_->SetBounds(image_x, 0, image_width, height()); image_->SetBounds(image_x, 0, image_width, height());
// Compute the label bounds. The label gets whatever size is left over after
// accounting for the preferred image width and padding amounts. Note that if
// the label has zero size it doesn't actually matter what we compute its X
// value to be, since it won't be visible.
const int label_x = image_x + GetImageAndPaddingWidth();
const int label_width =
std::max(0, width() - label_x - bubble_trailing_padding);
label_->SetBounds(label_x, 0, label_width, height());
} }
void IconLabelBubbleView::OnNativeThemeChanged( void IconLabelBubbleView::OnNativeThemeChanged(
......
...@@ -59,7 +59,8 @@ class TestIconLabelBubbleView : public IconLabelBubbleView { ...@@ -59,7 +59,8 @@ class TestIconLabelBubbleView : public IconLabelBubbleView {
SkColor GetBorderColor() const override { return kTestColor; } SkColor GetBorderColor() const override { return kTestColor; }
bool ShouldShowBackground() const override { bool ShouldShowBackground() const override {
return !IsShrinking() || label()->width() > 0; return !IsShrinking() ||
(width() >= MinimumWidthForImageWithBackgroundShown());
} }
double WidthMultiplier() const override { double WidthMultiplier() const override {
......
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