Bug 1839526 [wpt PR 40658] - Update wpt metadata, a=testonly
[gecko.git] / layout / style / PreferenceSheet.h
blob3b3c2f70b7259d0fa6dc1a53854d19b51abd8b5e
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Some prefable colors for style system use */
9 #ifndef mozilla_ColorPreferences_h
10 #define mozilla_ColorPreferences_h
12 #include "nsColor.h"
13 #include "mozilla/ColorScheme.h"
15 namespace mozilla {
17 namespace dom {
18 class Document;
21 struct PreferenceSheet {
22 struct Prefs {
23 struct Colors {
24 nscolor mLink = NS_RGB(0x00, 0x00, 0xEE);
25 nscolor mActiveLink = NS_RGB(0xEE, 0x00, 0x00);
26 nscolor mVisitedLink = NS_RGB(0x55, 0x1A, 0x8B);
28 nscolor mDefault = NS_RGB(0, 0, 0);
29 nscolor mDefaultBackground = NS_RGB(0xFF, 0xFF, 0xFF);
31 nscolor mFocusText = mDefault;
32 nscolor mFocusBackground = mDefaultBackground;
33 } mLightColors, mDarkColors;
35 const Colors& ColorsFor(ColorScheme aScheme) const {
36 return mMustUseLightColorSet || aScheme == ColorScheme::Light
37 ? mLightColors
38 : mDarkColors;
41 bool mIsChrome = false;
42 bool mUseAccessibilityTheme = false;
43 bool mUseDocumentColors = true;
44 bool mUsePrefColors = false;
45 bool mUseStandins = false;
46 bool mMustUseLightColorSet = false;
48 // Sometimes we can force a color scheme on a document, or honor the
49 // preferred color-scheme in more cases, depending on whether we're forcing
50 // colors or not.
51 enum class ColorSchemeChoice : uint8_t {
52 // We're not forcing colors, use standard algorithm based on specified
53 // style and meta tags and so on.
54 Standard,
55 // We can honor whatever the preferred color-scheme for the document is
56 // (the preferred color-scheme of the user, since we're forcing colors).
57 UserPreferred,
58 Light,
59 Dark,
62 ColorSchemeChoice mColorSchemeChoice = ColorSchemeChoice::Standard;
64 // Whether the non-native theme should use real system colors for widgets.
65 bool NonNativeThemeShouldBeHighContrast() const;
67 void Load(bool aIsChrome);
68 void LoadColors(bool aIsLight);
71 static void EnsureInitialized() {
72 if (sInitialized) {
73 return;
75 Initialize();
78 static void Refresh() {
79 sInitialized = false;
80 Initialize();
83 static bool AffectedByPref(const nsACString&);
85 static Prefs& ContentPrefs() {
86 MOZ_ASSERT(sInitialized);
87 return sContentPrefs;
90 static Prefs& ChromePrefs() {
91 MOZ_ASSERT(sInitialized);
92 return sChromePrefs;
95 static Prefs& PrintPrefs() {
96 MOZ_ASSERT(sInitialized);
97 return sPrintPrefs;
100 enum class PrefsKind {
101 Chrome,
102 Print,
103 Content,
106 static PrefsKind PrefsKindFor(const dom::Document&);
108 static bool ShouldUseChromePrefs(const dom::Document& aDocument) {
109 return PrefsKindFor(aDocument) == PrefsKind::Chrome;
112 static bool MayForceColors() { return !ContentPrefs().mUseDocumentColors; }
114 static const Prefs& PrefsFor(const dom::Document& aDocument) {
115 switch (PrefsKindFor(aDocument)) {
116 case PrefsKind::Chrome:
117 return ChromePrefs();
118 case PrefsKind::Print:
119 return PrintPrefs();
120 case PrefsKind::Content:
121 break;
123 return ContentPrefs();
126 private:
127 static bool sInitialized;
128 static Prefs sChromePrefs;
129 static Prefs sPrintPrefs;
130 static Prefs sContentPrefs;
132 static void Initialize();
135 } // namespace mozilla
137 #endif