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"
13 struct nsLookAndFeelIntPref
16 mozilla::LookAndFeel::IntID id
;
21 struct nsLookAndFeelFloatPref
24 mozilla::LookAndFeel::FloatID id
;
29 #define CACHE_BLOCK(x) ((x) >> 5)
30 #define CACHE_BIT(x) (1 << ((x) & 31))
32 #define COLOR_CACHE_SIZE (CACHE_BLOCK(LookAndFeel::eColorID_LAST_COLOR) + 1)
33 #define IS_COLOR_CACHED(x) (CACHE_BIT(x) & nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)])
34 #define CLEAR_COLOR_CACHE(x) nsXPLookAndFeel::sCachedColors[(x)] =0; \
35 nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] &= ~(CACHE_BIT(x));
36 #define CACHE_COLOR(x, y) nsXPLookAndFeel::sCachedColors[(x)] = y; \
37 nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] |= CACHE_BIT(x);
39 class nsXPLookAndFeel
: public mozilla::LookAndFeel
42 virtual ~nsXPLookAndFeel();
44 static nsLookAndFeel
* GetInstance();
45 static void Shutdown();
50 // All these routines will return NS_OK if they have a value,
51 // in which case the nsLookAndFeel should use that value;
52 // otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
53 // platform-specific nsLookAndFeel should use its own values instead.
55 nsresult
GetColorImpl(ColorID aID
, nscolor
&aResult
);
56 virtual nsresult
GetIntImpl(IntID aID
, int32_t &aResult
);
57 virtual nsresult
GetFloatImpl(FloatID aID
, float &aResult
);
59 // This one is different: there are no override prefs (fixme?), so
60 // there is no XP implementation, only per-system impls.
61 virtual bool GetFontImpl(FontID aID
, nsString
& aName
,
63 float aDevPixPerCSSPixel
) = 0;
65 virtual void RefreshImpl();
67 virtual char16_t
GetPasswordCharacterImpl()
72 virtual bool GetEchoPasswordImpl()
77 virtual uint32_t GetPasswordMaskDelayImpl()
85 static void IntPrefChanged(nsLookAndFeelIntPref
*data
);
86 static void FloatPrefChanged(nsLookAndFeelFloatPref
*data
);
87 static void ColorPrefChanged(unsigned int index
, const char *prefName
);
88 void InitFromPref(nsLookAndFeelIntPref
* aPref
);
89 void InitFromPref(nsLookAndFeelFloatPref
* aPref
);
90 void InitColorFromPref(int32_t aIndex
);
91 virtual nsresult
NativeGetColor(ColorID aID
, nscolor
&aResult
) = 0;
92 bool IsSpecialColor(ColorID aID
, nscolor
&aColor
);
94 static void OnPrefChanged(const char* aPref
, void* aClosure
);
96 static bool sInitialized
;
97 static nsLookAndFeelIntPref sIntPrefs
[];
98 static nsLookAndFeelFloatPref sFloatPrefs
[];
99 /* this length must not be shorter than the length of the longest string in the array
100 * see nsXPLookAndFeel.cpp
102 static const char sColorPrefs
[][38];
103 static int32_t sCachedColors
[LookAndFeel::eColorID_LAST_COLOR
];
104 static int32_t sCachedColorBits
[COLOR_CACHE_SIZE
];
105 static bool sUseNativeColors
;
107 static nsLookAndFeel
* sInstance
;
108 static bool sShutdown
;