Bug 1700051: part 28) Refactor `WordSplitState<T>::GetDOMWordSeparatorOffset` to...
[gecko.git] / widget / nsXPLookAndFeel.h
blobe6955e80291a328995986167de593bc3c2172e95
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef __nsXPLookAndFeel
7 #define __nsXPLookAndFeel
9 #include "mozilla/LookAndFeel.h"
10 #include "mozilla/widget/LookAndFeelTypes.h"
11 #include "nsTArray.h"
13 class nsLookAndFeel;
15 class nsXPLookAndFeel : public mozilla::LookAndFeel {
16 public:
17 using FullLookAndFeel = mozilla::widget::FullLookAndFeel;
18 using LookAndFeelFont = mozilla::widget::LookAndFeelFont;
19 using LookAndFeelTheme = mozilla::widget::LookAndFeelTheme;
21 virtual ~nsXPLookAndFeel();
23 static nsXPLookAndFeel* GetInstance();
24 static void Shutdown();
26 void Init();
28 // These functions will return a value specified by an override pref, if it
29 // exists, and otherwise will call into the NativeGetXxx function to get the
30 // platform-specific value.
32 // NS_ERROR_NOT_AVAILABLE is returned if there is neither an override pref or
33 // a platform-specific value.
34 nsresult GetColorValue(ColorID, ColorScheme, UseStandins, nscolor& aResult);
35 nsresult GetIntValue(IntID aID, int32_t& aResult);
36 nsresult GetFloatValue(FloatID aID, float& aResult);
37 // Same, but returns false if there is no platform-specific value.
38 // (There are no override prefs for font values.)
39 bool GetFontValue(FontID aID, nsString& aName, gfxFontStyle& aStyle);
41 virtual nsresult NativeGetInt(IntID aID, int32_t& aResult) = 0;
42 virtual nsresult NativeGetFloat(FloatID aID, float& aResult) = 0;
43 virtual nsresult NativeGetColor(ColorID, ColorScheme, nscolor& aResult) = 0;
44 virtual bool NativeGetFont(FontID aID, nsString& aName,
45 gfxFontStyle& aStyle) = 0;
47 virtual void RefreshImpl();
49 virtual char16_t GetPasswordCharacterImpl() { return char16_t('*'); }
51 virtual bool GetEchoPasswordImpl() { return false; }
53 virtual uint32_t GetPasswordMaskDelayImpl() { return 600; }
55 static bool LookAndFeelFontToStyle(const LookAndFeelFont&, nsString& aName,
56 gfxFontStyle&);
57 static LookAndFeelFont StyleToLookAndFeelFont(const nsAString& aName,
58 const gfxFontStyle&);
60 virtual void SetDataImpl(FullLookAndFeel&& aTables) {}
62 virtual void NativeInit() = 0;
64 virtual void WithThemeConfiguredForContent(
65 const std::function<void(const LookAndFeelTheme&, bool aChanged)>& aFn) {
66 aFn(LookAndFeelTheme{}, false);
69 // Whether the color should be from the parent theme, if the theme differs
70 // between parent and content processes.
71 virtual bool FromParentTheme(IntID) {
72 MOZ_ASSERT_UNREACHABLE(
73 "Should override if WithThemeConfiguredForContent can change the "
74 "theme");
75 return false;
77 virtual bool FromParentTheme(ColorID) {
78 MOZ_ASSERT_UNREACHABLE(
79 "Should override if WithThemeConfiguredForContent can change the "
80 "theme");
81 return false;
84 protected:
85 nsXPLookAndFeel() = default;
87 static nscolor GetStandinForNativeColor(ColorID);
88 void RecordTelemetry();
89 virtual void RecordLookAndFeelSpecificTelemetry() {}
91 static void OnPrefChanged(const char* aPref, void* aClosure);
93 static bool sInitialized;
95 static nsXPLookAndFeel* sInstance;
96 static bool sShutdown;
99 #endif