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

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: remove default 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 "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"
14 #include "ui/gfx/geometry/safe_integer_conversions.h"
13 15
14 ThemeServiceWin::ThemeServiceWin() { 16 ThemeServiceWin::ThemeServiceWin() {
15 // This just checks for Windows 10 instead of calling ShouldUseDwmFrameColor() 17 // 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 18 // 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 19 // use, so that it will be correct if at any time the user switches to the
18 // native frame. 20 // native frame.
19 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { 21 if (base::win::GetVersion() >= base::win::VERSION_WIN10) {
20 dwm_key_.reset(new base::win::RegKey( 22 dwm_key_.reset(new base::win::RegKey(
21 HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\DWM", KEY_READ)); 23 HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\DWM", KEY_READ));
22 if (dwm_key_->Valid()) 24 if (dwm_key_->Valid())
23 OnDwmKeyUpdated(); 25 OnDwmKeyUpdated();
24 else 26 else
25 dwm_key_.reset(); 27 dwm_key_.reset();
26 } 28 }
27 } 29 }
28 30
29 ThemeServiceWin::~ThemeServiceWin() { 31 ThemeServiceWin::~ThemeServiceWin() {
30 } 32 }
31 33
32 bool ThemeServiceWin::ShouldUseNativeFrame() const { 34 bool ThemeServiceWin::ShouldUseNativeFrame() const {
33 return !HasCustomImage(IDR_THEME_FRAME) && ui::win::IsAeroGlassEnabled(); 35 return !HasCustomImage(IDR_THEME_FRAME) && ui::win::IsAeroGlassEnabled();
34 } 36 }
35 37
36 SkColor ThemeServiceWin::GetDefaultColor(int id, bool incognito) const { 38 SkColor ThemeServiceWin::GetDefaultColor(int id, bool incognito) const {
37 if (ShouldUseDwmFrameColor()) { 39 if (ShouldUseDwmFrameColor()) {
38 // Active native windows on Windows 10 may have a custom frame color. 40 // Active native windows on Windows 10 may have a custom frame color.
39 if (id == ThemeProperties::COLOR_FRAME) 41 if (id == ThemeProperties::COLOR_FRAME)
40 return dwm_frame_color_; 42 return dwm_frame_color_;
41 43
44 if (id == ThemeProperties::COLOR_ACCENT_BORDER)
45 return dwm_accent_border_color_;
46
42 // Inactive native windows on Windows 10 always have a white frame. 47 // Inactive native windows on Windows 10 always have a white frame.
43 if (id == ThemeProperties::COLOR_FRAME_INACTIVE) 48 if (id == ThemeProperties::COLOR_FRAME_INACTIVE)
44 return SK_ColorWHITE; 49 return SK_ColorWHITE;
45 } 50 }
46 51
47 return ThemeService::GetDefaultColor(id, incognito); 52 return ThemeService::GetDefaultColor(id, incognito);
48 } 53 }
49 54
50 bool ThemeServiceWin::ShouldUseDwmFrameColor() const { 55 bool ThemeServiceWin::ShouldUseDwmFrameColor() const {
51 return ShouldUseNativeFrame() && 56 return ShouldUseNativeFrame() &&
52 (base::win::GetVersion() >= base::win::VERSION_WIN10); 57 (base::win::GetVersion() >= base::win::VERSION_WIN10);
53 } 58 }
54 59
55 void ThemeServiceWin::OnDwmKeyUpdated() { 60 void ThemeServiceWin::OnDwmKeyUpdated() {
56 // Attempt to read the accent color. 61 // Attempt to read the accent color.
57 DWORD accent_color, color_prevalence; 62 DWORD accent_color, color_prevalence;
58 dwm_frame_color_ = 63 dwm_frame_color_ =
59 ((dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) == 64 ((dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) ==
60 ERROR_SUCCESS) && 65 ERROR_SUCCESS) &&
61 (color_prevalence == 1) && 66 (color_prevalence == 1) &&
62 (dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS)) 67 (dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS))
63 ? skia::COLORREFToSkColor(accent_color) 68 ? skia::COLORREFToSkColor(accent_color)
64 : SK_ColorWHITE; 69 : SK_ColorWHITE;
65 70
71 dwm_accent_border_color_ = SK_ColorWHITE;
72 DWORD colorization_color, colorization_color_balance;
73 if ((dwm_key_->ReadValueDW(L"ColorizationColor", &colorization_color) ==
74 ERROR_SUCCESS) &&
75 (dwm_key_->ReadValueDW(L"ColorizationColorBalance",
76 &colorization_color_balance) == ERROR_SUCCESS)) {
77 // The accent border color is a linear blend between the colorization
78 // color and the neutral #d9d9d9. colorization_color_balance is the
79 // percentage of the colorization color in that blend.
80 //
81 // On Windows version 1611 colorization_color_balance can be 0xfffffff3 if
82 // the accent color is taken from the background and either the background
83 // is a solid color or was just changed to a slideshow. It's unclear what
84 // that value's supposed to mean, so change it to 80 to match Edge's
85 // behavior.
86 if (colorization_color_balance > 100)
87 colorization_color_balance = 80;
88
89 // colorization_color's high byte is not an alpha value, so replace it
90 // with 0xff to make an opaque ARGB color.
91 SkColor input_color = SkColorSetA(colorization_color, 0xff);
92
93 dwm_accent_border_color_ = color_utils::AlphaBlend(
94 input_color, SkColorSetRGB(0xd9, 0xd9, 0xd9),
95 gfx::ToRoundedInt(255 * colorization_color_balance / 100.f));
96 }
97
66 // Watch for future changes. 98 // Watch for future changes.
67 if (!dwm_key_->StartWatching(base::Bind( 99 if (!dwm_key_->StartWatching(base::Bind(
68 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this)))) 100 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this))))
69 dwm_key_.reset(); 101 dwm_key_.reset();
70 } 102 }
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_service_win.h ('k') | chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698