
[Detail] This change pumps system accent color for CSS property "accent-color" and AccentColor Keyword on Windows. Currently Chromium uses "AccentColorObserver" to get the system accent color from Windows using RegKey-"HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM". This change repurposes the observer to update NativeTheme instance for Web, which in turn sets `user-color` in ThemeHelper. With these changes enables the OS-defined accent color on Window to be used by: - HTML form elements that support CSS property-"accent-color" and set to use default system accent color - System color keyword - "AccentColor". This change also respects accent-color for Forced Color mode and do not override with user's selection [NOTE]: All these changes are behind "CssSystemAccentColor" runtime feature flag. And this flag is currently in "Experiment" due to fingerprint risk of using OS-defined accent color via System color keyword - "AccentColor". Refer to this CSSWG issue for more details: https://github.com/w3c/csswg-drafts/issues/10372 Bug: 40764875 Change-Id: I081bed37a483a984fc7c72c3a92f1373476799d6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5763388 Reviewed-by: Sam Davis Omekara <samomekarajr@microsoft.com> Reviewed-by: Thomas Lukaszewicz <tluk@chromium.org> Reviewed-by: Joey Arhar <jarhar@chromium.org> Commit-Queue: Priya Palanisamy <priyapal@microsoft.com> Reviewed-by: Alison Maher <almaher@microsoft.com> Reviewed-by: Avi Drissman <avi@chromium.org> Cr-Commit-Position: refs/heads/main@{#1337989}
58 lines
1.8 KiB
C++
58 lines
1.8 KiB
C++
// Copyright 2019 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "content/browser/theme_helper.h"
|
|
|
|
#include "base/no_destructor.h"
|
|
#include "build/build_config.h"
|
|
#include "content/browser/renderer_host/render_process_host_impl.h"
|
|
#include "content/common/renderer.mojom.h"
|
|
|
|
namespace content {
|
|
|
|
// static
|
|
ThemeHelper* ThemeHelper::GetInstance() {
|
|
static base::NoDestructor<ThemeHelper> s_theme_helper;
|
|
return s_theme_helper.get();
|
|
}
|
|
|
|
ThemeHelper::ThemeHelper() : theme_observation_(this) {
|
|
theme_observation_.Observe(ui::NativeTheme::GetInstanceForWeb());
|
|
}
|
|
|
|
ThemeHelper::~ThemeHelper() {}
|
|
|
|
mojom::UpdateSystemColorInfoParamsPtr MakeUpdateSystemColorInfoParams(
|
|
ui::NativeTheme* native_theme) {
|
|
mojom::UpdateSystemColorInfoParamsPtr params =
|
|
mojom::UpdateSystemColorInfoParams::New();
|
|
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN)
|
|
params->accent_color = native_theme->user_color();
|
|
#endif
|
|
|
|
return params;
|
|
}
|
|
|
|
void ThemeHelper::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
|
|
DCHECK(theme_observation_.IsObservingSource(observed_theme));
|
|
|
|
mojom::UpdateSystemColorInfoParamsPtr params =
|
|
MakeUpdateSystemColorInfoParams(observed_theme);
|
|
for (auto iter = RenderProcessHost::AllHostsIterator(); !iter.IsAtEnd();
|
|
iter.Advance()) {
|
|
if (iter.GetCurrentValue()->IsInitializedAndNotDead()) {
|
|
iter.GetCurrentValue()->GetRendererInterface()->UpdateSystemColorInfo(
|
|
params->Clone());
|
|
}
|
|
}
|
|
}
|
|
|
|
void ThemeHelper::SendSystemColorInfo(mojom::Renderer* renderer) const {
|
|
mojom::UpdateSystemColorInfoParamsPtr params =
|
|
MakeUpdateSystemColorInfoParams(ui::NativeTheme::GetInstanceForWeb());
|
|
renderer->UpdateSystemColorInfo(std::move(params));
|
|
}
|
|
|
|
} // namespace content
|