| 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; |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 /** | 838 /** |
| 839 * Overrides the text announced when focusing on the field for accessibility
. This value will | 839 * Overrides the text announced when focusing on the field for accessibility
. This value will |
| 840 * be cleared automatically when the text content changes for this view. | 840 * be cleared automatically when the text content changes for this view. |
| 841 * @param accessibilityOverride The text to be announced instead of the curr
ent text value | 841 * @param accessibilityOverride The text to be announced instead of the curr
ent text value |
| 842 * (or null if the text content should be read)
. | 842 * (or null if the text content should be read)
. |
| 843 */ | 843 */ |
| 844 public void setAccessibilityTextOverride(String accessibilityOverride) { | 844 public void setAccessibilityTextOverride(String accessibilityOverride) { |
| 845 mAccessibilityTextOverride = accessibilityOverride; | 845 mAccessibilityTextOverride = accessibilityOverride; |
| 846 } | 846 } |
| 847 | 847 |
| 848 private void scrollToTLD() { | 848 /** |
| 849 * Scroll to ensure the TLD is visible. |
| 850 * @return Whether the TLD was discovered and successfully scrolled to. |
| 851 */ |
| 852 public boolean scrollToTLD() { |
| 849 Editable url = getText(); | 853 Editable url = getText(); |
| 850 if (url == null || url.length() < 1) return; | 854 if (url == null || url.length() < 1) return false; |
| 851 String urlString = url.toString(); | 855 String urlString = url.toString(); |
| 852 URL javaUrl; | 856 String prePath = LocationBarLayout.splitPathFromUrlDisplayText(urlString
).first; |
| 853 try { | 857 if (prePath == null || prePath.isEmpty()) return false; |
| 854 javaUrl = new URL(urlString); | 858 setSelection(prePath.length()); |
| 855 } catch (MalformedURLException mue) { | 859 return true; |
| 856 return; | |
| 857 } | |
| 858 String host = javaUrl.getHost(); | |
| 859 if (host == null || host.isEmpty()) return; | |
| 860 int hostStart = urlString.indexOf(host); | |
| 861 int hostEnd = hostStart + host.length(); | |
| 862 setSelection(hostEnd); | |
| 863 } | 860 } |
| 864 | 861 |
| 865 @Override | 862 @Override |
| 866 protected void onTextChanged(CharSequence text, int start, int lengthBefore,
int lengthAfter) { | 863 protected void onTextChanged(CharSequence text, int start, int lengthBefore,
int lengthAfter) { |
| 867 if (DEBUG) { | 864 if (DEBUG) { |
| 868 Log.i(TAG, "onTextChanged -- text: %s, start: %d, lengthBefore: %d,
lengthAfter: %d", | 865 Log.i(TAG, "onTextChanged -- text: %s, start: %d, lengthBefore: %d,
lengthAfter: %d", |
| 869 text, start, lengthBefore, lengthAfter); | 866 text, start, lengthBefore, lengthAfter); |
| 870 } | 867 } |
| 871 | 868 |
| 872 super.onTextChanged(text, start, lengthBefore, lengthAfter); | 869 super.onTextChanged(text, start, lengthBefore, lengthAfter); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 return (int) paint.measureText(ELLIPSIS); | 1225 return (int) paint.measureText(ELLIPSIS); |
| 1229 } | 1226 } |
| 1230 | 1227 |
| 1231 @Override | 1228 @Override |
| 1232 public void draw(Canvas canvas, CharSequence text, int start, int end, | 1229 public void draw(Canvas canvas, CharSequence text, int start, int end, |
| 1233 float x, int top, int y, int bottom, Paint paint) { | 1230 float x, int top, int y, int bottom, Paint paint) { |
| 1234 canvas.drawText(ELLIPSIS, x, y, paint); | 1231 canvas.drawText(ELLIPSIS, x, y, paint); |
| 1235 } | 1232 } |
| 1236 } | 1233 } |
| 1237 } | 1234 } |
| OLD | NEW |