Commit a6f2d030 authored by Carlos IL's avatar Carlos IL Committed by Commit Bot

Reset ElideAnimation gradient mask on animation stop

Prior to this fix, stale rectangles where showing at the start of a
new animation.

Bug: 1112848
Change-Id: Ie41eae474a2c2477b436a6b450cda099225f90f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2341839
Commit-Queue: Carlos IL <carlosil@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796068}
parent 30cb8ccd
...@@ -246,6 +246,10 @@ void OmniboxViewViews::ElideAnimation::Start( ...@@ -246,6 +246,10 @@ void OmniboxViewViews::ElideAnimation::Start(
} }
void OmniboxViewViews::ElideAnimation::Stop() { void OmniboxViewViews::ElideAnimation::Stop() {
// Reset the smoothing rectangles whenever the animation stops to prevent
// stale rectangles from showing at the start of the next animation.
view_->elide_animation_smoothing_rect_left_ = gfx::Rect();
view_->elide_animation_smoothing_rect_right_ = gfx::Rect();
if (animation_) if (animation_)
animation_->Stop(); animation_->Stop();
} }
......
...@@ -203,12 +203,17 @@ class OmniboxViewViews : public OmniboxView, ...@@ -203,12 +203,17 @@ class OmniboxViewViews : public OmniboxView,
FRIEND_TEST_ALL_PREFIXES( FRIEND_TEST_ALL_PREFIXES(
OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest, OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
VerticalAndHorizontalPosition); VerticalAndHorizontalPosition);
FRIEND_TEST_ALL_PREFIXES(
OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
NoStaleGradientMask);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest, ModifierKeys); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest, ModifierKeys);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest, FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
SameDocNavigations); SameDocNavigations);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest, FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
SameDocNavigationDuringAnimation); SameDocNavigationDuringAnimation);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest, GradientMask); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest, GradientMask);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
GradientMaskResetAfterStop);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest, FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
UserInteractionDuringAnimation); UserInteractionDuringAnimation);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest, FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
......
...@@ -2725,6 +2725,43 @@ TEST_P(OmniboxViewViewsHideOnInteractionTest, GradientMask) { ...@@ -2725,6 +2725,43 @@ TEST_P(OmniboxViewViewsHideOnInteractionTest, GradientMask) {
simplified_rect.right() + offset); simplified_rect.right() + offset);
} }
// Tests that gradient mask is reset when animation is stopped.
TEST_P(OmniboxViewViewsHideOnInteractionTest, GradientMaskResetAfterStop) {
if (base::i18n::IsRTL()) {
// TODO(crbug.com/1101472): Re-enable this test once gradient mask is
// implemented for RTL UI.
return;
}
SetUpSimplifiedDomainTest();
gfx::RenderText* render_text = omnibox_view()->GetRenderText();
content::MockNavigationHandle navigation;
navigation.set_is_same_document(false);
omnibox_view()->DidFinishNavigation(&navigation);
ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
render_text, gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
kSimplifiedDomainDisplayUrl.size())));
// Simulate a user interaction to begin animating to the simplified domain.
omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
OmniboxViewViews::ElideAnimation* elide_animation =
omnibox_view()->GetElideAfterInteractionAnimationForTesting();
ASSERT_TRUE(elide_animation);
EXPECT_TRUE(elide_animation->IsAnimating());
// Advance animation so it sets the gradient mask, then stop it.
gfx::AnimationContainerElement* elide_as_element =
elide_animation->GetAnimationForTesting();
elide_as_element->SetStartTime(base::TimeTicks());
elide_as_element->Step(base::TimeTicks() + base::TimeDelta::FromSeconds(1));
elide_animation->Stop();
// Both gradient mask rectangles should have a width of 0 once the animation
// has stopped.
EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_left_.width(), 0);
EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_right_.width(), 0);
}
// Tests that in the hide-on-interaction field trial, a second user interaction // Tests that in the hide-on-interaction field trial, a second user interaction
// does not interfere with an animation that is currently running. This is // does not interfere with an animation that is currently running. This is
// similar to SameDocNavigationDuringAnimation except that this test checks that // similar to SameDocNavigationDuringAnimation except that this test checks that
...@@ -2896,6 +2933,73 @@ TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest, ...@@ -2896,6 +2933,73 @@ TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
EXPECT_TRUE(elide_animation->IsAnimating()); EXPECT_TRUE(elide_animation->IsAnimating());
} }
// Tests that the last gradient mask from a previous animation is no longer
// visible when starting a new animation.
TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
NoStaleGradientMask) {
if (base::i18n::IsRTL()) {
// TODO(crbug.com/1101472): Re-enable this test once gradient mask is
// implemented for RTL UI.
return;
}
SetUpSimplifiedDomainTest();
gfx::RenderText* render_text = omnibox_view()->GetRenderText();
content::MockNavigationHandle navigation;
navigation.set_is_same_document(false);
omnibox_view()->DidFinishNavigation(&navigation);
ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
render_text, gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
kSimplifiedDomainDisplayUrl.size())));
// Simulate a user interaction to begin animating to the simplified domain.
omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
OmniboxViewViews::ElideAnimation* elide_animation =
omnibox_view()->GetElideAfterInteractionAnimationForTesting();
ASSERT_TRUE(elide_animation);
EXPECT_TRUE(elide_animation->IsAnimating());
// Allow elide animation to finish.
gfx::AnimationContainerElement* elide_as_element =
elide_animation->GetAnimationForTesting();
elide_as_element->SetStartTime(base::TimeTicks());
elide_as_element->Step(base::TimeTicks() + base::TimeDelta::FromSeconds(4));
// Hover over the omnibox to trigger unelide animation.
omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
OmniboxViewViews::ElideAnimation* hover_animation =
omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
ASSERT_TRUE(hover_animation);
EXPECT_TRUE(hover_animation->IsAnimating());
// Allow unelide animation to finish.
gfx::AnimationContainerElement* unelide_as_element =
hover_animation->GetAnimationForTesting();
unelide_as_element->SetStartTime(base::TimeTicks());
unelide_as_element->Step(base::TimeTicks() + base::TimeDelta::FromSeconds(4));
// Both gradient mask rectangles will be full sized at this point
EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_left_.width(),
OmniboxViewViews::kSmoothingGradientMaxWidth - 1);
EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_right_.width(),
OmniboxViewViews::kSmoothingGradientMaxWidth - 1);
// Select the text in the omnibox, then click on the page, this will trigger
// an elision with no animation.
omnibox_view()->SelectAll(false);
blink::WebMouseEvent event;
event.SetType(blink::WebInputEvent::Type::kMouseDown);
omnibox_view()->DidGetUserInteraction(event);
// Hover over the omnibox to trigger the unelide animation.
omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
// Even though the unelide animation hasn't advanced, the gradient mask
// rectangles should have been reset.
EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_left_.width(), 0);
EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_right_.width(), 0);
}
// Tests that in the reveal-on-hover field trial variation (without // Tests that in the reveal-on-hover field trial variation (without
// hide-on-interaction), the path is faded back in after focus, then blur, then // hide-on-interaction), the path is faded back in after focus, then blur, then
// hover. // hover.
......
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