Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2370)

Unified Diff: chrome/browser/themes/theme_service_win.cc

Issue 2381283003: Have Chrome draw top window border when using custom titlebar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add include Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
index 4aab2c4219d3244790e283ae8a1a8e88eccb7f66..05809109cb4a66c02a6955159bd88aaac861a551 100644
--- a/chrome/browser/themes/theme_service_win.cc
+++ b/chrome/browser/themes/theme_service_win.cc
@@ -4,7 +4,10 @@
#include "chrome/browser/themes/theme_service_win.h"
+#include <algorithm>
+
#include "base/bind.h"
+#include "base/numerics/safe_conversions.h"
#include "base/win/windows_version.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/grit/theme_resources.h"
@@ -39,6 +42,9 @@ SkColor ThemeServiceWin::GetDefaultColor(int id, bool incognito) const {
if (id == ThemeProperties::COLOR_FRAME)
return dwm_frame_color_;
+ if (id == ThemeProperties::COLOR_ACCENT_BORDER)
+ return dwm_accent_color_;
+
// Inactive native windows on Windows 10 always have a white frame.
if (id == ThemeProperties::COLOR_FRAME_INACTIVE)
return SK_ColorWHITE;
@@ -52,6 +58,11 @@ bool ThemeServiceWin::ShouldUseDwmFrameColor() const {
(base::win::GetVersion() >= base::win::VERSION_WIN10);
}
+// This can accept alpha < 0 or > 1.
Peter Kasting 2016/10/06 08:02:46 ...But we never call it with < 0, right? Graphica
Bret 2016/10/06 20:48:09 Yeah don't mention it's allowed to be "out of boun
+static uint8_t alpha_blend_component(uint8_t a, uint8_t b, float alpha) {
+ return base::saturated_cast<uint8_t>(std::round(a * alpha + b * (1 - alpha)));
+}
+
void ThemeServiceWin::OnDwmKeyUpdated() {
// Attempt to read the accent color.
DWORD accent_color, color_prevalence;
@@ -63,6 +74,29 @@ void ThemeServiceWin::OnDwmKeyUpdated() {
? skia::COLORREFToSkColor(accent_color)
: SK_ColorWHITE;
+ dwm_accent_color_ = SK_ColorWHITE;
Peter Kasting 2016/10/06 08:02:46 I didn't check: for native drawing, does the Color
Bret 2016/10/06 20:48:09 No, the border is always colored the same way even
+ DWORD colorization_color, colorization_color_balance;
+ if ((dwm_key_->ReadValueDW(L"ColorizationColor", &colorization_color) ==
+ ERROR_SUCCESS) &&
+ (dwm_key_->ReadValueDW(L"ColorizationColorBalance",
+ &colorization_color_balance) == ERROR_SUCCESS)) {
+ constexpr DWORD max_colorization_balance = 120u;
+ // Alpha can be > 1.0 if the accent color is taken from the background and
+ // either the background is a solid color or was just changed to a
+ // slideshow.
Peter Kasting 2016/10/06 08:02:46 Is it true that the colorization color balance is
Bret 2016/10/06 20:48:09 I just tried thrashing my own registry values on 1
+ float alpha =
+ std::min(colorization_color_balance, max_colorization_balance) / 100.f;
+ const uint8_t gray_level = 0xd9;
Peter Kasting 2016/10/06 08:02:47 Nit: Comment where this comes from. More accurate
+
+ // colorization_color's alpha can be 0xc4 or 0.
Peter Kasting 2016/10/06 08:02:47 Nit: As Bret noted, this isn't really an alpha val
+ SkColor input_color = SkColorSetA(colorization_color, 0xff);
+
+ dwm_accent_color_ = SkColorSetRGB(
+ alpha_blend_component(SkColorGetR(input_color), gray_level, alpha),
+ alpha_blend_component(SkColorGetG(input_color), gray_level, alpha),
+ alpha_blend_component(SkColorGetB(input_color), gray_level, alpha));
+ }
+
// Watch for future changes.
if (!dwm_key_->StartWatching(base::Bind(
&ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this))))

Powered by Google App Engine
This is Rietveld 408576698