1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 #ifndef mozilla_widget_Theme_h
8 #define mozilla_widget_Theme_h
11 #include "mozilla/gfx/2D.h"
12 #include "mozilla/gfx/Rect.h"
13 #include "mozilla/gfx/Types.h"
15 #include "nsNativeTheme.h"
16 #include "ScrollbarDrawing.h"
20 enum class StyleSystemColor
: uint8_t;
24 class Theme
: protected nsNativeTheme
, public nsITheme
{
26 using sRGBColor
= gfx::sRGBColor
;
27 using DrawTarget
= gfx::DrawTarget
;
28 using Path
= gfx::Path
;
29 using Rect
= gfx::Rect
;
30 using Point
= gfx::Point
;
31 using RectCornerRadii
= gfx::RectCornerRadii
;
32 using Colors
= ThemeColors
;
33 using AccentColor
= ThemeAccentColor
;
34 using ElementState
= dom::ElementState
;
37 explicit Theme(UniquePtr
<ScrollbarDrawing
>&& aScrollbarDrawing
)
38 : mScrollbarDrawing(std::move(aScrollbarDrawing
)) {
39 mScrollbarDrawing
->RecomputeScrollbarParams();
43 static void Shutdown();
44 static void LookAndFeelChanged();
46 using DPIRatio
= CSSToLayoutDeviceScale
;
48 NS_DECL_ISUPPORTS_INHERITED
50 // The nsITheme interface.
51 NS_IMETHOD
DrawWidgetBackground(gfxContext
* aContext
, nsIFrame
*,
52 StyleAppearance
, const nsRect
& aRect
,
53 const nsRect
& aDirtyRect
,
54 DrawOverflow
) override
;
56 bool CreateWebRenderCommandsForWidget(
57 wr::DisplayListBuilder
& aBuilder
, wr::IpcResourceUpdateQueue
& aResources
,
58 const layers::StackingContextHelper
& aSc
,
59 layers::RenderRootStateManager
* aManager
, nsIFrame
*, StyleAppearance
,
60 const nsRect
& aRect
) override
;
62 // PaintBackendData will be either a DrawTarget, or a WebRenderBackendData.
64 // The return value represents whether the widget could be painted with the
66 template <typename PaintBackendData
>
67 bool DoDrawWidgetBackground(PaintBackendData
&, nsIFrame
*, StyleAppearance
,
68 const nsRect
&, DrawOverflow
);
70 [[nodiscard
]] LayoutDeviceIntMargin
GetWidgetBorder(nsDeviceContext
* aContext
,
72 StyleAppearance
) override
;
73 bool GetWidgetPadding(nsDeviceContext
* aContext
, nsIFrame
*, StyleAppearance
,
74 LayoutDeviceIntMargin
* aResult
) override
;
75 bool GetWidgetOverflow(nsDeviceContext
* aContext
, nsIFrame
*, StyleAppearance
,
76 nsRect
* aOverflowRect
) override
;
77 LayoutDeviceIntSize
GetMinimumWidgetSize(nsPresContext
*, nsIFrame
*,
78 StyleAppearance
) override
;
79 Transparency
GetWidgetTransparency(nsIFrame
*, StyleAppearance
) override
;
80 NS_IMETHOD
WidgetStateChanged(nsIFrame
*, StyleAppearance
, nsAtom
* aAttribute
,
82 const nsAttrValue
* aOldValue
) override
;
83 NS_IMETHOD
ThemeChanged() override
;
84 bool WidgetAppearanceDependsOnWindowFocus(StyleAppearance
) override
;
85 /*bool NeedToClearBackgroundBehindWidget(
86 nsIFrame*, StyleAppearance) override;*/
87 ThemeGeometryType
ThemeGeometryTypeForWidget(nsIFrame
*,
88 StyleAppearance
) override
;
89 bool ThemeSupportsWidget(nsPresContext
*, nsIFrame
*, StyleAppearance
) override
;
90 bool WidgetIsContainer(StyleAppearance
) override
;
91 bool ThemeDrawsFocusForWidget(nsIFrame
*, StyleAppearance
) override
;
92 bool ThemeNeedsComboboxDropmarker() override
;
94 LayoutDeviceIntCoord
GetScrollbarSize(const nsPresContext
*,
95 StyleScrollbarWidth
, Overlay
) final
;
97 nscoord
GetCheckboxRadioPrefSize() override
;
99 static UniquePtr
<ScrollbarDrawing
> ScrollbarStyle();
102 virtual ~Theme() = default;
104 DPIRatio
GetDPIRatio(nsPresContext
*, StyleAppearance
);
105 DPIRatio
GetDPIRatio(nsIFrame
*, StyleAppearance
);
107 std::tuple
<sRGBColor
, sRGBColor
, sRGBColor
> ComputeCheckboxColors(
108 const ElementState
&, StyleAppearance
, const Colors
&);
109 enum class OutlineCoversBorder
: bool { No
, Yes
};
110 sRGBColor
ComputeBorderColor(const ElementState
&, const Colors
&,
111 OutlineCoversBorder
);
113 std::pair
<sRGBColor
, sRGBColor
> ComputeButtonColors(const ElementState
&,
115 nsIFrame
* = nullptr);
116 std::pair
<sRGBColor
, sRGBColor
> ComputeTextfieldColors(const ElementState
&,
118 OutlineCoversBorder
);
119 std::pair
<sRGBColor
, sRGBColor
> ComputeRangeProgressColors(
120 const ElementState
&, const Colors
&);
121 std::pair
<sRGBColor
, sRGBColor
> ComputeRangeTrackColors(const ElementState
&,
123 std::pair
<sRGBColor
, sRGBColor
> ComputeRangeThumbColors(const ElementState
&,
125 std::pair
<sRGBColor
, sRGBColor
> ComputeProgressColors(const Colors
&);
126 std::pair
<sRGBColor
, sRGBColor
> ComputeProgressTrackColors(const Colors
&);
127 std::pair
<sRGBColor
, sRGBColor
> ComputeMeterchunkColors(
128 const ElementState
& aMeterState
, const Colors
&);
129 std::array
<sRGBColor
, 3> ComputeFocusRectColors(const Colors
&);
131 template <typename PaintBackendData
>
132 void PaintRoundedFocusRect(PaintBackendData
&, const LayoutDeviceRect
&,
133 const Colors
&, DPIRatio
, CSSCoord aRadius
,
135 template <typename PaintBackendData
>
136 void PaintAutoStyleOutline(nsIFrame
*, PaintBackendData
&,
137 const LayoutDeviceRect
&, const Colors
&, DPIRatio
);
139 void PaintCheckboxControl(DrawTarget
& aDrawTarget
, const LayoutDeviceRect
&,
140 const ElementState
&, const Colors
&, DPIRatio
);
141 void PaintCheckMark(DrawTarget
&, const LayoutDeviceRect
&, const sRGBColor
&);
142 void PaintIndeterminateMark(DrawTarget
&, const LayoutDeviceRect
&,
145 template <typename PaintBackendData
>
146 void PaintStrokedCircle(PaintBackendData
&, const LayoutDeviceRect
&,
147 const sRGBColor
& aBackgroundColor
,
148 const sRGBColor
& aBorderColor
,
149 const CSSCoord aBorderWidth
, DPIRatio
);
150 void PaintCircleShadow(DrawTarget
&, const LayoutDeviceRect
& aBoxRect
,
151 const LayoutDeviceRect
& aClipRect
, float aShadowAlpha
,
152 const CSSPoint
& aShadowOffset
,
153 CSSCoord aShadowBlurStdDev
, DPIRatio
);
154 void PaintCircleShadow(WebRenderBackendData
&,
155 const LayoutDeviceRect
& aBoxRect
,
156 const LayoutDeviceRect
& aClipRect
, float aShadowAlpha
,
157 const CSSPoint
& aShadowOffset
,
158 CSSCoord aShadowBlurStdDev
, DPIRatio
);
159 template <typename PaintBackendData
>
160 void PaintRadioControl(PaintBackendData
&, const LayoutDeviceRect
&,
161 const ElementState
&, const Colors
&, DPIRatio
);
162 template <typename PaintBackendData
>
163 void PaintRadioCheckmark(PaintBackendData
&, const LayoutDeviceRect
&,
164 const ElementState
&, DPIRatio
);
165 template <typename PaintBackendData
>
166 void PaintTextField(PaintBackendData
&, const LayoutDeviceRect
&,
167 const ElementState
&, const Colors
&, DPIRatio
);
168 template <typename PaintBackendData
>
169 void PaintListbox(PaintBackendData
&, const LayoutDeviceRect
&,
170 const ElementState
&, const Colors
&, DPIRatio
);
171 template <typename PaintBackendData
>
172 void PaintMenulist(PaintBackendData
&, const LayoutDeviceRect
&,
173 const ElementState
&, const Colors
&, DPIRatio
);
174 void PaintMenulistArrowButton(nsIFrame
*, DrawTarget
&, const LayoutDeviceRect
&,
175 const ElementState
&);
176 void PaintSpinnerButton(nsIFrame
*, DrawTarget
&, const LayoutDeviceRect
&,
177 const ElementState
&, StyleAppearance
, const Colors
&,
179 template <typename PaintBackendData
>
180 void PaintRange(nsIFrame
*, PaintBackendData
&, const LayoutDeviceRect
&,
181 const ElementState
&, const Colors
&, DPIRatio
,
183 template <typename PaintBackendData
>
184 void PaintProgress(nsIFrame
*, PaintBackendData
&, const LayoutDeviceRect
&,
185 const ElementState
&, const Colors
&, DPIRatio
,
187 template <typename PaintBackendData
>
188 void PaintButton(nsIFrame
*, PaintBackendData
&, const LayoutDeviceRect
&,
189 const ElementState
&, const Colors
&, DPIRatio
);
191 static void PrefChangedCallback(const char*, void*) {
192 LookAndFeel::NotifyChangedAllWindows(ThemeChangeKind::Layout
);
195 void SetScrollbarDrawing(UniquePtr
<ScrollbarDrawing
>&& aScrollbarDrawing
) {
196 mScrollbarDrawing
= std::move(aScrollbarDrawing
);
197 mScrollbarDrawing
->RecomputeScrollbarParams();
199 ScrollbarDrawing
& GetScrollbarDrawing() const { return *mScrollbarDrawing
; }
200 UniquePtr
<ScrollbarDrawing
> mScrollbarDrawing
;
202 bool ThemeSupportsScrollbarButtons() override
;
205 } // namespace widget
206 } // namespace mozilla