Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/themes/theme_service_win.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/win/windows_version.h" | |
| 9 #include "chrome/browser/themes/theme_properties.h" | |
| 10 #include "grit/theme_resources.h" | |
| 11 #include "skia/ext/skia_utils_win.h" | |
| 12 #include "ui/base/win/shell.h" | |
| 13 | |
| 14 ThemeServiceWin::ThemeServiceWin() { | |
|
Evan Stade
2016/03/03 01:24:25
init dwm_frame_color_?
Peter Kasting
2016/03/03 09:23:06
There's no need, since the code in the conditional
Evan Stade
2016/03/03 18:17:19
yes, but we run static analysis tools that don't k
| |
| 15 // 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 // use, so that it will be correct if at any time the user switches to the | |
| 18 // native frame. | |
| 19 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { | |
| 20 dwm_key_.reset(new base::win::RegKey( | |
| 21 HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\DWM", KEY_READ)); | |
| 22 OnDwmKeyUpdated(); | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 ThemeServiceWin::~ThemeServiceWin() { | |
| 27 } | |
| 28 | |
| 29 bool ThemeServiceWin::ShouldUseNativeFrame() const { | |
| 30 return !HasCustomImage(IDR_THEME_FRAME) && ui::win::IsAeroGlassEnabled(); | |
| 31 } | |
| 32 | |
| 33 SkColor ThemeServiceWin::GetDefaultColor(int id, bool incognito) const { | |
| 34 if (ShouldUseDwmFrameColor()) { | |
| 35 switch (id) { | |
| 36 // Active native windows on Windows 10 may have a custom frame color. | |
| 37 case ThemeProperties::COLOR_FRAME: | |
|
Bret
2016/03/02 22:54:03
i still think "frame" is a confusing name for this
Peter Kasting
2016/03/03 09:23:06
I understand where you're coming from.
That said,
| |
| 38 case ThemeProperties::COLOR_FRAME_INCOGNITO: | |
|
Evan Stade
2016/03/03 01:24:25
I don't think you can hit this (or the other incog
Peter Kasting
2016/03/03 09:23:06
You're right. I misread the original code before
| |
| 39 return dwm_frame_color_; | |
| 40 | |
| 41 // Inactive native windows on Windows 10 always have a white frame. | |
| 42 case ThemeProperties::COLOR_FRAME_INACTIVE: | |
| 43 case ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE: | |
| 44 return SK_ColorWHITE; | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 return ThemeService::GetDefaultColor(id, incognito); | |
| 49 } | |
| 50 | |
| 51 bool ThemeServiceWin::ShouldUseDwmFrameColor() const { | |
| 52 return ShouldUseNativeFrame() && | |
| 53 (base::win::GetVersion() >= base::win::VERSION_WIN10); | |
| 54 } | |
| 55 | |
| 56 void ThemeServiceWin::OnDwmKeyUpdated() { | |
| 57 // Attempt to read the accent color. | |
| 58 DWORD accent_color, color_prevalence; | |
| 59 dwm_frame_color_ = | |
| 60 ((dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) == | |
| 61 ERROR_SUCCESS) && | |
| 62 (color_prevalence == 1) && | |
| 63 (dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS)) | |
| 64 ? skia::COLORREFToSkColor(accent_color) | |
| 65 : SK_ColorWHITE; | |
| 66 | |
| 67 // Watch for future changes. | |
| 68 if (!dwm_key_->StartWatching(base::Bind( | |
| 69 &ThemeServiceWin::OnDwmKeyUpdated, base::Unretained(this)))) | |
| 70 dwm_key_.reset(); | |
| 71 } | |
| OLD | NEW |