Bug 1792034 [wpt PR 36019] - Make location.search always expect UTF-8, a=testonly
[gecko.git] / widget / Theme.h
blobcda6a0db8ae03006c76f2b3b4f395c1f1d7863d4
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;
34 using ElementState = dom::ElementState;
36 public:
37 explicit Theme(UniquePtr<ScrollbarDrawing>&& aScrollbarDrawing)
38 : mScrollbarDrawing(std::move(aScrollbarDrawing)) {
39 mScrollbarDrawing->RecomputeScrollbarParams();
42 static void Init();
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
65 // given back-end.
66 template <typename PaintBackendData>
67 bool DoDrawWidgetBackground(PaintBackendData&, nsIFrame*, StyleAppearance,
68 const nsRect&, DrawOverflow);
70 [[nodiscard]] LayoutDeviceIntMargin GetWidgetBorder(nsDeviceContext* aContext,
71 nsIFrame*,
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 NS_IMETHOD GetMinimumWidgetSize(nsPresContext* aPresContext, nsIFrame*,
78 StyleAppearance, LayoutDeviceIntSize* aResult,
79 bool* aIsOverridable) override;
80 Transparency GetWidgetTransparency(nsIFrame*, StyleAppearance) override;
81 NS_IMETHOD WidgetStateChanged(nsIFrame*, StyleAppearance, nsAtom* aAttribute,
82 bool* aShouldRepaint,
83 const nsAttrValue* aOldValue) override;
84 NS_IMETHOD ThemeChanged() override;
85 bool WidgetAppearanceDependsOnWindowFocus(StyleAppearance) override;
86 /*bool NeedToClearBackgroundBehindWidget(
87 nsIFrame*, StyleAppearance) override;*/
88 ThemeGeometryType ThemeGeometryTypeForWidget(nsIFrame*,
89 StyleAppearance) override;
90 bool ThemeSupportsWidget(nsPresContext*, nsIFrame*, StyleAppearance) override;
91 bool WidgetIsContainer(StyleAppearance) override;
92 bool ThemeDrawsFocusForWidget(nsIFrame*, StyleAppearance) override;
93 bool ThemeNeedsComboboxDropmarker() override;
94 ScrollbarSizes GetScrollbarSizes(nsPresContext*, StyleScrollbarWidth,
95 Overlay) override;
97 nscoord GetCheckboxRadioPrefSize() override;
99 static UniquePtr<ScrollbarDrawing> ScrollbarStyle();
101 protected:
102 virtual ~Theme() = default;
104 static DPIRatio GetDPIRatio(nsPresContext*, StyleAppearance);
105 static 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&,
114 const Colors&,
115 nsIFrame* = nullptr);
116 std::pair<sRGBColor, sRGBColor> ComputeTextfieldColors(const ElementState&,
117 const Colors&,
118 OutlineCoversBorder);
119 std::pair<sRGBColor, sRGBColor> ComputeRangeProgressColors(
120 const ElementState&, const Colors&);
121 std::pair<sRGBColor, sRGBColor> ComputeRangeTrackColors(const ElementState&,
122 const Colors&);
123 std::pair<sRGBColor, sRGBColor> ComputeRangeThumbColors(const ElementState&,
124 const Colors&);
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,
134 CSSCoord aOffset);
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&,
143 const sRGBColor&);
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&,
178 DPIRatio);
179 template <typename PaintBackendData>
180 void PaintRange(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&,
181 const ElementState&, const Colors&, DPIRatio,
182 bool aHorizontal);
183 template <typename PaintBackendData>
184 void PaintProgress(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&,
185 const ElementState&, const Colors&, DPIRatio,
186 bool aIsMeter);
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
208 #endif