PreferenceSheet.h (3108B)
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 "mozilla/ColorScheme.h" 13 #include "nsColor.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 } mLightColors, mDarkColors; 31 32 const Colors& ColorsFor(ColorScheme aScheme) const { 33 return mMustUseLightColorSet || aScheme == ColorScheme::Light 34 ? mLightColors 35 : mDarkColors; 36 } 37 38 bool mIsChrome = false; 39 bool mUseAccessibilityTheme = false; 40 bool mUseDocumentColors = true; 41 bool mUsePrefColors = false; 42 bool mUseStandins = false; 43 bool mMustUseLightColorSet = false; 44 bool mMustUseLightSystemColors = false; 45 46 ColorScheme mColorScheme = ColorScheme::Light; 47 48 void Load(bool aIsChrome); 49 void LoadColors(bool aIsLight); 50 }; 51 52 static void Refresh() { 53 sInitialized = false; 54 Initialize(); 55 } 56 57 enum class ChromeColorSchemeSetting { Light, Dark, System }; 58 static ChromeColorSchemeSetting ColorSchemeSettingForChrome(); 59 60 static ColorScheme ColorSchemeForChrome() { 61 MOZ_ASSERT(sInitialized); 62 return ChromePrefs().mColorScheme; 63 } 64 65 static ColorScheme PreferredColorSchemeForContent() { 66 MOZ_ASSERT(sInitialized); 67 return ContentPrefs().mColorScheme; 68 } 69 static ColorScheme ThemeDerivedColorSchemeForContent(); 70 71 static Prefs& ContentPrefs() { 72 MOZ_ASSERT(sInitialized); 73 return sContentPrefs; 74 } 75 76 static Prefs& ChromePrefs() { 77 MOZ_ASSERT(sInitialized); 78 return sChromePrefs; 79 } 80 81 static Prefs& PrintPrefs() { 82 MOZ_ASSERT(sInitialized); 83 return sPrintPrefs; 84 } 85 86 enum class PrefsKind { 87 Chrome, 88 Print, 89 Content, 90 }; 91 92 static PrefsKind PrefsKindFor(const dom::Document&); 93 94 static bool ShouldUseChromePrefs(const dom::Document& aDocument) { 95 return PrefsKindFor(aDocument) == PrefsKind::Chrome; 96 } 97 98 static bool MayForceColors() { return !ContentPrefs().mUseDocumentColors; } 99 100 static const Prefs& PrefsFor(const dom::Document& aDocument) { 101 switch (PrefsKindFor(aDocument)) { 102 case PrefsKind::Chrome: 103 return ChromePrefs(); 104 case PrefsKind::Print: 105 return PrintPrefs(); 106 case PrefsKind::Content: 107 break; 108 } 109 return ContentPrefs(); 110 } 111 112 private: 113 static bool sInitialized; 114 static Prefs sChromePrefs; 115 static Prefs sPrintPrefs; 116 static Prefs sContentPrefs; 117 118 static void Initialize(); 119 }; 120 121 } // namespace mozilla 122 123 #endif