| Index: chrome/android/java/src/org/chromium/chrome/browser/omnibox/UrlBar.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/UrlBar.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/UrlBar.java
|
| index ef895eef94f325ae567280d4ffcc55d3b25ac76a..507f13328c1c8e10490c6374c617efd1f192d418 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/UrlBar.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/UrlBar.java
|
| @@ -432,16 +432,7 @@ public class UrlBar extends VerticallyFixedEditText {
|
|
|
| if (focused) StartupMetrics.getInstance().recordFocusedOmnibox();
|
|
|
| - // When unfocused, force left-to-right rendering at the paragraph level (which is desired
|
| - // for URLs). Right-to-left runs are still rendered RTL, but will not flip the whole URL
|
| - // around. This is consistent with OmniboxViewViews on desktop. When focused, render text
|
| - // normally (to allow users to make non-URL searches and to avoid showing Android's split
|
| - // insertion point when an RTL user enters RTL text).
|
| - if (focused) {
|
| - ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_INHERIT);
|
| - } else {
|
| - ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_LTR);
|
| - }
|
| + fixupTextDirection();
|
| // Always align to the same as the paragraph direction (LTR = left, RTL = right).
|
| ApiCompatibilityUtils.setTextAlignment(this, TEXT_ALIGNMENT_TEXT_START);
|
| }
|
| @@ -465,6 +456,25 @@ public class UrlBar extends VerticallyFixedEditText {
|
| }
|
| }
|
|
|
| + /**
|
| + * Sets the {@link UrlBar}'s text direction based on focus and contents.
|
| + *
|
| + * Should be called whenever focus or text contents change.
|
| + */
|
| + private void fixupTextDirection() {
|
| + // When unfocused, force left-to-right rendering at the paragraph level (which is desired
|
| + // for URLs). Right-to-left runs are still rendered RTL, but will not flip the whole URL
|
| + // around. This is consistent with OmniboxViewViews on desktop. When focused, render text
|
| + // normally (to allow users to make non-URL searches and to avoid showing Android's split
|
| + // insertion point when an RTL user enters RTL text). Also render text normally when the
|
| + // text field is empty (because then it displays an instruction that is not a URL).
|
| + if (mFocused || length() == 0) {
|
| + ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_INHERIT);
|
| + } else {
|
| + ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_LTR);
|
| + }
|
| + }
|
| +
|
| @Override
|
| protected void onWindowVisibilityChanged(int visibility) {
|
| super.onWindowVisibilityChanged(visibility);
|
| @@ -853,6 +863,8 @@ public class UrlBar extends VerticallyFixedEditText {
|
| clearAutocompleteSpanIfInvalid();
|
| }
|
| }
|
| +
|
| + fixupTextDirection();
|
| }
|
|
|
| private void clearAutocompleteSpanIfInvalid() {
|
|
|