Chromium Code Reviews| Index: chrome/browser/themes/theme_service.cc |
| diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc |
| index 18f0a4f9630ac6396646bf44dd09837828dfe5cd..746d78cbb1829e51e8deb521e145a4bc8cfb2037 100644 |
| --- a/chrome/browser/themes/theme_service.cc |
| +++ b/chrome/browser/themes/theme_service.cc |
| @@ -55,6 +55,8 @@ |
| #endif |
| #if defined(OS_WIN) |
| +#include "base/win/windows_version.h" |
| +#include "skia/ext/skia_utils_win.h" |
| #include "ui/base/win/shell.h" |
| #endif |
| @@ -168,7 +170,19 @@ ThemeService::ThemeService() |
| number_of_infobars_(0), |
| original_theme_provider_(*this, false), |
| incognito_theme_provider_(*this, true), |
| - weak_ptr_factory_(this) {} |
| + weak_ptr_factory_(this) { |
| +#if defined(OS_WIN) |
| + // This just checks for Windows 10 instead of calling ShouldUseDwmFrameColor() |
| + // because we want to monitor the frame color even when a custom frame is in |
| + // use, so that it will be correct if at any time the user switches to the |
| + // native frame. |
| + if (base::win::GetVersion() >= base::win::VERSION_WIN10) { |
| + dwm_key_.reset(new base::win::RegKey( |
| + HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\DWM", KEY_READ)); |
|
Bret
2016/02/29 18:29:03
Are you sure this is actually the frame color? Whe
Peter Kasting
2016/02/29 19:57:06
On my system, the swatch color and the frame color
|
| + OnDwmKeyUpdated(); |
| + } |
| +#endif |
| +} |
| ThemeService::~ThemeService() { |
| FreePlatformCaches(); |
| @@ -475,6 +489,20 @@ SkColor ThemeService::GetColor(int id, bool incognito) const { |
| const int kLabelBackground = |
| ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND; |
| switch (id) { |
| +#if defined(OS_WIN) |
| + case ThemeProperties::COLOR_FRAME: |
| + case ThemeProperties::COLOR_FRAME_INCOGNITO: |
| + // Active native windows on Windows 10 may have a custom frame color. |
| + if (ShouldUseDwmFrameColor()) |
| + return dwm_frame_color_; |
| + break; |
| + case ThemeProperties::COLOR_FRAME_INACTIVE: |
| + case ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE: |
| + // Inactive native windows on Windows 10 always have a white frame. |
| + if (ShouldUseDwmFrameColor()) |
| + return SK_ColorWHITE; |
| + break; |
| +#endif |
| case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON: |
| return color_utils::HSLShift( |
| gfx::kChromeIconGrey, |
| @@ -738,6 +766,30 @@ void ThemeService::SetSupervisedUserTheme() { |
| } |
| #endif |
| +#if defined(OS_WIN) |
| +bool ThemeService::ShouldUseDwmFrameColor() const { |
| + return ShouldUseNativeFrame() && |
| + (base::win::GetVersion() >= base::win::VERSION_WIN10); |
| +} |
| + |
| +void ThemeService::OnDwmKeyUpdated() { |
| + // Attempt to read the accent color. |
| + DWORD accent_color, color_prevalence; |
| + dwm_frame_color_ = |
| + ((dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) == |
| + ERROR_SUCCESS) && |
| + (color_prevalence == 1) && |
| + (dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS)) |
| + ? skia::COLORREFToSkColor(accent_color) |
| + : SK_ColorWHITE; |
| + |
| + // Watch for future changes. |
| + if (!dwm_key_->StartWatching( |
| + base::Bind(&ThemeService::OnDwmKeyUpdated, base::Unretained(this)))) |
| + dwm_key_.reset(); |
| +} |
| +#endif |
| + |
| void ThemeService::OnInfobarDisplayed() { |
| number_of_infobars_++; |
| } |