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 nsresult
GetKeyboardLayoutImpl(nsACString
& aLayout
) override
;
52 static const nscolor kBlack
= NS_RGB(0, 0, 0);
53 static const nscolor kWhite
= NS_RGB(255, 255, 255);
54 void OnColorSchemeSettingChanged();
61 using ThemeFamily
= mozilla::StyleGtkThemeFamily
;
64 static bool WidgetUsesImage(WidgetNodeType aNodeType
);
65 void RecordLookAndFeelSpecificTelemetry() override
;
66 static bool ShouldHonorThemeScrollbarColors();
67 mozilla::Maybe
<ColorScheme
> ComputeColorSchemeSetting();
72 // We use up to two themes (one light, one dark), which might have different
73 // sets of fonts and colors.
77 bool mHighContrast
= false;
78 bool mPreferDarkTheme
= false;
80 ThemeFamily mFamily
{0};
83 nsString mDefaultFontName
;
84 nsString mButtonFontName
;
85 nsString mFieldFontName
;
86 nsString mMenuFontName
;
87 gfxFontStyle mDefaultFontStyle
;
88 gfxFontStyle mButtonFontStyle
;
89 gfxFontStyle mFieldFontStyle
;
90 gfxFontStyle mMenuFontStyle
;
93 nscolor mGrayText
= kBlack
;
98 ColorPair mHeaderBarInactive
;
100 ColorPair mButtonHover
;
101 ColorPair mButtonActive
;
102 nscolor mButtonBorder
= kBlack
;
103 nscolor mThreeDHighlight
= kBlack
;
104 nscolor mThreeDShadow
= kBlack
;
105 nscolor mOddCellBackground
= kWhite
;
106 nscolor mNativeHyperLinkText
= kBlack
;
107 nscolor mNativeVisitedHyperLinkText
= kBlack
;
108 // FIXME: This doesn't seem like it'd be sound since we use Window for
109 // -moz-Combobox... But I guess we rely on chrome code not setting
110 // appearance: none on selects or overriding the color if they do.
111 nscolor mComboBoxText
= kBlack
;
116 nscolor mSidebarBorder
= kBlack
;
118 nscolor mMozWindowActiveBorder
= kBlack
;
119 nscolor mMozWindowInactiveBorder
= kBlack
;
121 ColorPair mCellHighlight
;
122 ColorPair mSelectedText
;
124 ColorPair mSelectedItem
;
126 ColorPair mMozColHeader
;
127 ColorPair mMozColHeaderHover
;
128 ColorPair mMozColHeaderActive
;
131 ColorPair mTitlebarInactive
;
133 nscolor mThemedScrollbar
= kWhite
;
134 nscolor mThemedScrollbarInactive
= kWhite
;
135 nscolor mThemedScrollbarThumb
= kBlack
;
136 nscolor mThemedScrollbarThumbHover
= kBlack
;
137 nscolor mThemedScrollbarThumbActive
= kBlack
;
138 nscolor mThemedScrollbarThumbInactive
= kBlack
;
140 float mCaretRatio
= 0.0f
;
141 int32_t mTitlebarRadius
= 0;
142 int32_t mTitlebarButtonSpacing
= 0;
143 char16_t mInvisibleCharacter
= 0;
144 bool mMenuSupportsDrag
= false;
147 nsresult
GetColor(ColorID
, nscolor
&) const;
148 bool GetFont(FontID
, nsString
& aFontName
, gfxFontStyle
&) const;
149 void InitCellHighlightColors();
152 PerThemeData mSystemTheme
;
154 // If the system theme is light, a dark theme. Otherwise, a light theme. The
155 // alternative theme to the current one is preferred, but otherwise we fall
156 // back to Adwaita / Adwaita Dark, respectively.
157 PerThemeData mAltTheme
;
159 const PerThemeData
& LightTheme() const {
160 return mSystemTheme
.mIsDark
? mAltTheme
: mSystemTheme
;
163 const PerThemeData
& DarkTheme() const {
164 return mSystemTheme
.mIsDark
? mSystemTheme
: mAltTheme
;
167 const PerThemeData
& EffectiveTheme() const {
168 return mSystemThemeOverridden
? mAltTheme
: mSystemTheme
;
171 uint32_t mDBusID
= 0;
172 RefPtr
<GDBusProxy
> mDBusSettingsProxy
;
173 RefPtr
<GFile
> mKdeColors
;
174 RefPtr
<GFileMonitor
> mKdeColorsMonitor
;
175 mozilla::Maybe
<ColorScheme
> mColorSchemePreference
;
176 int32_t mCaretBlinkTime
= 0;
177 int32_t mCaretBlinkCount
= -1;
178 bool mCSDMaximizeButton
= false;
179 bool mCSDMinimizeButton
= false;
180 bool mCSDCloseButton
= false;
181 bool mCSDReversedPlacement
= false;
182 bool mPrefersReducedMotion
= false;
183 bool mInitialized
= false;
184 bool mSystemThemeOverridden
= false;
185 int32_t mCSDMaximizeButtonPosition
= 0;
186 int32_t mCSDMinimizeButtonPosition
= 0;
187 int32_t mCSDCloseButtonPosition
= 0;
188 TitlebarAction mDoubleClickAction
= TitlebarAction::None
;
189 TitlebarAction mMiddleClickAction
= TitlebarAction::None
;
191 RefPtr
<GtkCssProvider
> mRoundedCornerProvider
;
192 void UpdateRoundedBottomCornerStyles();
194 void ClearRoundedCornerProvider();
205 void RestoreSystemTheme();
206 void InitializeGlobalSettings();
207 // Returns whether we found an alternative theme.
208 bool ConfigureAltTheme();
209 void ConfigureAndInitializeAltTheme();
210 void ConfigureFinalEffectiveTheme();
211 void MaybeApplyAdwaitaOverrides();