Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef __nsXPLookAndFeel |
michael@0 | 7 | #define __nsXPLookAndFeel |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/LookAndFeel.h" |
michael@0 | 10 | |
michael@0 | 11 | class nsLookAndFeel; |
michael@0 | 12 | |
michael@0 | 13 | struct nsLookAndFeelIntPref |
michael@0 | 14 | { |
michael@0 | 15 | const char* name; |
michael@0 | 16 | mozilla::LookAndFeel::IntID id; |
michael@0 | 17 | bool isSet; |
michael@0 | 18 | int32_t intVar; |
michael@0 | 19 | }; |
michael@0 | 20 | |
michael@0 | 21 | struct nsLookAndFeelFloatPref |
michael@0 | 22 | { |
michael@0 | 23 | const char* name; |
michael@0 | 24 | mozilla::LookAndFeel::FloatID id; |
michael@0 | 25 | bool isSet; |
michael@0 | 26 | float floatVar; |
michael@0 | 27 | }; |
michael@0 | 28 | |
michael@0 | 29 | #define CACHE_BLOCK(x) ((x) >> 5) |
michael@0 | 30 | #define CACHE_BIT(x) (1 << ((x) & 31)) |
michael@0 | 31 | |
michael@0 | 32 | #define COLOR_CACHE_SIZE (CACHE_BLOCK(LookAndFeel::eColorID_LAST_COLOR) + 1) |
michael@0 | 33 | #define IS_COLOR_CACHED(x) (CACHE_BIT(x) & nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)]) |
michael@0 | 34 | #define CLEAR_COLOR_CACHE(x) nsXPLookAndFeel::sCachedColors[(x)] =0; \ |
michael@0 | 35 | nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] &= ~(CACHE_BIT(x)); |
michael@0 | 36 | #define CACHE_COLOR(x, y) nsXPLookAndFeel::sCachedColors[(x)] = y; \ |
michael@0 | 37 | nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] |= CACHE_BIT(x); |
michael@0 | 38 | |
michael@0 | 39 | class nsXPLookAndFeel: public mozilla::LookAndFeel |
michael@0 | 40 | { |
michael@0 | 41 | public: |
michael@0 | 42 | virtual ~nsXPLookAndFeel(); |
michael@0 | 43 | |
michael@0 | 44 | static nsLookAndFeel* GetInstance(); |
michael@0 | 45 | static void Shutdown(); |
michael@0 | 46 | |
michael@0 | 47 | void Init(); |
michael@0 | 48 | |
michael@0 | 49 | // |
michael@0 | 50 | // All these routines will return NS_OK if they have a value, |
michael@0 | 51 | // in which case the nsLookAndFeel should use that value; |
michael@0 | 52 | // otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the |
michael@0 | 53 | // platform-specific nsLookAndFeel should use its own values instead. |
michael@0 | 54 | // |
michael@0 | 55 | nsresult GetColorImpl(ColorID aID, bool aUseStandinsForNativeColors, |
michael@0 | 56 | nscolor &aResult); |
michael@0 | 57 | virtual nsresult GetIntImpl(IntID aID, int32_t &aResult); |
michael@0 | 58 | virtual nsresult GetFloatImpl(FloatID aID, float &aResult); |
michael@0 | 59 | |
michael@0 | 60 | // This one is different: there are no override prefs (fixme?), so |
michael@0 | 61 | // there is no XP implementation, only per-system impls. |
michael@0 | 62 | virtual bool GetFontImpl(FontID aID, nsString& aName, |
michael@0 | 63 | gfxFontStyle& aStyle, |
michael@0 | 64 | float aDevPixPerCSSPixel) = 0; |
michael@0 | 65 | |
michael@0 | 66 | virtual void RefreshImpl(); |
michael@0 | 67 | |
michael@0 | 68 | virtual char16_t GetPasswordCharacterImpl() |
michael@0 | 69 | { |
michael@0 | 70 | return char16_t('*'); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | virtual bool GetEchoPasswordImpl() |
michael@0 | 74 | { |
michael@0 | 75 | return false; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | virtual uint32_t GetPasswordMaskDelayImpl() |
michael@0 | 79 | { |
michael@0 | 80 | return 600; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | protected: |
michael@0 | 84 | nsXPLookAndFeel(); |
michael@0 | 85 | |
michael@0 | 86 | static void IntPrefChanged(nsLookAndFeelIntPref *data); |
michael@0 | 87 | static void FloatPrefChanged(nsLookAndFeelFloatPref *data); |
michael@0 | 88 | static void ColorPrefChanged(unsigned int index, const char *prefName); |
michael@0 | 89 | void InitFromPref(nsLookAndFeelIntPref* aPref); |
michael@0 | 90 | void InitFromPref(nsLookAndFeelFloatPref* aPref); |
michael@0 | 91 | void InitColorFromPref(int32_t aIndex); |
michael@0 | 92 | virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult) = 0; |
michael@0 | 93 | bool IsSpecialColor(ColorID aID, nscolor &aColor); |
michael@0 | 94 | bool ColorIsNotCSSAccessible(ColorID aID); |
michael@0 | 95 | nscolor GetStandinForNativeColor(ColorID aID); |
michael@0 | 96 | |
michael@0 | 97 | static void OnPrefChanged(const char* aPref, void* aClosure); |
michael@0 | 98 | |
michael@0 | 99 | static bool sInitialized; |
michael@0 | 100 | static nsLookAndFeelIntPref sIntPrefs[]; |
michael@0 | 101 | static nsLookAndFeelFloatPref sFloatPrefs[]; |
michael@0 | 102 | /* this length must not be shorter than the length of the longest string in the array |
michael@0 | 103 | * see nsXPLookAndFeel.cpp |
michael@0 | 104 | */ |
michael@0 | 105 | static const char sColorPrefs[][38]; |
michael@0 | 106 | static int32_t sCachedColors[LookAndFeel::eColorID_LAST_COLOR]; |
michael@0 | 107 | static int32_t sCachedColorBits[COLOR_CACHE_SIZE]; |
michael@0 | 108 | static bool sUseNativeColors; |
michael@0 | 109 | |
michael@0 | 110 | static nsLookAndFeel* sInstance; |
michael@0 | 111 | static bool sShutdown; |
michael@0 | 112 | }; |
michael@0 | 113 | |
michael@0 | 114 | #endif |