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

Side by Side Diff: chrome/browser/themes/theme_service_win.cc

Issue 2605443002: Ensure UI elements contrast with the right frame color. (Closed)
Patch Set: use optional Created 3 years, 11 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
« no previous file with comments | « chrome/browser/themes/theme_service_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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 return dwm_frame_color_; 49 // uses because some things (like the incognito icon) use this color to
50 if (id == ThemeProperties::COLOR_FRAME_INACTIVE) 50 // decide whether they should draw in light or dark mode. Incognito colors
51 return dwm_inactive_frame_color_; 51 // should be the same as non-incognito in all cases here.
52 if (id == ThemeProperties::COLOR_FRAME) {
53 if (dwm_frame_color_)
54 return dwm_frame_color_.value();
55 if (!ShouldCustomDrawSystemTitlebar())
56 return SK_ColorWHITE;
57 // Fall through and use default.
58 }
59 if (id == ThemeProperties::COLOR_FRAME_INACTIVE) {
60 if (!ShouldCustomDrawSystemTitlebar()) {
61 return inactive_frame_color_from_registry_
62 ? dwm_inactive_frame_color_.value()
63 : SK_ColorWHITE;
64 }
65 if (dwm_inactive_frame_color_)
66 return dwm_inactive_frame_color_.value();
67 // Fall through 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 bool use_dwm_frame_color =
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;
70 if (use_dwm_frame_color_) { 86 inactive_frame_color_from_registry_ = false;
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_.value(),
82 GetTint(ThemeProperties::TINT_FRAME_INACTIVE, false)); 100 GetTint(ThemeProperties::TINT_FRAME_INACTIVE, false));
83 } 101 }
102 } else {
103 dwm_frame_color_.reset();
104 dwm_inactive_frame_color_.reset();
84 } 105 }
85 106
86 dwm_accent_border_color_ = SK_ColorWHITE; 107 dwm_accent_border_color_ = SK_ColorWHITE;
87 DWORD colorization_color, colorization_color_balance; 108 DWORD colorization_color, colorization_color_balance;
88 if ((dwm_key_->ReadValueDW(L"ColorizationColor", &colorization_color) == 109 if ((dwm_key_->ReadValueDW(L"ColorizationColor", &colorization_color) ==
89 ERROR_SUCCESS) && 110 ERROR_SUCCESS) &&
90 (dwm_key_->ReadValueDW(L"ColorizationColorBalance", 111 (dwm_key_->ReadValueDW(L"ColorizationColorBalance",
91 &colorization_color_balance) == ERROR_SUCCESS)) { 112 &colorization_color_balance) == ERROR_SUCCESS)) {
92 // The accent border color is a linear blend between the colorization 113 // The accent border color is a linear blend between the colorization
93 // color and the neutral #d9d9d9. colorization_color_balance is the 114 // color and the neutral #d9d9d9. colorization_color_balance is the
(...skipping 14 matching lines...) Expand all
108 dwm_accent_border_color_ = color_utils::AlphaBlend( 129 dwm_accent_border_color_ = color_utils::AlphaBlend(
109 input_color, SkColorSetRGB(0xd9, 0xd9, 0xd9), 130 input_color, SkColorSetRGB(0xd9, 0xd9, 0xd9),
110 gfx::ToRoundedInt(255 * colorization_color_balance / 100.f)); 131 gfx::ToRoundedInt(255 * colorization_color_balance / 100.f));
111 } 132 }
112 133
113 // Watch for future changes. 134 // Watch for future changes.
114 if (!dwm_key_->StartWatching(base::Bind( 135 if (!dwm_key_->StartWatching(base::Bind(
115 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this)))) 136 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this))))
116 dwm_key_.reset(); 137 dwm_key_.reset();
117 } 138 }
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_service_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698