Commit a60324bd authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

Fix some status bar issues

Fix two issues introduced by https://crrev.com/c/1568092
+ Scrim status bar color on pre-L. The old "parity" logic does not
  work now that we calculate the status bar color instead of passing in
  a previously used status bar base color.
+ In tab grid switcher, the url focus percentage can change before
  #onObservingDifferentTab() is notified, so we need to avoid calling
  #updateStatusBarColor() in #onUrlExpansionPercentageChanged() with
  the out-of-date tab.

Bug: 952752, 953665
Change-Id: I175b1e2d3136fd5dc190d4ec8cdba2f88888c23d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1572702
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652588}
parent 10078163
......@@ -88,6 +88,7 @@ public class StatusBarColorController
private float mStatusBarScrimFraction;
private float mToolbarUrlExpansionPercentage;
private boolean mShouldUpdateStatusBarColorForNTP;
/**
* @param chromeActivity The {@link ChromeActivity} that this class is attached to.
......@@ -99,7 +100,7 @@ public class StatusBarColorController
mStatusBarColorProvider = chromeActivity;
mStatusBarScrimDelegate = (fraction) -> {
mStatusBarScrimFraction = fraction;
updateStatusBarColor(null);
updateStatusBarColor(mCurrentTab);
};
Resources resources = chromeActivity.getResources();
......@@ -120,9 +121,31 @@ public class StatusBarColorController
updateStatusBarColor(tab);
}
@Override
public void onContentChanged(Tab tab) {
final boolean newShouldUpdateStatusBarColorForNTP = isStandardNTP();
// Also update the status bar color if the content was previously an NTP, because an
// NTP can use a different status bar color than the default theme color. In this
// case, the theme color might not change, and thus #onDidChangeThemeColor might
// not get called.
if (mShouldUpdateStatusBarColorForNTP || newShouldUpdateStatusBarColorForNTP) {
updateStatusBarColor(tab);
}
mShouldUpdateStatusBarColorForNTP = newShouldUpdateStatusBarColorForNTP;
}
@Override
public void onDestroyed(Tab tab) {
// Make sure that #mCurrentTab is cleared because #onObservingDifferentTab() might
// not be notified early enough when #onUrlExpansionPercentageChanged() is called.
mCurrentTab = null;
mShouldUpdateStatusBarColorForNTP = false;
}
@Override
protected void onObservingDifferentTab(Tab tab) {
mCurrentTab = tab;
mShouldUpdateStatusBarColorForNTP = isStandardNTP();
// |tab == null| means we're switching tabs - by the tab switcher or by swiping
// on the omnibox. These cases are dealt with differently, elsewhere.
......@@ -180,7 +203,7 @@ public class StatusBarColorController
@Override
public void onUrlExpansionPercentageChanged(float percentage) {
mToolbarUrlExpansionPercentage = percentage;
if (isStandardNTP()) updateStatusBarColor(mCurrentTab);
if (mShouldUpdateStatusBarColorForNTP) updateStatusBarColor(mCurrentTab);
}
/**
......
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