Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
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"
11 class nsLookAndFeel;
13 struct nsLookAndFeelIntPref
14 {
15 const char* name;
16 mozilla::LookAndFeel::IntID id;
17 bool isSet;
18 int32_t intVar;
19 };
21 struct nsLookAndFeelFloatPref
22 {
23 const char* name;
24 mozilla::LookAndFeel::FloatID id;
25 bool isSet;
26 float floatVar;
27 };
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
40 {
41 public:
42 virtual ~nsXPLookAndFeel();
44 static nsLookAndFeel* GetInstance();
45 static void Shutdown();
47 void Init();
49 //
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.
54 //
55 nsresult GetColorImpl(ColorID aID, bool aUseStandinsForNativeColors,
56 nscolor &aResult);
57 virtual nsresult GetIntImpl(IntID aID, int32_t &aResult);
58 virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
60 // This one is different: there are no override prefs (fixme?), so
61 // there is no XP implementation, only per-system impls.
62 virtual bool GetFontImpl(FontID aID, nsString& aName,
63 gfxFontStyle& aStyle,
64 float aDevPixPerCSSPixel) = 0;
66 virtual void RefreshImpl();
68 virtual char16_t GetPasswordCharacterImpl()
69 {
70 return char16_t('*');
71 }
73 virtual bool GetEchoPasswordImpl()
74 {
75 return false;
76 }
78 virtual uint32_t GetPasswordMaskDelayImpl()
79 {
80 return 600;
81 }
83 protected:
84 nsXPLookAndFeel();
86 static void IntPrefChanged(nsLookAndFeelIntPref *data);
87 static void FloatPrefChanged(nsLookAndFeelFloatPref *data);
88 static void ColorPrefChanged(unsigned int index, const char *prefName);
89 void InitFromPref(nsLookAndFeelIntPref* aPref);
90 void InitFromPref(nsLookAndFeelFloatPref* aPref);
91 void InitColorFromPref(int32_t aIndex);
92 virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult) = 0;
93 bool IsSpecialColor(ColorID aID, nscolor &aColor);
94 bool ColorIsNotCSSAccessible(ColorID aID);
95 nscolor GetStandinForNativeColor(ColorID aID);
97 static void OnPrefChanged(const char* aPref, void* aClosure);
99 static bool sInitialized;
100 static nsLookAndFeelIntPref sIntPrefs[];
101 static nsLookAndFeelFloatPref sFloatPrefs[];
102 /* this length must not be shorter than the length of the longest string in the array
103 * see nsXPLookAndFeel.cpp
104 */
105 static const char sColorPrefs[][38];
106 static int32_t sCachedColors[LookAndFeel::eColorID_LAST_COLOR];
107 static int32_t sCachedColorBits[COLOR_CACHE_SIZE];
108 static bool sUseNativeColors;
110 static nsLookAndFeel* sInstance;
111 static bool sShutdown;
112 };
114 #endif