Commit 8c2e3651 authored by Carlos IL's avatar Carlos IL Committed by Commit Bot

Fix URL elision logic with RTL UI

This fixes the URL elision and animation logic when the UI is RTL.
This does not yet address RTL URLs, just fixes the logic when Chrome
itself is in RTL mode, but only works with LTR URLs.
Gradient mask is not currently functional if UI is RTL, so this disables
it in that case.

Bug: 1101472
Change-Id: Ib89ebb6eb21882aa83ec923ec1720f25468bc6d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333293
Auto-Submit: Carlos IL <carlosil@chromium.org>
Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: Carlos IL <carlosil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795060}
parent 77cd5d73
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/check_op.h" #include "base/check_op.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/i18n/rtl.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -232,8 +233,13 @@ void OmniboxViewViews::ElideAnimation::Start( ...@@ -232,8 +233,13 @@ void OmniboxViewViews::ElideAnimation::Start(
starting_display_offset_ = render_text_->GetUpdatedDisplayOffset().x(); starting_display_offset_ = render_text_->GetUpdatedDisplayOffset().x();
// Shift the text to where |elide_to_bounds| starts, relative to the current // Shift the text to where |elide_to_bounds| starts, relative to the current
// display rect. // display rect.
ending_display_offset_ = if (base::i18n::IsRTL()) {
starting_display_offset_ - (elide_to_rect_.x() - elide_from_rect_.x()); ending_display_offset_ = starting_display_offset_ +
elide_from_rect_.right() - elide_to_rect_.right();
} else {
ending_display_offset_ =
starting_display_offset_ - (elide_to_rect_.x() - elide_from_rect_.x());
}
animation_->Start(); animation_->Start();
} }
...@@ -282,8 +288,10 @@ void OmniboxViewViews::ElideAnimation::AnimationProgressed( ...@@ -282,8 +288,10 @@ void OmniboxViewViews::ElideAnimation::AnimationProgressed(
animation->GetCurrentValue(), elide_from_rect_, elide_to_rect_); animation->GetCurrentValue(), elide_from_rect_, elide_to_rect_);
DCHECK_EQ(bounds.y(), old_bounds.y()); DCHECK_EQ(bounds.y(), old_bounds.y());
DCHECK_EQ(bounds.height(), old_bounds.height()); DCHECK_EQ(bounds.height(), old_bounds.height());
gfx::Rect shifted_bounds(old_bounds.x(), old_bounds.y(), bounds.width(), gfx::Rect shifted_bounds(base::i18n::IsRTL()
old_bounds.height()); ? old_bounds.right() - bounds.width()
: old_bounds.x(),
old_bounds.y(), bounds.width(), old_bounds.height());
render_text_->SetDisplayRect(shifted_bounds); render_text_->SetDisplayRect(shifted_bounds);
current_offset_ = gfx::Tween::IntValueBetween(animation->GetCurrentValue(), current_offset_ = gfx::Tween::IntValueBetween(animation->GetCurrentValue(),
starting_display_offset_, starting_display_offset_,
...@@ -294,6 +302,13 @@ void OmniboxViewViews::ElideAnimation::AnimationProgressed( ...@@ -294,6 +302,13 @@ void OmniboxViewViews::ElideAnimation::AnimationProgressed(
view_->ApplyColor(GetCurrentColor(), range); view_->ApplyColor(GetCurrentColor(), range);
} }
// TODO(crbug.com/1101472): The smoothing gradient mask is not yet implemented
// correctly for RTL UI.
if (base::i18n::IsRTL()) {
view_->SchedulePaint();
return;
}
// The gradient mask should be a fixed width, except if that width would // The gradient mask should be a fixed width, except if that width would
// cause it to mask the unelided section. In that case we set it to the // cause it to mask the unelided section. In that case we set it to the
// maximum width possible that won't cover the unelided section. // maximum width possible that won't cover the unelided section.
...@@ -2487,22 +2502,37 @@ void OmniboxViewViews::ElideURL() { ...@@ -2487,22 +2502,37 @@ void OmniboxViewViews::ElideURL() {
} }
// |simplified_domain_rect| gives us the current bounds of the simplified // |simplified_domain_rect| gives us the current bounds of the simplified
// domain substring. We shift it to the leftmost edge of the omnibox (as // domain substring. We shift it to the leftmost (rightmost if UI is RTL) edge
// determined by the x position of the current display rect), and then scroll // of the omnibox (as determined by the x position of the current display
// to where the simplified domain begins, so that the simplified domain // rect), and then scroll to where the simplified domain begins, so that the
// appears at the leftmost edge. // simplified domain appears at the leftmost/rightmost edge.
gfx::Rect old_bounds = GetRenderText()->display_rect(); gfx::Rect old_bounds = GetRenderText()->display_rect();
int shifted_simplified_domain_x_pos;
// The x position of the elided domain will depend on whether the UI is LTR or
// RTL.
if (base::i18n::IsRTL()) {
shifted_simplified_domain_x_pos =
old_bounds.right() - simplified_domain_rect.width();
} else {
shifted_simplified_domain_x_pos = old_bounds.x();
}
// Use |old_bounds| for y and height values because the URL should never shift // Use |old_bounds| for y and height values because the URL should never shift
// vertically while eliding to/from simplified domain. // vertically while eliding to/from simplified domain.
gfx::Rect shifted_simplified_domain_rect(old_bounds.x(), old_bounds.y(), gfx::Rect shifted_simplified_domain_rect(
simplified_domain_rect.width(), shifted_simplified_domain_x_pos, old_bounds.y(),
old_bounds.height()); simplified_domain_rect.width(), old_bounds.height());
GetRenderText()->SetDisplayRect(shifted_simplified_domain_rect); GetRenderText()->SetDisplayRect(shifted_simplified_domain_rect);
// Scroll the text to where the simplified domain begins, relative to the // Scroll the text to where the simplified domain begins, relative to the
// leftmost edge of the current display rect. // leftmost (rightmost if UI is RTL) edge of the current display rect.
GetRenderText()->SetDisplayOffset( if (base::i18n::IsRTL()) {
GetRenderText()->GetUpdatedDisplayOffset().x() - GetRenderText()->SetDisplayOffset(
(simplified_domain_rect.x() - old_bounds.x())); GetRenderText()->GetUpdatedDisplayOffset().x() + old_bounds.right() -
simplified_domain_rect.right());
} else {
GetRenderText()->SetDisplayOffset(
GetRenderText()->GetUpdatedDisplayOffset().x() -
(simplified_domain_rect.x() - old_bounds.x()));
}
// GetSubstringBounds() rounds outward internally, so there may be small // GetSubstringBounds() rounds outward internally, so there may be small
// portions of text still showing. Set the ranges surrounding the simplified // portions of text still showing. Set the ranges surrounding the simplified
......
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