Commit af5c81b4 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Minor refactoring in advance of fixing bug 621004.

* Use tints to compute frame colors in more cases
* Pull dark mode computation out to a temp to make it easy to reuse later
* Separate "shouldn't theme" and "should theme but can't" frame cases

Bug: none
Change-Id: I093e0e88c99fc061a04be69e15203ee3f16d2fb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1941169
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Bret Sepulveda <bsep@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719945}
parent 9d9e947b
......@@ -141,10 +141,15 @@ base::Optional<SkColor> GetIncognitoColor(int id) {
switch (id) {
case ThemeProperties::COLOR_FRAME:
case ThemeProperties::COLOR_BACKGROUND_TAB:
return gfx::kGoogleGrey900;
return color_utils::HSLShift(
GetLightModeColor(ThemeProperties::COLOR_FRAME),
ThemeProperties::GetDefaultTint(ThemeProperties::TINT_FRAME, true));
case ThemeProperties::COLOR_FRAME_INACTIVE:
case ThemeProperties::COLOR_BACKGROUND_TAB_INACTIVE:
return gfx::kGoogleGrey800;
return color_utils::HSLShift(
GetLightModeColor(ThemeProperties::COLOR_FRAME),
ThemeProperties::GetDefaultTint(ThemeProperties::TINT_FRAME_INACTIVE,
true));
case ThemeProperties::COLOR_DOWNLOAD_SHELF:
case ThemeProperties::COLOR_STATUS_BUBBLE:
case ThemeProperties::COLOR_INFOBAR:
......@@ -259,19 +264,18 @@ color_utils::HSL ThemeProperties::GetDefaultTint(int id, bool incognito) {
DCHECK(id != TINT_FRAME_INCOGNITO && id != TINT_FRAME_INCOGNITO_INACTIVE)
<< "These values should be queried via their respective non-incognito "
"equivalents and an appropriate |incognito| value.";
// If you change these defaults, you must increment the version number in
// browser_theme_pack.cc.
const bool dark_mode =
ui::NativeTheme::GetInstanceForNativeUi()->ShouldUseDarkColors();
// TINT_BUTTONS is used by ThemeService::GetDefaultColor() for both incognito
// and dark mode, and so must be applied to both.
if ((id == TINT_BUTTONS) &&
(incognito ||
ui::NativeTheme::GetInstanceForNativeUi()->ShouldUseDarkColors()))
if ((id == TINT_BUTTONS) && (incognito || dark_mode))
return {-1, 0.57, 0.9605}; // kChromeIconGrey -> kGoogleGrey100
// The frame tints are used only when parsing browser themes, and should not
// take dark mode into account, lest themes with custom frame images get those
// images unexpectedly modified just because the user is in dark mode.
if ((id == TINT_FRAME) && incognito)
return {-1, 0.7, 0.075}; // #DEE1E6 -> kGoogleGrey900
if (id == TINT_FRAME_INACTIVE) {
......
......@@ -157,8 +157,7 @@ SkColor BrowserNonClientFrameView::GetFrameColor(
!app_controller->has_tab_strip())
return *app_controller->GetThemeColor();
return ThemeProperties::GetDefaultColor(color_id,
browser_view_->IsIncognito());
return GetUnthemedColor(color_id);
}
void BrowserNonClientFrameView::UpdateFrameColor() {
......@@ -402,11 +401,18 @@ BrowserNonClientFrameView::GetThemeProviderForProfile() const {
}
SkColor BrowserNonClientFrameView::GetThemeOrDefaultColor(int color_id) const {
if (!frame_->ShouldUseTheme())
return GetUnthemedColor(color_id);
// During shutdown, there may no longer be a widget, and thus no theme
// provider.
const auto* theme_provider = GetThemeProvider();
return frame_->ShouldUseTheme() && theme_provider
? theme_provider->GetColor(color_id)
: ThemeProperties::GetDefaultColor(color_id,
return theme_provider ? theme_provider->GetColor(color_id)
: gfx::kPlaceholderColor;
}
SkColor BrowserNonClientFrameView::GetUnthemedColor(int color_id) const {
DCHECK(!frame_->ShouldUseTheme());
return ThemeProperties::GetDefaultColor(color_id,
browser_view_->IsIncognito());
}
......@@ -187,6 +187,9 @@ class BrowserNonClientFrameView : public views::NonClientFrameView,
// default theme properties.
SkColor GetThemeOrDefaultColor(int color_id) const;
// Returns the color of the given |color_id| for an un-themed frame.
SkColor GetUnthemedColor(int color_id) const;
// The frame that hosts this view.
BrowserFrame* frame_;
......
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