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/. */
6 
7 /* Some prefable colors for style system use */
8 
9 #ifndef mozilla_ColorPreferences_h
10 #define mozilla_ColorPreferences_h
11 
12 #include "nsColor.h"
13 #include "mozilla/ColorScheme.h"
14 
15 namespace mozilla {
16 
17 namespace dom {
18 class Document;
19 }
20 
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);
27 
28       nscolor mDefault = NS_RGB(0, 0, 0);
29       nscolor mDefaultBackground = NS_RGB(0xFF, 0xFF, 0xFF);
30 
31       nscolor mFocusText = mDefault;
32       nscolor mFocusBackground = mDefaultBackground;
33     } mLightColors, mDarkColors;
34 
ColorsForPreferenceSheet::Prefs35     const Colors& ColorsFor(ColorScheme aScheme) const {
36       return aScheme == ColorScheme::Light ? mLightColors : mDarkColors;
37     }
38 
39     bool mIsChrome = false;
40     bool mUseAccessibilityTheme = false;
41 
42     bool mUseDocumentColors = true;
43 
44     // Whether the non-native theme should use real system colors for widgets.
45     bool NonNativeThemeShouldBeHighContrast() const;
46 
47     void Load(bool aIsChrome);
48     void LoadColors(bool aIsLight);
49   };
50 
EnsureInitializedPreferenceSheet51   static void EnsureInitialized() {
52     if (sInitialized) {
53       return;
54     }
55     Initialize();
56   }
57 
RefreshPreferenceSheet58   static void Refresh() {
59     sInitialized = false;
60     Initialize();
61   }
62 
63   static bool AffectedByPref(const nsACString&);
64 
ContentPrefsPreferenceSheet65   static Prefs& ContentPrefs() {
66     MOZ_ASSERT(sInitialized);
67     return sContentPrefs;
68   }
69 
ChromePrefsPreferenceSheet70   static Prefs& ChromePrefs() {
71     MOZ_ASSERT(sInitialized);
72     return sChromePrefs;
73   }
74 
PrintPrefsPreferenceSheet75   static Prefs& PrintPrefs() {
76     MOZ_ASSERT(sInitialized);
77     return sPrintPrefs;
78   }
79 
80   enum class PrefsKind {
81     Chrome,
82     Print,
83     Content,
84   };
85 
86   static PrefsKind PrefsKindFor(const dom::Document&);
87 
ShouldUseChromePrefsPreferenceSheet88   static bool ShouldUseChromePrefs(const dom::Document& aDocument) {
89     return PrefsKindFor(aDocument) == PrefsKind::Chrome;
90   }
91 
MayForceColorsPreferenceSheet92   static bool MayForceColors() { return !ContentPrefs().mUseDocumentColors; }
93 
PrefsForPreferenceSheet94   static const Prefs& PrefsFor(const dom::Document& aDocument) {
95     switch (PrefsKindFor(aDocument)) {
96       case PrefsKind::Chrome:
97         return ChromePrefs();
98       case PrefsKind::Print:
99         return PrintPrefs();
100       case PrefsKind::Content:
101         break;
102     }
103     return ContentPrefs();
104   }
105 
106  private:
107   static bool sInitialized;
108   static Prefs sChromePrefs;
109   static Prefs sPrintPrefs;
110   static Prefs sContentPrefs;
111 
112   static void Initialize();
113 };
114 
115 }  // namespace mozilla
116 
117 #endif
118