Backed out changeset 51eeece91171 (bug 1613280) for causing mochitest-plain failures...
[gecko.git] / gfx / src / nsITheme.h
blob48f563751fc7e94d0524a874e3001dab6efadc36
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/. */
7 /* service providing platform-specific native rendering for widgets */
9 #ifndef nsITheme_h_
10 #define nsITheme_h_
12 #include "mozilla/AlreadyAddRefed.h"
13 #include "nsISupports.h"
14 #include "nsID.h"
15 #include "nscore.h"
16 #include "Units.h"
18 struct nsRect;
19 class gfxContext;
20 class nsAttrValue;
21 class nsPresContext;
22 class nsDeviceContext;
23 class nsIFrame;
24 class nsAtom;
25 class nsIWidget;
27 namespace mozilla {
28 class ComputedStyle;
29 enum class StyleAppearance : uint8_t;
30 enum class StyleScrollbarWidth : uint8_t;
31 namespace layers {
32 class StackingContextHelper;
33 class RenderRootStateManager;
34 } // namespace layers
35 namespace widget {
36 class Theme;
37 } // namespace widget
38 namespace wr {
39 class DisplayListBuilder;
40 class IpcResourceUpdateQueue;
41 } // namespace wr
42 } // namespace mozilla
44 // IID for the nsITheme interface
45 // {7329f760-08cb-450f-8225-dae729096dec}
46 #define NS_ITHEME_IID \
47 { \
48 0x7329f760, 0x08cb, 0x450f, { \
49 0x82, 0x25, 0xda, 0xe7, 0x29, 0x09, 0x6d, 0xec \
50 } \
53 /**
54 * nsITheme is a service that provides platform-specific native
55 * rendering for widgets. In other words, it provides the necessary
56 * operations to draw a rendering object (an nsIFrame) as a native
57 * widget.
59 * All the methods on nsITheme take a rendering context or device
60 * context, a frame (the rendering object), and a widget type (one of
61 * the constants in nsThemeConstants.h).
63 class nsITheme : public nsISupports {
64 protected:
65 using LayoutDeviceIntMargin = mozilla::LayoutDeviceIntMargin;
66 using LayoutDeviceIntSize = mozilla::LayoutDeviceIntSize;
67 using LayoutDeviceIntCoord = mozilla::LayoutDeviceIntCoord;
68 using StyleAppearance = mozilla::StyleAppearance;
69 using StyleScrollbarWidth = mozilla::StyleScrollbarWidth;
70 using ComputedStyle = mozilla::ComputedStyle;
72 public:
73 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITHEME_IID)
75 /**
76 * Draw the actual theme background.
77 * @param aContext the context to draw into
78 * @param aFrame the frame for the widget that we're drawing
79 * @param aWidgetType the -moz-appearance value to draw
80 * @param aRect the rectangle defining the area occupied by the widget
81 * @param aDirtyRect the rectangle that needs to be drawn
82 * @param DrawOverflow whether outlines, shadows and other such overflowing
83 * things should be drawn. Honoring this creates better results for
84 * box-shadow, though it's not a hard requirement.
86 enum class DrawOverflow { No, Yes };
87 NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
88 StyleAppearance aWidgetType,
89 const nsRect& aRect, const nsRect& aDirtyRect,
90 DrawOverflow = DrawOverflow::Yes) = 0;
92 /**
93 * Create WebRender commands for the theme background.
94 * @return true if the theme knows how to create WebRender commands for the
95 * given widget type, false if DrawWidgetBackground need sto be called
96 * instead.
98 virtual bool CreateWebRenderCommandsForWidget(
99 mozilla::wr::DisplayListBuilder& aBuilder,
100 mozilla::wr::IpcResourceUpdateQueue& aResources,
101 const mozilla::layers::StackingContextHelper& aSc,
102 mozilla::layers::RenderRootStateManager* aManager, nsIFrame* aFrame,
103 StyleAppearance aWidgetType, const nsRect& aRect) {
104 return false;
108 * Returns the minimum widths of a scrollbar for a given style, that is, the
109 * minimum width for a vertical scrollbar, and the minimum height of a
110 * horizontal scrollbar.
112 enum class Overlay { No, Yes };
113 virtual LayoutDeviceIntCoord GetScrollbarSize(const nsPresContext*,
114 StyleScrollbarWidth,
115 Overlay) = 0;
118 * Return the border for the widget, in device pixels.
120 [[nodiscard]] virtual LayoutDeviceIntMargin GetWidgetBorder(
121 nsDeviceContext* aContext, nsIFrame* aFrame,
122 StyleAppearance aWidgetType) = 0;
125 * This method can return false to indicate that the CSS padding
126 * value should be used. Otherwise, it will fill in aResult with the
127 * computed padding, in pixels, and return true.
129 * XXXldb This ought to be required to return true for non-containers
130 * so that we don't let specified padding that has no effect change
131 * the computed padding and potentially the size.
133 virtual bool GetWidgetPadding(nsDeviceContext* aContext, nsIFrame* aFrame,
134 StyleAppearance aWidgetType,
135 LayoutDeviceIntMargin* aResult) = 0;
138 * On entry, *aResult is positioned at 0,0 and sized to the new size
139 * of aFrame (aFrame->GetSize() may be stale and should not be used).
140 * This method can return false to indicate that no special
141 * overflow area is required by the native widget. Otherwise it will
142 * fill in aResult with the desired overflow area, in appunits, relative
143 * to the frame origin, and return true.
145 * This overflow area is used to determine what area needs to be
146 * repainted when the widget changes. However, it does not affect the
147 * widget's size or what area is reachable by scrollbars. (In other
148 * words, in layout terms, it affects ink overflow but not
149 * scrollable overflow.)
151 virtual bool GetWidgetOverflow(nsDeviceContext* aContext, nsIFrame* aFrame,
152 StyleAppearance aWidgetType,
153 /*INOUT*/ nsRect* aOverflowRect) {
154 return false;
158 * Get the preferred content-box size of a checkbox / radio button, in app
159 * units. Historically 9px.
161 virtual nscoord GetCheckboxRadioPrefSize() {
162 return mozilla::CSSPixel::ToAppUnits(9);
166 * Get the minimum border-box size of a widget, in device pixels.
168 virtual mozilla::LayoutDeviceIntSize GetMinimumWidgetSize(
169 nsPresContext* aPresContext, nsIFrame* aFrame,
170 StyleAppearance aWidgetType) = 0;
172 enum Transparency { eOpaque = 0, eTransparent, eUnknownTransparency };
175 * Returns what we know about the transparency of the widget.
177 virtual Transparency GetWidgetTransparency(nsIFrame* aFrame,
178 StyleAppearance aWidgetType) {
179 return eUnknownTransparency;
183 * Sets |*aShouldRepaint| to indicate whether an attribute or content state
184 * change should trigger a repaint. Call with null |aAttribute| (and
185 * null |aOldValue|) for content state changes.
187 NS_IMETHOD WidgetStateChanged(nsIFrame* aFrame, StyleAppearance aWidgetType,
188 nsAtom* aAttribute, bool* aShouldRepaint,
189 const nsAttrValue* aOldValue) = 0;
191 NS_IMETHOD ThemeChanged() = 0;
193 virtual bool WidgetAppearanceDependsOnWindowFocus(
194 StyleAppearance aWidgetType) {
195 return false;
199 * ThemeGeometryType values are used for describing themed nsIFrames in
200 * calls to nsIWidget::UpdateThemeGeometries. We don't simply pass the
201 * -moz-appearance value ("widget type") of the frame because the widget may
202 * want to treat different frames with the same -moz-appearance differently
203 * based on other properties of the frame. So we give the theme a first look
204 * at the frame in nsITheme::ThemeGeometryTypeForWidget and pass the
205 * returned ThemeGeometryType along to the widget.
206 * Each theme backend defines the ThemeGeometryType values it needs in its
207 * own nsITheme subclass. eThemeGeometryTypeUnknown is the only value that's
208 * shared between backends.
210 typedef uint8_t ThemeGeometryType;
211 enum { eThemeGeometryTypeUnknown = 0 };
214 * Returns the theme geometry type that should be used in the ThemeGeometry
215 * array that's passed to the widget using nsIWidget::UpdateThemeGeometries.
216 * A return value of eThemeGeometryTypeUnknown means that this frame will
217 * not be included in the ThemeGeometry array.
219 virtual ThemeGeometryType ThemeGeometryTypeForWidget(
220 nsIFrame* aFrame, StyleAppearance aWidgetType) {
221 return eThemeGeometryTypeUnknown;
225 * Can the nsITheme implementation handle this widget?
227 virtual bool ThemeSupportsWidget(nsPresContext* aPresContext,
228 nsIFrame* aFrame,
229 StyleAppearance aWidgetType) = 0;
231 virtual bool WidgetIsContainer(StyleAppearance aWidgetType) = 0;
234 * Does the nsITheme implementation draw its own focus ring for this widget?
236 virtual bool ThemeDrawsFocusForWidget(nsIFrame*, StyleAppearance) = 0;
238 // Whether we want an inner focus ring for buttons and menulists.
239 virtual bool ThemeWantsButtonInnerFocusRing() { return false; }
242 * Should we insert a dropmarker inside of combobox button?
244 virtual bool ThemeNeedsComboboxDropmarker() = 0;
246 virtual bool ThemeSupportsScrollbarButtons() = 0;
249 NS_DEFINE_STATIC_IID_ACCESSOR(nsITheme, NS_ITHEME_IID)
251 // Singleton accessor functions, these should never return null.
253 // Do not use directly, use nsPresContext::Theme instead.
254 extern already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly();
255 extern already_AddRefed<nsITheme> do_GetBasicNativeThemeDoNotUseDirectly();
256 extern already_AddRefed<nsITheme> do_GetRDMThemeDoNotUseDirectly();
258 // Native theme creation function, these should never return null.
259 extern already_AddRefed<mozilla::widget::Theme>
260 do_CreateNativeThemeDoNotUseDirectly();
262 #endif