Chromium Code Reviews| Index: chrome/browser/themes/theme_service_win.cc |
| diff --git a/chrome/browser/themes/theme_service_win.cc b/chrome/browser/themes/theme_service_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6a6685a06d4e9ec57eb5a80ed598443f56969393 |
| --- /dev/null |
| +++ b/chrome/browser/themes/theme_service_win.cc |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/themes/theme_service_win.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/win/windows_version.h" |
| +#include "chrome/browser/themes/theme_properties.h" |
| +#include "grit/theme_resources.h" |
| +#include "skia/ext/skia_utils_win.h" |
| +#include "ui/base/win/shell.h" |
| + |
| +ThemeServiceWin::ThemeServiceWin() { |
|
Evan Stade
2016/03/03 01:24:25
init dwm_frame_color_?
Peter Kasting
2016/03/03 09:23:06
There's no need, since the code in the conditional
Evan Stade
2016/03/03 18:17:19
yes, but we run static analysis tools that don't k
|
| + // 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)); |
| + OnDwmKeyUpdated(); |
| + } |
| +} |
| + |
| +ThemeServiceWin::~ThemeServiceWin() { |
| +} |
| + |
| +bool ThemeServiceWin::ShouldUseNativeFrame() const { |
| + return !HasCustomImage(IDR_THEME_FRAME) && ui::win::IsAeroGlassEnabled(); |
| +} |
| + |
| +SkColor ThemeServiceWin::GetDefaultColor(int id, bool incognito) const { |
| + if (ShouldUseDwmFrameColor()) { |
| + switch (id) { |
| + // Active native windows on Windows 10 may have a custom frame color. |
| + case ThemeProperties::COLOR_FRAME: |
|
Bret
2016/03/02 22:54:03
i still think "frame" is a confusing name for this
Peter Kasting
2016/03/03 09:23:06
I understand where you're coming from.
That said,
|
| + case ThemeProperties::COLOR_FRAME_INCOGNITO: |
|
Evan Stade
2016/03/03 01:24:25
I don't think you can hit this (or the other incog
Peter Kasting
2016/03/03 09:23:06
You're right. I misread the original code before
|
| + return dwm_frame_color_; |
| + |
| + // Inactive native windows on Windows 10 always have a white frame. |
| + case ThemeProperties::COLOR_FRAME_INACTIVE: |
| + case ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE: |
| + return SK_ColorWHITE; |
| + } |
| + } |
| + |
| + return ThemeService::GetDefaultColor(id, incognito); |
| +} |
| + |
| +bool ThemeServiceWin::ShouldUseDwmFrameColor() const { |
| + return ShouldUseNativeFrame() && |
| + (base::win::GetVersion() >= base::win::VERSION_WIN10); |
| +} |
| + |
| +void ThemeServiceWin::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( |
| + &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this)))) |
| + dwm_key_.reset(); |
| +} |