Bug 1756130 [wpt PR 32898] - [CSP] Enhance unsafe-eval test to check both realms...
[gecko.git] / widget / nsXPLookAndFeel.h
blob3218c9c7bd0253439d59130264c0008f445ac6c4
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/Maybe.h"
10 #include "mozilla/LookAndFeel.h"
11 #include "mozilla/widget/LookAndFeelTypes.h"
12 #include "nsTArray.h"
14 class nsLookAndFeel;
16 class nsXPLookAndFeel : public mozilla::LookAndFeel {
17 public:
18 using FullLookAndFeel = mozilla::widget::FullLookAndFeel;
19 using LookAndFeelFont = mozilla::widget::LookAndFeelFont;
20 using LookAndFeelTheme = mozilla::widget::LookAndFeelTheme;
22 virtual ~nsXPLookAndFeel();
24 static nsXPLookAndFeel* GetInstance();
25 static void Shutdown();
27 void Init();
29 // Gets the pref name for a given color, just for debugging purposes.
30 static const char* GetColorPrefName(ColorID);
32 // These functions will return a value specified by an override pref, if it
33 // exists, and otherwise will call into the NativeGetXxx function to get the
34 // platform-specific value.
36 // NS_ERROR_NOT_AVAILABLE is returned if there is neither an override pref or
37 // a platform-specific value.
38 nsresult GetColorValue(ColorID, ColorScheme, UseStandins, nscolor& aResult);
39 nsresult GetIntValue(IntID aID, int32_t& aResult);
40 nsresult GetFloatValue(FloatID aID, float& aResult);
41 // Same, but returns false if there is no platform-specific value.
42 // (There are no override prefs for font values.)
43 bool GetFontValue(FontID aID, nsString& aName, gfxFontStyle& aStyle);
45 virtual nsresult NativeGetInt(IntID aID, int32_t& aResult) = 0;
46 virtual nsresult NativeGetFloat(FloatID aID, float& aResult) = 0;
47 virtual nsresult NativeGetColor(ColorID, ColorScheme, nscolor& aResult) = 0;
48 virtual bool NativeGetFont(FontID aID, nsString& aName,
49 gfxFontStyle& aStyle) = 0;
51 virtual void RefreshImpl();
53 virtual char16_t GetPasswordCharacterImpl() { return char16_t('*'); }
55 virtual bool GetEchoPasswordImpl() { return false; }
57 virtual uint32_t GetPasswordMaskDelayImpl() { return 600; }
59 virtual bool GetDefaultDrawInTitlebar() { return true; }
61 static bool LookAndFeelFontToStyle(const LookAndFeelFont&, nsString& aName,
62 gfxFontStyle&);
63 static LookAndFeelFont StyleToLookAndFeelFont(const nsAString& aName,
64 const gfxFontStyle&);
66 virtual void SetDataImpl(FullLookAndFeel&& aTables) {}
68 virtual void NativeInit() = 0;
70 virtual void GetGtkContentTheme(LookAndFeelTheme&) {}
71 virtual void GetThemeInfo(nsACString&) {}
73 protected:
74 nsXPLookAndFeel() = default;
76 static nscolor GetStandinForNativeColor(ColorID, ColorScheme);
78 // A platform-agnostic dark-color scheme, for platforms where we don't have
79 // "native" dark colors, like Windows and Android.
81 // TODO: In the future we should use this as well for standins (i.e.,
82 // resistFingerprinting, etc).
83 static mozilla::Maybe<nscolor> GenericDarkColor(ColorID);
85 void RecordTelemetry();
86 virtual void RecordLookAndFeelSpecificTelemetry() {}
88 static void OnPrefChanged(const char* aPref, void* aClosure);
90 static bool sInitialized;
92 static nsXPLookAndFeel* sInstance;
93 static bool sShutdown;
96 #endif