Commit 9eac333a authored by Pavel Yatsuk's avatar Pavel Yatsuk Committed by Commit Bot

A few random LocationBarLayout cleanups

- A few SearchEngineStatusIcon related values are passed through and
  shouldn't be retained
- mVoiceRecognitionHandler made private and checks for null are removed
  as it is created in ctor.
- LocationBarTablet uses cached mVoiceSearchEnabled instead of calling
  mVoiceRecognitionHandler
- mUrlFocusChangeInProgress made private
- SearchActivityLocationBarLayout explicitly sets the property to
  display mic button even when location bar is not focused instead of
  manipulating visibility through focus change percent

R=pnoland@chromium.org
BUG=1035210

Change-Id: I38435e0d7b5363e7ae05cb58f257af800a6ca0d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1972785
Commit-Queue: Pavel Yatsuk <pavely@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728707}
parent ccbe6998
...@@ -84,6 +84,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -84,6 +84,7 @@ public class LocationBarLayout extends FrameLayout
protected ImageButton mDeleteButton; protected ImageButton mDeleteButton;
protected ImageButton mMicButton; protected ImageButton mMicButton;
private boolean mShouldShowMicButtonWhenUnfocused;
protected UrlBar mUrlBar; protected UrlBar mUrlBar;
private final boolean mIsTablet; private final boolean mIsTablet;
...@@ -100,24 +101,21 @@ public class LocationBarLayout extends FrameLayout ...@@ -100,24 +101,21 @@ public class LocationBarLayout extends FrameLayout
private WindowAndroid mWindowAndroid; private WindowAndroid mWindowAndroid;
private WindowDelegate mWindowDelegate; private WindowDelegate mWindowDelegate;
protected String mSearchEngineUrl = "";
private String mOriginalUrl = ""; private String mOriginalUrl = "";
protected boolean mUrlFocusChangeInProgress; private boolean mUrlFocusChangeInProgress;
protected boolean mNativeInitialized; protected boolean mNativeInitialized;
protected boolean mShouldShowSearchEngineLogo;
protected boolean mIsSearchEngineGoogle;
private boolean mUrlHasFocus; private boolean mUrlHasFocus;
private boolean mUrlFocusedFromFakebox; private boolean mUrlFocusedFromFakebox;
private boolean mUrlFocusedWithoutAnimations; private boolean mUrlFocusedWithoutAnimations;
private boolean mVoiceSearchEnabled; protected boolean mVoiceSearchEnabled;
private OmniboxPrerender mOmniboxPrerender; private OmniboxPrerender mOmniboxPrerender;
protected float mUrlFocusChangePercent; protected float mUrlFocusChangePercent;
protected LinearLayout mUrlActionContainer; protected LinearLayout mUrlActionContainer;
protected LocationBarVoiceRecognitionHandler mVoiceRecognitionHandler; private LocationBarVoiceRecognitionHandler mVoiceRecognitionHandler;
protected CompositeTouchDelegate mCompositeTouchDelegate; protected CompositeTouchDelegate mCompositeTouchDelegate;
...@@ -327,7 +325,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -327,7 +325,7 @@ public class LocationBarLayout extends FrameLayout
updateVisualsForState(); updateVisualsForState();
updateMicButtonVisibility(mUrlFocusChangePercent); updateMicButtonVisibility();
} }
/** /**
...@@ -418,7 +416,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -418,7 +416,7 @@ public class LocationBarLayout extends FrameLayout
// The accessibility bounding box is not properly updated when focusing the Omnibox // The accessibility bounding box is not properly updated when focusing the Omnibox
// from the NTP fakebox. Clearing/re-requesting focus triggers the bounding box to // from the NTP fakebox. Clearing/re-requesting focus triggers the bounding box to
// be recalculated. // be recalculated.
if (didFocusUrlFromFakebox() && !inProgress && mUrlHasFocus if (didFocusUrlFromFakebox() && mUrlHasFocus
&& AccessibilityUtil.isAccessibilityEnabled()) { && AccessibilityUtil.isAccessibilityEnabled()) {
String existingText = mUrlCoordinator.getTextWithoutAutocomplete(); String existingText = mUrlCoordinator.getTextWithoutAutocomplete();
mUrlBar.clearFocus(); mUrlBar.clearFocus();
...@@ -443,12 +441,12 @@ public class LocationBarLayout extends FrameLayout ...@@ -443,12 +441,12 @@ public class LocationBarLayout extends FrameLayout
* Triggered when the URL input field has gained or lost focus. * Triggered when the URL input field has gained or lost focus.
* @param hasFocus Whether the URL field has gained focus. * @param hasFocus Whether the URL field has gained focus.
*/ */
public void onUrlFocusChange(boolean hasFocus) { protected void onUrlFocusChange(boolean hasFocus) {
mUrlHasFocus = hasFocus; mUrlHasFocus = hasFocus;
updateButtonVisibility(); updateButtonVisibility();
updateShouldAnimateIconChanges(); updateShouldAnimateIconChanges();
if (hasFocus) { if (mUrlHasFocus) {
if (mNativeInitialized) RecordUserAction.record("FocusLocation"); if (mNativeInitialized) RecordUserAction.record("FocusLocation");
UrlBarData urlBarData = mToolbarDataProvider.getUrlBarData(); UrlBarData urlBarData = mToolbarDataProvider.getUrlBarData();
if (urlBarData.editingText != null) { if (urlBarData.editingText != null) {
...@@ -486,9 +484,9 @@ public class LocationBarLayout extends FrameLayout ...@@ -486,9 +484,9 @@ public class LocationBarLayout extends FrameLayout
mStatusViewCoordinator.onUrlFocusChange(mUrlHasFocus); mStatusViewCoordinator.onUrlFocusChange(mUrlHasFocus);
if (!mUrlFocusedWithoutAnimations) handleUrlFocusAnimation(hasFocus); if (!mUrlFocusedWithoutAnimations) handleUrlFocusAnimation(mUrlHasFocus);
if (hasFocus && mToolbarDataProvider.hasTab() && !mToolbarDataProvider.isIncognito()) { if (mUrlHasFocus && mToolbarDataProvider.hasTab() && !mToolbarDataProvider.isIncognito()) {
if (mNativeInitialized if (mNativeInitialized
&& TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle()) { && TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle()) {
GeolocationHeader.primeLocationForGeoHeader(); GeolocationHeader.primeLocationForGeoHeader();
...@@ -776,7 +774,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -776,7 +774,7 @@ public class LocationBarLayout extends FrameLayout
RecordUserAction.record("MobileOmniboxDeleteUrl"); RecordUserAction.record("MobileOmniboxDeleteUrl");
return; return;
} else if (v == mMicButton && mVoiceRecognitionHandler != null) { } else if (v == mMicButton) {
RecordUserAction.record("MobileOmniboxVoiceSearch"); RecordUserAction.record("MobileOmniboxVoiceSearch");
mVoiceRecognitionHandler.startVoiceRecognition( mVoiceRecognitionHandler.startVoiceRecognition(
LocationBarVoiceRecognitionHandler.VoiceInteractionSource.OMNIBOX); LocationBarVoiceRecognitionHandler.VoiceInteractionSource.OMNIBOX);
...@@ -972,12 +970,8 @@ public class LocationBarLayout extends FrameLayout ...@@ -972,12 +970,8 @@ public class LocationBarLayout extends FrameLayout
@Override @Override
public void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo, public void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo,
boolean isSearchEngineGoogle, String searchEngineUrl) { boolean isSearchEngineGoogle, String searchEngineUrl) {
mSearchEngineUrl = searchEngineUrl;
mIsSearchEngineGoogle = isSearchEngineGoogle;
mShouldShowSearchEngineLogo = shouldShowSearchEngineLogo;
mStatusViewCoordinator.updateSearchEngineStatusIcon( mStatusViewCoordinator.updateSearchEngineStatusIcon(
mShouldShowSearchEngineLogo, mIsSearchEngineGoogle, mSearchEngineUrl); shouldShowSearchEngineLogo, isSearchEngineGoogle, searchEngineUrl);
} }
@Override @Override
...@@ -1063,16 +1057,23 @@ public class LocationBarLayout extends FrameLayout ...@@ -1063,16 +1057,23 @@ public class LocationBarLayout extends FrameLayout
/** /**
* Updates the display of the mic button. * Updates the display of the mic button.
*
* @param urlFocusChangePercent The completion percentage of the URL focus change animation.
*/ */
protected void updateMicButtonVisibility(float urlFocusChangePercent) { protected void updateMicButtonVisibility() {
boolean visible = !shouldShowDeleteButton(); boolean visible = !shouldShowDeleteButton();
boolean showMicButton = mVoiceSearchEnabled && visible boolean showMicButton = mVoiceSearchEnabled && visible
&& (mUrlBar.hasFocus() || mUrlFocusChangeInProgress || urlFocusChangePercent > 0f); && (mUrlBar.hasFocus() || mUrlFocusChangeInProgress || mUrlFocusChangePercent > 0f
|| mShouldShowMicButtonWhenUnfocused);
mMicButton.setVisibility(showMicButton ? VISIBLE : GONE); mMicButton.setVisibility(showMicButton ? VISIBLE : GONE);
} }
/**
* Value determines if mic button should be shown when location bar is not focused. By default
* mic button is not shown. It is only shown for SearchActivityLocationBarLayout.
*/
protected void setShouldShowMicButtonWhenUnfocused(boolean shouldShowMicButtonWhenUnfocused) {
mShouldShowMicButtonWhenUnfocused = shouldShowMicButtonWhenUnfocused;
}
/** /**
* Call to force the UI to update the state of various buttons based on whether or not the * Call to force the UI to update the state of various buttons based on whether or not the
* current tab is incognito. * current tab is incognito.
......
...@@ -338,7 +338,7 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -338,7 +338,7 @@ public class LocationBarPhone extends LocationBarLayout {
@Override @Override
protected void updateButtonVisibility() { protected void updateButtonVisibility() {
super.updateButtonVisibility(); super.updateButtonVisibility();
updateMicButtonVisibility(mUrlFocusChangePercent); updateMicButtonVisibility();
} }
@Override @Override
......
...@@ -251,7 +251,7 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -251,7 +251,7 @@ public class LocationBarTablet extends LocationBarLayout {
if (showSaveOfflineButton) mSaveOfflineButton.setEnabled(isSaveOfflineButtonEnabled()); if (showSaveOfflineButton) mSaveOfflineButton.setEnabled(isSaveOfflineButtonEnabled());
if (!mShouldShowButtonsWhenUnfocused) { if (!mShouldShowButtonsWhenUnfocused) {
updateMicButtonVisibility(mUrlFocusChangePercent); updateMicButtonVisibility();
} else { } else {
mMicButton.setVisibility(shouldShowMicButton() ? View.VISIBLE : View.GONE); mMicButton.setVisibility(shouldShowMicButton() ? View.VISIBLE : View.GONE);
} }
...@@ -423,7 +423,7 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -423,7 +423,7 @@ public class LocationBarTablet extends LocationBarLayout {
if (shouldShowSaveOfflineButton() && mSaveOfflineButton.getVisibility() == View.VISIBLE) { if (shouldShowSaveOfflineButton() && mSaveOfflineButton.getVisibility() == View.VISIBLE) {
animators.add(createHideButtonAnimator(mSaveOfflineButton)); animators.add(createHideButtonAnimator(mSaveOfflineButton));
} else if (!(mUrlBar.isFocused() && mDeleteButton.getVisibility() != View.VISIBLE)) { } else if (!(mUrlBar.hasFocus() && mDeleteButton.getVisibility() != View.VISIBLE)) {
// If the save offline button isn't enabled, the microphone button always shows when // If the save offline button isn't enabled, the microphone button always shows when
// buttons are shown in the unfocused location bar. When buttons are hidden in the // buttons are shown in the unfocused location bar. When buttons are hidden in the
// unfocused location bar, the microphone shows if the location bar is focused and the // unfocused location bar, the microphone shows if the location bar is focused and the
...@@ -543,13 +543,13 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -543,13 +543,13 @@ public class LocationBarTablet extends LocationBarLayout {
// There are two actions, bookmark and save offline, and they should be shown if the // There are two actions, bookmark and save offline, and they should be shown if the
// omnibox isn't focused. // omnibox isn't focused.
return !(mUrlBar.hasFocus() || mUrlFocusChangeInProgress); return !(mUrlBar.hasFocus() || isUrlFocusChangeInProgress());
} }
private boolean shouldShowMicButton() { private boolean shouldShowMicButton() {
// If the download UI is enabled, the mic button should be only be shown when the url bar // If the download UI is enabled, the mic button should be only be shown when the url bar
// is focused. // is focused.
return mVoiceRecognitionHandler != null && mVoiceRecognitionHandler.isVoiceSearchEnabled() return mVoiceSearchEnabled && mNativeInitialized
&& mNativeInitialized && (mUrlBar.hasFocus() || mUrlFocusChangeInProgress); && (mUrlBar.hasFocus() || isUrlFocusChangeInProgress());
} }
} }
...@@ -41,6 +41,7 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout { ...@@ -41,6 +41,7 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
super(context, attrs, R.layout.location_bar_base); super(context, attrs, R.layout.location_bar_base);
setUrlBarFocusable(true); setUrlBarFocusable(true);
setBackground(ToolbarPhone.createModernLocationBarBackground(getResources())); setBackground(ToolbarPhone.createModernLocationBarBackground(getResources()));
setShouldShowMicButtonWhenUnfocused(true);
mPendingSearchPromoDecision = LocaleManager.getInstance().needToCheckForSearchEnginePromo(); mPendingSearchPromoDecision = LocaleManager.getInstance().needToCheckForSearchEnginePromo();
getAutocompleteCoordinator().setShouldPreventOmniboxAutocomplete( getAutocompleteCoordinator().setShouldPreventOmniboxAutocomplete(
...@@ -82,10 +83,8 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout { ...@@ -82,10 +83,8 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
void onDeferredStartup(boolean isVoiceSearchIntent) { void onDeferredStartup(boolean isVoiceSearchIntent) {
getAutocompleteCoordinator().prefetchZeroSuggestResults(); getAutocompleteCoordinator().prefetchZeroSuggestResults();
if (mVoiceRecognitionHandler != null) { SearchWidgetProvider.updateCachedVoiceSearchAvailability(
SearchWidgetProvider.updateCachedVoiceSearchAvailability( getLocationBarVoiceRecognitionHandler().isVoiceSearchEnabled());
mVoiceRecognitionHandler.isVoiceSearchEnabled());
}
if (isVoiceSearchIntent && mUrlBar.isFocused()) onUrlFocusChange(true); if (isVoiceSearchIntent && mUrlBar.isFocused()) onUrlFocusChange(true);
assert !LocaleManager.getInstance().needToCheckForSearchEnginePromo(); assert !LocaleManager.getInstance().needToCheckForSearchEnginePromo();
...@@ -128,9 +127,8 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout { ...@@ -128,9 +127,8 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
private void beginQueryInternal(boolean isVoiceSearchIntent) { private void beginQueryInternal(boolean isVoiceSearchIntent) {
assert !mPendingSearchPromoDecision; assert !mPendingSearchPromoDecision;
if (mVoiceRecognitionHandler != null && mVoiceRecognitionHandler.isVoiceSearchEnabled() if (getLocationBarVoiceRecognitionHandler().isVoiceSearchEnabled() && isVoiceSearchIntent) {
&& isVoiceSearchIntent) { getLocationBarVoiceRecognitionHandler().startVoiceRecognition(
mVoiceRecognitionHandler.startVoiceRecognition(
LocationBarVoiceRecognitionHandler.VoiceInteractionSource.SEARCH_WIDGET); LocationBarVoiceRecognitionHandler.VoiceInteractionSource.SEARCH_WIDGET);
} else { } else {
focusTextBox(); focusTextBox();
...@@ -140,7 +138,7 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout { ...@@ -140,7 +138,7 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
@Override @Override
protected void updateButtonVisibility() { protected void updateButtonVisibility() {
super.updateButtonVisibility(); super.updateButtonVisibility();
updateMicButtonVisibility(1.0f); updateMicButtonVisibility();
findViewById(R.id.url_action_container).setVisibility(View.VISIBLE); findViewById(R.id.url_action_container).setVisibility(View.VISIBLE);
} }
......
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