| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.omnibox; | 5 package org.chromium.chrome.browser.omnibox; |
| 6 | 6 |
| 7 import android.content.ClipData; | 7 import android.content.ClipData; |
| 8 import android.content.ClipboardManager; | 8 import android.content.ClipboardManager; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
| 11 import android.graphics.Canvas; | 11 import android.graphics.Canvas; |
| 12 import android.graphics.Paint; | 12 import android.graphics.Paint; |
| 13 import android.graphics.Rect; | 13 import android.graphics.Rect; |
| 14 import android.net.Uri; | 14 import android.net.Uri; |
| 15 import android.os.Build; |
| 15 import android.os.StrictMode; | 16 import android.os.StrictMode; |
| 16 import android.os.SystemClock; | 17 import android.os.SystemClock; |
| 17 import android.text.Editable; | 18 import android.text.Editable; |
| 18 import android.text.Layout; | 19 import android.text.Layout; |
| 19 import android.text.Selection; | 20 import android.text.Selection; |
| 20 import android.text.Spanned; | 21 import android.text.Spanned; |
| 21 import android.text.TextUtils; | 22 import android.text.TextUtils; |
| 22 import android.text.style.ReplacementSpan; | 23 import android.text.style.ReplacementSpan; |
| 23 import android.util.AttributeSet; | 24 import android.util.AttributeSet; |
| 24 import android.util.Pair; | 25 import android.util.Pair; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 public class UrlBar extends VerticallyFixedEditText { | 59 public class UrlBar extends VerticallyFixedEditText { |
| 59 private static final String TAG = "cr_UrlBar"; | 60 private static final String TAG = "cr_UrlBar"; |
| 60 | 61 |
| 61 private static final boolean DEBUG = false; | 62 private static final boolean DEBUG = false; |
| 62 | 63 |
| 63 // TextView becomes very slow on long strings, so we limit maximum length | 64 // TextView becomes very slow on long strings, so we limit maximum length |
| 64 // of what is displayed to the user, see limitDisplayableLength(). | 65 // of what is displayed to the user, see limitDisplayableLength(). |
| 65 private static final int MAX_DISPLAYABLE_LENGTH = 4000; | 66 private static final int MAX_DISPLAYABLE_LENGTH = 4000; |
| 66 private static final int MAX_DISPLAYABLE_LENGTH_LOW_END = 1000; | 67 private static final int MAX_DISPLAYABLE_LENGTH_LOW_END = 1000; |
| 67 | 68 |
| 69 // Unicode "Left-To-Right Mark" (LRM) character. |
| 70 private static final char LRM = '\u200E'; |
| 71 |
| 68 /** The contents of the URL that precede the path/query after being formatte
d. */ | 72 /** The contents of the URL that precede the path/query after being formatte
d. */ |
| 69 private String mFormattedUrlLocation; | 73 private String mFormattedUrlLocation; |
| 70 | 74 |
| 71 /** The contents of the URL that precede the path/query before formatting. *
/ | 75 /** The contents of the URL that precede the path/query before formatting. *
/ |
| 72 private String mOriginalUrlLocation; | 76 private String mOriginalUrlLocation; |
| 73 | 77 |
| 74 private boolean mFirstDrawComplete; | 78 private boolean mFirstDrawComplete; |
| 75 | 79 |
| 76 /** | 80 /** |
| 77 * The text direction of the URL or query: LAYOUT_DIRECTION_LOCALE, LAYOUT_D
IRECTION_LTR, or | 81 * The text direction of the URL or query: LAYOUT_DIRECTION_LOCALE, LAYOUT_D
IRECTION_LTR, or |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 | 755 |
| 752 /** | 756 /** |
| 753 * Sets the text content of the URL bar. | 757 * Sets the text content of the URL bar. |
| 754 * | 758 * |
| 755 * @param url The original URL (or generic text) that can be used for copy/c
ut/paste. | 759 * @param url The original URL (or generic text) that can be used for copy/c
ut/paste. |
| 756 * @param formattedUrl Formatted URL for user display. Null if there isn't o
ne. | 760 * @param formattedUrl Formatted URL for user display. Null if there isn't o
ne. |
| 757 * @return Whether the visible text has changed. | 761 * @return Whether the visible text has changed. |
| 758 */ | 762 */ |
| 759 public boolean setUrl(String url, String formattedUrl) { | 763 public boolean setUrl(String url, String formattedUrl) { |
| 760 if (!TextUtils.isEmpty(formattedUrl)) { | 764 if (!TextUtils.isEmpty(formattedUrl)) { |
| 765 // Because Android versions 4.2 and before lack proper RTL support, |
| 766 // force the formatted URL to render as LTR using an LRM character. |
| 767 // See: https://www.ietf.org/rfc/rfc3987.txt and crbug.com/709417 |
| 768 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 769 formattedUrl = LRM + formattedUrl; |
| 770 } |
| 771 |
| 761 try { | 772 try { |
| 762 URL javaUrl = new URL(url); | 773 URL javaUrl = new URL(url); |
| 763 mFormattedUrlLocation = | 774 mFormattedUrlLocation = |
| 764 getUrlContentsPrePath(formattedUrl, javaUrl.getHost()); | 775 getUrlContentsPrePath(formattedUrl, javaUrl.getHost()); |
| 765 mOriginalUrlLocation = | 776 mOriginalUrlLocation = |
| 766 getUrlContentsPrePath(url, javaUrl.getHost()); | 777 getUrlContentsPrePath(url, javaUrl.getHost()); |
| 767 } catch (MalformedURLException mue) { | 778 } catch (MalformedURLException mue) { |
| 768 mOriginalUrlLocation = null; | 779 mOriginalUrlLocation = null; |
| 769 mFormattedUrlLocation = null; | 780 mFormattedUrlLocation = null; |
| 770 } | 781 } |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 return (int) paint.measureText(ELLIPSIS); | 1245 return (int) paint.measureText(ELLIPSIS); |
| 1235 } | 1246 } |
| 1236 | 1247 |
| 1237 @Override | 1248 @Override |
| 1238 public void draw(Canvas canvas, CharSequence text, int start, int end, | 1249 public void draw(Canvas canvas, CharSequence text, int start, int end, |
| 1239 float x, int top, int y, int bottom, Paint paint) { | 1250 float x, int top, int y, int bottom, Paint paint) { |
| 1240 canvas.drawText(ELLIPSIS, x, y, paint); | 1251 canvas.drawText(ELLIPSIS, x, y, paint); |
| 1241 } | 1252 } |
| 1242 } | 1253 } |
| 1243 } | 1254 } |
| OLD | NEW |