Commit b422141f authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

Clean up scrim logic in LocationBarLayout

Scrim visibility in the location bar is now completely controlled by
a single function. The scrim observer is now added and removed based
on the scrim visibility to avoid conflict with other observers (like
the bottom sheet).

Bug: 834927
Change-Id: I172ca637dde5bc026b1b7f629bc34c6d939dff2d
Reviewed-on: https://chromium-review.googlesource.com/1026168
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558785}
parent 966d2bb8
...@@ -188,7 +188,7 @@ public class LocationBarLayout ...@@ -188,7 +188,7 @@ public class LocationBarLayout
private Runnable mRequestSuggestions; private Runnable mRequestSuggestions;
private ViewGroup mOmniboxResultsContainer; private ViewGroup mOmniboxResultsContainer;
protected FadingBackgroundView mFadingView; private FadingBackgroundView mFadingView;
private boolean mSuggestionsShown; private boolean mSuggestionsShown;
private boolean mUrlHasFocus; private boolean mUrlHasFocus;
...@@ -1108,8 +1108,8 @@ public class LocationBarLayout ...@@ -1108,8 +1108,8 @@ public class LocationBarLayout
listener.onUrlFocusChange(hasFocus); listener.onUrlFocusChange(hasFocus);
} }
updateOmniboxResultsContainer(); maybeShowOmniboxResultsContainer();
if (hasFocus) updateFadingBackgroundView(true); updateFadingBackgroundView(hasFocus, false);
} }
/** /**
...@@ -1713,7 +1713,7 @@ public class LocationBarLayout ...@@ -1713,7 +1713,7 @@ public class LocationBarLayout
mSuggestionList.setVisibility(GONE); mSuggestionList.setVisibility(GONE);
} }
} }
updateOmniboxResultsContainer(); maybeShowOmniboxResultsContainer();
} }
/** /**
...@@ -2291,12 +2291,10 @@ public class LocationBarLayout ...@@ -2291,12 +2291,10 @@ public class LocationBarLayout
mOmniboxResultsContainer = (ViewGroup) overlayStub.inflate(); mOmniboxResultsContainer = (ViewGroup) overlayStub.inflate();
} }
private void updateOmniboxResultsContainer() { private void maybeShowOmniboxResultsContainer() {
if (mSuggestionsShown || mUrlHasFocus) { if (mSuggestionsShown || mUrlHasFocus) {
initOmniboxResultsContainer(); initOmniboxResultsContainer();
updateOmniboxResultsContainerVisibility(true); updateOmniboxResultsContainerVisibility(true);
} else if (mOmniboxResultsContainer != null) {
updateFadingBackgroundView(false);
} }
} }
...@@ -2313,21 +2311,10 @@ public class LocationBarLayout ...@@ -2313,21 +2311,10 @@ public class LocationBarLayout
} }
} }
/**
* Initialize the fading background for when the omnibox is focused.
*/
protected void initFadingOverlayView() {
mFadingView =
(FadingBackgroundView) getRootView().findViewById(R.id.fading_focus_target);
mFadingView.addObserver(this);
}
@Override @Override
public void onFadingViewClick() { public void onFadingViewClick() {
setUrlBarFocus(false); setUrlBarFocus(false);
updateFadingBackgroundView(false, false);
// If the bottom sheet is used, it will control the fading view.
if (mBottomSheet == null) updateFadingBackgroundView(false);
} }
@Override @Override
...@@ -2348,23 +2335,22 @@ public class LocationBarLayout ...@@ -2348,23 +2335,22 @@ public class LocationBarLayout
* Update the fading background view that shows when the omnibox is focused. If Chrome Home is * Update the fading background view that shows when the omnibox is focused. If Chrome Home is
* enabled, this method is a no-op. * enabled, this method is a no-op.
* @param visible Whether the background should be made visible. * @param visible Whether the background should be made visible.
* @param ignoreNtpChecks Whether the checks for the ntp should be considered when updating the
* scrim.
*/ */
private void updateFadingBackgroundView(boolean visible) { protected void updateFadingBackgroundView(boolean visible, boolean ignoreNtpChecks) {
if (mFadingView == null) initFadingOverlayView(); if (mFadingView == null) mFadingView = getRootView().findViewById(R.id.fading_focus_target);
// If Chrome Home is enabled (the bottom sheet is not null), it will be controlling the
// fading view, so block any updating here.
if (mToolbarDataProvider == null || mBottomSheet != null) return;
NewTabPage ntp = mToolbarDataProvider.getNewTabPageForCurrentTab(); NewTabPage ntp = mToolbarDataProvider.getNewTabPageForCurrentTab();
boolean locationBarShownInNTP = ntp != null && ntp.isLocationBarShownInNTP(); boolean locationBarShownInNTP = ntp != null && ntp.isLocationBarShownInNTP();
if (visible && !locationBarShownInNTP) { if (visible && (!locationBarShownInNTP || ignoreNtpChecks)) {
mFadingView.addObserver(this);
// If the location bar is shown in the NTP, the toolbar will eventually trigger a // If the location bar is shown in the NTP, the toolbar will eventually trigger a
// fade in. // fade in.
mFadingView.showFadingOverlay(); mFadingView.showFadingOverlay();
} else { } else {
mFadingView.hideFadingOverlay(!locationBarShownInNTP); mFadingView.hideFadingOverlay(!locationBarShownInNTP);
mFadingView.removeObserver(this);
} }
} }
......
...@@ -188,8 +188,7 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -188,8 +188,7 @@ public class LocationBarPhone extends LocationBarLayout {
NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab(); NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
if (hasFocus && ntp != null && ntp.isLocationBarShownInNTP() && mBottomSheet == null) { if (hasFocus && ntp != null && ntp.isLocationBarShownInNTP() && mBottomSheet == null) {
if (mFadingView == null) initFadingOverlayView(); updateFadingBackgroundView(true, true);
mFadingView.showFadingOverlay();
} }
} }
......
...@@ -172,6 +172,14 @@ public class FadingBackgroundView extends View implements View.OnClickListener { ...@@ -172,6 +172,14 @@ public class FadingBackgroundView extends View implements View.OnClickListener {
mObservers.addObserver(observer); mObservers.addObserver(observer);
} }
/**
* Removes an observer to this fading view.
* @param observer The observer to be removed.
*/
public void removeObserver(FadingViewObserver observer) {
mObservers.removeObserver(observer);
}
@Override @Override
public void onClick(View view) { public void onClick(View view) {
for (FadingViewObserver o : mObservers) o.onFadingViewClick(); for (FadingViewObserver o : mObservers) o.onFadingViewClick();
......
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