Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / gtk / nsLookAndFeel.h
blob1ef28afe2145d7876e7a4fc1d8c52ad9e28d34d1
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
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"
13 #include "nsCOMPtr.h"
14 #include "gfxFont.h"
16 enum WidgetNodeType : int;
17 struct _GtkStyle;
18 typedef struct _GDBusProxy GDBusProxy;
19 typedef struct _GtkCssProvider GtkCssProvider;
20 typedef struct _GFile GFile;
21 typedef struct _GFileMonitor GFileMonitor;
23 namespace mozilla {
24 enum class StyleGtkThemeFamily : uint8_t;
27 class nsLookAndFeel final : public nsXPLookAndFeel {
28 public:
29 nsLookAndFeel();
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();
54 struct ColorPair {
55 nscolor mBg = kWhite;
56 nscolor mFg = kBlack;
59 using ThemeFamily = mozilla::StyleGtkThemeFamily;
61 protected:
62 static bool WidgetUsesImage(WidgetNodeType aNodeType);
63 void RecordLookAndFeelSpecificTelemetry() override;
64 static bool ShouldHonorThemeScrollbarColors();
65 mozilla::Maybe<ColorScheme> ComputeColorSchemeSetting();
67 void WatchDBus();
68 void UnwatchDBus();
70 // We use up to two themes (one light, one dark), which might have different
71 // sets of fonts and colors.
72 struct PerThemeData {
73 nsCString mName;
74 bool mIsDark = false;
75 bool mHighContrast = false;
76 bool mPreferDarkTheme = false;
78 ThemeFamily mFamily{0};
80 // Cached fonts
81 nsString mDefaultFontName;
82 nsString mButtonFontName;
83 nsString mFieldFontName;
84 nsString mMenuFontName;
85 gfxFontStyle mDefaultFontStyle;
86 gfxFontStyle mButtonFontStyle;
87 gfxFontStyle mFieldFontStyle;
88 gfxFontStyle mMenuFontStyle;
90 // Cached colors
91 nscolor mGrayText = kBlack;
92 ColorPair mInfo;
93 ColorPair mMenu;
94 ColorPair mMenuHover;
95 ColorPair mHeaderBar;
96 ColorPair mHeaderBarInactive;
97 ColorPair mButton;
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;
110 ColorPair mField;
111 ColorPair mWindow;
112 ColorPair mDialog;
113 ColorPair mSidebar;
114 nscolor mSidebarBorder = kBlack;
116 nscolor mMozWindowActiveBorder = kBlack;
117 nscolor mMozWindowInactiveBorder = kBlack;
119 ColorPair mCellHighlight;
120 ColorPair mSelectedText;
121 ColorPair mAccent;
122 ColorPair mSelectedItem;
124 ColorPair mMozColHeader;
125 ColorPair mMozColHeaderHover;
126 ColorPair mMozColHeaderActive;
128 ColorPair mTitlebar;
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;
144 void Init();
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();
194 void EnsureInit() {
195 if (mInitialized) {
196 return;
198 Initialize();
201 void Initialize();
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();
212 #endif