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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/themes/theme_service_win.h" 5 #include "chrome/browser/themes/theme_service_win.h"
6 6
7 #include <algorithm>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/numerics/safe_conversions.h"
8 #include "base/win/windows_version.h" 11 #include "base/win/windows_version.h"
9 #include "chrome/browser/themes/theme_properties.h" 12 #include "chrome/browser/themes/theme_properties.h"
10 #include "chrome/grit/theme_resources.h" 13 #include "chrome/grit/theme_resources.h"
11 #include "skia/ext/skia_utils_win.h" 14 #include "skia/ext/skia_utils_win.h"
12 #include "ui/base/win/shell.h" 15 #include "ui/base/win/shell.h"
13 16
14 ThemeServiceWin::ThemeServiceWin() { 17 ThemeServiceWin::ThemeServiceWin() {
15 // This just checks for Windows 10 instead of calling ShouldUseDwmFrameColor() 18 // This just checks for Windows 10 instead of calling ShouldUseDwmFrameColor()
16 // because we want to monitor the frame color even when a custom frame is in 19 // because we want to monitor the frame color even when a custom frame is in
17 // use, so that it will be correct if at any time the user switches to the 20 // use, so that it will be correct if at any time the user switches to the
(...skipping 14 matching lines...) Expand all
32 bool ThemeServiceWin::ShouldUseNativeFrame() const { 35 bool ThemeServiceWin::ShouldUseNativeFrame() const {
33 return !HasCustomImage(IDR_THEME_FRAME) && ui::win::IsAeroGlassEnabled(); 36 return !HasCustomImage(IDR_THEME_FRAME) && ui::win::IsAeroGlassEnabled();
34 } 37 }
35 38
36 SkColor ThemeServiceWin::GetDefaultColor(int id, bool incognito) const { 39 SkColor ThemeServiceWin::GetDefaultColor(int id, bool incognito) const {
37 if (ShouldUseDwmFrameColor()) { 40 if (ShouldUseDwmFrameColor()) {
38 // Active native windows on Windows 10 may have a custom frame color. 41 // Active native windows on Windows 10 may have a custom frame color.
39 if (id == ThemeProperties::COLOR_FRAME) 42 if (id == ThemeProperties::COLOR_FRAME)
40 return dwm_frame_color_; 43 return dwm_frame_color_;
41 44
45 if (id == ThemeProperties::COLOR_ACCENT_BORDER)
46 return dwm_accent_color_;
47
42 // Inactive native windows on Windows 10 always have a white frame. 48 // Inactive native windows on Windows 10 always have a white frame.
43 if (id == ThemeProperties::COLOR_FRAME_INACTIVE) 49 if (id == ThemeProperties::COLOR_FRAME_INACTIVE)
44 return SK_ColorWHITE; 50 return SK_ColorWHITE;
45 } 51 }
46 52
47 return ThemeService::GetDefaultColor(id, incognito); 53 return ThemeService::GetDefaultColor(id, incognito);
48 } 54 }
49 55
50 bool ThemeServiceWin::ShouldUseDwmFrameColor() const { 56 bool ThemeServiceWin::ShouldUseDwmFrameColor() const {
51 return ShouldUseNativeFrame() && 57 return ShouldUseNativeFrame() &&
52 (base::win::GetVersion() >= base::win::VERSION_WIN10); 58 (base::win::GetVersion() >= base::win::VERSION_WIN10);
53 } 59 }
54 60
61 // 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
62 static uint8_t alpha_blend_component(uint8_t a, uint8_t b, float alpha) {
63 return base::saturated_cast<uint8_t>(std::round(a * alpha + b * (1 - alpha)));
64 }
65
55 void ThemeServiceWin::OnDwmKeyUpdated() { 66 void ThemeServiceWin::OnDwmKeyUpdated() {
56 // Attempt to read the accent color. 67 // Attempt to read the accent color.
57 DWORD accent_color, color_prevalence; 68 DWORD accent_color, color_prevalence;
58 dwm_frame_color_ = 69 dwm_frame_color_ =
59 ((dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) == 70 ((dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) ==
60 ERROR_SUCCESS) && 71 ERROR_SUCCESS) &&
61 (color_prevalence == 1) && 72 (color_prevalence == 1) &&
62 (dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS)) 73 (dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS))
63 ? skia::COLORREFToSkColor(accent_color) 74 ? skia::COLORREFToSkColor(accent_color)
64 : SK_ColorWHITE; 75 : SK_ColorWHITE;
65 76
77 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
78 DWORD colorization_color, colorization_color_balance;
79 if ((dwm_key_->ReadValueDW(L"ColorizationColor", &colorization_color) ==
80 ERROR_SUCCESS) &&
81 (dwm_key_->ReadValueDW(L"ColorizationColorBalance",
82 &colorization_color_balance) == ERROR_SUCCESS)) {
83 constexpr DWORD max_colorization_balance = 120u;
84 // Alpha can be > 1.0 if the accent color is taken from the background and
85 // either the background is a solid color or was just changed to a
86 // 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
87 float alpha =
88 std::min(colorization_color_balance, max_colorization_balance) / 100.f;
89 const uint8_t gray_level = 0xd9;
Peter Kasting 2016/10/06 08:02:47 Nit: Comment where this comes from. More accurate
90
91 // 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
92 SkColor input_color = SkColorSetA(colorization_color, 0xff);
93
94 dwm_accent_color_ = SkColorSetRGB(
95 alpha_blend_component(SkColorGetR(input_color), gray_level, alpha),
96 alpha_blend_component(SkColorGetG(input_color), gray_level, alpha),
97 alpha_blend_component(SkColorGetB(input_color), gray_level, alpha));
98 }
99
66 // Watch for future changes. 100 // Watch for future changes.
67 if (!dwm_key_->StartWatching(base::Bind( 101 if (!dwm_key_->StartWatching(base::Bind(
68 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this)))) 102 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this))))
69 dwm_key_.reset(); 103 dwm_key_.reset();
70 } 104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698