Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsITheme.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
/* service providing platform-specific native rendering for widgets */
8
9
#ifndef nsITheme_h_
10
#define nsITheme_h_
11
12
#include "nsISupports.h"
13
#include "nsCOMPtr.h"
14
#include "nsColor.h"
15
#include "Units.h"
16
17
struct nsRect;
18
class gfxContext;
19
class nsAttrValue;
20
class nsPresContext;
21
class nsDeviceContext;
22
class nsIFrame;
23
class nsAtom;
24
class nsIWidget;
25
26
namespace mozilla {
27
class ComputedStyle;
28
enum class StyleAppearance : uint8_t;
29
namespace layers {
30
class StackingContextHelper;
31
class WebRenderLayerManager;
32
}
33
namespace wr {
34
class DisplayListBuilder;
35
class IpcResourceUpdateQueue;
36
}
37
}
38
39
// IID for the nsITheme interface
40
// {7329f760-08cb-450f-8225-dae729096dec}
41
 #define NS_ITHEME_IID     \
42
{ 0x7329f760, 0x08cb, 0x450f, \
43
  { 0x82, 0x25, 0xda, 0xe7, 0x29, 0x09, 0x6d, 0xec } }
44
45
/**
46
 * nsITheme is a service that provides platform-specific native
47
 * rendering for widgets.  In other words, it provides the necessary
48
 * operations to draw a rendering object (an nsIFrame) as a native
49
 * widget.
50
 *
51
 * All the methods on nsITheme take a rendering context or device
52
 * context, a frame (the rendering object), and a widget type (one of
53
 * the constants in nsThemeConstants.h).
54
 */
55
class nsITheme: public nsISupports {
56
protected:
57
  using LayoutDeviceIntMargin = mozilla::LayoutDeviceIntMargin;
58
  using WidgetType = mozilla::StyleAppearance;
59
60
public:
61
  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITHEME_IID)
62
63
  /**
64
   * Draw the actual theme background.
65
   * @param aContext the context to draw into
66
   * @param aFrame the frame for the widget that we're drawing
67
   * @param aWidgetType the -moz-appearance value to draw
68
   * @param aRect the rectangle defining the area occupied by the widget
69
   * @param aDirtyRect the rectangle that needs to be drawn
70
   */
71
  NS_IMETHOD DrawWidgetBackground(gfxContext* aContext,
72
                                  nsIFrame* aFrame,
73
                                  WidgetType aWidgetType,
74
                                  const nsRect& aRect,
75
                                  const nsRect& aDirtyRect) = 0;
76
77
  /**
78
   * Get the used color of the given widget when it's specified as auto.
79
   * It's currently only used for scrollbar-*-color properties.
80
   */
81
  virtual nscolor GetWidgetAutoColor(mozilla::ComputedStyle* aStyle,
82
                                     WidgetType aWidgetType)
83
0
  { return NS_RGB(0, 0, 0); }
84
85
  /**
86
   * Create WebRender commands for the theme background.
87
   * @return true if the theme knows how to create WebRender commands for the
88
   *         given widget type, false if DrawWidgetBackground need sto be called
89
   *         instead.
90
   */
91
  virtual bool CreateWebRenderCommandsForWidget(mozilla::wr::DisplayListBuilder& aBuilder,
92
                                                mozilla::wr::IpcResourceUpdateQueue& aResources,
93
                                                const mozilla::layers::StackingContextHelper& aSc,
94
                                                mozilla::layers::WebRenderLayerManager* aManager,
95
                                                nsIFrame* aFrame,
96
                                                WidgetType aWidgetType,
97
0
                                                const nsRect& aRect) { return false; }
98
99
  /**
100
   * Return the border for the widget, in device pixels.
101
   */
102
  virtual MOZ_MUST_USE LayoutDeviceIntMargin GetWidgetBorder(nsDeviceContext* aContext,
103
                                                             nsIFrame* aFrame,
104
                                                             WidgetType aWidgetType) = 0;
105
106
  /**
107
   * This method can return false to indicate that the CSS padding
108
   * value should be used.  Otherwise, it will fill in aResult with the
109
   * computed padding, in pixels, and return true.
110
   *
111
   * XXXldb This ought to be required to return true for non-containers
112
   * so that we don't let specified padding that has no effect change
113
   * the computed padding and potentially the size.
114
   */
115
  virtual bool GetWidgetPadding(nsDeviceContext* aContext,
116
                                nsIFrame* aFrame,
117
                                WidgetType aWidgetType,
118
                                LayoutDeviceIntMargin* aResult) = 0;
119
120
  /**
121
   * On entry, *aResult is positioned at 0,0 and sized to the new size
122
   * of aFrame (aFrame->GetSize() may be stale and should not be used).
123
   * This method can return false to indicate that no special
124
   * overflow area is required by the native widget. Otherwise it will
125
   * fill in aResult with the desired overflow area, in appunits, relative
126
   * to the frame origin, and return true.
127
   *
128
   * This overflow area is used to determine what area needs to be
129
   * repainted when the widget changes.  However, it does not affect the
130
   * widget's size or what area is reachable by scrollbars.  (In other
131
   * words, in layout terms, it affects visual overflow but not
132
   * scrollable overflow.)
133
   */
134
  virtual bool GetWidgetOverflow(nsDeviceContext* aContext,
135
                                 nsIFrame* aFrame,
136
                                 WidgetType aWidgetType,
137
                                 /*INOUT*/ nsRect* aOverflowRect)
138
0
  { return false; }
139
140
  /**
141
   * Get the minimum border-box size of a widget, in *pixels* (in
142
   * |aResult|).  If |aIsOverridable| is set to true, this size is a
143
   * minimum size; if false, this size is the only valid size for the
144
   * widget.
145
   */
146
  NS_IMETHOD GetMinimumWidgetSize(nsPresContext* aPresContext,
147
                                  nsIFrame* aFrame,
148
                                  WidgetType aWidgetType,
149
                                  mozilla::LayoutDeviceIntSize* aResult,
150
                                  bool* aIsOverridable)=0;
151
152
153
  enum Transparency {
154
    eOpaque = 0,
155
    eTransparent,
156
    eUnknownTransparency
157
  };
158
159
  /**
160
   * Returns what we know about the transparency of the widget.
161
   */
162
  virtual Transparency GetWidgetTransparency(nsIFrame* aFrame, WidgetType aWidgetType)
163
0
  { return eUnknownTransparency; }
164
165
  /**
166
   * Sets |*aShouldRepaint| to indicate whether an attribute or content state
167
   * change should trigger a repaint.  Call with null |aAttribute| (and
168
   * null |aOldValue|) for content state changes.
169
   */
170
  NS_IMETHOD WidgetStateChanged(nsIFrame* aFrame, WidgetType aWidgetType,
171
                                nsAtom* aAttribute, bool* aShouldRepaint,
172
                                const nsAttrValue* aOldValue)=0;
173
174
  NS_IMETHOD ThemeChanged()=0;
175
176
  virtual bool WidgetAppearanceDependsOnWindowFocus(WidgetType aWidgetType)
177
0
  { return false; }
178
179
  virtual bool NeedToClearBackgroundBehindWidget(nsIFrame* aFrame, WidgetType aWidgetType)
180
0
  { return false; }
181
182
  /**
183
   * ThemeGeometryType values are used for describing themed nsIFrames in
184
   * calls to nsIWidget::UpdateThemeGeometries. We don't simply pass the
185
   * -moz-appearance value ("widget type") of the frame because the widget may
186
   * want to treat different frames with the same -moz-appearance differently
187
   * based on other properties of the frame. So we give the theme a first look
188
   * at the frame in nsITheme::ThemeGeometryTypeForWidget and pass the
189
   * returned ThemeGeometryType along to the widget.
190
   * Each theme backend defines the ThemeGeometryType values it needs in its
191
   * own nsITheme subclass. eThemeGeometryTypeUnknown is the only value that's
192
   * shared between backends.
193
   */
194
  typedef uint8_t ThemeGeometryType;
195
  enum {
196
    eThemeGeometryTypeUnknown = 0
197
  };
198
199
  /**
200
   * Returns the theme geometry type that should be used in the ThemeGeometry
201
   * array that's passed to the widget using nsIWidget::UpdateThemeGeometries.
202
   * A return value of eThemeGeometryTypeUnknown means that this frame will
203
   * not be included in the ThemeGeometry array.
204
   */
205
  virtual ThemeGeometryType ThemeGeometryTypeForWidget(nsIFrame* aFrame,
206
                                                       WidgetType aWidgetType)
207
0
  { return eThemeGeometryTypeUnknown; }
208
209
  /**
210
   * Can the nsITheme implementation handle this widget?
211
   */
212
  virtual bool ThemeSupportsWidget(nsPresContext* aPresContext,
213
                                   nsIFrame* aFrame,
214
                                   WidgetType aWidgetType) = 0;
215
216
  virtual bool WidgetIsContainer(WidgetType aWidgetType) = 0;
217
218
  /**
219
   * Does the nsITheme implementation draw its own focus ring for this widget?
220
   */
221
  virtual bool ThemeDrawsFocusForWidget(WidgetType aWidgetType) = 0;
222
  
223
  /**
224
    * Should we insert a dropmarker inside of combobox button?
225
   */
226
  virtual bool ThemeNeedsComboboxDropmarker() = 0;
227
};
228
229
NS_DEFINE_STATIC_IID_ACCESSOR(nsITheme, NS_ITHEME_IID)
230
231
// Singleton accessor function
232
extern already_AddRefed<nsITheme> do_GetNativeTheme();
233
234
#endif