Bug 1700051: part 46) Const-qualify `mozInlineSpellStatus::mAnchorRange`. r=smaug
[gecko.git] / gfx / src / nsITheme.h
blob7813f138b3bae60162d440d132745e4ebc970e73
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 wr {
36 class DisplayListBuilder;
37 class IpcResourceUpdateQueue;
38 } // namespace wr
39 } // namespace mozilla
41 // IID for the nsITheme interface
42 // {7329f760-08cb-450f-8225-dae729096dec}
43 #define NS_ITHEME_IID \
44 { \
45 0x7329f760, 0x08cb, 0x450f, { \
46 0x82, 0x25, 0xda, 0xe7, 0x29, 0x09, 0x6d, 0xec \
47 } \
50 /**
51 * nsITheme is a service that provides platform-specific native
52 * rendering for widgets. In other words, it provides the necessary
53 * operations to draw a rendering object (an nsIFrame) as a native
54 * widget.
56 * All the methods on nsITheme take a rendering context or device
57 * context, a frame (the rendering object), and a widget type (one of
58 * the constants in nsThemeConstants.h).
60 class nsITheme : public nsISupports {
61 protected:
62 using LayoutDeviceIntMargin = mozilla::LayoutDeviceIntMargin;
63 using LayoutDeviceIntSize = mozilla::LayoutDeviceIntSize;
64 using LayoutDeviceIntCoord = mozilla::LayoutDeviceIntCoord;
65 using StyleAppearance = mozilla::StyleAppearance;
66 using StyleScrollbarWidth = mozilla::StyleScrollbarWidth;
67 using ComputedStyle = mozilla::ComputedStyle;
69 public:
70 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITHEME_IID)
72 /**
73 * Draw the actual theme background.
74 * @param aContext the context to draw into
75 * @param aFrame the frame for the widget that we're drawing
76 * @param aWidgetType the -moz-appearance value to draw
77 * @param aRect the rectangle defining the area occupied by the widget
78 * @param aDirtyRect the rectangle that needs to be drawn
79 * @param DrawOverflow whether outlines, shadows and other such overflowing
80 * things should be drawn. Honoring this creates better results for
81 * box-shadow, though it's not a hard requirement.
83 enum class DrawOverflow { No, Yes };
84 NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
85 StyleAppearance aWidgetType,
86 const nsRect& aRect, const nsRect& aDirtyRect,
87 DrawOverflow = DrawOverflow::Yes) = 0;
89 /**
90 * Create WebRender commands for the theme background.
91 * @return true if the theme knows how to create WebRender commands for the
92 * given widget type, false if DrawWidgetBackground need sto be called
93 * instead.
95 virtual bool CreateWebRenderCommandsForWidget(
96 mozilla::wr::DisplayListBuilder& aBuilder,
97 mozilla::wr::IpcResourceUpdateQueue& aResources,
98 const mozilla::layers::StackingContextHelper& aSc,
99 mozilla::layers::RenderRootStateManager* aManager, nsIFrame* aFrame,
100 StyleAppearance aWidgetType, const nsRect& aRect) {
101 return false;
105 * Returns the minimum widths of a scrollbar for a given style, that is, the
106 * minimum width for a vertical scrollbar, and the minimum height of a
107 * horizontal scrollbar.
109 enum class Overlay { No, Yes };
110 struct ScrollbarSizes {
111 LayoutDeviceIntCoord mVertical;
112 LayoutDeviceIntCoord mHorizontal;
114 virtual ScrollbarSizes GetScrollbarSizes(nsPresContext*, 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 *pixels* (in
167 * |aResult|). If |aIsOverridable| is set to true, this size is a
168 * minimum size; if false, this size is the only valid size for the
169 * widget.
171 NS_IMETHOD GetMinimumWidgetSize(nsPresContext* aPresContext, nsIFrame* aFrame,
172 StyleAppearance aWidgetType,
173 mozilla::LayoutDeviceIntSize* aResult,
174 bool* aIsOverridable) = 0;
176 enum Transparency { eOpaque = 0, eTransparent, eUnknownTransparency };
179 * Returns what we know about the transparency of the widget.
181 virtual Transparency GetWidgetTransparency(nsIFrame* aFrame,
182 StyleAppearance aWidgetType) {
183 return eUnknownTransparency;
187 * Sets |*aShouldRepaint| to indicate whether an attribute or content state
188 * change should trigger a repaint. Call with null |aAttribute| (and
189 * null |aOldValue|) for content state changes.
191 NS_IMETHOD WidgetStateChanged(nsIFrame* aFrame, StyleAppearance aWidgetType,
192 nsAtom* aAttribute, bool* aShouldRepaint,
193 const nsAttrValue* aOldValue) = 0;
195 NS_IMETHOD ThemeChanged() = 0;
197 virtual bool WidgetAppearanceDependsOnWindowFocus(
198 StyleAppearance aWidgetType) {
199 return false;
203 * ThemeGeometryType values are used for describing themed nsIFrames in
204 * calls to nsIWidget::UpdateThemeGeometries. We don't simply pass the
205 * -moz-appearance value ("widget type") of the frame because the widget may
206 * want to treat different frames with the same -moz-appearance differently
207 * based on other properties of the frame. So we give the theme a first look
208 * at the frame in nsITheme::ThemeGeometryTypeForWidget and pass the
209 * returned ThemeGeometryType along to the widget.
210 * Each theme backend defines the ThemeGeometryType values it needs in its
211 * own nsITheme subclass. eThemeGeometryTypeUnknown is the only value that's
212 * shared between backends.
214 typedef uint8_t ThemeGeometryType;
215 enum { eThemeGeometryTypeUnknown = 0 };
218 * Returns the theme geometry type that should be used in the ThemeGeometry
219 * array that's passed to the widget using nsIWidget::UpdateThemeGeometries.
220 * A return value of eThemeGeometryTypeUnknown means that this frame will
221 * not be included in the ThemeGeometry array.
223 virtual ThemeGeometryType ThemeGeometryTypeForWidget(
224 nsIFrame* aFrame, StyleAppearance aWidgetType) {
225 return eThemeGeometryTypeUnknown;
229 * Can the nsITheme implementation handle this widget?
231 virtual bool ThemeSupportsWidget(nsPresContext* aPresContext,
232 nsIFrame* aFrame,
233 StyleAppearance aWidgetType) = 0;
235 virtual bool WidgetIsContainer(StyleAppearance aWidgetType) = 0;
238 * Does the nsITheme implementation draw its own focus ring for this widget?
240 virtual bool ThemeDrawsFocusForWidget(StyleAppearance aWidgetType) = 0;
243 * Whether we want an inner focus ring for buttons and such.
245 * Usually, we don't want it if we have our own focus indicators, but windows
246 * is special, because it wants it even though focus also alters the border
247 * color and such.
249 virtual bool ThemeWantsButtonInnerFocusRing(StyleAppearance aAppearance) {
250 return !ThemeDrawsFocusForWidget(aAppearance);
254 * Should we insert a dropmarker inside of combobox button?
256 virtual bool ThemeNeedsComboboxDropmarker() = 0;
258 virtual bool ThemeSupportsScrollbarButtons() { return true; }
261 NS_DEFINE_STATIC_IID_ACCESSOR(nsITheme, NS_ITHEME_IID)
263 // Singleton accessor functions, these should never return null.
265 // Do not use directly, use nsPresContext::Theme instead.
266 extern already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly();
267 extern already_AddRefed<nsITheme> do_GetBasicNativeThemeDoNotUseDirectly();
269 #endif