michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef __nsXPLookAndFeel michael@0: #define __nsXPLookAndFeel michael@0: michael@0: #include "mozilla/LookAndFeel.h" michael@0: michael@0: class nsLookAndFeel; michael@0: michael@0: struct nsLookAndFeelIntPref michael@0: { michael@0: const char* name; michael@0: mozilla::LookAndFeel::IntID id; michael@0: bool isSet; michael@0: int32_t intVar; michael@0: }; michael@0: michael@0: struct nsLookAndFeelFloatPref michael@0: { michael@0: const char* name; michael@0: mozilla::LookAndFeel::FloatID id; michael@0: bool isSet; michael@0: float floatVar; michael@0: }; michael@0: michael@0: #define CACHE_BLOCK(x) ((x) >> 5) michael@0: #define CACHE_BIT(x) (1 << ((x) & 31)) michael@0: michael@0: #define COLOR_CACHE_SIZE (CACHE_BLOCK(LookAndFeel::eColorID_LAST_COLOR) + 1) michael@0: #define IS_COLOR_CACHED(x) (CACHE_BIT(x) & nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)]) michael@0: #define CLEAR_COLOR_CACHE(x) nsXPLookAndFeel::sCachedColors[(x)] =0; \ michael@0: nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] &= ~(CACHE_BIT(x)); michael@0: #define CACHE_COLOR(x, y) nsXPLookAndFeel::sCachedColors[(x)] = y; \ michael@0: nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] |= CACHE_BIT(x); michael@0: michael@0: class nsXPLookAndFeel: public mozilla::LookAndFeel michael@0: { michael@0: public: michael@0: virtual ~nsXPLookAndFeel(); michael@0: michael@0: static nsLookAndFeel* GetInstance(); michael@0: static void Shutdown(); michael@0: michael@0: void Init(); michael@0: michael@0: // michael@0: // All these routines will return NS_OK if they have a value, michael@0: // in which case the nsLookAndFeel should use that value; michael@0: // otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the michael@0: // platform-specific nsLookAndFeel should use its own values instead. michael@0: // michael@0: nsresult GetColorImpl(ColorID aID, bool aUseStandinsForNativeColors, michael@0: nscolor &aResult); michael@0: virtual nsresult GetIntImpl(IntID aID, int32_t &aResult); michael@0: virtual nsresult GetFloatImpl(FloatID aID, float &aResult); michael@0: michael@0: // This one is different: there are no override prefs (fixme?), so michael@0: // there is no XP implementation, only per-system impls. michael@0: virtual bool GetFontImpl(FontID aID, nsString& aName, michael@0: gfxFontStyle& aStyle, michael@0: float aDevPixPerCSSPixel) = 0; michael@0: michael@0: virtual void RefreshImpl(); michael@0: michael@0: virtual char16_t GetPasswordCharacterImpl() michael@0: { michael@0: return char16_t('*'); michael@0: } michael@0: michael@0: virtual bool GetEchoPasswordImpl() michael@0: { michael@0: return false; michael@0: } michael@0: michael@0: virtual uint32_t GetPasswordMaskDelayImpl() michael@0: { michael@0: return 600; michael@0: } michael@0: michael@0: protected: michael@0: nsXPLookAndFeel(); michael@0: michael@0: static void IntPrefChanged(nsLookAndFeelIntPref *data); michael@0: static void FloatPrefChanged(nsLookAndFeelFloatPref *data); michael@0: static void ColorPrefChanged(unsigned int index, const char *prefName); michael@0: void InitFromPref(nsLookAndFeelIntPref* aPref); michael@0: void InitFromPref(nsLookAndFeelFloatPref* aPref); michael@0: void InitColorFromPref(int32_t aIndex); michael@0: virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult) = 0; michael@0: bool IsSpecialColor(ColorID aID, nscolor &aColor); michael@0: bool ColorIsNotCSSAccessible(ColorID aID); michael@0: nscolor GetStandinForNativeColor(ColorID aID); michael@0: michael@0: static void OnPrefChanged(const char* aPref, void* aClosure); michael@0: michael@0: static bool sInitialized; michael@0: static nsLookAndFeelIntPref sIntPrefs[]; michael@0: static nsLookAndFeelFloatPref sFloatPrefs[]; michael@0: /* this length must not be shorter than the length of the longest string in the array michael@0: * see nsXPLookAndFeel.cpp michael@0: */ michael@0: static const char sColorPrefs[][38]; michael@0: static int32_t sCachedColors[LookAndFeel::eColorID_LAST_COLOR]; michael@0: static int32_t sCachedColorBits[COLOR_CACHE_SIZE]; michael@0: static bool sUseNativeColors; michael@0: michael@0: static nsLookAndFeel* sInstance; michael@0: static bool sShutdown; michael@0: }; michael@0: michael@0: #endif