Chromium Code Reviews| 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/grit/theme_resources.h" | 10 #include "chrome/grit/theme_resources.h" |
| 11 #include "skia/ext/skia_utils_win.h" | 11 #include "skia/ext/skia_utils_win.h" |
| 12 #include "ui/base/win/shell.h" | 12 #include "ui/base/win/shell.h" |
| 13 #include "ui/gfx/color_utils.h" | |
| 13 | 14 |
| 14 ThemeServiceWin::ThemeServiceWin() { | 15 ThemeServiceWin::ThemeServiceWin() { |
| 15 // This just checks for Windows 10 instead of calling ShouldUseDwmFrameColor() | 16 // 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 | 17 // 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 | 18 // use, so that it will be correct if at any time the user switches to the |
| 18 // native frame. | 19 // native frame. |
| 19 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { | 20 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { |
| 20 dwm_key_.reset(new base::win::RegKey( | 21 dwm_key_.reset(new base::win::RegKey( |
| 21 HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\DWM", KEY_READ)); | 22 HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\DWM", KEY_READ)); |
| 22 if (dwm_key_->Valid()) | 23 if (dwm_key_->Valid()) |
| 23 OnDwmKeyUpdated(); | 24 OnDwmKeyUpdated(); |
| 24 else | 25 else |
| 25 dwm_key_.reset(); | 26 dwm_key_.reset(); |
| 26 } | 27 } |
| 27 } | 28 } |
| 28 | 29 |
| 29 ThemeServiceWin::~ThemeServiceWin() { | 30 ThemeServiceWin::~ThemeServiceWin() { |
| 30 } | 31 } |
| 31 | 32 |
| 32 bool ThemeServiceWin::ShouldUseNativeFrame() const { | 33 bool ThemeServiceWin::ShouldUseNativeFrame() const { |
| 33 return !HasCustomImage(IDR_THEME_FRAME) && ui::win::IsAeroGlassEnabled(); | 34 return !HasCustomImage(IDR_THEME_FRAME) && ui::win::IsAeroGlassEnabled(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 SkColor ThemeServiceWin::GetDefaultColor(int id, bool incognito) const { | 37 SkColor ThemeServiceWin::GetDefaultColor(int id, bool incognito) const { |
| 37 if (ShouldUseDwmFrameColor()) { | 38 if (ShouldUseDwmFrameColor()) { |
| 38 // Active native windows on Windows 10 may have a custom frame color. | 39 // Active native windows on Windows 10 may have a custom frame color. |
| 39 if (id == ThemeProperties::COLOR_FRAME) | 40 if (id == ThemeProperties::COLOR_FRAME) |
| 40 return dwm_frame_color_; | 41 return dwm_frame_color_; |
| 41 | 42 |
| 43 if (id == ThemeProperties::COLOR_ACCENT_BORDER) | |
| 44 return dwm_accent_border_color_; | |
| 45 | |
| 42 // Inactive native windows on Windows 10 always have a white frame. | 46 // Inactive native windows on Windows 10 always have a white frame. |
| 43 if (id == ThemeProperties::COLOR_FRAME_INACTIVE) | 47 if (id == ThemeProperties::COLOR_FRAME_INACTIVE) |
| 44 return SK_ColorWHITE; | 48 return SK_ColorWHITE; |
| 45 } | 49 } |
| 46 | 50 |
| 47 return ThemeService::GetDefaultColor(id, incognito); | 51 return ThemeService::GetDefaultColor(id, incognito); |
| 48 } | 52 } |
| 49 | 53 |
| 50 bool ThemeServiceWin::ShouldUseDwmFrameColor() const { | 54 bool ThemeServiceWin::ShouldUseDwmFrameColor() const { |
| 51 return ShouldUseNativeFrame() && | 55 return ShouldUseNativeFrame() && |
| 52 (base::win::GetVersion() >= base::win::VERSION_WIN10); | 56 (base::win::GetVersion() >= base::win::VERSION_WIN10); |
| 53 } | 57 } |
| 54 | 58 |
| 55 void ThemeServiceWin::OnDwmKeyUpdated() { | 59 void ThemeServiceWin::OnDwmKeyUpdated() { |
| 56 // Attempt to read the accent color. | 60 // Attempt to read the accent color. |
| 57 DWORD accent_color, color_prevalence; | 61 DWORD accent_color, color_prevalence; |
| 58 dwm_frame_color_ = | 62 dwm_frame_color_ = |
| 59 ((dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) == | 63 ((dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) == |
| 60 ERROR_SUCCESS) && | 64 ERROR_SUCCESS) && |
| 61 (color_prevalence == 1) && | 65 (color_prevalence == 1) && |
| 62 (dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS)) | 66 (dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS)) |
| 63 ? skia::COLORREFToSkColor(accent_color) | 67 ? skia::COLORREFToSkColor(accent_color) |
| 64 : SK_ColorWHITE; | 68 : SK_ColorWHITE; |
| 65 | 69 |
| 70 dwm_accent_border_color_ = SK_ColorWHITE; | |
| 71 DWORD colorization_color, colorization_color_balance; | |
| 72 if ((dwm_key_->ReadValueDW(L"ColorizationColor", &colorization_color) == | |
|
Peter Kasting
2016/10/11 21:09:34
Does calling DwmGetColorizationColor() get this va
| |
| 73 ERROR_SUCCESS) && | |
| 74 (dwm_key_->ReadValueDW(L"ColorizationColorBalance", | |
| 75 &colorization_color_balance) == ERROR_SUCCESS)) { | |
| 76 // The accent border color is a linear blend between the colorization | |
| 77 // color and the neutral #d9d9d9. colorization_color_balance is the | |
| 78 // percentage of the colorization color in that blend. | |
| 79 // | |
| 80 // On Windows version 1611 colorization_color_balance can be 0xfffffff3 if | |
| 81 // the accent color is taken from the background and either the background | |
| 82 // is a solid color or was just changed to a slideshow. It's unclear what | |
| 83 // that value's supposed to mean, so change it to 80 to match Edge's | |
| 84 // behavior. | |
| 85 if (colorization_color_balance > 100) | |
| 86 colorization_color_balance = 80; | |
| 87 | |
| 88 // colorization_color's high byte can be 0xc4 or 0, so replace it with | |
| 89 // an 0xff alpha to make an opaque color. | |
|
Peter Kasting
2016/10/11 20:01:38
Nit: I would be clearer about the meaning of this
Bret
2016/10/11 20:48:19
Oh oops! You're right, this could be wrong if the
Peter Kasting
2016/10/11 20:56:51
Hmm, that function looks like it assumes 0BGR inst
Bret
2016/10/11 21:10:15
Oh I misread the definition of COLORREFToSkColor.
Peter Kasting
2016/10/11 21:26:26
As noted in my reply to jbauman, I think this is a
| |
| 90 SkColor input_color = SkColorSetA(colorization_color, 0xff); | |
| 91 | |
| 92 dwm_accent_border_color_ = | |
| 93 color_utils::AlphaBlend(input_color, SkColorSetRGB(0xd9, 0xd9, 0xd9), | |
| 94 255 * colorization_color_balance / 100.f); | |
|
Peter Kasting
2016/10/11 20:01:38
This implicitly truncates float to int. Do one of
| |
| 95 } | |
| 96 | |
| 66 // Watch for future changes. | 97 // Watch for future changes. |
| 67 if (!dwm_key_->StartWatching(base::Bind( | 98 if (!dwm_key_->StartWatching(base::Bind( |
| 68 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this)))) | 99 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this)))) |
| 69 dwm_key_.reset(); | 100 dwm_key_.reset(); |
| 70 } | 101 } |
| OLD | NEW |