| 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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 if (!focused) mAutocompleteSpan.clearSpan(); | 437 if (!focused) mAutocompleteSpan.clearSpan(); |
| 438 super.onFocusChanged(focused, direction, previouslyFocusedRect); | 438 super.onFocusChanged(focused, direction, previouslyFocusedRect); |
| 439 | 439 |
| 440 if (focused && mFirstFocusTimeMs == 0) { | 440 if (focused && mFirstFocusTimeMs == 0) { |
| 441 mFirstFocusTimeMs = SystemClock.elapsedRealtime(); | 441 mFirstFocusTimeMs = SystemClock.elapsedRealtime(); |
| 442 if (mOmniboxLivenessListener != null) mOmniboxLivenessListener.onOmn
iboxFocused(); | 442 if (mOmniboxLivenessListener != null) mOmniboxLivenessListener.onOmn
iboxFocused(); |
| 443 } | 443 } |
| 444 | 444 |
| 445 if (focused) StartupMetrics.getInstance().recordFocusedOmnibox(); | 445 if (focused) StartupMetrics.getInstance().recordFocusedOmnibox(); |
| 446 | 446 |
| 447 // When unfocused, force left-to-right rendering at the paragraph level
(which is desired | 447 fixupTextDirection(); |
| 448 // for URLs). Right-to-left runs are still rendered RTL, but will not fl
ip the whole URL | |
| 449 // around. This is consistent with OmniboxViewViews on desktop. When foc
used, render text | |
| 450 // normally (to allow users to make non-URL searches and to avoid showin
g Android's split | |
| 451 // insertion point when an RTL user enters RTL text). | |
| 452 if (focused) { | |
| 453 ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_INHERIT)
; | |
| 454 } else { | |
| 455 ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_LTR); | |
| 456 } | |
| 457 // Always align to the same as the paragraph direction (LTR = left, RTL
= right). | 448 // Always align to the same as the paragraph direction (LTR = left, RTL
= right). |
| 458 ApiCompatibilityUtils.setTextAlignment(this, TEXT_ALIGNMENT_TEXT_START); | 449 ApiCompatibilityUtils.setTextAlignment(this, TEXT_ALIGNMENT_TEXT_START); |
| 459 } | 450 } |
| 460 | 451 |
| 461 /** | 452 /** |
| 462 * @return The elapsed realtime timestamp in ms of the first time the url ba
r was focused, | 453 * @return The elapsed realtime timestamp in ms of the first time the url ba
r was focused, |
| 463 * 0 if never. | 454 * 0 if never. |
| 464 */ | 455 */ |
| 465 public long getFirstFocusTime() { | 456 public long getFirstFocusTime() { |
| 466 return mFirstFocusTimeMs; | 457 return mFirstFocusTimeMs; |
| 467 } | 458 } |
| 468 | 459 |
| 469 /** | 460 /** |
| 470 * Sets whether this {@link UrlBar} should be focusable. | 461 * Sets whether this {@link UrlBar} should be focusable. |
| 471 */ | 462 */ |
| 472 public void setAllowFocus(boolean allowFocus) { | 463 public void setAllowFocus(boolean allowFocus) { |
| 473 mAllowFocus = allowFocus; | 464 mAllowFocus = allowFocus; |
| 474 if (mFirstDrawComplete) { | 465 if (mFirstDrawComplete) { |
| 475 setFocusable(allowFocus); | 466 setFocusable(allowFocus); |
| 476 setFocusableInTouchMode(allowFocus); | 467 setFocusableInTouchMode(allowFocus); |
| 477 } | 468 } |
| 478 } | 469 } |
| 479 | 470 |
| 471 /** |
| 472 * Sets the {@link UrlBar}'s text direction based on focus and contents. |
| 473 * |
| 474 * Should be called whenever focus or text contents change. |
| 475 */ |
| 476 private void fixupTextDirection() { |
| 477 // When unfocused, force left-to-right rendering at the paragraph level
(which is desired |
| 478 // for URLs). Right-to-left runs are still rendered RTL, but will not fl
ip the whole URL |
| 479 // around. This is consistent with OmniboxViewViews on desktop. When foc
used, render text |
| 480 // normally (to allow users to make non-URL searches and to avoid showin
g Android's split |
| 481 // insertion point when an RTL user enters RTL text). Also render text n
ormally when the |
| 482 // text field is empty (because then it displays an instruction that is
not a URL). |
| 483 if (mFocused || length() == 0) { |
| 484 ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_INHERIT)
; |
| 485 } else { |
| 486 ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_LTR); |
| 487 } |
| 488 } |
| 489 |
| 480 @Override | 490 @Override |
| 481 protected void onWindowVisibilityChanged(int visibility) { | 491 protected void onWindowVisibilityChanged(int visibility) { |
| 482 super.onWindowVisibilityChanged(visibility); | 492 super.onWindowVisibilityChanged(visibility); |
| 483 if (visibility == View.GONE && isFocused()) mShowKeyboardOnWindowFocus =
true; | 493 if (visibility == View.GONE && isFocused()) mShowKeyboardOnWindowFocus =
true; |
| 484 } | 494 } |
| 485 | 495 |
| 486 @Override | 496 @Override |
| 487 public void onWindowFocusChanged(boolean hasWindowFocus) { | 497 public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 488 super.onWindowFocusChanged(hasWindowFocus); | 498 super.onWindowFocusChanged(hasWindowFocus); |
| 489 if (hasWindowFocus) { | 499 if (hasWindowFocus) { |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 // Verify the autocomplete is still valid after the text change. | 868 // Verify the autocomplete is still valid after the text change. |
| 859 if (mAutocompleteSpan != null | 869 if (mAutocompleteSpan != null |
| 860 && mAutocompleteSpan.mUserText != null | 870 && mAutocompleteSpan.mUserText != null |
| 861 && mAutocompleteSpan.mAutocompleteText != null) { | 871 && mAutocompleteSpan.mAutocompleteText != null) { |
| 862 if (getText().getSpanStart(mAutocompleteSpan) < 0) { | 872 if (getText().getSpanStart(mAutocompleteSpan) < 0) { |
| 863 mAutocompleteSpan.clearSpan(); | 873 mAutocompleteSpan.clearSpan(); |
| 864 } else { | 874 } else { |
| 865 clearAutocompleteSpanIfInvalid(); | 875 clearAutocompleteSpanIfInvalid(); |
| 866 } | 876 } |
| 867 } | 877 } |
| 878 |
| 879 fixupTextDirection(); |
| 868 } | 880 } |
| 869 | 881 |
| 870 private void clearAutocompleteSpanIfInvalid() { | 882 private void clearAutocompleteSpanIfInvalid() { |
| 871 Editable editableText = getEditableText(); | 883 Editable editableText = getEditableText(); |
| 872 CharSequence previousUserText = mAutocompleteSpan.mUserText; | 884 CharSequence previousUserText = mAutocompleteSpan.mUserText; |
| 873 CharSequence previousAutocompleteText = mAutocompleteSpan.mAutocompleteT
ext; | 885 CharSequence previousAutocompleteText = mAutocompleteSpan.mAutocompleteT
ext; |
| 874 if (editableText.length() | 886 if (editableText.length() |
| 875 != (previousUserText.length() + previousAutocompleteText.length(
))) { | 887 != (previousUserText.length() + previousAutocompleteText.length(
))) { |
| 876 mAutocompleteSpan.clearSpan(); | 888 mAutocompleteSpan.clearSpan(); |
| 877 } else if (TextUtils.indexOf(getText(), previousUserText) != 0 | 889 } else if (TextUtils.indexOf(getText(), previousUserText) != 0 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 return (int) paint.measureText(ELLIPSIS); | 1180 return (int) paint.measureText(ELLIPSIS); |
| 1169 } | 1181 } |
| 1170 | 1182 |
| 1171 @Override | 1183 @Override |
| 1172 public void draw(Canvas canvas, CharSequence text, int start, int end, | 1184 public void draw(Canvas canvas, CharSequence text, int start, int end, |
| 1173 float x, int top, int y, int bottom, Paint paint) { | 1185 float x, int top, int y, int bottom, Paint paint) { |
| 1174 canvas.drawText(ELLIPSIS, x, y, paint); | 1186 canvas.drawText(ELLIPSIS, x, y, paint); |
| 1175 } | 1187 } |
| 1176 } | 1188 } |
| 1177 } | 1189 } |
| OLD | NEW |