Skip to content

Commit

Permalink
[Status Bar] Synchronize the toolbar and the status bar color in sear…
Browse files Browse the repository at this point in the history
…ch widget.

Bug: 1378752
Change-Id: I786020cb7f5e6e17232b92fc1ec198996f969297

Screenshot light(old): http://screen/B6ipcP6DaTzvmdu
Screenshot light(new): http://screen/ALax7eQE2Mnepoe
Screenshot dark(old): http://screen/6TWkQ239RYcuydR
Screenshot dark(new): http://screen/37Hrre7o5ZY2Lzf
Screenshot light(old, tablet): http://screen/AgtiAkxmhRWfUhZ
Screenshot light(new, tablet): http://screen/4JMWqYfdiDTdun2

Change-Id: I786020cb7f5e6e17232b92fc1ec198996f969297
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3984309
Reviewed-by: Ted Choc <tedchoc@chromium.org>
Commit-Queue: Rong Tan <rongtan@google.com>
Reviewed-by: Sky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1070642}
  • Loading branch information
Rong Tan authored and Chromium LUCI CQ committed Nov 12, 2022
1 parent df16329 commit e177599
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager.SnackbarManageable;
import org.chromium.chrome.browser.ui.native_page.NativePage;
import org.chromium.chrome.browser.ui.searchactivityutils.SearchActivityConstants;
import org.chromium.chrome.browser.ui.system.StatusBarColorController;
import org.chromium.components.browser_ui.modaldialog.AppModalPresenter;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.util.BrowserControlsVisibilityDelegate;
Expand Down Expand Up @@ -192,6 +193,16 @@ protected void triggerLayoutInflation() {
mAnchorView = mContentView.findViewById(R.id.toolbar);
updateAnchorViewLayout();

// Create status bar color controller and assign to search activity.
if (OmniboxFeatures.shouldMatchToolbarAndStatusBarColor()) {
// Update the status bar's color based on the toolbar color.
Drawable anchorViewBackground = mAnchorView.getBackground();
if (anchorViewBackground instanceof ColorDrawable) {
int anchorViewColor = ((ColorDrawable) anchorViewBackground).getColor();
StatusBarColorController.setStatusBarColor(this.getWindow(), anchorViewColor);
}
}

OverrideUrlLoadingDelegate overrideUrlLoadingDelegate =
(String url, @PageTransition int transition, String postDataType, byte[] postData,
boolean incognito) -> {
Expand Down Expand Up @@ -613,6 +624,10 @@ private void applyColor(@ColorInt int color) {
Drawable toolbarBackground = mContentView.findViewById(R.id.toolbar).getBackground();
locationbarBackground.setTint(color);
toolbarBackground.setTint(color);

if (OmniboxFeatures.shouldMatchToolbarAndStatusBarColor()) {
StatusBarColorController.setStatusBarColor(this.getWindow(), color);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.chromium.base.supplier.ObservableSupplier;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.layouts.FilterLayoutStateObserver;
import org.chromium.chrome.browser.layouts.LayoutManager;
import org.chromium.chrome.browser.layouts.LayoutStateProvider;
Expand Down Expand Up @@ -145,7 +144,7 @@ public void onShown(Tab tab, @TabSelectionType int type) {

@Override
public void onDidChangeThemeColor(Tab tab, int color) {
if (ChromeFeatureList.sOmniboxMatchToolbarAndStatusBarColor.isEnabled()) {
if (OmniboxFeatures.shouldMatchToolbarAndStatusBarColor()) {
// The theme color change assignment will override the feature flag which
// matches the toolbar and the status bar color, specifically for custom tabs
// with theme colors.
Expand Down Expand Up @@ -260,7 +259,7 @@ public void onUrlExpansionProgressChanged(float fraction) {
// TopToolbarCoordinator.ToolbarColorObserver implementation.
@Override
public void onToolbarColorChanged(int color) {
if (!ChromeFeatureList.sOmniboxMatchToolbarAndStatusBarColor.isEnabled()) {
if (!OmniboxFeatures.shouldMatchToolbarAndStatusBarColor()) {
return;
}

Expand All @@ -278,12 +277,12 @@ public void onToolbarColorChanged(int color) {
@Override
public void onStatusIndicatorColorChanged(@ColorInt int newColor) {
mStatusIndicatorColor = newColor;
if (!ChromeFeatureList.sOmniboxMatchToolbarAndStatusBarColor.isEnabled()) {
updateStatusBarColor();
} else {
if (OmniboxFeatures.shouldMatchToolbarAndStatusBarColor()) {
// The status indicator color assignment will override the feature flag which matches
// the toolbar and the status bar color.
updateStatusBarColor(calculateBaseStatusBarColor());
} else {
updateStatusBarColor();
}
}

Expand All @@ -299,12 +298,12 @@ public void onUrlFocusChange(boolean hasFocus) {
*/
public void setStatusBarScrimFraction(float fraction) {
mStatusBarScrimFraction = fraction;
if (!ChromeFeatureList.sOmniboxMatchToolbarAndStatusBarColor.isEnabled()) {
updateStatusBarColor();
} else {
if (OmniboxFeatures.shouldMatchToolbarAndStatusBarColor()) {
// The scrim fraction color assignment will override the feature flag which matches
// the toolbar and the status bar color.
updateStatusBarColor(calculateBaseStatusBarColor());
} else {
updateStatusBarColor();
}
}

Expand All @@ -324,7 +323,7 @@ public void setTabModelSelector(TabModelSelector tabModelSelector) {
public void updateStatusBarColor() {
// We will synchronize the status bar's color with toolbar's color if the feature flag is
// toggled, so we skip the original color assignment here.
if (ChromeFeatureList.sOmniboxMatchToolbarAndStatusBarColor.isEnabled()) {
if (OmniboxFeatures.shouldMatchToolbarAndStatusBarColor()) {
return;
}
updateStatusBarColor(calculateBaseStatusBarColor());
Expand All @@ -344,7 +343,7 @@ public void updateStatusBarColor(@ColorInt int color) {

int statusBarColor = applyStatusBarIndicatorColor(mStatusBarColorWithoutStatusIndicator);
statusBarColor = applyCurrentScrimToColor(statusBarColor);
setStatusBarColor(statusBarColor);
setStatusBarColor(mWindow, statusBarColor);
}

// TODO(sinansahin): Confirm pre-M expectations with UX and update as needed.
Expand Down Expand Up @@ -418,15 +417,16 @@ public void updateStatusBarColor(@ColorInt int color) {
/**
* Set device status bar to a given color. Also, set the status bar icons to a dark color if
* needed.
* @param window The current window of the UI view.
* @param color The color that the status bar should be set to.
*/
private void setStatusBarColor(@ColorInt int color) {
public static void setStatusBarColor(Window window, @ColorInt int color) {
if (UiUtils.isSystemUiThemingDisabled()) return;

final View root = mWindow.getDecorView().getRootView();
final View root = window.getDecorView().getRootView();
boolean needsDarkStatusBarIcons = !ColorUtils.shouldUseLightForegroundOnBackground(color);
ApiCompatibilityUtils.setStatusBarIconColor(root, needsDarkStatusBarIcons);
ApiCompatibilityUtils.setStatusBarColor(mWindow, color);
ApiCompatibilityUtils.setStatusBarColor(window, color);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,11 @@ private static boolean enabledModernizeVisualUpdateOnTablet() {
public static boolean shouldRemoveExcessiveRecycledViewClearCalls() {
return ChromeFeatureList.sOmniboxRemoveExcessiveRecycledViewClearCalls.isEnabled();
}

/**
* Returns whether we the toolbar snd status bar color should be matched.
*/
public static boolean shouldMatchToolbarAndStatusBarColor() {
return ChromeFeatureList.sOmniboxMatchToolbarAndStatusBarColor.isEnabled();
}
}

0 comments on commit e177599

Please sign in to comment.