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" |
(...skipping 25 matching lines...) Expand all Loading... | |
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 (DwmColorsAllowed()) { | 42 if (DwmColorsAllowed()) { |
43 if (id == ThemeProperties::COLOR_ACCENT_BORDER) | 43 if (id == ThemeProperties::COLOR_ACCENT_BORDER) |
44 return dwm_accent_border_color_; | 44 return dwm_accent_border_color_; |
45 | 45 |
46 if (use_dwm_frame_color_) { | 46 // When we're custom-drawing the titlebar we want to use either the colors |
47 // Incognito frame is the same as normal when we're using DWM colors. | 47 // we calculated in OnDwmKeyUpdated() or the default colors. When we're not |
48 if (id == ThemeProperties::COLOR_FRAME) | 48 // custom-drawing the titlebar we want to match the color Windows actually |
49 // uses because some things (like the incognito icon) use this color to | |
50 // decide whether they should draw in light or dark mode. Incognito colors | |
51 // should be the same as non-incognito in all cases here. | |
52 if (id == ThemeProperties::COLOR_FRAME) { | |
53 if (use_dwm_frame_color_) | |
49 return dwm_frame_color_; | 54 return dwm_frame_color_; |
50 if (id == ThemeProperties::COLOR_FRAME_INACTIVE) | 55 if (!ShouldCustomDrawSystemTitlebar()) |
56 return SK_ColorWHITE; | |
57 // Fallthrough and use default. | |
Evan Stade
2016/12/29 16:34:07
nit: "Fall through"
Bret
2017/01/03 22:49:53
Done.
| |
58 } | |
59 if (id == ThemeProperties::COLOR_FRAME_INACTIVE) { | |
60 if (!ShouldCustomDrawSystemTitlebar()) { | |
61 if (inactive_frame_color_from_registry_) | |
Evan Stade
2016/12/29 16:34:07
nit: ternary?
Bret
2017/01/03 22:49:53
Done.
| |
62 return dwm_inactive_frame_color_; | |
63 return SK_ColorWHITE; | |
64 } | |
65 if (use_dwm_frame_color_) | |
51 return dwm_inactive_frame_color_; | 66 return dwm_inactive_frame_color_; |
67 // Fallthrough and use default. | |
52 } | 68 } |
53 } | 69 } |
54 | 70 |
55 return ThemeService::GetDefaultColor(id, incognito); | 71 return ThemeService::GetDefaultColor(id, incognito); |
56 } | 72 } |
57 | 73 |
58 bool ThemeServiceWin::DwmColorsAllowed() const { | 74 bool ThemeServiceWin::DwmColorsAllowed() const { |
59 return ShouldUseNativeFrame() && | 75 return ShouldUseNativeFrame() && |
60 (base::win::GetVersion() >= base::win::VERSION_WIN10); | 76 (base::win::GetVersion() >= base::win::VERSION_WIN10); |
61 } | 77 } |
62 | 78 |
63 void ThemeServiceWin::OnDwmKeyUpdated() { | 79 void ThemeServiceWin::OnDwmKeyUpdated() { |
64 DWORD accent_color, color_prevalence; | 80 DWORD accent_color, color_prevalence; |
65 use_dwm_frame_color_ = | 81 use_dwm_frame_color_ = |
Evan Stade
2016/12/29 16:34:07
can we use base::Optional for dwm_frame_color_ (an
Bret
2017/01/03 22:49:52
I made this change and it helps a little bit. But
| |
66 dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS && | 82 dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS && |
67 dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) == | 83 dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) == |
68 ERROR_SUCCESS && | 84 ERROR_SUCCESS && |
69 color_prevalence == 1; | 85 color_prevalence == 1; |
86 inactive_frame_color_from_registry_ = false; | |
70 if (use_dwm_frame_color_) { | 87 if (use_dwm_frame_color_) { |
71 dwm_frame_color_ = skia::COLORREFToSkColor(accent_color); | 88 dwm_frame_color_ = skia::COLORREFToSkColor(accent_color); |
72 DWORD accent_color_inactive; | 89 DWORD accent_color_inactive; |
73 if (dwm_key_->ReadValueDW(L"AccentColorInactive", &accent_color_inactive) == | 90 if (dwm_key_->ReadValueDW(L"AccentColorInactive", &accent_color_inactive) == |
74 ERROR_SUCCESS) { | 91 ERROR_SUCCESS) { |
75 dwm_inactive_frame_color_ = | 92 dwm_inactive_frame_color_ = |
76 skia::COLORREFToSkColor(accent_color_inactive); | 93 skia::COLORREFToSkColor(accent_color_inactive); |
94 inactive_frame_color_from_registry_ = true; | |
77 } else { | 95 } else { |
78 // Tint to create inactive color. Always use the non-incognito version of | 96 // Tint to create inactive color. Always use the non-incognito version of |
79 // the tint, since the frame should look the same in both modes. | 97 // the tint, since the frame should look the same in both modes. |
80 dwm_inactive_frame_color_ = color_utils::HSLShift( | 98 dwm_inactive_frame_color_ = color_utils::HSLShift( |
81 dwm_frame_color_, | 99 dwm_frame_color_, |
82 GetTint(ThemeProperties::TINT_FRAME_INACTIVE, false)); | 100 GetTint(ThemeProperties::TINT_FRAME_INACTIVE, false)); |
83 } | 101 } |
84 } | 102 } |
85 | 103 |
86 dwm_accent_border_color_ = SK_ColorWHITE; | 104 dwm_accent_border_color_ = SK_ColorWHITE; |
(...skipping 21 matching lines...) Expand all Loading... | |
108 dwm_accent_border_color_ = color_utils::AlphaBlend( | 126 dwm_accent_border_color_ = color_utils::AlphaBlend( |
109 input_color, SkColorSetRGB(0xd9, 0xd9, 0xd9), | 127 input_color, SkColorSetRGB(0xd9, 0xd9, 0xd9), |
110 gfx::ToRoundedInt(255 * colorization_color_balance / 100.f)); | 128 gfx::ToRoundedInt(255 * colorization_color_balance / 100.f)); |
111 } | 129 } |
112 | 130 |
113 // Watch for future changes. | 131 // Watch for future changes. |
114 if (!dwm_key_->StartWatching(base::Bind( | 132 if (!dwm_key_->StartWatching(base::Bind( |
115 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this)))) | 133 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this)))) |
116 dwm_key_.reset(); | 134 dwm_key_.reset(); |
117 } | 135 } |
OLD | NEW |