| 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 0ce7dcc00292c84e43810cb25eba2abeb75f04c6..4edd972b37166d84ac5e4f7249f7e26675739b6c 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
|
| @@ -444,16 +444,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);
|
| }
|
| @@ -477,6 +468,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);
|
| @@ -865,6 +875,8 @@ public class UrlBar extends VerticallyFixedEditText {
|
| clearAutocompleteSpanIfInvalid();
|
| }
|
| }
|
| +
|
| + fixupTextDirection();
|
| }
|
|
|
| private void clearAutocompleteSpanIfInvalid() {
|
|
|