Coverage Report

Created: 2018-09-25 14:53

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