Bug 1918285 - Avoid lz4frame symbols being exported from gtest libxul. r=firefox...
[gecko.git] / widget / Theme.h
blobe7882d497bfeb44d16e868714af7644f9ada8d83
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 nscoord GetCheckboxRadioPrefSize() override;
98 static UniquePtr<ScrollbarDrawing> ScrollbarStyle();
100 protected:
101 virtual ~Theme() = default;
103 DPIRatio GetDPIRatio(nsPresContext*, StyleAppearance);
104 DPIRatio GetDPIRatio(nsIFrame*, StyleAppearance);
106 std::tuple<sRGBColor, sRGBColor, sRGBColor> ComputeCheckboxColors(
107 const ElementState&, StyleAppearance, const Colors&);
108 enum class OutlineCoversBorder : bool { No, Yes };
109 sRGBColor ComputeBorderColor(const ElementState&, const Colors&,
110 OutlineCoversBorder);
112 std::pair<sRGBColor, sRGBColor> ComputeButtonColors(const ElementState&,
113 const Colors&,
114 nsIFrame* = nullptr);
115 std::pair<sRGBColor, sRGBColor> ComputeTextfieldColors(const ElementState&,
116 const Colors&,
117 OutlineCoversBorder);
118 std::pair<sRGBColor, sRGBColor> ComputeRangeProgressColors(
119 const ElementState&, const Colors&);
120 std::pair<sRGBColor, sRGBColor> ComputeRangeTrackColors(const ElementState&,
121 const Colors&);
122 std::pair<sRGBColor, sRGBColor> ComputeRangeThumbColors(const ElementState&,
123 const Colors&);
124 std::pair<sRGBColor, sRGBColor> ComputeProgressColors(const Colors&);
125 std::pair<sRGBColor, sRGBColor> ComputeProgressTrackColors(const Colors&);
126 std::pair<sRGBColor, sRGBColor> ComputeMeterchunkColors(
127 const ElementState& aMeterState, const Colors&);
128 std::array<sRGBColor, 3> ComputeFocusRectColors(const Colors&);
130 template <typename PaintBackendData>
131 void PaintRoundedFocusRect(PaintBackendData&, const LayoutDeviceRect&,
132 const Colors&, DPIRatio, CSSCoord aRadius,
133 CSSCoord aOffset);
134 template <typename PaintBackendData>
135 void PaintAutoStyleOutline(nsIFrame*, PaintBackendData&,
136 const LayoutDeviceRect&, const Colors&, DPIRatio);
138 void PaintCheckboxControl(DrawTarget& aDrawTarget, const LayoutDeviceRect&,
139 const ElementState&, const Colors&, DPIRatio);
140 void PaintCheckMark(DrawTarget&, const LayoutDeviceRect&, const sRGBColor&);
141 void PaintIndeterminateMark(DrawTarget&, const LayoutDeviceRect&,
142 const sRGBColor&);
144 template <typename PaintBackendData>
145 void PaintStrokedCircle(PaintBackendData&, const LayoutDeviceRect&,
146 const sRGBColor& aBackgroundColor,
147 const sRGBColor& aBorderColor,
148 const CSSCoord aBorderWidth, DPIRatio);
149 void PaintCircleShadow(DrawTarget&, const LayoutDeviceRect& aBoxRect,
150 const LayoutDeviceRect& aClipRect, float aShadowAlpha,
151 const CSSPoint& aShadowOffset,
152 CSSCoord aShadowBlurStdDev, DPIRatio);
153 void PaintCircleShadow(WebRenderBackendData&,
154 const LayoutDeviceRect& aBoxRect,
155 const LayoutDeviceRect& aClipRect, float aShadowAlpha,
156 const CSSPoint& aShadowOffset,
157 CSSCoord aShadowBlurStdDev, DPIRatio);
158 template <typename PaintBackendData>
159 void PaintRadioControl(PaintBackendData&, const LayoutDeviceRect&,
160 const ElementState&, const Colors&, DPIRatio);
161 template <typename PaintBackendData>
162 void PaintRadioCheckmark(PaintBackendData&, const LayoutDeviceRect&,
163 const ElementState&, DPIRatio);
164 template <typename PaintBackendData>
165 void PaintTextField(PaintBackendData&, const LayoutDeviceRect&,
166 const ElementState&, const Colors&, DPIRatio);
167 template <typename PaintBackendData>
168 void PaintListbox(PaintBackendData&, const LayoutDeviceRect&,
169 const ElementState&, const Colors&, DPIRatio);
170 template <typename PaintBackendData>
171 void PaintMenulist(PaintBackendData&, const LayoutDeviceRect&,
172 const ElementState&, const Colors&, DPIRatio);
173 void PaintMenulistArrow(nsIFrame*, DrawTarget&, const LayoutDeviceRect&);
174 void PaintSpinnerButton(nsIFrame*, DrawTarget&, const LayoutDeviceRect&,
175 const ElementState&, StyleAppearance, const Colors&,
176 DPIRatio);
177 template <typename PaintBackendData>
178 void PaintRange(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&,
179 const ElementState&, const Colors&, DPIRatio,
180 bool aHorizontal);
181 template <typename PaintBackendData>
182 void PaintProgress(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&,
183 const ElementState&, const Colors&, DPIRatio,
184 bool aIsMeter);
185 template <typename PaintBackendData>
186 void PaintButton(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&,
187 StyleAppearance, const ElementState&, const Colors&,
188 DPIRatio);
190 static void PrefChangedCallback(const char*, void*) {
191 LookAndFeel::NotifyChangedAllWindows(ThemeChangeKind::Layout);
194 void SetScrollbarDrawing(UniquePtr<ScrollbarDrawing>&& aScrollbarDrawing) {
195 mScrollbarDrawing = std::move(aScrollbarDrawing);
196 mScrollbarDrawing->RecomputeScrollbarParams();
198 ScrollbarDrawing& GetScrollbarDrawing() const { return *mScrollbarDrawing; }
199 UniquePtr<ScrollbarDrawing> mScrollbarDrawing;
201 bool ThemeSupportsScrollbarButtons() override;
204 } // namespace widget
205 } // namespace mozilla
207 #endif