blob: 3d0101361be4841a74bfbe1f4c550c47c64c35aa [file] [log] [blame]
[email protected]990e6222012-11-16 13:31:181// Copyright (c) 2012 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 "ui/native_theme/native_theme.h"
6
varkhaef6637f2016-02-26 22:12:277#include <cstring>
8
Findit72e2f8a2019-06-29 00:07:589#include "base/bind.h"
Leonard Greye66472c2018-10-16 16:19:4910#include "base/command_line.h"
11#include "ui/base/ui_base_switches.h"
Findit72e2f8a2019-06-29 00:07:5812#include "ui/native_theme/dark_mode_observer.h"
13#include "ui/native_theme/native_theme_observer.h"
[email protected]f58e31c52014-04-25 20:20:0714
[email protected]a673f352012-11-20 00:52:2915namespace ui {
[email protected]990e6222012-11-16 13:31:1816
varkhaef6637f2016-02-26 22:12:2717NativeTheme::ExtraParams::ExtraParams() {
18 memset(this, 0, sizeof(*this));
19}
20
vmpstrbf0d713a2016-03-24 20:22:5421NativeTheme::ExtraParams::ExtraParams(const ExtraParams& other) {
22 memcpy(this, &other, sizeof(*this));
23}
24
[email protected]f58e31c52014-04-25 20:20:0725void NativeTheme::AddObserver(NativeThemeObserver* observer) {
26 native_theme_observers_.AddObserver(observer);
27}
28
29void NativeTheme::RemoveObserver(NativeThemeObserver* observer) {
30 native_theme_observers_.RemoveObserver(observer);
31}
32
33void NativeTheme::NotifyObservers() {
ericwilligers44bb4272016-10-19 00:15:2434 for (NativeThemeObserver& observer : native_theme_observers_)
35 observer.OnNativeThemeUpdated(this);
[email protected]f58e31c52014-04-25 20:20:0736}
37
[email protected]a673f352012-11-20 00:52:2938NativeTheme::NativeTheme()
Evan Stade89ccf1d2019-06-04 22:38:5239 : is_dark_mode_(IsForcedDarkMode()),
Leonard Greyc79e032b02019-04-29 14:52:0540 is_high_contrast_(IsForcedHighContrast()) {}
[email protected]a673f352012-11-20 00:52:2941
Findit72e2f8a2019-06-29 00:07:5842NativeTheme::~NativeTheme() {
43 if (dark_mode_parent_observer_)
44 dark_mode_parent_observer_->Stop();
45}
[email protected]7f98def2012-12-10 22:04:1746
Leonard Greye66472c2018-10-16 16:19:4947bool NativeTheme::SystemDarkModeEnabled() const {
Leonard Greyc79e032b02019-04-29 14:52:0548 return is_dark_mode_;
49}
50
Leonard Grey5be670c2019-06-13 17:56:2951bool NativeTheme::SystemDarkModeSupported() const {
52 return false;
53}
54
Leonard Greyc79e032b02019-04-29 14:52:0555bool NativeTheme::UsesHighContrastColors() const {
56 return is_high_contrast_;
57}
58
59bool NativeTheme::IsForcedDarkMode() const {
60 static bool kIsForcedDarkMode =
61 base::CommandLine::ForCurrentProcess()->HasSwitch(
62 switches::kForceDarkMode);
63 return kIsForcedDarkMode;
64}
65
66bool NativeTheme::IsForcedHighContrast() const {
67 static bool kIsForcedHighContrast =
68 base::CommandLine::ForCurrentProcess()->HasSwitch(
69 switches::kForceHighContrast);
70 return kIsForcedHighContrast;
Leonard Greye66472c2018-10-16 16:19:4971}
72
Evan Liu7cdbf8872019-06-19 16:47:2173base::Optional<CaptionStyle> NativeTheme::GetSystemCaptionStyle() const {
Rahul Singh1862faa92019-03-06 22:41:4374 return CaptionStyle::FromSystemSettings();
Elly Fong-Jonesf92897392019-01-24 16:05:4975}
76
Findit72e2f8a2019-06-29 00:07:5877void NativeTheme::SetDarkModeParent(NativeTheme* dark_mode_parent) {
78 dark_mode_parent_observer_ = std::make_unique<DarkModeObserver>(
79 dark_mode_parent,
80 base::BindRepeating(&NativeTheme::OnParentDarkModeChanged,
81 base::Unretained(this)));
82 dark_mode_parent_observer_->Start();
83}
Leonard Greyfc5624982019-05-01 16:50:1484
Findit72e2f8a2019-06-29 00:07:5885void NativeTheme::OnParentDarkModeChanged(bool is_dark_mode) {
86 set_dark_mode(is_dark_mode);
87 NotifyObservers();
88}
[email protected]990e6222012-11-16 13:31:1889} // namespace ui