1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/xpwidgets/nsXPLookAndFeel.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef __nsXPLookAndFeel 1.10 +#define __nsXPLookAndFeel 1.11 + 1.12 +#include "mozilla/LookAndFeel.h" 1.13 + 1.14 +class nsLookAndFeel; 1.15 + 1.16 +struct nsLookAndFeelIntPref 1.17 +{ 1.18 + const char* name; 1.19 + mozilla::LookAndFeel::IntID id; 1.20 + bool isSet; 1.21 + int32_t intVar; 1.22 +}; 1.23 + 1.24 +struct nsLookAndFeelFloatPref 1.25 +{ 1.26 + const char* name; 1.27 + mozilla::LookAndFeel::FloatID id; 1.28 + bool isSet; 1.29 + float floatVar; 1.30 +}; 1.31 + 1.32 +#define CACHE_BLOCK(x) ((x) >> 5) 1.33 +#define CACHE_BIT(x) (1 << ((x) & 31)) 1.34 + 1.35 +#define COLOR_CACHE_SIZE (CACHE_BLOCK(LookAndFeel::eColorID_LAST_COLOR) + 1) 1.36 +#define IS_COLOR_CACHED(x) (CACHE_BIT(x) & nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)]) 1.37 +#define CLEAR_COLOR_CACHE(x) nsXPLookAndFeel::sCachedColors[(x)] =0; \ 1.38 + nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] &= ~(CACHE_BIT(x)); 1.39 +#define CACHE_COLOR(x, y) nsXPLookAndFeel::sCachedColors[(x)] = y; \ 1.40 + nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] |= CACHE_BIT(x); 1.41 + 1.42 +class nsXPLookAndFeel: public mozilla::LookAndFeel 1.43 +{ 1.44 +public: 1.45 + virtual ~nsXPLookAndFeel(); 1.46 + 1.47 + static nsLookAndFeel* GetInstance(); 1.48 + static void Shutdown(); 1.49 + 1.50 + void Init(); 1.51 + 1.52 + // 1.53 + // All these routines will return NS_OK if they have a value, 1.54 + // in which case the nsLookAndFeel should use that value; 1.55 + // otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the 1.56 + // platform-specific nsLookAndFeel should use its own values instead. 1.57 + // 1.58 + nsresult GetColorImpl(ColorID aID, bool aUseStandinsForNativeColors, 1.59 + nscolor &aResult); 1.60 + virtual nsresult GetIntImpl(IntID aID, int32_t &aResult); 1.61 + virtual nsresult GetFloatImpl(FloatID aID, float &aResult); 1.62 + 1.63 + // This one is different: there are no override prefs (fixme?), so 1.64 + // there is no XP implementation, only per-system impls. 1.65 + virtual bool GetFontImpl(FontID aID, nsString& aName, 1.66 + gfxFontStyle& aStyle, 1.67 + float aDevPixPerCSSPixel) = 0; 1.68 + 1.69 + virtual void RefreshImpl(); 1.70 + 1.71 + virtual char16_t GetPasswordCharacterImpl() 1.72 + { 1.73 + return char16_t('*'); 1.74 + } 1.75 + 1.76 + virtual bool GetEchoPasswordImpl() 1.77 + { 1.78 + return false; 1.79 + } 1.80 + 1.81 + virtual uint32_t GetPasswordMaskDelayImpl() 1.82 + { 1.83 + return 600; 1.84 + } 1.85 + 1.86 +protected: 1.87 + nsXPLookAndFeel(); 1.88 + 1.89 + static void IntPrefChanged(nsLookAndFeelIntPref *data); 1.90 + static void FloatPrefChanged(nsLookAndFeelFloatPref *data); 1.91 + static void ColorPrefChanged(unsigned int index, const char *prefName); 1.92 + void InitFromPref(nsLookAndFeelIntPref* aPref); 1.93 + void InitFromPref(nsLookAndFeelFloatPref* aPref); 1.94 + void InitColorFromPref(int32_t aIndex); 1.95 + virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult) = 0; 1.96 + bool IsSpecialColor(ColorID aID, nscolor &aColor); 1.97 + bool ColorIsNotCSSAccessible(ColorID aID); 1.98 + nscolor GetStandinForNativeColor(ColorID aID); 1.99 + 1.100 + static void OnPrefChanged(const char* aPref, void* aClosure); 1.101 + 1.102 + static bool sInitialized; 1.103 + static nsLookAndFeelIntPref sIntPrefs[]; 1.104 + static nsLookAndFeelFloatPref sFloatPrefs[]; 1.105 + /* this length must not be shorter than the length of the longest string in the array 1.106 + * see nsXPLookAndFeel.cpp 1.107 + */ 1.108 + static const char sColorPrefs[][38]; 1.109 + static int32_t sCachedColors[LookAndFeel::eColorID_LAST_COLOR]; 1.110 + static int32_t sCachedColorBits[COLOR_CACHE_SIZE]; 1.111 + static bool sUseNativeColors; 1.112 + 1.113 + static nsLookAndFeel* sInstance; 1.114 + static bool sShutdown; 1.115 +}; 1.116 + 1.117 +#endif