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 nsXPLookAndFeel::TitlebarAction
GetTitlebarAction(
46 TitlebarEvent aEvent
) override
;
48 void GetThemeInfo(nsACString
&) override
;
50 static const nscolor kBlack
= NS_RGB(0, 0, 0);
51 static const nscolor kWhite
= NS_RGB(255, 255, 255);
52 void OnColorSchemeSettingChanged();
59 using ThemeFamily
= mozilla::StyleGtkThemeFamily
;
62 static bool WidgetUsesImage(WidgetNodeType aNodeType
);
63 void RecordLookAndFeelSpecificTelemetry() override
;
64 static bool ShouldHonorThemeScrollbarColors();
65 mozilla::Maybe
<ColorScheme
> ComputeColorSchemeSetting();
70 // We use up to two themes (one light, one dark), which might have different
71 // sets of fonts and colors.
75 bool mHighContrast
= false;
76 bool mPreferDarkTheme
= false;
78 ThemeFamily mFamily
{0};
81 nsString mDefaultFontName
;
82 nsString mButtonFontName
;
83 nsString mFieldFontName
;
84 nsString mMenuFontName
;
85 gfxFontStyle mDefaultFontStyle
;
86 gfxFontStyle mButtonFontStyle
;
87 gfxFontStyle mFieldFontStyle
;
88 gfxFontStyle mMenuFontStyle
;
91 nscolor mGrayText
= kBlack
;
96 ColorPair mHeaderBarInactive
;
98 ColorPair mButtonHover
;
99 ColorPair mButtonActive
;
100 nscolor mButtonBorder
= kBlack
;
101 nscolor mThreeDHighlight
= kBlack
;
102 nscolor mThreeDShadow
= kBlack
;
103 nscolor mOddCellBackground
= kWhite
;
104 nscolor mNativeHyperLinkText
= kBlack
;
105 nscolor mNativeVisitedHyperLinkText
= kBlack
;
106 // FIXME: This doesn't seem like it'd be sound since we use Window for
107 // -moz-Combobox... But I guess we rely on chrome code not setting
108 // appearance: none on selects or overriding the color if they do.
109 nscolor mComboBoxText
= kBlack
;
114 nscolor mSidebarBorder
= kBlack
;
116 nscolor mMozWindowActiveBorder
= kBlack
;
117 nscolor mMozWindowInactiveBorder
= kBlack
;
119 ColorPair mCellHighlight
;
120 ColorPair mSelectedText
;
122 ColorPair mSelectedItem
;
124 ColorPair mMozColHeader
;
125 ColorPair mMozColHeaderHover
;
126 ColorPair mMozColHeaderActive
;
129 ColorPair mTitlebarInactive
;
131 nscolor mThemedScrollbar
= kWhite
;
132 nscolor mThemedScrollbarInactive
= kWhite
;
133 nscolor mThemedScrollbarThumb
= kBlack
;
134 nscolor mThemedScrollbarThumbHover
= kBlack
;
135 nscolor mThemedScrollbarThumbActive
= kBlack
;
136 nscolor mThemedScrollbarThumbInactive
= kBlack
;
138 float mCaretRatio
= 0.0f
;
139 int32_t mTitlebarRadius
= 0;
140 int32_t mTitlebarButtonSpacing
= 0;
141 char16_t mInvisibleCharacter
= 0;
142 bool mMenuSupportsDrag
= false;
145 nsresult
GetColor(ColorID
, nscolor
&) const;
146 bool GetFont(FontID
, nsString
& aFontName
, gfxFontStyle
&) const;
147 void InitCellHighlightColors();
150 PerThemeData mSystemTheme
;
152 // If the system theme is light, a dark theme. Otherwise, a light theme. The
153 // alternative theme to the current one is preferred, but otherwise we fall
154 // back to Adwaita / Adwaita Dark, respectively.
155 PerThemeData mAltTheme
;
157 const PerThemeData
& LightTheme() const {
158 return mSystemTheme
.mIsDark
? mAltTheme
: mSystemTheme
;
161 const PerThemeData
& DarkTheme() const {
162 return mSystemTheme
.mIsDark
? mSystemTheme
: mAltTheme
;
165 const PerThemeData
& EffectiveTheme() const {
166 return mSystemThemeOverridden
? mAltTheme
: mSystemTheme
;
169 uint32_t mDBusID
= 0;
170 RefPtr
<GDBusProxy
> mDBusSettingsProxy
;
171 RefPtr
<GFile
> mKdeColors
;
172 RefPtr
<GFileMonitor
> mKdeColorsMonitor
;
173 mozilla::Maybe
<ColorScheme
> mColorSchemePreference
;
174 int32_t mCaretBlinkTime
= 0;
175 int32_t mCaretBlinkCount
= -1;
176 bool mCSDMaximizeButton
= false;
177 bool mCSDMinimizeButton
= false;
178 bool mCSDCloseButton
= false;
179 bool mCSDReversedPlacement
= false;
180 bool mPrefersReducedMotion
= false;
181 bool mInitialized
= false;
182 bool mSystemThemeOverridden
= false;
183 int32_t mCSDMaximizeButtonPosition
= 0;
184 int32_t mCSDMinimizeButtonPosition
= 0;
185 int32_t mCSDCloseButtonPosition
= 0;
186 TitlebarAction mDoubleClickAction
= TitlebarAction::None
;
187 TitlebarAction mMiddleClickAction
= TitlebarAction::None
;
189 RefPtr
<GtkCssProvider
> mRoundedCornerProvider
;
190 void UpdateRoundedBottomCornerStyles();
192 void ClearRoundedCornerProvider();
203 void RestoreSystemTheme();
204 void InitializeGlobalSettings();
205 // Returns whether we found an alternative theme.
206 bool ConfigureAltTheme();
207 void ConfigureAndInitializeAltTheme();
208 void ConfigureFinalEffectiveTheme();
209 void MaybeApplyAdwaitaOverrides();