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

Fix elide URL on interaction for RTL UI

Enabling kHideSteadyStateUrlPathQueryAndRefOnInteraction caused the URL
to be misaligned due to a problem with how the display rectangle was
calculated in
OmniboxViewViews::ShowFullURLWithoutSchemeAndTrivialSubdomain, this CL
fixes that issue

Bug: 1114332
Change-Id: Id716ea84248f568c3fe6dc5f007631ac7c64edc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343872Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Carlos IL <carlosil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797056}
parent 2cb92bbf
......@@ -2636,8 +2636,11 @@ void OmniboxViewViews::ShowFullURLWithoutSchemeAndTrivialSubdomain() {
// then set the display offset to scroll the scheme and trivial subdomain out
// of visibility.
GetRenderText()->SetDisplayRect(
gfx::Rect(current_display_rect.x(), display_url_bounds.y(),
display_url_bounds.width(), display_url_bounds.height()));
gfx::Rect(base::i18n::IsRTL()
? current_display_rect.right() - display_url_bounds.width()
: current_display_rect.x(),
display_url_bounds.y(), display_url_bounds.width(),
display_url_bounds.height()));
GetRenderText()->SetDisplayOffset(
-1 * (display_url_bounds.x() - current_display_rect.x()));
......
......@@ -196,6 +196,9 @@ class OmniboxViewViews : public OmniboxView,
FRIEND_TEST_ALL_PREFIXES(
OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
HideOnInteractionAfterFocusAndBlur);
FRIEND_TEST_ALL_PREFIXES(
OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
URLPositionWithHideOnInteraction);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, AfterBlur);
FRIEND_TEST_ALL_PREFIXES(
OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
......
......@@ -2969,6 +2969,73 @@ TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
EXPECT_TRUE(elide_animation->IsAnimating());
}
// Tests that in the hide-on-interaction field trial variation, the URL is
// aligned as appropriate for LTR and RTL UIs during the different stages
// of elision.
// Regression test for crbug.com/1114332
TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
URLPositionWithHideOnInteraction) {
SetUpSimplifiedDomainTest();
gfx::RenderText* render_text = omnibox_view()->GetRenderText();
// Initially the display rect of the render text matches the omnibox bounds,
// store a copy of it.
gfx::Rect omnibox_bounds(render_text->display_rect());
content::MockNavigationHandle navigation;
navigation.set_is_same_document(false);
omnibox_view()->DidFinishNavigation(&navigation);
// Simulate a user interaction to fade out the path.
omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
OmniboxViewViews::ElideAnimation* elide_animation =
omnibox_view()->GetElideAfterInteractionAnimationForTesting();
gfx::AnimationContainerElement* elide_as_element =
elide_animation->GetAnimationForTesting();
elide_as_element->SetStartTime(base::TimeTicks());
elide_as_element->Step(base::TimeTicks() + base::TimeDelta::FromSeconds(1));
ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
kSimplifiedDomainDisplayUrlSubdomain,
kSimplifiedDomainDisplayUrlHostnameAndScheme,
kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
// Check the URL is right aligned if the UI is RTL, or left aligned if it is
// LTR.
if (base::i18n::IsRTL()) {
EXPECT_EQ(render_text->display_rect().x(),
omnibox_bounds.right() - render_text->display_rect().width());
} else {
EXPECT_EQ(render_text->display_rect().x(), omnibox_bounds.x());
}
// Call OnFocus to trigger unelision.
omnibox_view()->OnFocus();
ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
render_text, gfx::Range(0, kSimplifiedDomainDisplayUrl.size())));
// Check alignment again
if (base::i18n::IsRTL()) {
EXPECT_EQ(render_text->display_rect().x(),
omnibox_bounds.right() - render_text->display_rect().width());
} else {
EXPECT_EQ(render_text->display_rect().x(), omnibox_bounds.x());
}
// Call OnBlur to return to the state on page load.
omnibox_view()->OnBlur();
ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
render_text, gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
kSimplifiedDomainDisplayUrl.size())));
// Check alignment again
if (base::i18n::IsRTL()) {
EXPECT_EQ(render_text->display_rect().x(),
omnibox_bounds.right() - render_text->display_rect().width());
} else {
EXPECT_EQ(render_text->display_rect().x(), omnibox_bounds.x());
}
}
// Tests that the last gradient mask from a previous animation is no longer
// visible when starting a new animation.
TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
......
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