Commit 3f285c90 authored by Kristi Park's avatar Kristi Park Committed by Commit Bot

Fix jitter when LocationIconView text label expands

LocationIconView overrides WidthMultiplier() in order to remove the
shrinking animation. However, IsShrinking() will still return true
during the shrinking phase due to |open_state_fraction_|, causing
GetSizeForLabelWidth() to briefly return a non-offset width.

Therefore, call a new function, SetUpForAnimation(), which will only
animate the label in.

Bug: 1012107
Change-Id: I2757003690d12edd6b24e0ea30d03d4ba622eba3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1850968
Commit-Queue: Kristi Park <kristipark@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705691}
parent 589815e2
...@@ -199,14 +199,17 @@ double IconLabelBubbleView::WidthMultiplier() const { ...@@ -199,14 +199,17 @@ double IconLabelBubbleView::WidthMultiplier() const {
double size_fraction = 1.0; double size_fraction = 1.0;
if (state < open_state_fraction_) if (state < open_state_fraction_)
size_fraction = state / open_state_fraction_; size_fraction = state / open_state_fraction_;
if (state > (1.0 - open_state_fraction_)) else if (state > (1.0 - open_state_fraction_))
size_fraction = (1.0 - state) / open_state_fraction_; size_fraction = (1.0 - state) / open_state_fraction_;
return size_fraction; return size_fraction;
} }
bool IconLabelBubbleView::IsShrinking() const { bool IconLabelBubbleView::IsShrinking() const {
return slide_animation_.is_animating() && !is_animation_paused_ && if (!slide_animation_.is_animating() || is_animation_paused_)
slide_animation_.GetCurrentValue() > (1.0 - open_state_fraction_); return false;
return slide_animation_.IsClosing() ||
(open_state_fraction_ < 1.0 &&
slide_animation_.GetCurrentValue() > (1.0 - open_state_fraction_));
} }
bool IconLabelBubbleView::ShowBubble(const ui::Event& event) { bool IconLabelBubbleView::ShowBubble(const ui::Event& event) {
...@@ -401,10 +404,6 @@ int IconLabelBubbleView::GetExtraInternalSpacing() const { ...@@ -401,10 +404,6 @@ int IconLabelBubbleView::GetExtraInternalSpacing() const {
return 0; return 0;
} }
base::TimeDelta IconLabelBubbleView::GetSlideDurationTime() const {
return base::TimeDelta::FromMilliseconds(3000);
}
int IconLabelBubbleView::GetWidthBetweenIconAndSeparator() const { int IconLabelBubbleView::GetWidthBetweenIconAndSeparator() const {
return ShouldShowSeparator() ? kIconLabelBubbleSpaceBesideSeparator : 0; return ShouldShowSeparator() ? kIconLabelBubbleSpaceBesideSeparator : 0;
} }
...@@ -421,13 +420,23 @@ const char* IconLabelBubbleView::GetClassName() const { ...@@ -421,13 +420,23 @@ const char* IconLabelBubbleView::GetClassName() const {
return "IconLabelBubbleView"; return "IconLabelBubbleView";
} }
void IconLabelBubbleView::SetUpForInOutAnimation() { void IconLabelBubbleView::SetUpForAnimation() {
SetInkDropMode(InkDropMode::ON); SetInkDropMode(InkDropMode::ON);
SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
label()->SetElideBehavior(gfx::NO_ELIDE); label()->SetElideBehavior(gfx::NO_ELIDE);
label()->SetVisible(false); label()->SetVisible(false);
slide_animation_.SetSlideDuration(GetSlideDurationTime()); slide_animation_.SetSlideDuration(base::TimeDelta::FromMilliseconds(150));
slide_animation_.SetTweenType(kIconLabelBubbleTweenType); slide_animation_.SetTweenType(kIconLabelBubbleTweenType);
open_state_fraction_ = 1.0;
}
void IconLabelBubbleView::SetUpForInOutAnimation() {
SetUpForAnimation();
// The duration of the slide includes the appearance of the label (600ms),
// statically showing the label (1800ms), and hiding the label (600ms). The
// proportion of time spent in each portion of the animation is controlled by
// kIconLabelBubbleOpenTimeFraction.
slide_animation_.SetSlideDuration(base::TimeDelta::FromMilliseconds(3000));
open_state_fraction_ = gfx::Tween::CalculateValue( open_state_fraction_ = gfx::Tween::CalculateValue(
kIconLabelBubbleTweenType, kIconLabelBubbleOpenTimeFraction); kIconLabelBubbleTweenType, kIconLabelBubbleOpenTimeFraction);
} }
......
...@@ -155,7 +155,12 @@ class IconLabelBubbleView : public views::InkDropObserver, ...@@ -155,7 +155,12 @@ class IconLabelBubbleView : public views::InkDropObserver,
gfx::Size GetSizeForLabelWidth(int label_width) const; gfx::Size GetSizeForLabelWidth(int label_width) const;
// Set up for icons that animate their labels in and then out. // Set up for icons that animate their labels in. Animating out is initiated
// manually.
void SetUpForAnimation();
// Set up for icons that animate their labels in and then automatically out
// after a period of time.
void SetUpForInOutAnimation(); void SetUpForInOutAnimation();
// Animates the view in and disables highlighting for hover and focus. If a // Animates the view in and disables highlighting for hover and focus. If a
...@@ -191,10 +196,6 @@ class IconLabelBubbleView : public views::InkDropObserver, ...@@ -191,10 +196,6 @@ class IconLabelBubbleView : public views::InkDropObserver,
// to the suggestion text, like in the SelectedKeywordView. // to the suggestion text, like in the SelectedKeywordView.
virtual int GetExtraInternalSpacing() const; virtual int GetExtraInternalSpacing() const;
// Subclasses that want a different duration for the slide animation can
// override this method.
virtual base::TimeDelta GetSlideDurationTime() const;
// Returns the width after the icon and before the separator. If the // Returns the width after the icon and before the separator. If the
// separator is not shown, and ShouldShowExtraEndSpace() is false, this // separator is not shown, and ShouldShowExtraEndSpace() is false, this
// returns 0. // returns 0.
......
...@@ -31,10 +31,9 @@ using security_state::SecurityLevel; ...@@ -31,10 +31,9 @@ using security_state::SecurityLevel;
LocationIconView::LocationIconView(const gfx::FontList& font_list, LocationIconView::LocationIconView(const gfx::FontList& font_list,
Delegate* delegate) Delegate* delegate)
: IconLabelBubbleView(font_list), delegate_(delegate) { : IconLabelBubbleView(font_list), delegate_(delegate) {
label()->SetElideBehavior(gfx::ELIDE_MIDDLE);
SetID(VIEW_ID_LOCATION_ICON); SetID(VIEW_ID_LOCATION_ICON);
Update(true); Update(true);
SetUpForInOutAnimation(); SetUpForAnimation();
// Readability is guaranteed by the omnibox theme. // Readability is guaranteed by the omnibox theme.
label()->SetAutoColorReadabilityEnabled(false); label()->SetAutoColorReadabilityEnabled(false);
...@@ -262,10 +261,6 @@ bool LocationIconView::IsTriggerableEvent(const ui::Event& event) { ...@@ -262,10 +261,6 @@ bool LocationIconView::IsTriggerableEvent(const ui::Event& event) {
return IconLabelBubbleView::IsTriggerableEvent(event); return IconLabelBubbleView::IsTriggerableEvent(event);
} }
double LocationIconView::WidthMultiplier() const {
return GetAnimationValue();
}
gfx::Size LocationIconView::GetMinimumSizeForPreferredSize( gfx::Size LocationIconView::GetMinimumSizeForPreferredSize(
gfx::Size size) const { gfx::Size size) const {
const int kMinCharacters = 10; const int kMinCharacters = 10;
...@@ -273,7 +268,3 @@ gfx::Size LocationIconView::GetMinimumSizeForPreferredSize( ...@@ -273,7 +268,3 @@ gfx::Size LocationIconView::GetMinimumSizeForPreferredSize(
GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters))); GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters)));
return size; return size;
} }
base::TimeDelta LocationIconView::GetSlideDurationTime() const {
return base::TimeDelta::FromMilliseconds(150);
}
...@@ -106,7 +106,6 @@ class LocationIconView : public IconLabelBubbleView { ...@@ -106,7 +106,6 @@ class LocationIconView : public IconLabelBubbleView {
protected: protected:
// IconLabelBubbleView: // IconLabelBubbleView:
bool IsTriggerableEvent(const ui::Event& event) override; bool IsTriggerableEvent(const ui::Event& event) override;
double WidthMultiplier() const override;
private: private:
// The security level when the location icon was last updated. Used to decide // The security level when the location icon was last updated. Used to decide
...@@ -121,8 +120,6 @@ class LocationIconView : public IconLabelBubbleView { ...@@ -121,8 +120,6 @@ class LocationIconView : public IconLabelBubbleView {
// Returns what the minimum size would be if the preferred size were |size|. // Returns what the minimum size would be if the preferred size were |size|.
gfx::Size GetMinimumSizeForPreferredSize(gfx::Size size) const; gfx::Size GetMinimumSizeForPreferredSize(gfx::Size size) const;
base::TimeDelta GetSlideDurationTime() const override;
Delegate* delegate_; Delegate* delegate_;
// Used to scope the lifetime of asynchronous icon fetch callbacks to the // Used to scope the lifetime of asynchronous icon fetch callbacks to the
......
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