1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef __nsLookAndFeel
9 #define __nsLookAndFeel
11 #include "X11UndefineNone.h"
12 #include "nsXPLookAndFeel.h"
16 enum WidgetNodeType
: int;
18 typedef struct _GDBusProxy GDBusProxy
;
19 typedef struct _GtkCssProvider GtkCssProvider
;
20 typedef struct _GFile GFile
;
21 typedef struct _GFileMonitor GFileMonitor
;
24 enum class StyleGtkThemeFamily
: uint8_t;
27 class nsLookAndFeel final
: public nsXPLookAndFeel
{
30 virtual ~nsLookAndFeel();
32 void NativeInit() final
;
33 void RefreshImpl() override
;
34 nsresult
NativeGetInt(IntID aID
, int32_t& aResult
) override
;
35 nsresult
NativeGetFloat(FloatID aID
, float& aResult
) override
;
36 nsresult
NativeGetColor(ColorID
, ColorScheme
, nscolor
& aResult
) override
;
37 bool NativeGetFont(FontID aID
, nsString
& aFontName
,
38 gfxFontStyle
& aFontStyle
) override
;
40 char16_t
GetPasswordCharacterImpl() override
;
41 bool GetEchoPasswordImpl() override
;
43 bool GetDefaultDrawInTitlebar() override
;
45 void GetThemeInfo(nsACString
&) override
;
47 static const nscolor kBlack
= NS_RGB(0, 0, 0);
48 static const nscolor kWhite
= NS_RGB(255, 255, 255);
49 void OnColorSchemeSettingChanged();
56 using ThemeFamily
= mozilla::StyleGtkThemeFamily
;
59 static bool WidgetUsesImage(WidgetNodeType aNodeType
);
60 void RecordLookAndFeelSpecificTelemetry() override
;
61 static bool ShouldHonorThemeScrollbarColors();
62 mozilla::Maybe
<ColorScheme
> ComputeColorSchemeSetting();
67 // We use up to two themes (one light, one dark), which might have different
68 // sets of fonts and colors.
72 bool mHighContrast
= false;
73 bool mPreferDarkTheme
= false;
75 ThemeFamily mFamily
{0};
78 nsString mDefaultFontName
;
79 nsString mButtonFontName
;
80 nsString mFieldFontName
;
81 nsString mMenuFontName
;
82 gfxFontStyle mDefaultFontStyle
;
83 gfxFontStyle mButtonFontStyle
;
84 gfxFontStyle mFieldFontStyle
;
85 gfxFontStyle mMenuFontStyle
;
88 nscolor mGrayText
= kBlack
;
93 ColorPair mHeaderBarInactive
;
95 ColorPair mButtonHover
;
96 ColorPair mButtonActive
;
97 nscolor mButtonBorder
= kBlack
;
98 nscolor mThreeDHighlight
= kBlack
;
99 nscolor mThreeDShadow
= kBlack
;
100 nscolor mOddCellBackground
= kWhite
;
101 nscolor mNativeHyperLinkText
= kBlack
;
102 nscolor mNativeVisitedHyperLinkText
= kBlack
;
103 // FIXME: This doesn't seem like it'd be sound since we use Window for
104 // -moz-Combobox... But I guess we rely on chrome code not setting
105 // appearance: none on selects or overriding the color if they do.
106 nscolor mComboBoxText
= kBlack
;
111 nscolor mSidebarBorder
= kBlack
;
113 nscolor mMozWindowActiveBorder
= kBlack
;
114 nscolor mMozWindowInactiveBorder
= kBlack
;
116 ColorPair mCellHighlight
;
117 ColorPair mSelectedText
;
119 ColorPair mSelectedItem
;
121 ColorPair mMozColHeader
;
122 ColorPair mMozColHeaderHover
;
123 ColorPair mMozColHeaderActive
;
126 ColorPair mTitlebarInactive
;
128 nscolor mThemedScrollbar
= kWhite
;
129 nscolor mThemedScrollbarInactive
= kWhite
;
130 nscolor mThemedScrollbarThumb
= kBlack
;
131 nscolor mThemedScrollbarThumbHover
= kBlack
;
132 nscolor mThemedScrollbarThumbActive
= kBlack
;
133 nscolor mThemedScrollbarThumbInactive
= kBlack
;
135 float mCaretRatio
= 0.0f
;
136 int32_t mTitlebarRadius
= 0;
137 char16_t mInvisibleCharacter
= 0;
138 bool mMenuSupportsDrag
= false;
141 nsresult
GetColor(ColorID
, nscolor
&) const;
142 bool GetFont(FontID
, nsString
& aFontName
, gfxFontStyle
&) const;
143 void InitCellHighlightColors();
146 PerThemeData mSystemTheme
;
148 // If the system theme is light, a dark theme. Otherwise, a light theme. The
149 // alternative theme to the current one is preferred, but otherwise we fall
150 // back to Adwaita / Adwaita Dark, respectively.
151 PerThemeData mAltTheme
;
153 const PerThemeData
& LightTheme() const {
154 return mSystemTheme
.mIsDark
? mAltTheme
: mSystemTheme
;
157 const PerThemeData
& DarkTheme() const {
158 return mSystemTheme
.mIsDark
? mSystemTheme
: mAltTheme
;
161 const PerThemeData
& EffectiveTheme() const {
162 return mSystemThemeOverridden
? mAltTheme
: mSystemTheme
;
165 uint32_t mDBusID
= 0;
166 RefPtr
<GDBusProxy
> mDBusSettingsProxy
;
167 RefPtr
<GFile
> mKdeColors
;
168 RefPtr
<GFileMonitor
> mKdeColorsMonitor
;
169 mozilla::Maybe
<ColorScheme
> mColorSchemePreference
;
170 int32_t mCaretBlinkTime
= 0;
171 int32_t mCaretBlinkCount
= -1;
172 bool mCSDMaximizeButton
= false;
173 bool mCSDMinimizeButton
= false;
174 bool mCSDCloseButton
= false;
175 bool mCSDReversedPlacement
= false;
176 bool mPrefersReducedMotion
= false;
177 bool mInitialized
= false;
178 bool mSystemThemeOverridden
= false;
179 int32_t mCSDMaximizeButtonPosition
= 0;
180 int32_t mCSDMinimizeButtonPosition
= 0;
181 int32_t mCSDCloseButtonPosition
= 0;
183 RefPtr
<GtkCssProvider
> mRoundedCornerProvider
;
184 void UpdateRoundedBottomCornerStyles();
186 void ClearRoundedCornerProvider();
197 void RestoreSystemTheme();
198 void InitializeGlobalSettings();
199 // Returns whether we found an alternative theme.
200 bool ConfigureAltTheme();
201 void ConfigureAndInitializeAltTheme();
202 void ConfigureFinalEffectiveTheme();
203 void MaybeApplyAdwaitaOverrides();