Skip to content

Commit

Permalink
[win] Remove the kDisableWindows10CustomTitlebar switch
Browse files Browse the repository at this point in the history
This CL removes the obsolete --disable-windows10-custom-titlebar switch
and some related logic.

Bug: 1059931
Change-Id: I86c79e43c077e3aa5d82d858de7c78c78ee0c629
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4534461
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1145012}
  • Loading branch information
jloeffler4 authored and Chromium LUCI CQ committed May 17, 2023
1 parent 453e5e0 commit d6581b4
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 145 deletions.
3 changes: 1 addition & 2 deletions chrome/browser/themes/theme_helper_win.cc
Expand Up @@ -19,6 +19,5 @@ int ThemeHelperWin::GetDefaultDisplayProperty(int id) const {

bool ThemeHelperWin::ShouldUseNativeFrame(
const CustomThemeSupplier* theme_supplier) const {
return !ShouldAlwaysUseSystemTitlebar() ||
!HasCustomImage(IDR_THEME_FRAME, theme_supplier);
return true;
}
116 changes: 37 additions & 79 deletions chrome/browser/ui/color/win/native_chrome_color_mixer_win.cc
Expand Up @@ -8,7 +8,6 @@
#include "base/functional/bind.h"
#include "base/no_destructor.h"
#include "base/win/windows_version.h"
#include "chrome/browser/themes/browser_theme_pack.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/win/titlebar_config.h"
Expand Down Expand Up @@ -45,13 +44,6 @@ class FrameColorHelper {
static FrameColorHelper* Get();

private:
// Returns whether there is a custom image provided for the given id.
bool HasCustomImage(int id, const ui::ColorProviderManager::Key& key) const;

// Returns true if colors from DWM can be used, i.e. this is a native frame
// on Windows 8+.
bool DwmColorsAllowed(const ui::ColorProviderManager::Key& key) const;

// Returns the Tint for the given |id|. If there is no tint, the identity tint
// {-1, -1, -1} is returned and won't tint the color on which it is used.
color_utils::HSL GetTint(int id,
Expand Down Expand Up @@ -97,66 +89,45 @@ void FrameColorHelper::AddNativeChromeColors(
return absl::nullopt;
};

if (DwmColorsAllowed(key)) {
// When we're custom-drawing the titlebar we want to use either the colors
// we calculated in OnDwmKeyUpdated() or the default colors. When we're not
// custom-drawing the titlebar we want to match the color Windows actually
// uses because some things (like the incognito icon) use this color to
// decide whether they should draw in light or dark mode. Incognito colors
// should be the same as non-incognito in all cases here.

constexpr SkColor kSystemSolidLightFrameColor = SK_ColorWHITE;
constexpr SkColor kSystemSolidDarkActiveFrameColor = SK_ColorBLACK;
constexpr SkColor kSystemSolidDarkInactiveFrameColor =
SkColorSetRGB(0x2B, 0x2B, 0x2B);

constexpr SkColor kSystemMicaLightFrameColor =
SkColorSetRGB(0xE8, 0xE8, 0xE8);
constexpr SkColor kSystemMicaDarkFrameColor =
SkColorSetRGB(0x20, 0x20, 0x20);

if (auto color = get_theme_color(TP::COLOR_FRAME_ACTIVE)) {
mixer[ui::kColorFrameActive] = {color.value()};
} else if (dwm_frame_color_) {
mixer[ui::kColorFrameActive] = {dwm_frame_color_.value()};
} else if (ShouldDefaultThemeUseMicaTitlebar() && !key.app_controller) {
mixer[ui::kColorFrameActive] = {key.color_mode == ColorMode::kDark
// When we're custom-drawing the titlebar we want to use either the colors
// we calculated in OnDwmKeyUpdated() or the default colors. When we're not
// custom-drawing the titlebar we want to match the color Windows actually
// uses because some things (like the incognito icon) use this color to
// decide whether they should draw in light or dark mode. Incognito colors
// should be the same as non-incognito in all cases here.

constexpr SkColor kSystemMicaLightFrameColor =
SkColorSetRGB(0xE8, 0xE8, 0xE8);
constexpr SkColor kSystemMicaDarkFrameColor = SkColorSetRGB(0x20, 0x20, 0x20);

if (auto color = get_theme_color(TP::COLOR_FRAME_ACTIVE)) {
mixer[ui::kColorFrameActive] = {color.value()};
} else if (dwm_frame_color_) {
mixer[ui::kColorFrameActive] = {dwm_frame_color_.value()};
} else if (ShouldDefaultThemeUseMicaTitlebar() && !key.app_controller) {
mixer[ui::kColorFrameActive] = {key.color_mode == ColorMode::kDark
? kSystemMicaDarkFrameColor
: kSystemMicaLightFrameColor};
}

if (auto color = get_theme_color(TP::COLOR_FRAME_INACTIVE)) {
mixer[ui::kColorFrameInactive] = {color.value()};
} else if (dwm_inactive_frame_color_) {
mixer[ui::kColorFrameInactive] = {dwm_inactive_frame_color_.value()};
} else if (ShouldDefaultThemeUseMicaTitlebar() && !key.app_controller) {
mixer[ui::kColorFrameInactive] = {key.color_mode == ColorMode::kDark
? kSystemMicaDarkFrameColor
: kSystemMicaLightFrameColor};
} else if (ShouldAlwaysUseSystemTitlebar()) {
mixer[ui::kColorFrameActive] = {key.color_mode == ColorMode::kDark
? kSystemSolidDarkActiveFrameColor
: kSystemSolidLightFrameColor};
}

if (auto color = get_theme_color(TP::COLOR_FRAME_INACTIVE)) {
mixer[ui::kColorFrameInactive] = {color.value()};
} else if (dwm_inactive_frame_color_) {
mixer[ui::kColorFrameInactive] = {dwm_inactive_frame_color_.value()};
} else if (ShouldDefaultThemeUseMicaTitlebar() && !key.app_controller) {
mixer[ui::kColorFrameInactive] = {key.color_mode == ColorMode::kDark
? kSystemMicaDarkFrameColor
: kSystemMicaLightFrameColor};
} else if (ShouldAlwaysUseSystemTitlebar()) {
mixer[ui::kColorFrameInactive] = {key.color_mode == ColorMode::kDark
? kSystemSolidDarkInactiveFrameColor
: kSystemSolidLightFrameColor};
} else if (dwm_frame_color_) {
mixer[ui::kColorFrameInactive] =
ui::HSLShift({dwm_frame_color_.value()},
GetTint(ThemeProperties::TINT_FRAME_INACTIVE, key));
}

if (ShouldDefaultThemeUseMicaTitlebar() && !key.app_controller) {
mixer[kColorNewTabButtonBackgroundFrameActive] = {SK_ColorTRANSPARENT};
mixer[kColorNewTabButtonInkDropFrameActive] =
ui::GetColorWithMaxContrast(ui::kColorFrameActive);
}
} else {
if (auto color = get_theme_color(TP::COLOR_FRAME_ACTIVE))
mixer[ui::kColorFrameActive] = {color.value()};
if (auto color = get_theme_color(TP::COLOR_FRAME_INACTIVE))
mixer[ui::kColorFrameInactive] = {color.value()};
} else if (dwm_frame_color_) {
mixer[ui::kColorFrameInactive] =
ui::HSLShift({dwm_frame_color_.value()},
GetTint(ThemeProperties::TINT_FRAME_INACTIVE, key));
}

if (ShouldDefaultThemeUseMicaTitlebar() && !key.app_controller) {
mixer[kColorNewTabButtonBackgroundFrameActive] = {SK_ColorTRANSPARENT};
mixer[kColorNewTabButtonInkDropFrameActive] =
ui::GetColorWithMaxContrast(ui::kColorFrameActive);
}
}

Expand All @@ -179,19 +150,6 @@ FrameColorHelper* FrameColorHelper::Get() {
return g_frame_color_helper.get();
}

bool FrameColorHelper::HasCustomImage(
int id,
const ui::ColorProviderManager::Key& key) const {
return BrowserThemePack::IsPersistentImageID(id) && key.custom_theme &&
key.custom_theme->HasCustomImage(id);
}

bool FrameColorHelper::DwmColorsAllowed(
const ui::ColorProviderManager::Key& key) const {
return !ShouldAlwaysUseSystemTitlebar() ||
!HasCustomImage(IDR_THEME_FRAME, key);
}

color_utils::HSL FrameColorHelper::GetTint(
int id,
const ui::ColorProviderManager::Key& key) const {
Expand Down
32 changes: 15 additions & 17 deletions chrome/browser/ui/views/frame/browser_frame_view_win.cc
Expand Up @@ -406,7 +406,7 @@ void BrowserFrameViewWin::ResetWindowControls() {
void BrowserFrameViewWin::OnThemeChanged() {
BrowserNonClientFrameView::OnThemeChanged();
if (!ShouldBrowserCustomDrawTitlebar(browser_view())) {
SetSystemTitlebarAttributes();
SetSystemMicaTitlebarAttributes();
}
}

Expand Down Expand Up @@ -632,26 +632,24 @@ bool BrowserFrameViewWin::ShouldShowWindowTitle(TitlebarType type) const {

void BrowserFrameViewWin::TabletModeChanged() {
if (!ShouldBrowserCustomDrawTitlebar(browser_view())) {
SetSystemTitlebarAttributes();
SetSystemMicaTitlebarAttributes();
}
}

void BrowserFrameViewWin::SetSystemTitlebarAttributes() {
if (SystemTitlebarSupportsDarkMode()) {
const BOOL dark_titlebar_enabled = GetNativeTheme()->ShouldUseDarkColors();
DwmSetWindowAttribute(views::HWNDForWidget(frame()),
DWMWA_USE_IMMERSIVE_DARK_MODE, &dark_titlebar_enabled,
sizeof(dark_titlebar_enabled));
}
void BrowserFrameViewWin::SetSystemMicaTitlebarAttributes() {
CHECK(SystemTitlebarCanUseMicaMaterial());

if (ShouldBrowserUseMicaTitlebar(browser_view())) {
const DWM_SYSTEMBACKDROP_TYPE dwm_backdrop_type =
browser_view()->GetTabStripVisible() ? DWMSBT_TABBEDWINDOW
: DWMSBT_MAINWINDOW;
DwmSetWindowAttribute(views::HWNDForWidget(frame()),
DWMWA_SYSTEMBACKDROP_TYPE, &dwm_backdrop_type,
sizeof(dwm_backdrop_type));
}
const BOOL dark_titlebar_enabled = GetNativeTheme()->ShouldUseDarkColors();
DwmSetWindowAttribute(views::HWNDForWidget(frame()),
DWMWA_USE_IMMERSIVE_DARK_MODE, &dark_titlebar_enabled,
sizeof(dark_titlebar_enabled));

const DWM_SYSTEMBACKDROP_TYPE dwm_backdrop_type =
browser_view()->GetTabStripVisible() ? DWMSBT_TABBEDWINDOW
: DWMSBT_MAINWINDOW;
DwmSetWindowAttribute(views::HWNDForWidget(frame()),
DWMWA_SYSTEMBACKDROP_TYPE, &dwm_backdrop_type,
sizeof(dwm_backdrop_type));
}

SkColor BrowserFrameViewWin::GetTitlebarColor() const {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/frame/browser_frame_view_win.h
Expand Up @@ -145,8 +145,8 @@ class BrowserFrameViewWin : public BrowserNonClientFrameView,
// Called when the device enters or exits tablet mode.
void TabletModeChanged();

// Sets DWM attributes for rendering the system-drawn titlebar.
void SetSystemTitlebarAttributes();
// Sets DWM attributes for rendering the system-drawn Mica titlebar.
void SetSystemMicaTitlebarAttributes();

// Paint various sub-components of this view.
void PaintTitlebar(gfx::Canvas* canvas) const;
Expand Down
33 changes: 6 additions & 27 deletions chrome/browser/win/titlebar_config.cc
Expand Up @@ -4,12 +4,10 @@

#include "chrome/browser/win/titlebar_config.h"

#include "base/command_line.h"
#include "base/win/windows_version.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/chrome_switches.h"
#include "ui/color/win/accent_color_observer.h"
#include "ui/native_theme/native_theme.h"

Expand All @@ -22,27 +20,12 @@ BASE_FEATURE(kWindows11MicaTitlebar,
} // namespace

bool ShouldBrowserCustomDrawTitlebar(BrowserView* browser_view) {
return !ShouldAlwaysUseSystemTitlebar() &&
!ShouldBrowserUseMicaTitlebar(browser_view);
}

bool ShouldAlwaysUseSystemTitlebar() {
// Cache flag lookup.
static const bool custom_titlebar_disabled =
base::CommandLine::InitializedForCurrentProcess() &&
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableWindows10CustomTitlebar);

return custom_titlebar_disabled;
}

bool ShouldBrowserUseMicaTitlebar(BrowserView* browser_view) {
return ShouldDefaultThemeUseMicaTitlebar() &&
(browser_view->browser()->is_type_normal() ||
browser_view->browser()->is_type_popup() ||
browser_view->browser()->is_type_devtools()) &&
ThemeServiceFactory::GetForProfile(browser_view->GetProfile())
->UsingSystemTheme();
return !ShouldDefaultThemeUseMicaTitlebar() ||
!ThemeServiceFactory::GetForProfile(browser_view->GetProfile())
->UsingSystemTheme() ||
(!browser_view->browser()->is_type_normal() &&
!browser_view->browser()->is_type_popup() &&
!browser_view->browser()->is_type_devtools());
}

bool ShouldDefaultThemeUseMicaTitlebar() {
Expand All @@ -56,7 +39,3 @@ bool SystemTitlebarCanUseMicaMaterial() {
return base::win::GetVersion() >= base::win::Version::WIN11_22H2 &&
base::FeatureList::IsEnabled(kWindows11MicaTitlebar);
}

bool SystemTitlebarSupportsDarkMode() {
return base::win::GetVersion() >= base::win::Version::WIN11;
}
13 changes: 0 additions & 13 deletions chrome/browser/win/titlebar_config.h
Expand Up @@ -5,21 +5,11 @@
#ifndef CHROME_BROWSER_WIN_TITLEBAR_CONFIG_H_
#define CHROME_BROWSER_WIN_TITLEBAR_CONFIG_H_

#include "base/feature_list.h"

class BrowserView;

// Returns whether we should custom draw the titlebar for a browser window.
bool ShouldBrowserCustomDrawTitlebar(BrowserView* browser_view);

// Returns whether we should always use the system titlebar, even when a theme
// is applied.
bool ShouldAlwaysUseSystemTitlebar();

// Returns whether we should use the Mica titlebar material for a browser
// window.
bool ShouldBrowserUseMicaTitlebar(BrowserView* browser_view);

// Returns whether we should use the Mica titlebar in standard browser windows
// using the default theme.
bool ShouldDefaultThemeUseMicaTitlebar();
Expand All @@ -28,7 +18,4 @@ bool ShouldDefaultThemeUseMicaTitlebar();
// material.
bool SystemTitlebarCanUseMicaMaterial();

// Returns whether the system-drawn titlebar can be drawn in dark mode.
bool SystemTitlebarSupportsDarkMode();

#endif // CHROME_BROWSER_WIN_TITLEBAR_CONFIG_H_
4 changes: 0 additions & 4 deletions chrome/common/chrome_switches.cc
Expand Up @@ -784,10 +784,6 @@ const char kMakeChromeDefault[] = "make-chrome-default";
#endif // BUILDFLAG(IS_MAC)

#if BUILDFLAG(IS_WIN)
// Disables custom-drawing the window titlebar on Windows 10.
const char kDisableWindows10CustomTitlebar[] =
"disable-windows10-custom-titlebar";

// Force-enables the profile shortcut manager. This is needed for tests since
// they use a custom-user-data-dir which disables this.
const char kEnableProfileShortcutManager[] = "enable-profile-shortcut-manager";
Expand Down
1 change: 0 additions & 1 deletion chrome/common/chrome_switches.h
Expand Up @@ -244,7 +244,6 @@ extern const char kMakeChromeDefault[];
#endif // BUILDFLAG(IS_MAC)

#if BUILDFLAG(IS_WIN)
extern const char kDisableWindows10CustomTitlebar[];
extern const char kEnableProfileShortcutManager[];
extern const char kFromInstaller[];
extern const char kHideIcons[];
Expand Down

2 comments on commit d6581b4

@DevInfinix
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was custom title bar feature removed

@teknixstuff
Copy link

@teknixstuff teknixstuff commented on d6581b4 Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DevInfinix pr #188 would restore it.

Please sign in to comment.