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
protected ImageButton mDeleteButton;
protected ImageButton mMicButton;
private boolean mShouldShowMicButtonWhenUnfocused;
protected UrlBar mUrlBar;
private final boolean mIsTablet;
......@@ -100,24 +101,21 @@ public class LocationBarLayout extends FrameLayout
private WindowAndroid mWindowAndroid;
private WindowDelegate mWindowDelegate;
protected String mSearchEngineUrl = "";
private String mOriginalUrl = "";
protected boolean mUrlFocusChangeInProgress;
private boolean mUrlFocusChangeInProgress;
protected boolean mNativeInitialized;
protected boolean mShouldShowSearchEngineLogo;
protected boolean mIsSearchEngineGoogle;
private boolean mUrlHasFocus;
private boolean mUrlFocusedFromFakebox;
private boolean mUrlFocusedWithoutAnimations;
private boolean mVoiceSearchEnabled;
protected boolean mVoiceSearchEnabled;
private OmniboxPrerender mOmniboxPrerender;
protected float mUrlFocusChangePercent;
protected LinearLayout mUrlActionContainer;
protected LocationBarVoiceRecognitionHandler mVoiceRecognitionHandler;
private LocationBarVoiceRecognitionHandler mVoiceRecognitionHandler;
protected CompositeTouchDelegate mCompositeTouchDelegate;
......@@ -327,7 +325,7 @@ public class LocationBarLayout extends FrameLayout
updateVisualsForState();
updateMicButtonVisibility(mUrlFocusChangePercent);
updateMicButtonVisibility();
}
/**
......@@ -418,7 +416,7 @@ public class LocationBarLayout extends FrameLayout
// 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
// be recalculated.
if (didFocusUrlFromFakebox() && !inProgress && mUrlHasFocus
if (didFocusUrlFromFakebox() && mUrlHasFocus
&& AccessibilityUtil.isAccessibilityEnabled()) {
String existingText = mUrlCoordinator.getTextWithoutAutocomplete();
mUrlBar.clearFocus();
......@@ -443,12 +441,12 @@ public class LocationBarLayout extends FrameLayout
* Triggered when the URL input field has gained or lost focus.
* @param hasFocus Whether the URL field has gained focus.
*/
public void onUrlFocusChange(boolean hasFocus) {
protected void onUrlFocusChange(boolean hasFocus) {
mUrlHasFocus = hasFocus;
updateButtonVisibility();
updateShouldAnimateIconChanges();
if (hasFocus) {
if (mUrlHasFocus) {
if (mNativeInitialized) RecordUserAction.record("FocusLocation");
UrlBarData urlBarData = mToolbarDataProvider.getUrlBarData();
if (urlBarData.editingText != null) {
......@@ -486,9 +484,9 @@ public class LocationBarLayout extends FrameLayout
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
&& TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle()) {
GeolocationHeader.primeLocationForGeoHeader();
......@@ -776,7 +774,7 @@ public class LocationBarLayout extends FrameLayout
RecordUserAction.record("MobileOmniboxDeleteUrl");
return;
} else if (v == mMicButton && mVoiceRecognitionHandler != null) {
} else if (v == mMicButton) {
RecordUserAction.record("MobileOmniboxVoiceSearch");
mVoiceRecognitionHandler.startVoiceRecognition(
LocationBarVoiceRecognitionHandler.VoiceInteractionSource.OMNIBOX);
......@@ -972,12 +970,8 @@ public class LocationBarLayout extends FrameLayout
@Override
public void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo,
boolean isSearchEngineGoogle, String searchEngineUrl) {
mSearchEngineUrl = searchEngineUrl;
mIsSearchEngineGoogle = isSearchEngineGoogle;
mShouldShowSearchEngineLogo = shouldShowSearchEngineLogo;
mStatusViewCoordinator.updateSearchEngineStatusIcon(
mShouldShowSearchEngineLogo, mIsSearchEngineGoogle, mSearchEngineUrl);
shouldShowSearchEngineLogo, isSearchEngineGoogle, searchEngineUrl);
}
@Override
......@@ -1063,16 +1057,23 @@ public class LocationBarLayout extends FrameLayout
/**
* 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 showMicButton = mVoiceSearchEnabled && visible
&& (mUrlBar.hasFocus() || mUrlFocusChangeInProgress || urlFocusChangePercent > 0f);
&& (mUrlBar.hasFocus() || mUrlFocusChangeInProgress || mUrlFocusChangePercent > 0f
|| mShouldShowMicButtonWhenUnfocused);
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
* current tab is incognito.
......
......@@ -338,7 +338,7 @@ public class LocationBarPhone extends LocationBarLayout {
@Override
protected void updateButtonVisibility() {
super.updateButtonVisibility();
updateMicButtonVisibility(mUrlFocusChangePercent);
updateMicButtonVisibility();
}
@Override
......
......@@ -251,7 +251,7 @@ public class LocationBarTablet extends LocationBarLayout {
if (showSaveOfflineButton) mSaveOfflineButton.setEnabled(isSaveOfflineButtonEnabled());
if (!mShouldShowButtonsWhenUnfocused) {
updateMicButtonVisibility(mUrlFocusChangePercent);
updateMicButtonVisibility();
} else {
mMicButton.setVisibility(shouldShowMicButton() ? View.VISIBLE : View.GONE);
}
......@@ -423,7 +423,7 @@ public class LocationBarTablet extends LocationBarLayout {
if (shouldShowSaveOfflineButton() && mSaveOfflineButton.getVisibility() == View.VISIBLE) {
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
// 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
......@@ -543,13 +543,13 @@ public class LocationBarTablet extends LocationBarLayout {
// There are two actions, bookmark and save offline, and they should be shown if the
// omnibox isn't focused.
return !(mUrlBar.hasFocus() || mUrlFocusChangeInProgress);
return !(mUrlBar.hasFocus() || isUrlFocusChangeInProgress());
}
private boolean shouldShowMicButton() {
// If the download UI is enabled, the mic button should be only be shown when the url bar
// is focused.
return mVoiceRecognitionHandler != null && mVoiceRecognitionHandler.isVoiceSearchEnabled()
&& mNativeInitialized && (mUrlBar.hasFocus() || mUrlFocusChangeInProgress);
return mVoiceSearchEnabled && mNativeInitialized
&& (mUrlBar.hasFocus() || isUrlFocusChangeInProgress());
}
}
......@@ -41,6 +41,7 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
super(context, attrs, R.layout.location_bar_base);
setUrlBarFocusable(true);
setBackground(ToolbarPhone.createModernLocationBarBackground(getResources()));
setShouldShowMicButtonWhenUnfocused(true);
mPendingSearchPromoDecision = LocaleManager.getInstance().needToCheckForSearchEnginePromo();
getAutocompleteCoordinator().setShouldPreventOmniboxAutocomplete(
......@@ -82,10 +83,8 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
void onDeferredStartup(boolean isVoiceSearchIntent) {
getAutocompleteCoordinator().prefetchZeroSuggestResults();
if (mVoiceRecognitionHandler != null) {
SearchWidgetProvider.updateCachedVoiceSearchAvailability(
mVoiceRecognitionHandler.isVoiceSearchEnabled());
}
SearchWidgetProvider.updateCachedVoiceSearchAvailability(
getLocationBarVoiceRecognitionHandler().isVoiceSearchEnabled());
if (isVoiceSearchIntent && mUrlBar.isFocused()) onUrlFocusChange(true);
assert !LocaleManager.getInstance().needToCheckForSearchEnginePromo();
......@@ -128,9 +127,8 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
private void beginQueryInternal(boolean isVoiceSearchIntent) {
assert !mPendingSearchPromoDecision;
if (mVoiceRecognitionHandler != null && mVoiceRecognitionHandler.isVoiceSearchEnabled()
&& isVoiceSearchIntent) {
mVoiceRecognitionHandler.startVoiceRecognition(
if (getLocationBarVoiceRecognitionHandler().isVoiceSearchEnabled() && isVoiceSearchIntent) {
getLocationBarVoiceRecognitionHandler().startVoiceRecognition(
LocationBarVoiceRecognitionHandler.VoiceInteractionSource.SEARCH_WIDGET);
} else {
focusTextBox();
......@@ -140,7 +138,7 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
@Override
protected void updateButtonVisibility() {
super.updateButtonVisibility();
updateMicButtonVisibility(1.0f);
updateMicButtonVisibility();
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