Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/widget/nsNativeTheme.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; 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
// This defines a common base class for nsITheme implementations, to reduce
7
// code duplication.
8
9
#ifndef _NSNATIVETHEME_H_
10
#define _NSNATIVETHEME_H_
11
12
#include "nsAlgorithm.h"
13
#include "nsAtom.h"
14
#include "nsCOMPtr.h"
15
#include "nsString.h"
16
#include "nsMargin.h"
17
#include "nsGkAtoms.h"
18
#include "nsTArray.h"
19
#include "nsINamed.h"
20
#include "nsITimer.h"
21
#include "nsIContent.h"
22
23
class nsIFrame;
24
class nsIPresShell;
25
class nsPresContext;
26
27
namespace mozilla {
28
class ComputedStyle;
29
enum class StyleAppearance : uint8_t;
30
class EventStates;
31
} // namespace mozilla
32
33
class nsNativeTheme : public nsITimerCallback, public nsINamed
34
{
35
 protected:
36
0
  virtual ~nsNativeTheme() {}
37
38
  NS_DECL_ISUPPORTS
39
  NS_DECL_NSITIMERCALLBACK
40
  NS_DECL_NSINAMED
41
42
  enum ScrollbarButtonType {
43
    eScrollbarButton_UpTop   = 0,
44
    eScrollbarButton_Down    = 1 << 0,
45
    eScrollbarButton_Bottom  = 1 << 1
46
  };
47
48
  enum TreeSortDirection {
49
    eTreeSortDirection_Descending,
50
    eTreeSortDirection_Natural,
51
    eTreeSortDirection_Ascending
52
  };
53
54
  nsNativeTheme();
55
56
  // Returns the content state (hover, focus, etc), see EventStateManager.h
57
  mozilla::EventStates GetContentState(nsIFrame* aFrame,
58
                                       mozilla::StyleAppearance aWidgetType);
59
60
  // Returns whether the widget is already styled by content
61
  // Normally called from ThemeSupportsWidget to turn off native theming
62
  // for elements that are already styled.
63
  bool IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
64
                      mozilla::StyleAppearance aWidgetType);
65
66
  // Accessors to widget-specific state information
67
68
  bool IsDisabled(nsIFrame* aFrame, mozilla::EventStates aEventStates);
69
70
  // RTL chrome direction
71
  static bool IsFrameRTL(nsIFrame* aFrame);
72
73
  bool IsHTMLContent(nsIFrame *aFrame);
74
  
75
  // button:
76
0
  bool IsDefaultButton(nsIFrame* aFrame) {
77
0
    return CheckBooleanAttr(aFrame, nsGkAtoms::_default);
78
0
  }
79
80
  bool IsButtonTypeMenu(nsIFrame* aFrame);
81
82
  // checkbox:
83
0
  bool IsChecked(nsIFrame* aFrame) {
84
0
    return GetCheckedOrSelected(aFrame, false);
85
0
  }
86
87
  // radiobutton:
88
0
  bool IsSelected(nsIFrame* aFrame) {
89
0
    return GetCheckedOrSelected(aFrame, true);
90
0
  }
91
92
0
  bool IsFocused(nsIFrame* aFrame) {
93
0
    return CheckBooleanAttr(aFrame, nsGkAtoms::focused);
94
0
  }
95
96
  // scrollbar button:
97
  int32_t GetScrollbarButtonType(nsIFrame* aFrame);
98
99
  // tab:
100
0
  bool IsSelectedTab(nsIFrame* aFrame) {
101
0
    return CheckBooleanAttr(aFrame, nsGkAtoms::visuallyselected);
102
0
  }
103
  
104
  bool IsNextToSelectedTab(nsIFrame* aFrame, int32_t aOffset);
105
  
106
0
  bool IsBeforeSelectedTab(nsIFrame* aFrame) {
107
0
    return IsNextToSelectedTab(aFrame, -1);
108
0
  }
109
  
110
0
  bool IsAfterSelectedTab(nsIFrame* aFrame) {
111
0
    return IsNextToSelectedTab(aFrame, 1);
112
0
  }
113
114
0
  bool IsLeftToSelectedTab(nsIFrame* aFrame) {
115
0
    return IsFrameRTL(aFrame) ? IsAfterSelectedTab(aFrame) : IsBeforeSelectedTab(aFrame);
116
0
  }
117
118
0
  bool IsRightToSelectedTab(nsIFrame* aFrame) {
119
0
    return IsFrameRTL(aFrame) ? IsBeforeSelectedTab(aFrame) : IsAfterSelectedTab(aFrame);
120
0
  }
121
122
  // button / toolbarbutton:
123
0
  bool IsCheckedButton(nsIFrame* aFrame) {
124
0
    return CheckBooleanAttr(aFrame, nsGkAtoms::checked);
125
0
  }
126
127
0
  bool IsSelectedButton(nsIFrame* aFrame) {
128
0
    return CheckBooleanAttr(aFrame, nsGkAtoms::checked) ||
129
0
           CheckBooleanAttr(aFrame, nsGkAtoms::selected);
130
0
  }
131
132
0
  bool IsOpenButton(nsIFrame* aFrame) {
133
0
    return CheckBooleanAttr(aFrame, nsGkAtoms::open);
134
0
  }
135
136
  bool IsPressedButton(nsIFrame* aFrame);
137
138
  // treeheadercell:
139
  TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame);
140
  bool IsLastTreeHeaderCell(nsIFrame* aFrame);
141
142
  // tab:
143
  bool IsBottomTab(nsIFrame* aFrame);
144
  bool IsFirstTab(nsIFrame* aFrame);
145
  
146
  bool IsHorizontal(nsIFrame* aFrame);
147
148
  // progressbar:
149
  bool IsIndeterminateProgress(nsIFrame* aFrame,
150
                               mozilla::EventStates aEventStates);
151
  bool IsVerticalProgress(nsIFrame* aFrame);
152
153
  // meter:
154
  bool IsVerticalMeter(nsIFrame* aFrame);
155
156
  // textfield:
157
0
  bool IsReadOnly(nsIFrame* aFrame) {
158
0
      return CheckBooleanAttr(aFrame, nsGkAtoms::readonly);
159
0
  }
160
161
  // menupopup:
162
  bool IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent);
163
164
  // True if it's not a menubar item or menulist item
165
  bool IsRegularMenuItem(nsIFrame *aFrame);
166
167
  nsIPresShell *GetPresShell(nsIFrame* aFrame);
168
  static bool CheckBooleanAttr(nsIFrame* aFrame, nsAtom* aAtom);
169
  static int32_t CheckIntAttr(nsIFrame* aFrame, nsAtom* aAtom, int32_t defaultValue);
170
171
  // Helpers for progressbar.
172
  static double GetProgressValue(nsIFrame* aFrame);
173
  static double GetProgressMaxValue(nsIFrame* aFrame);
174
175
  bool GetCheckedOrSelected(nsIFrame* aFrame, bool aCheckSelected);
176
  bool GetIndeterminate(nsIFrame* aFrame);
177
178
  bool QueueAnimatedContentForRefresh(nsIContent* aContent,
179
                                        uint32_t aMinimumFrameRate);
180
181
  nsIFrame* GetAdjacentSiblingFrameWithSameAppearance(nsIFrame* aFrame,
182
                                                      bool aNextSibling);
183
184
  bool IsRangeHorizontal(nsIFrame* aFrame);
185
186
  // scrollbar
187
  bool IsDarkBackground(nsIFrame* aFrame);
188
  // custom scrollbar
189
  typedef nscolor (*AutoColorGetter)(mozilla::ComputedStyle*);
190
  bool IsWidgetScrollbarPart(mozilla::StyleAppearance aWidgetType);
191
  nscolor GetScrollbarFaceColor(mozilla::ComputedStyle* aStyle,
192
                                AutoColorGetter aAutoGetter);
193
  nscolor GetScrollbarTrackColor(mozilla::ComputedStyle* aStyle,
194
                                 AutoColorGetter aAutoGetter);
195
196
 private:
197
  uint32_t mAnimatedContentTimeout;
198
  nsCOMPtr<nsITimer> mAnimatedContentTimer;
199
  AutoTArray<nsCOMPtr<nsIContent>, 20> mAnimatedContentList;
200
};
201
202
#endif // _NSNATIVETHEME_H_