Bug 1769628 [wpt PR 34081] - Update wpt metadata, a=testonly
[gecko.git] / widget / Theme.h
blob869a924d95d1f734cf7bb067a8bcaff28a330dbe
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
10 #include "Units.h"
11 #include "mozilla/gfx/2D.h"
12 #include "mozilla/gfx/Rect.h"
13 #include "mozilla/gfx/Types.h"
14 #include "nsITheme.h"
15 #include "nsNativeTheme.h"
16 #include "ScrollbarDrawing.h"
18 namespace mozilla {
20 enum class StyleSystemColor : uint8_t;
22 namespace widget {
24 class Theme : protected nsNativeTheme, public nsITheme {
25 protected:
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;
35 public:
36 explicit Theme(UniquePtr<ScrollbarDrawing>&& aScrollbarDrawing)
37 : mScrollbarDrawing(std::move(aScrollbarDrawing)) {
38 mScrollbarDrawing->RecomputeScrollbarParams();
41 static void Init();
42 static void Shutdown();
43 static void LookAndFeelChanged();
45 using DPIRatio = CSSToLayoutDeviceScale;
47 NS_DECL_ISUPPORTS_INHERITED
49 // The nsITheme interface.
50 NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame*,
51 StyleAppearance, const nsRect& aRect,
52 const nsRect& aDirtyRect,
53 DrawOverflow) override;
55 bool CreateWebRenderCommandsForWidget(
56 wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources,
57 const layers::StackingContextHelper& aSc,
58 layers::RenderRootStateManager* aManager, nsIFrame*, StyleAppearance,
59 const nsRect& aRect) override;
61 // PaintBackendData will be either a DrawTarget, or a WebRenderBackendData.
63 // The return value represents whether the widget could be painted with the
64 // given back-end.
65 template <typename PaintBackendData>
66 bool DoDrawWidgetBackground(PaintBackendData&, nsIFrame*, StyleAppearance,
67 const nsRect&, DrawOverflow);
69 [[nodiscard]] LayoutDeviceIntMargin GetWidgetBorder(nsDeviceContext* aContext,
70 nsIFrame*,
71 StyleAppearance) override;
72 bool GetWidgetPadding(nsDeviceContext* aContext, nsIFrame*, StyleAppearance,
73 LayoutDeviceIntMargin* aResult) override;
74 bool GetWidgetOverflow(nsDeviceContext* aContext, nsIFrame*, StyleAppearance,
75 nsRect* aOverflowRect) override;
76 NS_IMETHOD GetMinimumWidgetSize(nsPresContext* aPresContext, nsIFrame*,
77 StyleAppearance, LayoutDeviceIntSize* aResult,
78 bool* aIsOverridable) override;
79 Transparency GetWidgetTransparency(nsIFrame*, StyleAppearance) override;
80 NS_IMETHOD WidgetStateChanged(nsIFrame*, StyleAppearance, nsAtom* aAttribute,
81 bool* aShouldRepaint,
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;
93 ScrollbarSizes GetScrollbarSizes(nsPresContext*, StyleScrollbarWidth,
94 Overlay) override;
96 nscoord GetCheckboxRadioPrefSize() override;
98 static UniquePtr<ScrollbarDrawing> ScrollbarStyle();
100 protected:
101 virtual ~Theme() = default;
103 static DPIRatio GetDPIRatio(nsPresContext*, StyleAppearance);
104 static DPIRatio GetDPIRatio(nsIFrame*, StyleAppearance);
106 std::pair<sRGBColor, sRGBColor> ComputeCheckboxColors(const EventStates&,
107 StyleAppearance,
108 const Colors&);
109 sRGBColor ComputeCheckmarkColor(const EventStates&, const Colors&);
110 enum class OutlineCoversBorder : bool { No, Yes };
111 sRGBColor ComputeBorderColor(const EventStates&, const Colors&,
112 OutlineCoversBorder);
114 std::pair<sRGBColor, sRGBColor> ComputeButtonColors(const EventStates&,
115 const Colors&,
116 nsIFrame* = nullptr);
117 std::pair<sRGBColor, sRGBColor> ComputeTextfieldColors(const EventStates&,
118 const Colors&,
119 OutlineCoversBorder);
120 std::pair<sRGBColor, sRGBColor> ComputeRangeProgressColors(const EventStates&,
121 const Colors&);
122 std::pair<sRGBColor, sRGBColor> ComputeRangeTrackColors(const EventStates&,
123 const Colors&);
124 std::pair<sRGBColor, sRGBColor> ComputeRangeThumbColors(const EventStates&,
125 const Colors&);
126 std::pair<sRGBColor, sRGBColor> ComputeProgressColors(const Colors&);
127 std::pair<sRGBColor, sRGBColor> ComputeProgressTrackColors(const Colors&);
128 std::pair<sRGBColor, sRGBColor> ComputeMeterchunkColors(
129 const EventStates& aMeterState, const Colors&);
130 std::array<sRGBColor, 3> ComputeFocusRectColors(const Colors&);
132 template <typename PaintBackendData>
133 void PaintRoundedFocusRect(PaintBackendData&, const LayoutDeviceRect&,
134 const Colors&, DPIRatio, CSSCoord aRadius,
135 CSSCoord aOffset);
136 template <typename PaintBackendData>
137 void PaintAutoStyleOutline(nsIFrame*, PaintBackendData&,
138 const LayoutDeviceRect&, const Colors&, DPIRatio);
140 void PaintCheckboxControl(DrawTarget& aDrawTarget, const LayoutDeviceRect&,
141 const EventStates&, const Colors&, DPIRatio);
142 void PaintCheckMark(DrawTarget&, const LayoutDeviceRect&, const EventStates&,
143 const Colors&);
144 void PaintIndeterminateMark(DrawTarget&, const LayoutDeviceRect&,
145 const EventStates&, const Colors&);
147 template <typename PaintBackendData>
148 void PaintStrokedCircle(PaintBackendData&, const LayoutDeviceRect&,
149 const sRGBColor& aBackgroundColor,
150 const sRGBColor& aBorderColor,
151 const CSSCoord aBorderWidth, DPIRatio);
152 void PaintCircleShadow(DrawTarget&, const LayoutDeviceRect& aBoxRect,
153 const LayoutDeviceRect& aClipRect, float aShadowAlpha,
154 const CSSPoint& aShadowOffset,
155 CSSCoord aShadowBlurStdDev, DPIRatio);
156 void PaintCircleShadow(WebRenderBackendData&,
157 const LayoutDeviceRect& aBoxRect,
158 const LayoutDeviceRect& aClipRect, float aShadowAlpha,
159 const CSSPoint& aShadowOffset,
160 CSSCoord aShadowBlurStdDev, DPIRatio);
161 template <typename PaintBackendData>
162 void PaintRadioControl(PaintBackendData&, const LayoutDeviceRect&,
163 const EventStates&, const Colors&, DPIRatio);
164 template <typename PaintBackendData>
165 void PaintRadioCheckmark(PaintBackendData&, const LayoutDeviceRect&,
166 const EventStates&, DPIRatio);
167 template <typename PaintBackendData>
168 void PaintTextField(PaintBackendData&, const LayoutDeviceRect&,
169 const EventStates&, const Colors&, DPIRatio);
170 template <typename PaintBackendData>
171 void PaintListbox(PaintBackendData&, const LayoutDeviceRect&,
172 const EventStates&, const Colors&, DPIRatio);
173 template <typename PaintBackendData>
174 void PaintMenulist(PaintBackendData&, const LayoutDeviceRect&,
175 const EventStates&, const Colors&, DPIRatio);
176 void PaintMenulistArrowButton(nsIFrame*, DrawTarget&, const LayoutDeviceRect&,
177 const EventStates&);
178 void PaintSpinnerButton(nsIFrame*, DrawTarget&, const LayoutDeviceRect&,
179 const EventStates&, StyleAppearance, const Colors&,
180 DPIRatio);
181 template <typename PaintBackendData>
182 void PaintRange(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&,
183 const EventStates&, const Colors&, DPIRatio,
184 bool aHorizontal);
185 template <typename PaintBackendData>
186 void PaintProgress(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&,
187 const EventStates&, const Colors&, DPIRatio,
188 bool aIsMeter);
189 template <typename PaintBackendData>
190 void PaintButton(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&,
191 const EventStates&, const Colors&, DPIRatio);
193 static void PrefChangedCallback(const char*, void*) {
194 LookAndFeel::NotifyChangedAllWindows(ThemeChangeKind::Layout);
197 void SetScrollbarDrawing(UniquePtr<ScrollbarDrawing>&& aScrollbarDrawing) {
198 mScrollbarDrawing = std::move(aScrollbarDrawing);
199 mScrollbarDrawing->RecomputeScrollbarParams();
201 ScrollbarDrawing& GetScrollbarDrawing() const { return *mScrollbarDrawing; }
202 UniquePtr<ScrollbarDrawing> mScrollbarDrawing;
204 bool ThemeSupportsScrollbarButtons() override;
207 } // namespace widget
208 } // namespace mozilla
210 #endif