Commit f1310f9a authored by changwan's avatar changwan Committed by Commit bot

Polish up UrlBar's accessibility code

- Remove mDisableTextAccessibilityEvents and replace it by
mIgnoreTextChangeFromAutocomplete which is renamed from
mIgnoreAutocomplete
- Change the scope of setIgnoreTextChangesForAutocomplete() to be
  exactly the code that should be affected.
- Remove unused methods and fields

BUG=539536

Review-Url: https://codereview.chromium.org/2802803002
Cr-Commit-Position: refs/heads/master@{#462919}
parent d50c8a52
...@@ -71,9 +71,6 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -71,9 +71,6 @@ public class UrlBar extends VerticallyFixedEditText {
/** The contents of the URL that precede the path/query before formatting. */ /** The contents of the URL that precede the path/query before formatting. */
private String mOriginalUrlLocation; private String mOriginalUrlLocation;
/** Overrides the text announced during accessibility events. */
private String mAccessibilityTextOverride;
private boolean mShowKeyboardOnWindowFocus; private boolean mShowKeyboardOnWindowFocus;
private boolean mFirstDrawComplete; private boolean mFirstDrawComplete;
...@@ -109,7 +106,6 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -109,7 +106,6 @@ public class UrlBar extends VerticallyFixedEditText {
private Boolean mUseDarkColors; private Boolean mUseDarkColors;
private AccessibilityManager mAccessibilityManager; private AccessibilityManager mAccessibilityManager;
private boolean mDisableTextAccessibilityEvents;
/** /**
* Whether default TextView scrolling should be disabled because autocomplete has been added. * Whether default TextView scrolling should be disabled because autocomplete has been added.
...@@ -136,7 +132,7 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -136,7 +132,7 @@ public class UrlBar extends VerticallyFixedEditText {
// Set to true when the URL bar text is modified programmatically. Initially set // Set to true when the URL bar text is modified programmatically. Initially set
// to true until the old state has been loaded. // to true until the old state has been loaded.
private boolean mIgnoreAutocomplete = true; private boolean mIgnoreTextChangeFromAutocomplete = true;
private boolean mLastUrlEditWasDelete; private boolean mLastUrlEditWasDelete;
/** This tracks whether or not the last ACTION_DOWN event was when the url bar had focus. */ /** This tracks whether or not the last ACTION_DOWN event was when the url bar had focus. */
...@@ -286,7 +282,7 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -286,7 +282,7 @@ public class UrlBar extends VerticallyFixedEditText {
public void setIgnoreTextChangesForAutocomplete(boolean ignoreAutocomplete) { public void setIgnoreTextChangesForAutocomplete(boolean ignoreAutocomplete) {
assert mUrlBarDelegate != null; assert mUrlBarDelegate != null;
mIgnoreAutocomplete = ignoreAutocomplete; mIgnoreTextChangeFromAutocomplete = ignoreAutocomplete;
} }
/** /**
...@@ -301,7 +297,7 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -301,7 +297,7 @@ public class UrlBar extends VerticallyFixedEditText {
* at the beginning of the inline autocomplete text if present otherwise the very * at the beginning of the inline autocomplete text if present otherwise the very
* end of the current text). * end of the current text).
*/ */
public boolean isCursorAtEndOfTypedText() { private boolean isCursorAtEndOfTypedText() {
final int selectionStart = getSelectionStart(); final int selectionStart = getSelectionStart();
final int selectionEnd = getSelectionEnd(); final int selectionEnd = getSelectionEnd();
...@@ -320,7 +316,7 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -320,7 +316,7 @@ public class UrlBar extends VerticallyFixedEditText {
*/ */
// isInBatchEditMode is a package protected method on TextView, so we intentionally chose // isInBatchEditMode is a package protected method on TextView, so we intentionally chose
// a different name. // a different name.
public boolean isHandlingBatchInput() { private boolean isHandlingBatchInput() {
return mInBatchEditMode; return mInBatchEditMode;
} }
...@@ -743,15 +739,19 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -743,15 +739,19 @@ public class UrlBar extends VerticallyFixedEditText {
+ currentText.substring(mFormattedUrlLocation.length()); + currentText.substring(mFormattedUrlLocation.length());
selectedEndIndex = selectedEndIndex - mFormattedUrlLocation.length() selectedEndIndex = selectedEndIndex - mFormattedUrlLocation.length()
+ mOriginalUrlLocation.length(); + mOriginalUrlLocation.length();
setIgnoreTextChangesForAutocomplete(true); setIgnoreTextChangesForAutocomplete(true);
setText(newText); setText(newText);
setSelection(0, selectedEndIndex); setSelection(0, selectedEndIndex);
setIgnoreTextChangesForAutocomplete(false);
boolean retVal = super.onTextContextMenuItem(id); boolean retVal = super.onTextContextMenuItem(id);
if (getText().toString().equals(newText)) { if (getText().toString().equals(newText)) {
setIgnoreTextChangesForAutocomplete(true);
setText(currentText); setText(currentText);
setSelection(getText().length()); setSelection(getText().length());
}
setIgnoreTextChangesForAutocomplete(false); setIgnoreTextChangesForAutocomplete(false);
}
return retVal; return retVal;
} }
return super.onTextContextMenuItem(id); return super.onTextContextMenuItem(id);
...@@ -811,7 +811,6 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -811,7 +811,6 @@ public class UrlBar extends VerticallyFixedEditText {
CharSequence newText = TextUtils.concat(userText, inlineAutocompleteText); CharSequence newText = TextUtils.concat(userText, inlineAutocompleteText);
setIgnoreTextChangesForAutocomplete(true); setIgnoreTextChangesForAutocomplete(true);
mDisableTextAccessibilityEvents = true;
if (!TextUtils.equals(previousText, newText)) { if (!TextUtils.equals(previousText, newText)) {
// The previous text may also have included autocomplete text, so we only // The previous text may also have included autocomplete text, so we only
...@@ -843,7 +842,6 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -843,7 +842,6 @@ public class UrlBar extends VerticallyFixedEditText {
} }
setIgnoreTextChangesForAutocomplete(false); setIgnoreTextChangesForAutocomplete(false);
mDisableTextAccessibilityEvents = false;
} }
/** /**
...@@ -856,16 +854,6 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -856,16 +854,6 @@ public class UrlBar extends VerticallyFixedEditText {
return getText().length() - autoCompleteIndex; return getText().length() - autoCompleteIndex;
} }
/**
* Overrides the text announced when focusing on the field for accessibility. This value will
* be cleared automatically when the text content changes for this view.
* @param accessibilityOverride The text to be announced instead of the current text value
* (or null if the text content should be read).
*/
public void setAccessibilityTextOverride(String accessibilityOverride) {
mAccessibilityTextOverride = accessibilityOverride;
}
/** /**
* Scroll to ensure the TLD is visible. * Scroll to ensure the TLD is visible.
* @return Whether the TLD was discovered and successfully scrolled to. * @return Whether the TLD was discovered and successfully scrolled to.
...@@ -923,10 +911,11 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -923,10 +911,11 @@ public class UrlBar extends VerticallyFixedEditText {
// URL is being edited). // URL is being edited).
if (!TextUtils.equals(getEditableText(), text)) { if (!TextUtils.equals(getEditableText(), text)) {
super.setText(text, type); super.setText(text, type);
mAccessibilityTextOverride = null;
} }
// Verify the autocomplete is still valid after the text change. // Verify the autocomplete is still valid after the text change.
// Note: mAutocompleteSpan may be still null here if setText() is called in View
// constructor.
if (mAutocompleteSpan != null if (mAutocompleteSpan != null
&& mAutocompleteSpan.mUserText != null && mAutocompleteSpan.mUserText != null
&& mAutocompleteSpan.mAutocompleteText != null) { && mAutocompleteSpan.mAutocompleteText != null) {
...@@ -1011,7 +1000,7 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -1011,7 +1000,7 @@ public class UrlBar extends VerticallyFixedEditText {
@Override @Override
public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
if (mDisableTextAccessibilityEvents) { if (mIgnoreTextChangeFromAutocomplete) {
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED
|| event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) { || event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
return; return;
...@@ -1030,10 +1019,6 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -1030,10 +1019,6 @@ public class UrlBar extends VerticallyFixedEditText {
} finally { } finally {
StrictMode.setThreadPolicy(oldPolicy); StrictMode.setThreadPolicy(oldPolicy);
} }
if (mAccessibilityTextOverride != null) {
info.setText(mAccessibilityTextOverride);
}
} }
@VisibleForTesting @VisibleForTesting
...@@ -1204,7 +1189,7 @@ public class UrlBar extends VerticallyFixedEditText { ...@@ -1204,7 +1189,7 @@ public class UrlBar extends VerticallyFixedEditText {
private void notifyAutocompleteTextStateChanged(boolean textDeleted) { private void notifyAutocompleteTextStateChanged(boolean textDeleted) {
if (mUrlBarDelegate == null) return; if (mUrlBarDelegate == null) return;
if (!hasFocus()) return; if (!hasFocus()) return;
if (mIgnoreAutocomplete) return; if (mIgnoreTextChangeFromAutocomplete) return;
mLastUrlEditWasDelete = textDeleted; mLastUrlEditWasDelete = textDeleted;
mUrlBarDelegate.onTextChangedForAutocomplete(textDeleted); mUrlBarDelegate.onTextChangedForAutocomplete(textDeleted);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment