Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(839)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/omnibox/UrlBar.java

Issue 2225283002: Android Omnibox: Do not force LTR text direction when empty. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698