nsXPLookAndFeel.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/. */
  5. #ifndef __nsXPLookAndFeel
  6. #define __nsXPLookAndFeel
  7. #include "mozilla/LookAndFeel.h"
  8. #include "nsTArray.h"
  9. class nsLookAndFeel;
  10. struct nsLookAndFeelIntPref
  11. {
  12. const char* name;
  13. mozilla::LookAndFeel::IntID id;
  14. bool isSet;
  15. int32_t intVar;
  16. };
  17. struct nsLookAndFeelFloatPref
  18. {
  19. const char* name;
  20. mozilla::LookAndFeel::FloatID id;
  21. bool isSet;
  22. float floatVar;
  23. };
  24. #define CACHE_BLOCK(x) ((x) >> 5)
  25. #define CACHE_BIT(x) (1 << ((x) & 31))
  26. #define COLOR_CACHE_SIZE (CACHE_BLOCK(LookAndFeel::eColorID_LAST_COLOR) + 1)
  27. #define IS_COLOR_CACHED(x) (CACHE_BIT(x) & nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)])
  28. #define CLEAR_COLOR_CACHE(x) nsXPLookAndFeel::sCachedColors[(x)] =0; \
  29. nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] &= ~(CACHE_BIT(x));
  30. #define CACHE_COLOR(x, y) nsXPLookAndFeel::sCachedColors[(x)] = y; \
  31. nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] |= CACHE_BIT(x);
  32. class nsXPLookAndFeel: public mozilla::LookAndFeel
  33. {
  34. public:
  35. virtual ~nsXPLookAndFeel();
  36. static nsLookAndFeel* GetInstance();
  37. static void Shutdown();
  38. void Init();
  39. //
  40. // All these routines will return NS_OK if they have a value,
  41. // in which case the nsLookAndFeel should use that value;
  42. // otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
  43. // platform-specific nsLookAndFeel should use its own values instead.
  44. //
  45. nsresult GetColorImpl(ColorID aID, bool aUseStandinsForNativeColors,
  46. nscolor &aResult);
  47. virtual nsresult GetIntImpl(IntID aID, int32_t &aResult);
  48. virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
  49. // This one is different: there are no override prefs (fixme?), so
  50. // there is no XP implementation, only per-system impls.
  51. virtual bool GetFontImpl(FontID aID, nsString& aName,
  52. gfxFontStyle& aStyle,
  53. float aDevPixPerCSSPixel) = 0;
  54. virtual void RefreshImpl();
  55. virtual char16_t GetPasswordCharacterImpl()
  56. {
  57. return char16_t('*');
  58. }
  59. virtual bool GetEchoPasswordImpl()
  60. {
  61. return false;
  62. }
  63. virtual uint32_t GetPasswordMaskDelayImpl()
  64. {
  65. return 600;
  66. }
  67. virtual nsTArray<LookAndFeelInt> GetIntCacheImpl();
  68. virtual void SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) {}
  69. protected:
  70. nsXPLookAndFeel();
  71. static void IntPrefChanged(nsLookAndFeelIntPref *data);
  72. static void FloatPrefChanged(nsLookAndFeelFloatPref *data);
  73. static void ColorPrefChanged(unsigned int index, const char *prefName);
  74. void InitFromPref(nsLookAndFeelIntPref* aPref);
  75. void InitFromPref(nsLookAndFeelFloatPref* aPref);
  76. void InitColorFromPref(int32_t aIndex);
  77. virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult) = 0;
  78. bool IsSpecialColor(ColorID aID, nscolor &aColor);
  79. bool ColorIsNotCSSAccessible(ColorID aID);
  80. nscolor GetStandinForNativeColor(ColorID aID);
  81. static void OnPrefChanged(const char* aPref, void* aClosure);
  82. static bool sInitialized;
  83. static nsLookAndFeelIntPref sIntPrefs[];
  84. static nsLookAndFeelFloatPref sFloatPrefs[];
  85. /* this length must not be shorter than the length of the longest string in the array
  86. * see nsXPLookAndFeel.cpp
  87. */
  88. static const char sColorPrefs[][38];
  89. static int32_t sCachedColors[LookAndFeel::eColorID_LAST_COLOR];
  90. static int32_t sCachedColorBits[COLOR_CACHE_SIZE];
  91. static bool sUseNativeColors;
  92. static bool sUseStandinsForNativeColors;
  93. static bool sFindbarModalHighlight;
  94. static nsLookAndFeel* sInstance;
  95. static bool sShutdown;
  96. };
  97. #endif