Commit a37797f5 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

[omnibox] Remove animation from omnibox tab switch button.

I couldn't actually get this to trigger in practice; on trunk the button seems
to snap between widths.  That also seems like reasonable behavior and results in
noticeably simpler code.  Finally, when converting the result view to use layout
managers, I couldn't find a way to produce an animation-based behavior anyway.

Bug: none
Change-Id: I4d2750b675de4bda8758eac2f530ee8b1467dd0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1854533
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarKevin Bailey <krb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706162}
parent f69623b2
......@@ -37,8 +37,6 @@ OmniboxTabSwitchButton::OmniboxTabSwitchButton(
: MdTextButton(result_view, views::style::CONTEXT_BUTTON_MD),
popup_contents_view_(popup_contents_view),
result_view_(result_view),
initialized_(false),
animation_(new gfx::SlideAnimation(this)),
hint_(hint),
hint_short_(hint_short),
theme_provider_(theme_provider) {
......@@ -58,9 +56,9 @@ OmniboxTabSwitchButton::OmniboxTabSwitchButton(
} else {
SetText(hint_);
}
SetPreferredSize({full_text_width_, kButtonHeight});
SetTooltipText(hint_);
SetCornerRadius(kButtonHeight / 2.f);
animation_->SetSlideDuration(base::TimeDelta::FromMilliseconds(500));
SetElideBehavior(gfx::FADE_TAIL);
SetInstallFocusRingOnFocus(true);
......@@ -72,29 +70,6 @@ OmniboxTabSwitchButton::OmniboxTabSwitchButton(
OmniboxTabSwitchButton::~OmniboxTabSwitchButton() = default;
gfx::Size OmniboxTabSwitchButton::CalculatePreferredSize() const {
gfx::Size size = MdTextButton::CalculatePreferredSize();
size.set_height(kButtonHeight);
int current_width =
animation_->CurrentValueBetween(start_width_, goal_width_);
size.set_width(current_width);
return size;
}
void OmniboxTabSwitchButton::AnimationProgressed(
const gfx::Animation* animation) {
if (animation != animation_.get()) {
MdTextButton::AnimationProgressed(animation);
return;
}
// If done shrinking, correct text.
if (animation_->GetCurrentValue() == 1 && goal_width_ < start_width_)
SetText(goal_text_);
result_view_->Layout();
result_view_->SchedulePaint();
}
void OmniboxTabSwitchButton::StateChanged(ButtonState old_state) {
if (state() == STATE_NORMAL) {
// If used to be pressed, transfer ownership.
......@@ -124,23 +99,10 @@ void OmniboxTabSwitchButton::UpdateBackground() {
}
void OmniboxTabSwitchButton::ProvideWidthHint(int parent_width) {
int preferred_width = CalculateGoalWidth(parent_width, &goal_text_);
if (!initialized_) {
initialized_ = true;
goal_width_ = start_width_ = preferred_width;
animation_->Reset(1);
SetText(goal_text_);
return;
}
if (preferred_width != goal_width_) {
goal_width_ = preferred_width;
start_width_ = width();
// If growing/showing, set text-to-be and grow into it.
if (goal_width_ > start_width_)
SetText(goal_text_);
animation_->Reset(0);
animation_->Show();
}
base::string16 text;
int preferred_width = CalculateGoalWidth(parent_width, &text);
SetText(text);
SetPreferredSize({preferred_width, kButtonHeight});
}
void OmniboxTabSwitchButton::ProvideFocusHint() {
......
......@@ -10,10 +10,6 @@
class OmniboxPopupContentsView;
class OmniboxResultView;
namespace gfx {
class SlideAnimation;
}
class OmniboxTabSwitchButton : public views::MdTextButton {
public:
OmniboxTabSwitchButton(OmniboxPopupContentsView* popup_contents_view,
......@@ -26,8 +22,6 @@ class OmniboxTabSwitchButton : public views::MdTextButton {
~OmniboxTabSwitchButton() override;
// views::MdTextButton:
gfx::Size CalculatePreferredSize() const override;
void AnimationProgressed(const gfx::Animation* animation) override;
void StateChanged(ButtonState old_state) override;
// Called by parent views to change background on external (not mouse related)
......@@ -73,14 +67,6 @@ class OmniboxTabSwitchButton : public views::MdTextButton {
static int short_text_width_;
static int full_text_width_;
// To distinguish start-up case, where we don't want animation.
bool initialized_;
// Animation starting width, and final value.
int start_width_, goal_width_;
// The text to be displayed when we reach |goal_width_|.
base::string16 goal_text_;
std::unique_ptr<gfx::SlideAnimation> animation_;
// Label strings for hint text and its short version (may be same).
base::string16 hint_;
base::string16 hint_short_;
......
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