OLD | NEW |
---|---|
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/win/windows_version.h" | 8 #include "base/win/windows_version.h" |
9 #include "chrome/browser/themes/theme_properties.h" | 9 #include "chrome/browser/themes/theme_properties.h" |
10 #include "chrome/browser/win/titlebar_config.h" | 10 #include "chrome/browser/win/titlebar_config.h" |
11 #include "chrome/grit/theme_resources.h" | 11 #include "chrome/grit/theme_resources.h" |
12 #include "skia/ext/skia_utils_win.h" | 12 #include "skia/ext/skia_utils_win.h" |
13 #include "ui/base/win/shell.h" | 13 #include "ui/base/win/shell.h" |
14 #include "ui/gfx/color_utils.h" | 14 #include "ui/gfx/color_utils.h" |
15 #include "ui/gfx/geometry/safe_integer_conversions.h" | 15 #include "ui/gfx/geometry/safe_integer_conversions.h" |
16 | 16 |
17 ThemeServiceWin::ThemeServiceWin() { | 17 ThemeServiceWin::ThemeServiceWin() { |
18 // This just checks for Windows 10 instead of calling ShouldUseDwmFrameColor() | 18 // This just checks for Windows 10 instead of calling DwmColorsAllowed() |
19 // 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 |
20 // 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 |
21 // native frame. | 21 // native frame. |
22 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { | 22 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { |
23 dwm_key_.reset(new base::win::RegKey( | 23 dwm_key_.reset(new base::win::RegKey( |
24 HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\DWM", KEY_READ)); | 24 HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\DWM", KEY_READ)); |
25 if (dwm_key_->Valid()) | 25 if (dwm_key_->Valid()) |
26 OnDwmKeyUpdated(); | 26 OnDwmKeyUpdated(); |
27 else | 27 else |
28 dwm_key_.reset(); | 28 dwm_key_.reset(); |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 ThemeServiceWin::~ThemeServiceWin() { | 32 ThemeServiceWin::~ThemeServiceWin() { |
33 } | 33 } |
34 | 34 |
35 bool ThemeServiceWin::ShouldUseNativeFrame() const { | 35 bool ThemeServiceWin::ShouldUseNativeFrame() const { |
36 const bool use_native_frame_if_enabled = | 36 const bool use_native_frame_if_enabled = |
37 ShouldCustomDrawSystemTitlebar() || !HasCustomImage(IDR_THEME_FRAME); | 37 ShouldCustomDrawSystemTitlebar() || !HasCustomImage(IDR_THEME_FRAME); |
38 return use_native_frame_if_enabled && ui::win::IsAeroGlassEnabled(); | 38 return use_native_frame_if_enabled && ui::win::IsAeroGlassEnabled(); |
39 } | 39 } |
40 | 40 |
41 SkColor ThemeServiceWin::GetDefaultColor(int id, bool incognito) const { | 41 SkColor ThemeServiceWin::GetDefaultColor(int id, bool incognito) const { |
42 if (ShouldUseDwmFrameColor()) { | 42 if (DwmColorsAllowed()) { |
43 // Active native windows on Windows 10 may have a custom frame color. | |
44 if (id == ThemeProperties::COLOR_FRAME) | |
45 return dwm_frame_color_; | |
46 | |
47 if (id == ThemeProperties::COLOR_ACCENT_BORDER) | 43 if (id == ThemeProperties::COLOR_ACCENT_BORDER) |
48 return dwm_accent_border_color_; | 44 return dwm_accent_border_color_; |
49 | 45 |
50 // Inactive native windows on Windows 10 always have a white frame. | 46 if (use_dwm_frame_color_) { |
51 if (id == ThemeProperties::COLOR_FRAME_INACTIVE) | 47 // Incognito frame is the same as normal when we're using DWM colors. |
52 return SK_ColorWHITE; | 48 if (id == ThemeProperties::COLOR_FRAME) |
49 return dwm_frame_color_; | |
50 if (id == ThemeProperties::COLOR_FRAME_INACTIVE) | |
51 return dwm_inactive_frame_color_; | |
52 } | |
53 } | 53 } |
54 | 54 |
55 return ThemeService::GetDefaultColor(id, incognito); | 55 return ThemeService::GetDefaultColor(id, incognito); |
56 } | 56 } |
57 | 57 |
58 bool ThemeServiceWin::ShouldUseDwmFrameColor() const { | 58 bool ThemeServiceWin::DwmColorsAllowed() const { |
59 return ShouldUseNativeFrame() && | 59 return ShouldUseNativeFrame() && |
60 (base::win::GetVersion() >= base::win::VERSION_WIN10); | 60 (base::win::GetVersion() >= base::win::VERSION_WIN10); |
61 } | 61 } |
62 | 62 |
63 void ThemeServiceWin::OnDwmKeyUpdated() { | 63 void ThemeServiceWin::OnDwmKeyUpdated() { |
64 // Attempt to read the accent color. | |
65 DWORD accent_color, color_prevalence; | 64 DWORD accent_color, color_prevalence; |
66 dwm_frame_color_ = | 65 use_dwm_frame_color_ = |
67 ((dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) == | 66 dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS && |
68 ERROR_SUCCESS) && | 67 dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) == |
69 (color_prevalence == 1) && | 68 ERROR_SUCCESS && |
70 (dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS)) | 69 color_prevalence == 1; |
71 ? skia::COLORREFToSkColor(accent_color) | 70 if (use_dwm_frame_color_) { |
72 : SK_ColorWHITE; | 71 dwm_frame_color_ = skia::COLORREFToSkColor(accent_color); |
72 DWORD accent_color_inactive; | |
73 if (dwm_key_->ReadValueDW(L"AccentColorInactive", &accent_color_inactive) == | |
74 ERROR_SUCCESS) { | |
75 dwm_inactive_frame_color_ = | |
76 skia::COLORREFToSkColor(accent_color_inactive); | |
77 } else { | |
78 // 20% active color/80% white blend to create the inactive color. | |
79 dwm_inactive_frame_color_ = | |
80 color_utils::AlphaBlend(dwm_frame_color_, SK_ColorWHITE, 0x33); | |
Peter Kasting
2016/12/01 06:19:04
Nit: If you wint up preserving this, consider shif
Bret
2016/12/08 00:16:07
Done.
| |
81 } | |
82 } | |
73 | 83 |
74 dwm_accent_border_color_ = SK_ColorWHITE; | 84 dwm_accent_border_color_ = SK_ColorWHITE; |
75 DWORD colorization_color, colorization_color_balance; | 85 DWORD colorization_color, colorization_color_balance; |
76 if ((dwm_key_->ReadValueDW(L"ColorizationColor", &colorization_color) == | 86 if ((dwm_key_->ReadValueDW(L"ColorizationColor", &colorization_color) == |
77 ERROR_SUCCESS) && | 87 ERROR_SUCCESS) && |
78 (dwm_key_->ReadValueDW(L"ColorizationColorBalance", | 88 (dwm_key_->ReadValueDW(L"ColorizationColorBalance", |
79 &colorization_color_balance) == ERROR_SUCCESS)) { | 89 &colorization_color_balance) == ERROR_SUCCESS)) { |
80 // The accent border color is a linear blend between the colorization | 90 // The accent border color is a linear blend between the colorization |
81 // color and the neutral #d9d9d9. colorization_color_balance is the | 91 // color and the neutral #d9d9d9. colorization_color_balance is the |
82 // percentage of the colorization color in that blend. | 92 // percentage of the colorization color in that blend. |
(...skipping 13 matching lines...) Expand all Loading... | |
96 dwm_accent_border_color_ = color_utils::AlphaBlend( | 106 dwm_accent_border_color_ = color_utils::AlphaBlend( |
97 input_color, SkColorSetRGB(0xd9, 0xd9, 0xd9), | 107 input_color, SkColorSetRGB(0xd9, 0xd9, 0xd9), |
98 gfx::ToRoundedInt(255 * colorization_color_balance / 100.f)); | 108 gfx::ToRoundedInt(255 * colorization_color_balance / 100.f)); |
99 } | 109 } |
100 | 110 |
101 // Watch for future changes. | 111 // Watch for future changes. |
102 if (!dwm_key_->StartWatching(base::Bind( | 112 if (!dwm_key_->StartWatching(base::Bind( |
103 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this)))) | 113 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this)))) |
104 dwm_key_.reset(); | 114 dwm_key_.reset(); |
105 } | 115 } |
OLD | NEW |