Bug 1444460 [wpt PR 9948] - gyroscope: Rename LocalCoordinateSystem to GyroscopeLocal...
[gecko.git] / widget / nsXPLookAndFeel.h
blob2e671a597dd34915cc043321c0ea9220589bb51c
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 "nsTArray.h"
12 class nsLookAndFeel;
14 struct nsLookAndFeelIntPref
16 const char* name;
17 mozilla::LookAndFeel::IntID id;
18 bool isSet;
19 int32_t intVar;
22 struct nsLookAndFeelFloatPref
24 const char* name;
25 mozilla::LookAndFeel::FloatID id;
26 bool isSet;
27 float floatVar;
30 #define CACHE_BLOCK(x) ((x) >> 5)
31 #define CACHE_BIT(x) (1 << ((x) & 31))
33 #define COLOR_CACHE_SIZE (CACHE_BLOCK(LookAndFeel::eColorID_LAST_COLOR) + 1)
34 #define IS_COLOR_CACHED(x) (CACHE_BIT(x) & nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)])
35 #define CLEAR_COLOR_CACHE(x) nsXPLookAndFeel::sCachedColors[(x)] =0; \
36 nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] &= ~(CACHE_BIT(x));
37 #define CACHE_COLOR(x, y) nsXPLookAndFeel::sCachedColors[(x)] = y; \
38 nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] |= CACHE_BIT(x);
40 class nsXPLookAndFeel: public mozilla::LookAndFeel
42 public:
43 virtual ~nsXPLookAndFeel();
45 static nsXPLookAndFeel* GetInstance();
46 static void Shutdown();
48 void Init();
51 // All these routines will return NS_OK if they have a value,
52 // in which case the nsLookAndFeel should use that value;
53 // otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
54 // platform-specific nsLookAndFeel should use its own values instead.
56 nsresult GetColorImpl(ColorID aID, bool aUseStandinsForNativeColors,
57 nscolor &aResult);
58 virtual nsresult GetIntImpl(IntID aID, int32_t &aResult);
59 virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
61 // This one is different: there are no override prefs (fixme?), so
62 // there is no XP implementation, only per-system impls.
63 virtual bool GetFontImpl(FontID aID, nsString& aName,
64 gfxFontStyle& aStyle,
65 float aDevPixPerCSSPixel) = 0;
67 virtual void RefreshImpl();
69 virtual char16_t GetPasswordCharacterImpl()
71 return char16_t('*');
74 virtual bool GetEchoPasswordImpl()
76 return false;
79 virtual uint32_t GetPasswordMaskDelayImpl()
81 return 600;
84 virtual nsTArray<LookAndFeelInt> GetIntCacheImpl();
85 virtual void SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) {}
87 virtual void NativeInit() = 0;
89 protected:
90 nsXPLookAndFeel();
92 static void IntPrefChanged(nsLookAndFeelIntPref *data);
93 static void FloatPrefChanged(nsLookAndFeelFloatPref *data);
94 static void ColorPrefChanged(unsigned int index, const char *prefName);
95 void InitFromPref(nsLookAndFeelIntPref* aPref);
96 void InitFromPref(nsLookAndFeelFloatPref* aPref);
97 void InitColorFromPref(int32_t aIndex);
98 virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult) = 0;
99 bool IsSpecialColor(ColorID aID, nscolor &aColor);
100 bool ColorIsNotCSSAccessible(ColorID aID);
101 nscolor GetStandinForNativeColor(ColorID aID);
103 static void OnPrefChanged(const char* aPref, void* aClosure);
105 static bool sInitialized;
106 static nsLookAndFeelIntPref sIntPrefs[];
107 static nsLookAndFeelFloatPref sFloatPrefs[];
108 /* this length must not be shorter than the length of the longest string in the array
109 * see nsXPLookAndFeel.cpp
111 static const char sColorPrefs[][41];
112 static int32_t sCachedColors[LookAndFeel::eColorID_LAST_COLOR];
113 static int32_t sCachedColorBits[COLOR_CACHE_SIZE];
114 static bool sUseNativeColors;
115 static bool sUseStandinsForNativeColors;
116 static bool sFindbarModalHighlight;
118 static nsXPLookAndFeel* sInstance;
119 static bool sShutdown;
122 #endif