Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / widget / Theme.h
blob30832528d45be342528aed8f8c6c915daa1a145a
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 LayoutDeviceIntSize GetMinimumWidgetSize(nsPresContext*, nsIFrame*,
78 StyleAppearance) override;
79 Transparency GetWidgetTransparency(nsIFrame*, StyleAppearance) override;
80 bool WidgetAttributeChangeRequiresRepaint(StyleAppearance,
81 nsAtom* aAttribute) override;
82 NS_IMETHOD ThemeChanged() override;
83 bool WidgetAppearanceDependsOnWindowFocus(StyleAppearance) override;
84 /*bool NeedToClearBackgroundBehindWidget(
85 nsIFrame*, StyleAppearance) override;*/
86 ThemeGeometryType ThemeGeometryTypeForWidget(nsIFrame*,
87 StyleAppearance) override;
88 bool ThemeSupportsWidget(nsPresContext*, nsIFrame*, StyleAppearance) override;
89 bool WidgetIsContainer(StyleAppearance) override;
90 bool ThemeDrawsFocusForWidget(nsIFrame*, StyleAppearance) override;
91 bool ThemeNeedsComboboxDropmarker() override;
93 LayoutDeviceIntCoord GetScrollbarSize(const nsPresContext*,
94 StyleScrollbarWidth, Overlay) final;
96 CSSCoord GetCheckboxRadioPrefSize() override;
98 static UniquePtr<ScrollbarDrawing> ScrollbarStyle();
100 protected:
101 virtual ~Theme() = default;
103 DPIRatio GetDPIRatio(nsIFrame*, StyleAppearance);
105 std::tuple<sRGBColor, sRGBColor, sRGBColor> ComputeCheckboxColors(
106 const ElementState&, StyleAppearance, const Colors&);
107 enum class OutlineCoversBorder : bool { No, Yes };
108 sRGBColor ComputeBorderColor(const ElementState&, const Colors&,
109 OutlineCoversBorder);
111 std::pair<sRGBColor, sRGBColor> ComputeButtonColors(const ElementState&,
112 const Colors&);
113 std::pair<sRGBColor, sRGBColor> ComputeTextfieldColors(const ElementState&,
114 const Colors&,
115 OutlineCoversBorder);
116 std::pair<sRGBColor, sRGBColor> ComputeRangeProgressColors(
117 const ElementState&, const Colors&);
118 std::pair<sRGBColor, sRGBColor> ComputeRangeTrackColors(const ElementState&,
119 const Colors&);
120 std::pair<sRGBColor, sRGBColor> ComputeRangeThumbColors(const ElementState&,
121 const Colors&);
122 std::pair<sRGBColor, sRGBColor> ComputeProgressColors(const Colors&);
123 std::pair<sRGBColor, sRGBColor> ComputeProgressTrackColors(const Colors&);
124 std::pair<sRGBColor, sRGBColor> ComputeMeterchunkColors(
125 const ElementState& aMeterState, const Colors&);
127 enum class InvertColors : bool { No = false, Yes };
128 template <typename PaintBackendData>
129 void PaintAutoStyleOutline(PaintBackendData&, const LayoutDeviceRect&,
130 const Colors&, const RectCornerRadii& aInnerRadii,
131 LayoutDeviceCoord aOffset, InvertColors, DPIRatio);
132 template <typename PaintBackendData>
133 void PaintAutoStyleOutline(PaintBackendData&, const LayoutDeviceRect&,
134 const Colors&, CSSCoord aRadius, CSSCoord aOffset,
135 InvertColors, DPIRatio);
136 template <typename PaintBackendData>
137 void PaintAutoStyleOutline(nsIFrame*, PaintBackendData&,
138 const LayoutDeviceRect&, const Colors&, DPIRatio);
140 void PaintCheckboxControl(DrawTarget& aDrawTarget, const LayoutDeviceRect&,
141 const ElementState&, const Colors&, DPIRatio);
142 void PaintCheckMark(DrawTarget&, const LayoutDeviceRect&, const sRGBColor&);
143 void PaintIndeterminateMark(DrawTarget&, const LayoutDeviceRect&,
144 const sRGBColor&);
146 template <typename PaintBackendData>
147 void PaintStrokedCircle(PaintBackendData&, const LayoutDeviceRect&,
148 const sRGBColor& aBackgroundColor,
149 const sRGBColor& aBorderColor,
150 const CSSCoord aBorderWidth, DPIRatio);
151 void PaintCircleShadow(DrawTarget&, const LayoutDeviceRect& aBoxRect,
152 const LayoutDeviceRect& aClipRect, float aShadowAlpha,
153 const CSSPoint& aShadowOffset,
154 CSSCoord aShadowBlurStdDev, DPIRatio);
155 void PaintCircleShadow(WebRenderBackendData&,
156 const LayoutDeviceRect& aBoxRect,
157 const LayoutDeviceRect& aClipRect, float aShadowAlpha,
158 const CSSPoint& aShadowOffset,
159 CSSCoord aShadowBlurStdDev, DPIRatio);
160 template <typename PaintBackendData>
161 void PaintRadioControl(PaintBackendData&, const LayoutDeviceRect&,
162 const ElementState&, const Colors&, DPIRatio);
163 template <typename PaintBackendData>
164 void PaintRadioCheckmark(PaintBackendData&, const LayoutDeviceRect&,
165 const ElementState&, DPIRatio);
166 template <typename PaintBackendData>
167 void PaintTextField(PaintBackendData&, const LayoutDeviceRect&,
168 const ElementState&, const Colors&, DPIRatio);
169 template <typename PaintBackendData>
170 void PaintListbox(PaintBackendData&, const LayoutDeviceRect&,
171 const ElementState&, const Colors&, DPIRatio);
172 template <typename PaintBackendData>
173 void PaintMenulist(PaintBackendData&, const LayoutDeviceRect&,
174 const ElementState&, const Colors&, DPIRatio);
175 void PaintMenulistArrow(nsIFrame*, DrawTarget&, const LayoutDeviceRect&);
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(PaintBackendData&, const LayoutDeviceRect&, StyleAppearance,
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