1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "ThemeCocoa.h"
10 #include "ThemeDrawing.h"
12 #include "mozilla/MathAlgorithms.h"
13 #include "mozilla/ClearOnShutdown.h"
14 #include "mozilla/dom/Document.h"
15 #include "mozilla/dom/HTMLMeterElement.h"
16 #include "mozilla/dom/HTMLProgressElement.h"
17 #include "mozilla/gfx/Rect.h"
18 #include "mozilla/gfx/Types.h"
19 #include "mozilla/gfx/Filters.h"
20 #include "mozilla/RelativeLuminanceUtils.h"
21 #include "mozilla/StaticPrefs_widget.h"
22 #include "mozilla/webrender/WebRenderAPI.h"
23 #include "nsCSSColorUtils.h"
24 #include "nsCSSRendering.h"
25 #include "nsScrollbarFrame.h"
26 #include "nsIScrollableFrame.h"
27 #include "nsIScrollbarMediator.h"
28 #include "nsDeviceContext.h"
29 #include "nsLayoutUtils.h"
30 #include "nsRangeFrame.h"
31 #include "PathHelpers.h"
32 #include "ScrollbarDrawingAndroid.h"
33 #include "ScrollbarDrawingCocoa.h"
34 #include "ScrollbarDrawingGTK.h"
35 #include "ScrollbarDrawingWin.h"
36 #include "ScrollbarDrawingWin11.h"
39 # include "mozilla/WindowsVersion.h"
42 using namespace mozilla
;
43 using namespace mozilla::dom
;
44 using namespace mozilla::gfx
;
45 using namespace mozilla::widget
;
49 static constexpr gfx::sRGBColor
sColorGrey10(
50 gfx::sRGBColor::UnusualFromARGB(0xffe9e9ed));
51 static constexpr gfx::sRGBColor
sColorGrey10Alpha50(
52 gfx::sRGBColor::UnusualFromARGB(0x7fe9e9ed));
53 static constexpr gfx::sRGBColor
sColorGrey20(
54 gfx::sRGBColor::UnusualFromARGB(0xffd0d0d7));
55 static constexpr gfx::sRGBColor
sColorGrey30(
56 gfx::sRGBColor::UnusualFromARGB(0xffb1b1b9));
57 static constexpr gfx::sRGBColor
sColorGrey40(
58 gfx::sRGBColor::UnusualFromARGB(0xff8f8f9d));
59 static constexpr gfx::sRGBColor
sColorGrey40Alpha50(
60 gfx::sRGBColor::UnusualFromARGB(0x7f8f8f9d));
61 static constexpr gfx::sRGBColor
sColorGrey50(
62 gfx::sRGBColor::UnusualFromARGB(0xff676774));
63 static constexpr gfx::sRGBColor
sColorGrey60(
64 gfx::sRGBColor::UnusualFromARGB(0xff484851));
66 static constexpr gfx::sRGBColor
sColorMeterGreen10(
67 gfx::sRGBColor::UnusualFromARGB(0xff00ab60));
68 static constexpr gfx::sRGBColor
sColorMeterGreen20(
69 gfx::sRGBColor::UnusualFromARGB(0xff056139));
70 static constexpr gfx::sRGBColor
sColorMeterYellow10(
71 gfx::sRGBColor::UnusualFromARGB(0xffffbd4f));
72 static constexpr gfx::sRGBColor
sColorMeterYellow20(
73 gfx::sRGBColor::UnusualFromARGB(0xffd2811e));
74 static constexpr gfx::sRGBColor
sColorMeterRed10(
75 gfx::sRGBColor::UnusualFromARGB(0xffe22850));
76 static constexpr gfx::sRGBColor
sColorMeterRed20(
77 gfx::sRGBColor::UnusualFromARGB(0xff810220));
79 static const CSSCoord kMinimumRangeThumbSize
= 20.0f
;
80 static const CSSCoord kMinimumDropdownArrowButtonWidth
= 18.0f
;
81 static const CSSCoord kMinimumSpinnerButtonWidth
= 18.0f
;
82 static const CSSCoord kMinimumSpinnerButtonHeight
= 9.0f
;
83 static const CSSCoord kButtonBorderWidth
= 1.0f
;
84 static const CSSCoord kMenulistBorderWidth
= 1.0f
;
85 static const CSSCoord kTextFieldBorderWidth
= 1.0f
;
86 static const CSSCoord kRangeHeight
= 6.0f
;
87 static const CSSCoord kProgressbarHeight
= 6.0f
;
88 static const CSSCoord kMeterHeight
= 12.0f
;
90 // nsCheckboxRadioFrame takes the bottom of the content box as the baseline.
91 // This border-width makes its baseline 2px under the bottom, which is nice.
92 static constexpr CSSCoord kCheckboxRadioBorderWidth
= 2.0f
;
94 static constexpr sRGBColor sTransparent
= sRGBColor::White(0.0);
96 // This pushes and pops a clip rect to the draw target.
98 // This is done to reduce fuzz in places where we may have antialiasing,
99 // because skia is not clip-invariant: given different clips, it does not
100 // guarantee the same result, even if the painted content doesn't intersect
103 // This is a bit sad, overall, but...
104 struct MOZ_RAII AutoClipRect
{
105 AutoClipRect(DrawTarget
& aDt
, const LayoutDeviceRect
& aRect
) : mDt(aDt
) {
106 mDt
.PushClipRect(aRect
.ToUnknownRect());
109 ~AutoClipRect() { mDt
.PopClip(); }
115 static StaticRefPtr
<Theme
> gNativeInstance
;
116 static StaticRefPtr
<Theme
> gNonNativeInstance
;
117 static StaticRefPtr
<Theme
> gRDMInstance
;
122 already_AddRefed
<Theme
> do_CreateNativeThemeDoNotUseDirectly() {
123 // Android doesn't have a native theme.
124 return do_AddRef(new Theme(Theme::ScrollbarStyle()));
128 already_AddRefed
<nsITheme
> do_GetBasicNativeThemeDoNotUseDirectly() {
129 if (MOZ_UNLIKELY(!gNonNativeInstance
)) {
130 UniquePtr
<ScrollbarDrawing
> scrollbarDrawing
= Theme::ScrollbarStyle();
131 #ifdef MOZ_WIDGET_COCOA
132 gNonNativeInstance
= new ThemeCocoa(std::move(scrollbarDrawing
));
134 gNonNativeInstance
= new Theme(std::move(scrollbarDrawing
));
136 ClearOnShutdown(&gNonNativeInstance
);
138 return do_AddRef(gNonNativeInstance
);
141 already_AddRefed
<nsITheme
> do_GetNativeThemeDoNotUseDirectly() {
142 if (MOZ_UNLIKELY(!gNativeInstance
)) {
143 gNativeInstance
= do_CreateNativeThemeDoNotUseDirectly();
144 ClearOnShutdown(&gNativeInstance
);
146 return do_AddRef(gNativeInstance
);
149 already_AddRefed
<nsITheme
> do_GetRDMThemeDoNotUseDirectly() {
150 if (MOZ_UNLIKELY(!gRDMInstance
)) {
151 gRDMInstance
= new Theme(MakeUnique
<ScrollbarDrawingAndroid
>());
152 ClearOnShutdown(&gRDMInstance
);
154 return do_AddRef(gRDMInstance
);
157 namespace mozilla::widget
{
159 NS_IMPL_ISUPPORTS_INHERITED(Theme
, nsNativeTheme
, nsITheme
)
161 static constexpr nsLiteralCString kPrefs
[] = {
162 "widget.non-native-theme.use-theme-accent"_ns
,
163 "widget.non-native-theme.win.scrollbar.use-system-size"_ns
,
164 "widget.non-native-theme.scrollbar.size.override"_ns
,
165 "widget.non-native-theme.scrollbar.style"_ns
,
169 for (const auto& pref
: kPrefs
) {
170 Preferences::RegisterCallback(PrefChangedCallback
, pref
);
172 LookAndFeelChanged();
175 void Theme::Shutdown() {
176 for (const auto& pref
: kPrefs
) {
177 Preferences::UnregisterCallback(PrefChangedCallback
, pref
);
182 void Theme::LookAndFeelChanged() {
183 ThemeColors::RecomputeAccentColors();
184 if (gNonNativeInstance
) {
185 gNonNativeInstance
->SetScrollbarDrawing(ScrollbarStyle());
187 if (gNativeInstance
) {
188 gNativeInstance
->SetScrollbarDrawing(ScrollbarStyle());
192 auto Theme::GetDPIRatio(nsPresContext
* aPc
, StyleAppearance aAppearance
)
194 // Widgets react to zoom, except scrollbars.
195 if (IsWidgetScrollbarPart(aAppearance
)) {
196 return GetScrollbarDrawing().GetDPIRatioForScrollbarPart(aPc
);
198 return DPIRatio(float(AppUnitsPerCSSPixel()) / aPc
->AppUnitsPerDevPixel());
201 auto Theme::GetDPIRatio(nsIFrame
* aFrame
, StyleAppearance aAppearance
)
203 return GetDPIRatio(aFrame
->PresContext(), aAppearance
);
206 // Checkbox and radio need to preserve aspect-ratio for compat. We also snap the
207 // size to exact device pixels to avoid snapping disorting the circles.
208 static LayoutDeviceRect
CheckBoxRadioRect(const LayoutDeviceRect
& aRect
) {
209 // Place a square rect in the center of aRect.
210 auto size
= std::trunc(std::min(aRect
.width
, aRect
.height
));
211 auto position
= aRect
.Center() - LayoutDevicePoint(size
* 0.5, size
* 0.5);
212 return LayoutDeviceRect(position
, LayoutDeviceSize(size
, size
));
215 std::tuple
<sRGBColor
, sRGBColor
, sRGBColor
> Theme::ComputeCheckboxColors(
216 const ElementState
& aState
, StyleAppearance aAppearance
,
217 const Colors
& aColors
) {
218 MOZ_ASSERT(aAppearance
== StyleAppearance::Checkbox
||
219 aAppearance
== StyleAppearance::Radio
);
221 bool isDisabled
= aState
.HasState(ElementState::DISABLED
);
222 bool isChecked
= aState
.HasState(ElementState::CHECKED
);
223 bool isIndeterminate
= aAppearance
== StyleAppearance::Checkbox
&&
224 aState
.HasState(ElementState::INDETERMINATE
);
226 if (isChecked
|| isIndeterminate
) {
228 auto bg
= ComputeBorderColor(aState
, aColors
, OutlineCoversBorder::No
);
229 auto fg
= aColors
.HighContrast()
230 ? aColors
.System(StyleSystemColor::Graytext
)
231 : sRGBColor::White(aColors
.IsDark() ? .4f
: .8f
);
232 return std::make_tuple(bg
, bg
, fg
);
235 if (aColors
.HighContrast()) {
236 auto bg
= aColors
.System(StyleSystemColor::Selecteditem
);
237 auto fg
= aColors
.System(StyleSystemColor::Selecteditemtext
);
238 return std::make_tuple(bg
, bg
, fg
);
242 aState
.HasAllStates(ElementState::HOVER
| ElementState::ACTIVE
);
243 bool isHovered
= aState
.HasState(ElementState::HOVER
);
244 const auto& bg
= isActive
? aColors
.Accent().GetDarker()
245 : isHovered
? aColors
.Accent().GetDark()
246 : aColors
.Accent().Get();
247 const auto& fg
= aColors
.Accent().GetForeground();
248 return std::make_tuple(bg
, bg
, fg
);
252 ComputeTextfieldColors(aState
, aColors
, OutlineCoversBorder::No
);
253 // We don't paint a checkmark in this case so any color would do.
254 return std::make_tuple(bg
, border
, sTransparent
);
257 sRGBColor
Theme::ComputeBorderColor(const ElementState
& aState
,
258 const Colors
& aColors
,
259 OutlineCoversBorder aOutlineCoversBorder
) {
260 bool isDisabled
= aState
.HasState(ElementState::DISABLED
);
261 if (aColors
.HighContrast()) {
262 return aColors
.System(isDisabled
? StyleSystemColor::Graytext
263 : StyleSystemColor::Buttontext
);
266 aState
.HasAllStates(ElementState::HOVER
| ElementState::ACTIVE
);
267 bool isHovered
= aState
.HasState(ElementState::HOVER
);
268 bool isFocused
= aState
.HasState(ElementState::FOCUSRING
);
270 return sColorGrey40Alpha50
;
272 if (isFocused
&& aOutlineCoversBorder
== OutlineCoversBorder::Yes
) {
273 // If we draw the outline over the border, prevent issues where the border
274 // shows underneath if it snaps in the wrong direction by using a
275 // transparent border. An alternative to this is ensuring that we snap the
276 // offset in PaintRoundedFocusRect the same was a we snap border widths, so
277 // that negative offsets are guaranteed to cover the border.
278 // But this looks harder to mess up.
281 bool dark
= aColors
.IsDark();
283 return dark
? sColorGrey20
: sColorGrey60
;
286 return dark
? sColorGrey30
: sColorGrey50
;
291 std::pair
<sRGBColor
, sRGBColor
> Theme::ComputeButtonColors(
292 const ElementState
& aState
, const Colors
& aColors
, nsIFrame
* aFrame
) {
294 aState
.HasAllStates(ElementState::HOVER
| ElementState::ACTIVE
);
295 bool isDisabled
= aState
.HasState(ElementState::DISABLED
);
296 bool isHovered
= aState
.HasState(ElementState::HOVER
);
298 nscolor backgroundColor
= [&] {
300 return aColors
.SystemNs(StyleSystemColor::MozButtondisabledface
);
303 return aColors
.SystemNs(StyleSystemColor::MozButtonactiveface
);
306 return aColors
.SystemNs(StyleSystemColor::MozButtonhoverface
);
308 return aColors
.SystemNs(StyleSystemColor::Buttonface
);
311 if (aState
.HasState(ElementState::AUTOFILL
)) {
312 backgroundColor
= NS_ComposeColors(
314 aColors
.SystemNs(StyleSystemColor::MozAutofillBackground
));
317 const sRGBColor borderColor
=
318 ComputeBorderColor(aState
, aColors
, OutlineCoversBorder::Yes
);
319 return std::make_pair(sRGBColor::FromABGR(backgroundColor
), borderColor
);
322 std::pair
<sRGBColor
, sRGBColor
> Theme::ComputeTextfieldColors(
323 const ElementState
& aState
, const Colors
& aColors
,
324 OutlineCoversBorder aOutlineCoversBorder
) {
325 nscolor backgroundColor
= [&] {
326 if (aState
.HasState(ElementState::DISABLED
)) {
327 return aColors
.SystemNs(StyleSystemColor::MozDisabledfield
);
329 return aColors
.SystemNs(StyleSystemColor::Field
);
332 if (aState
.HasState(ElementState::AUTOFILL
)) {
333 backgroundColor
= NS_ComposeColors(
335 aColors
.SystemNs(StyleSystemColor::MozAutofillBackground
));
338 const sRGBColor borderColor
=
339 ComputeBorderColor(aState
, aColors
, aOutlineCoversBorder
);
340 return std::make_pair(sRGBColor::FromABGR(backgroundColor
), borderColor
);
343 std::pair
<sRGBColor
, sRGBColor
> Theme::ComputeRangeProgressColors(
344 const ElementState
& aState
, const Colors
& aColors
) {
345 if (aColors
.HighContrast()) {
346 return aColors
.SystemPair(StyleSystemColor::Selecteditem
,
347 StyleSystemColor::Buttontext
);
351 aState
.HasAllStates(ElementState::HOVER
| ElementState::ACTIVE
);
352 bool isDisabled
= aState
.HasState(ElementState::DISABLED
);
353 bool isHovered
= aState
.HasState(ElementState::HOVER
);
356 return std::make_pair(sColorGrey40Alpha50
, sColorGrey40Alpha50
);
358 if (isActive
|| isHovered
) {
359 return std::make_pair(aColors
.Accent().GetDark(),
360 aColors
.Accent().GetDarker());
362 return std::make_pair(aColors
.Accent().Get(), aColors
.Accent().GetDark());
365 std::pair
<sRGBColor
, sRGBColor
> Theme::ComputeRangeTrackColors(
366 const ElementState
& aState
, const Colors
& aColors
) {
367 if (aColors
.HighContrast()) {
368 return aColors
.SystemPair(StyleSystemColor::Window
,
369 StyleSystemColor::Buttontext
);
372 aState
.HasAllStates(ElementState::HOVER
| ElementState::ACTIVE
);
373 bool isDisabled
= aState
.HasState(ElementState::DISABLED
);
374 bool isHovered
= aState
.HasState(ElementState::HOVER
);
377 return std::make_pair(sColorGrey10Alpha50
, sColorGrey40Alpha50
);
379 if (isActive
|| isHovered
) {
380 return std::make_pair(sColorGrey20
, sColorGrey50
);
382 return std::make_pair(sColorGrey10
, sColorGrey40
);
385 std::pair
<sRGBColor
, sRGBColor
> Theme::ComputeRangeThumbColors(
386 const ElementState
& aState
, const Colors
& aColors
) {
387 if (aColors
.HighContrast()) {
388 return aColors
.SystemPair(StyleSystemColor::Selecteditemtext
,
389 StyleSystemColor::Selecteditem
);
393 aState
.HasAllStates(ElementState::HOVER
| ElementState::ACTIVE
);
394 bool isDisabled
= aState
.HasState(ElementState::DISABLED
);
395 bool isHovered
= aState
.HasState(ElementState::HOVER
);
397 const sRGBColor
& backgroundColor
= [&] {
402 return aColors
.Accent().Get();
410 const sRGBColor borderColor
= sRGBColor::OpaqueWhite();
411 return std::make_pair(backgroundColor
, borderColor
);
414 std::pair
<sRGBColor
, sRGBColor
> Theme::ComputeProgressColors(
415 const Colors
& aColors
) {
416 if (aColors
.HighContrast()) {
417 return aColors
.SystemPair(StyleSystemColor::Selecteditem
,
418 StyleSystemColor::Buttontext
);
420 return std::make_pair(aColors
.Accent().Get(), aColors
.Accent().GetDark());
423 std::pair
<sRGBColor
, sRGBColor
> Theme::ComputeProgressTrackColors(
424 const Colors
& aColors
) {
425 if (aColors
.HighContrast()) {
426 return aColors
.SystemPair(StyleSystemColor::Buttonface
,
427 StyleSystemColor::Buttontext
);
429 return std::make_pair(sColorGrey10
, sColorGrey40
);
432 std::pair
<sRGBColor
, sRGBColor
> Theme::ComputeMeterchunkColors(
433 const ElementState
& aMeterState
, const Colors
& aColors
) {
434 if (aColors
.HighContrast()) {
435 return ComputeProgressColors(aColors
);
437 sRGBColor borderColor
= sColorMeterGreen20
;
438 sRGBColor chunkColor
= sColorMeterGreen10
;
440 if (aMeterState
.HasState(ElementState::SUB_OPTIMUM
)) {
441 borderColor
= sColorMeterYellow20
;
442 chunkColor
= sColorMeterYellow10
;
443 } else if (aMeterState
.HasState(ElementState::SUB_SUB_OPTIMUM
)) {
444 borderColor
= sColorMeterRed20
;
445 chunkColor
= sColorMeterRed10
;
448 return std::make_pair(chunkColor
, borderColor
);
451 std::array
<sRGBColor
, 3> Theme::ComputeFocusRectColors(const Colors
& aColors
) {
452 if (aColors
.HighContrast()) {
453 return {aColors
.System(StyleSystemColor::Selecteditem
),
454 aColors
.System(StyleSystemColor::Buttontext
),
455 aColors
.System(StyleSystemColor::Window
)};
457 const auto& accent
= aColors
.Accent();
458 const sRGBColor middle
=
459 aColors
.IsDark() ? sRGBColor::Black(.3f
) : sRGBColor::White(.3f
);
460 return {accent
.Get(), middle
, accent
.GetLight()};
463 template <typename PaintBackendData
>
464 void Theme::PaintRoundedFocusRect(PaintBackendData
& aBackendData
,
465 const LayoutDeviceRect
& aRect
,
466 const Colors
& aColors
, DPIRatio aDpiRatio
,
467 CSSCoord aRadius
, CSSCoord aOffset
) {
468 // NOTE(emilio): If the widths or offsets here change, make sure to tweak
469 // the GetWidgetOverflow path for FocusOutline.
470 auto [innerColor
, middleColor
, outerColor
] = ComputeFocusRectColors(aColors
);
472 LayoutDeviceRect
focusRect(aRect
);
474 // The focus rect is painted outside of the border area (aRect), see:
476 // data:text/html,<div style="border: 1px solid; outline: 2px solid
479 // But some controls might provide a negative offset to cover the border, if
481 CSSCoord strokeWidth
= 2.0f
;
482 auto strokeWidthDevPx
=
483 LayoutDeviceCoord(ThemeDrawing::SnapBorderWidth(strokeWidth
, aDpiRatio
));
484 CSSCoord strokeRadius
= aRadius
;
485 focusRect
.Inflate(aOffset
* aDpiRatio
+ strokeWidthDevPx
);
487 ThemeDrawing::PaintRoundedRectWithRadius(
488 aBackendData
, focusRect
, sTransparent
, innerColor
, strokeWidth
,
489 strokeRadius
, aDpiRatio
);
491 strokeWidth
= CSSCoord(1.0f
);
493 LayoutDeviceCoord(ThemeDrawing::SnapBorderWidth(strokeWidth
, aDpiRatio
));
494 strokeRadius
+= strokeWidth
;
495 focusRect
.Inflate(strokeWidthDevPx
);
497 ThemeDrawing::PaintRoundedRectWithRadius(
498 aBackendData
, focusRect
, sTransparent
, middleColor
, strokeWidth
,
499 strokeRadius
, aDpiRatio
);
501 strokeWidth
= CSSCoord(2.0f
);
503 LayoutDeviceCoord(ThemeDrawing::SnapBorderWidth(strokeWidth
, aDpiRatio
));
504 strokeRadius
+= strokeWidth
;
505 focusRect
.Inflate(strokeWidthDevPx
);
507 ThemeDrawing::PaintRoundedRectWithRadius(
508 aBackendData
, focusRect
, sTransparent
, outerColor
, strokeWidth
,
509 strokeRadius
, aDpiRatio
);
512 void Theme::PaintCheckboxControl(DrawTarget
& aDrawTarget
,
513 const LayoutDeviceRect
& aRect
,
514 const ElementState
& aState
,
515 const Colors
& aColors
, DPIRatio aDpiRatio
) {
516 auto [backgroundColor
, borderColor
, checkColor
] =
517 ComputeCheckboxColors(aState
, StyleAppearance::Checkbox
, aColors
);
519 const CSSCoord radius
= 2.0f
;
520 CSSCoord borderWidth
= kCheckboxRadioBorderWidth
;
521 if (backgroundColor
== borderColor
) {
524 ThemeDrawing::PaintRoundedRectWithRadius(aDrawTarget
, aRect
,
525 backgroundColor
, borderColor
,
526 borderWidth
, radius
, aDpiRatio
);
529 if (aState
.HasState(ElementState::INDETERMINATE
)) {
530 PaintIndeterminateMark(aDrawTarget
, aRect
, checkColor
);
531 } else if (aState
.HasState(ElementState::CHECKED
)) {
532 PaintCheckMark(aDrawTarget
, aRect
, checkColor
);
535 if (aState
.HasState(ElementState::FOCUSRING
)) {
536 PaintRoundedFocusRect(aDrawTarget
, aRect
, aColors
, aDpiRatio
, 5.0f
, 1.0f
);
540 constexpr CSSCoord kCheckboxRadioContentBoxSize
= 10.0f
;
541 constexpr CSSCoord kCheckboxRadioBorderBoxSize
=
542 kCheckboxRadioContentBoxSize
+ kCheckboxRadioBorderWidth
* 2.0f
;
544 void Theme::PaintCheckMark(DrawTarget
& aDrawTarget
,
545 const LayoutDeviceRect
& aRect
,
546 const sRGBColor
& aColor
) {
547 // Points come from the coordinates on a 14X14 (kCheckboxRadioBorderBoxSize)
548 // unit box centered at 0,0
549 const float checkPolygonX
[] = {-4.5f
, -1.5f
, -0.5f
, 5.0f
, 4.75f
,
550 3.5f
, -0.5f
, -1.5f
, -3.5f
};
551 const float checkPolygonY
[] = {0.5f
, 4.0f
, 4.0f
, -2.5f
, -4.0f
,
552 -4.0f
, 1.0f
, 1.25f
, -1.0f
};
553 const int32_t checkNumPoints
= sizeof(checkPolygonX
) / sizeof(float);
555 ThemeDrawing::ScaleToFillRect(aRect
, kCheckboxRadioBorderBoxSize
);
556 auto center
= aRect
.Center().ToUnknownPoint();
558 RefPtr
<PathBuilder
> builder
= aDrawTarget
.CreatePathBuilder();
559 Point p
= center
+ Point(checkPolygonX
[0] * scale
, checkPolygonY
[0] * scale
);
561 for (int32_t i
= 1; i
< checkNumPoints
; i
++) {
562 p
= center
+ Point(checkPolygonX
[i
] * scale
, checkPolygonY
[i
] * scale
);
565 RefPtr
<Path
> path
= builder
->Finish();
567 aDrawTarget
.Fill(path
, ColorPattern(ToDeviceColor(aColor
)));
570 void Theme::PaintIndeterminateMark(DrawTarget
& aDrawTarget
,
571 const LayoutDeviceRect
& aRect
,
572 const sRGBColor
& aColor
) {
573 const CSSCoord borderWidth
= 2.0f
;
575 ThemeDrawing::ScaleToFillRect(aRect
, kCheckboxRadioBorderBoxSize
);
577 Rect rect
= aRect
.ToUnknownRect();
578 rect
.y
+= (rect
.height
/ 2) - (borderWidth
* scale
/ 2);
579 rect
.height
= borderWidth
* scale
;
580 rect
.x
+= (borderWidth
* scale
) + (borderWidth
* scale
/ 8);
581 rect
.width
-= ((borderWidth
* scale
) + (borderWidth
* scale
/ 8)) * 2;
583 aDrawTarget
.FillRect(rect
, ColorPattern(ToDeviceColor(aColor
)));
586 template <typename PaintBackendData
>
587 void Theme::PaintStrokedCircle(PaintBackendData
& aPaintData
,
588 const LayoutDeviceRect
& aRect
,
589 const sRGBColor
& aBackgroundColor
,
590 const sRGBColor
& aBorderColor
,
591 const CSSCoord aBorderWidth
,
592 DPIRatio aDpiRatio
) {
593 auto radius
= LayoutDeviceCoord(aRect
.Size().width
) / aDpiRatio
;
594 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, aRect
, aBackgroundColor
,
595 aBorderColor
, aBorderWidth
, radius
,
599 void Theme::PaintCircleShadow(WebRenderBackendData
& aWrData
,
600 const LayoutDeviceRect
& aBoxRect
,
601 const LayoutDeviceRect
& aClipRect
,
602 float aShadowAlpha
, const CSSPoint
& aShadowOffset
,
603 CSSCoord aShadowBlurStdDev
, DPIRatio aDpiRatio
) {
604 const bool kBackfaceIsVisible
= true;
605 const LayoutDeviceCoord stdDev
= aShadowBlurStdDev
* aDpiRatio
;
606 const LayoutDevicePoint shadowOffset
= aShadowOffset
* aDpiRatio
;
607 const IntSize inflation
=
608 gfxAlphaBoxBlur::CalculateBlurRadius(gfxPoint(stdDev
, stdDev
));
609 LayoutDeviceRect shadowRect
= aBoxRect
;
610 shadowRect
.MoveBy(shadowOffset
);
611 shadowRect
.Inflate(inflation
.width
, inflation
.height
);
612 const auto boxRect
= wr::ToLayoutRect(aBoxRect
);
613 aWrData
.mBuilder
.PushBoxShadow(
614 wr::ToLayoutRect(shadowRect
), wr::ToLayoutRect(aClipRect
),
615 kBackfaceIsVisible
, boxRect
,
616 wr::ToLayoutVector2D(aShadowOffset
* aDpiRatio
),
617 wr::ToColorF(DeviceColor(0.0f
, 0.0f
, 0.0f
, aShadowAlpha
)), stdDev
,
618 /* aSpread = */ 0.0f
,
619 wr::ToBorderRadius(gfx::RectCornerRadii(aBoxRect
.Size().width
)),
620 wr::BoxShadowClipMode::Outset
);
623 void Theme::PaintCircleShadow(DrawTarget
& aDrawTarget
,
624 const LayoutDeviceRect
& aBoxRect
,
625 const LayoutDeviceRect
& aClipRect
,
626 float aShadowAlpha
, const CSSPoint
& aShadowOffset
,
627 CSSCoord aShadowBlurStdDev
, DPIRatio aDpiRatio
) {
628 Float stdDev
= aShadowBlurStdDev
* aDpiRatio
;
629 Point offset
= (aShadowOffset
* aDpiRatio
).ToUnknownPoint();
631 RefPtr
<FilterNode
> blurFilter
=
632 aDrawTarget
.CreateFilter(FilterType::GAUSSIAN_BLUR
);
637 blurFilter
->SetAttribute(ATT_GAUSSIAN_BLUR_STD_DEVIATION
, stdDev
);
640 gfxAlphaBoxBlur::CalculateBlurRadius(gfxPoint(stdDev
, stdDev
));
641 Rect inflatedRect
= aBoxRect
.ToUnknownRect();
642 inflatedRect
.Inflate(inflation
.width
, inflation
.height
);
643 Rect sourceRectInFilterSpace
=
644 inflatedRect
- aBoxRect
.TopLeft().ToUnknownPoint();
645 Point destinationPointOfSourceRect
= inflatedRect
.TopLeft() + offset
;
647 IntSize dtSize
= RoundedToInt(aBoxRect
.Size().ToUnknownSize());
648 RefPtr
<DrawTarget
> ellipseDT
= aDrawTarget
.CreateSimilarDrawTargetForFilter(
649 dtSize
, SurfaceFormat::A8
, blurFilter
, blurFilter
,
650 sourceRectInFilterSpace
, destinationPointOfSourceRect
);
655 AutoClipRect
clipRect(aDrawTarget
, aClipRect
);
657 RefPtr
<Path
> ellipse
= MakePathForEllipse(
658 *ellipseDT
, (aBoxRect
- aBoxRect
.TopLeft()).Center().ToUnknownPoint(),
659 aBoxRect
.Size().ToUnknownSize());
660 ellipseDT
->Fill(ellipse
,
661 ColorPattern(DeviceColor(0.0f
, 0.0f
, 0.0f
, aShadowAlpha
)));
662 RefPtr
<SourceSurface
> ellipseSurface
= ellipseDT
->Snapshot();
664 blurFilter
->SetInput(IN_GAUSSIAN_BLUR_IN
, ellipseSurface
);
665 aDrawTarget
.DrawFilter(blurFilter
, sourceRectInFilterSpace
,
666 destinationPointOfSourceRect
);
669 template <typename PaintBackendData
>
670 void Theme::PaintRadioControl(PaintBackendData
& aPaintData
,
671 const LayoutDeviceRect
& aRect
,
672 const ElementState
& aState
, const Colors
& aColors
,
673 DPIRatio aDpiRatio
) {
674 auto [backgroundColor
, borderColor
, checkColor
] =
675 ComputeCheckboxColors(aState
, StyleAppearance::Radio
, aColors
);
677 CSSCoord borderWidth
= kCheckboxRadioBorderWidth
;
678 if (backgroundColor
== borderColor
) {
681 PaintStrokedCircle(aPaintData
, aRect
, backgroundColor
, borderColor
,
682 borderWidth
, aDpiRatio
);
685 if (aState
.HasState(ElementState::CHECKED
)) {
686 LayoutDeviceRect
rect(aRect
);
687 auto width
= LayoutDeviceCoord(
688 ThemeDrawing::SnapBorderWidth(kCheckboxRadioBorderWidth
, aDpiRatio
));
691 PaintStrokedCircle(aPaintData
, rect
, backgroundColor
, checkColor
,
692 kCheckboxRadioBorderWidth
, aDpiRatio
);
695 if (aState
.HasState(ElementState::FOCUSRING
)) {
696 PaintRoundedFocusRect(aPaintData
, aRect
, aColors
, aDpiRatio
, 5.0f
, 1.0f
);
700 template <typename PaintBackendData
>
701 void Theme::PaintTextField(PaintBackendData
& aPaintData
,
702 const LayoutDeviceRect
& aRect
,
703 const ElementState
& aState
, const Colors
& aColors
,
704 DPIRatio aDpiRatio
) {
705 auto [backgroundColor
, borderColor
] =
706 ComputeTextfieldColors(aState
, aColors
, OutlineCoversBorder::Yes
);
708 const CSSCoord radius
= 2.0f
;
710 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, aRect
, backgroundColor
,
711 borderColor
, kTextFieldBorderWidth
,
714 if (aState
.HasState(ElementState::FOCUSRING
)) {
715 PaintRoundedFocusRect(aPaintData
, aRect
, aColors
, aDpiRatio
,
716 radius
+ kTextFieldBorderWidth
,
717 -kTextFieldBorderWidth
);
721 template <typename PaintBackendData
>
722 void Theme::PaintListbox(PaintBackendData
& aPaintData
,
723 const LayoutDeviceRect
& aRect
,
724 const ElementState
& aState
, const Colors
& aColors
,
725 DPIRatio aDpiRatio
) {
726 const CSSCoord radius
= 2.0f
;
727 auto [backgroundColor
, borderColor
] =
728 ComputeTextfieldColors(aState
, aColors
, OutlineCoversBorder::Yes
);
730 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, aRect
, backgroundColor
,
731 borderColor
, kMenulistBorderWidth
,
734 if (aState
.HasState(ElementState::FOCUSRING
)) {
735 PaintRoundedFocusRect(aPaintData
, aRect
, aColors
, aDpiRatio
,
736 radius
+ kMenulistBorderWidth
, -kMenulistBorderWidth
);
740 template <typename PaintBackendData
>
741 void Theme::PaintMenulist(PaintBackendData
& aDrawTarget
,
742 const LayoutDeviceRect
& aRect
,
743 const ElementState
& aState
, const Colors
& aColors
,
744 DPIRatio aDpiRatio
) {
745 const CSSCoord radius
= 4.0f
;
746 auto [backgroundColor
, borderColor
] = ComputeButtonColors(aState
, aColors
);
748 ThemeDrawing::PaintRoundedRectWithRadius(aDrawTarget
, aRect
, backgroundColor
,
749 borderColor
, kMenulistBorderWidth
,
752 if (aState
.HasState(ElementState::FOCUSRING
)) {
753 PaintRoundedFocusRect(aDrawTarget
, aRect
, aColors
, aDpiRatio
,
754 radius
+ kMenulistBorderWidth
, -kMenulistBorderWidth
);
758 enum class PhysicalArrowDirection
{
764 void Theme::PaintMenulistArrow(nsIFrame
* aFrame
, DrawTarget
& aDrawTarget
,
765 const LayoutDeviceRect
& aRect
) {
766 // not const: these may be negated in-place below
767 float polygonX
[] = {-4.0f
, -0.5f
, 0.5f
, 4.0f
, 4.0f
,
768 3.0f
, 0.0f
, 0.0f
, -3.0f
, -4.0f
};
769 float polygonY
[] = {-1, 3.0f
, 3.0f
, -1.0f
, -2.0f
,
770 -2.0f
, 1.5f
, 1.5f
, -2.0f
, -2.0f
};
772 const float kPolygonSize
= kMinimumDropdownArrowButtonWidth
;
773 const auto direction
= [&] {
774 const auto wm
= aFrame
->GetWritingMode();
775 switch (wm
.GetBlockDir()) {
776 case WritingMode::BlockDir::eBlockLR
:
777 return PhysicalArrowDirection::Right
;
778 case WritingMode::BlockDir::eBlockRL
:
779 return PhysicalArrowDirection::Left
;
780 case WritingMode::BlockDir::eBlockTB
:
781 return PhysicalArrowDirection::Bottom
;
783 MOZ_ASSERT_UNREACHABLE("Unknown direction?");
784 return PhysicalArrowDirection::Bottom
;
787 auto const [xs
, ys
] = [&] {
788 using Pair
= std::pair
<const float*, const float*>;
790 case PhysicalArrowDirection::Left
:
791 // rotate 90°: [[0,1],[-1,0]]
792 for (float& f
: polygonY
) {
795 return Pair(polygonY
, polygonX
);
797 case PhysicalArrowDirection::Right
:
798 // rotate 270°: [[0,-1],[1,0]]
799 for (float& f
: polygonX
) {
802 return Pair(polygonY
, polygonX
);
804 case PhysicalArrowDirection::Bottom
:
805 // rotate 0°: [[1,0],[0,1]]
806 return Pair(polygonX
, polygonY
);
808 MOZ_ASSERT_UNREACHABLE("Unknown direction?");
809 return Pair(polygonX
, polygonY
);
812 const auto arrowColor
= sRGBColor::FromABGR(
813 nsLayoutUtils::GetColor(aFrame
, &nsStyleText::mWebkitTextFillColor
));
814 ThemeDrawing::PaintArrow(aDrawTarget
, aRect
, xs
, ys
, kPolygonSize
,
815 ArrayLength(polygonX
), arrowColor
);
818 void Theme::PaintSpinnerButton(nsIFrame
* aFrame
, DrawTarget
& aDrawTarget
,
819 const LayoutDeviceRect
& aRect
,
820 const ElementState
& aState
,
821 StyleAppearance aAppearance
,
822 const Colors
& aColors
, DPIRatio aDpiRatio
) {
823 auto [backgroundColor
, borderColor
] = ComputeButtonColors(aState
, aColors
);
825 aDrawTarget
.FillRect(aRect
.ToUnknownRect(),
826 ColorPattern(ToDeviceColor(backgroundColor
)));
828 const float kPolygonX
[] = {-3.5f
, -0.5f
, 0.5f
, 3.5f
, 3.5f
,
829 2.5f
, 0.0f
, 0.0f
, -2.5f
, -3.5f
};
830 float polygonY
[] = {-1.5f
, 1.5f
, 1.5f
, -1.5f
, -2.5f
,
831 -2.5f
, 0.0f
, 0.0f
, -2.5f
, -2.5f
};
833 const float kPolygonSize
= kMinimumSpinnerButtonHeight
;
834 if (aAppearance
== StyleAppearance::SpinnerUpbutton
) {
835 for (auto& coord
: polygonY
) {
840 ThemeDrawing::PaintArrow(aDrawTarget
, aRect
, kPolygonX
, polygonY
,
841 kPolygonSize
, ArrayLength(kPolygonX
), borderColor
);
844 template <typename PaintBackendData
>
845 void Theme::PaintRange(nsIFrame
* aFrame
, PaintBackendData
& aPaintData
,
846 const LayoutDeviceRect
& aRect
,
847 const ElementState
& aState
, const Colors
& aColors
,
848 DPIRatio aDpiRatio
, bool aHorizontal
) {
849 nsRangeFrame
* rangeFrame
= do_QueryFrame(aFrame
);
854 auto tickMarks
= rangeFrame
->TickMarks();
855 double progress
= rangeFrame
->GetValueAsFractionOfRange();
857 LayoutDeviceRect
thumbRect(0, 0, kMinimumRangeThumbSize
* aDpiRatio
,
858 kMinimumRangeThumbSize
* aDpiRatio
);
859 LayoutDeviceRect
progressClipRect(aRect
);
860 LayoutDeviceRect
trackClipRect(aRect
);
861 const LayoutDeviceCoord verticalSize
= kRangeHeight
* aDpiRatio
;
862 const LayoutDeviceCoord
tickMarkWidth(
863 ThemeDrawing::SnapBorderWidth(1.0f
, aDpiRatio
));
864 const LayoutDeviceCoord
tickMarkHeight(
865 ThemeDrawing::SnapBorderWidth(5.0f
, aDpiRatio
));
866 LayoutDevicePoint tickMarkOrigin
, tickMarkDirection
;
867 LayoutDeviceSize tickMarkSize
;
869 rect
.height
= verticalSize
;
870 rect
.y
= aRect
.y
+ (aRect
.height
- rect
.height
) / 2;
871 tickMarkSize
= LayoutDeviceSize(tickMarkWidth
, tickMarkHeight
);
872 thumbRect
.y
= aRect
.y
+ (aRect
.height
- thumbRect
.height
) / 2;
874 if (IsFrameRTL(aFrame
)) {
876 LayoutDevicePoint(aRect
.XMost() - thumbRect
.width
/ 2, aRect
.YMost());
877 tickMarkDirection
= LayoutDevicePoint(-1.0f
, 0.0f
);
879 aRect
.x
+ (aRect
.width
- thumbRect
.width
) * (1.0 - progress
);
880 float midPoint
= thumbRect
.Center().X();
881 trackClipRect
.SetBoxX(aRect
.X(), midPoint
);
882 progressClipRect
.SetBoxX(midPoint
, aRect
.XMost());
885 LayoutDevicePoint(aRect
.x
+ thumbRect
.width
/ 2, aRect
.YMost());
886 tickMarkDirection
= LayoutDevicePoint(1.0, 0.0f
);
887 thumbRect
.x
= aRect
.x
+ (aRect
.width
- thumbRect
.width
) * progress
;
888 float midPoint
= thumbRect
.Center().X();
889 progressClipRect
.SetBoxX(aRect
.X(), midPoint
);
890 trackClipRect
.SetBoxX(midPoint
, aRect
.XMost());
893 rect
.width
= verticalSize
;
894 rect
.x
= aRect
.x
+ (aRect
.width
- rect
.width
) / 2;
895 tickMarkOrigin
= LayoutDevicePoint(aRect
.XMost() - tickMarkHeight
/ 4,
896 aRect
.YMost() - thumbRect
.width
/ 2);
897 tickMarkDirection
= LayoutDevicePoint(0.0f
, -1.0f
);
898 tickMarkSize
= LayoutDeviceSize(tickMarkHeight
, tickMarkWidth
);
899 thumbRect
.x
= aRect
.x
+ (aRect
.width
- thumbRect
.width
) / 2;
901 if (rangeFrame
->IsUpwards()) {
903 aRect
.y
+ (aRect
.height
- thumbRect
.height
) * (1.0 - progress
);
904 float midPoint
= thumbRect
.Center().Y();
905 trackClipRect
.SetBoxY(aRect
.Y(), midPoint
);
906 progressClipRect
.SetBoxY(midPoint
, aRect
.YMost());
908 thumbRect
.y
= aRect
.y
+ (aRect
.height
- thumbRect
.height
) * progress
;
909 float midPoint
= thumbRect
.Center().Y();
910 trackClipRect
.SetBoxY(midPoint
, aRect
.YMost());
911 progressClipRect
.SetBoxY(aRect
.Y(), midPoint
);
915 const CSSCoord borderWidth
= 1.0f
;
916 const CSSCoord radius
= 3.0f
;
918 auto [progressColor
, progressBorderColor
] =
919 ComputeRangeProgressColors(aState
, aColors
);
920 auto [trackColor
, trackBorderColor
] =
921 ComputeRangeTrackColors(aState
, aColors
);
922 auto tickMarkColor
= trackBorderColor
;
924 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, rect
, progressClipRect
,
925 progressColor
, progressBorderColor
,
926 borderWidth
, radius
, aDpiRatio
);
928 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, rect
, trackClipRect
,
929 trackColor
, trackBorderColor
,
930 borderWidth
, radius
, aDpiRatio
);
932 if (!aState
.HasState(ElementState::DISABLED
)) {
933 // Ensure the shadow doesn't expand outside of our overflow rect declared in
934 // GetWidgetOverflow().
935 auto overflowRect
= aRect
;
936 overflowRect
.Inflate(CSSCoord(6.0f
) * aDpiRatio
);
938 PaintCircleShadow(aPaintData
, thumbRect
, overflowRect
, 0.3f
,
939 CSSPoint(0.0f
, 2.0f
), 2.0f
, aDpiRatio
);
942 tickMarkDirection
.x
*= aRect
.width
- thumbRect
.width
;
943 tickMarkDirection
.y
*= aRect
.height
- thumbRect
.height
;
945 LayoutDevicePoint(tickMarkSize
.width
, tickMarkSize
.height
) / 2;
946 auto tickMarkRect
= LayoutDeviceRect(tickMarkOrigin
, tickMarkSize
);
947 for (auto tickMark
: tickMarks
) {
948 auto tickMarkOffset
=
950 float(rangeFrame
->GetDoubleAsFractionOfRange(tickMark
));
951 ThemeDrawing::FillRect(aPaintData
, tickMarkRect
+ tickMarkOffset
,
955 // Draw the thumb on top.
956 const CSSCoord thumbBorderWidth
= 2.0f
;
957 auto [thumbColor
, thumbBorderColor
] =
958 ComputeRangeThumbColors(aState
, aColors
);
960 PaintStrokedCircle(aPaintData
, thumbRect
, thumbColor
, thumbBorderColor
,
961 thumbBorderWidth
, aDpiRatio
);
963 if (aState
.HasState(ElementState::FOCUSRING
)) {
964 PaintRoundedFocusRect(aPaintData
, aRect
, aColors
, aDpiRatio
, radius
, 1.0f
);
968 template <typename PaintBackendData
>
969 void Theme::PaintProgress(nsIFrame
* aFrame
, PaintBackendData
& aPaintData
,
970 const LayoutDeviceRect
& aRect
,
971 const ElementState
& aState
, const Colors
& aColors
,
972 DPIRatio aDpiRatio
, bool aIsMeter
) {
973 const CSSCoord borderWidth
= 1.0f
;
974 const CSSCoord radius
= aIsMeter
? 6.0f
: 3.0f
;
976 LayoutDeviceRect
rect(aRect
);
977 const LayoutDeviceCoord thickness
=
978 (aIsMeter
? kMeterHeight
: kProgressbarHeight
) * aDpiRatio
;
980 const bool isHorizontal
= !nsNativeTheme::IsVerticalProgress(aFrame
);
982 // Center it vertically.
983 rect
.y
+= (rect
.height
- thickness
) / 2;
984 rect
.height
= thickness
;
986 // Center it horizontally.
987 rect
.x
+= (rect
.width
- thickness
) / 2;
988 rect
.width
= thickness
;
992 // Paint the track, unclipped.
993 auto [backgroundColor
, borderColor
] = ComputeProgressTrackColors(aColors
);
994 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, rect
, rect
,
995 backgroundColor
, borderColor
,
996 borderWidth
, radius
, aDpiRatio
);
999 // Now paint the chunk, clipped as needed.
1000 LayoutDeviceRect clipRect
= rect
;
1001 if (aState
.HasState(ElementState::INDETERMINATE
)) {
1002 // For indeterminate progress, we paint an animated chunk of 1/3 of the
1005 // Animation speed and math borrowed from GTK.
1006 const LayoutDeviceCoord size
= isHorizontal
? rect
.width
: rect
.height
;
1007 const LayoutDeviceCoord barSize
= size
* 0.3333f
;
1008 const LayoutDeviceCoord travel
= 2.0f
* (size
- barSize
);
1010 // Period equals to travel / pixelsPerMillisecond where pixelsPerMillisecond
1011 // equals progressSize / 1000.0. This is equivalent to 1600.
1012 const unsigned kPeriod
= 1600;
1014 const int t
= PR_IntervalToMilliseconds(PR_IntervalNow()) % kPeriod
;
1015 const LayoutDeviceCoord dx
= travel
* float(t
) / float(kPeriod
);
1017 rect
.width
= barSize
;
1018 rect
.x
+= (dx
< travel
* .5f
) ? dx
: travel
- dx
;
1020 rect
.height
= barSize
;
1021 rect
.y
+= (dx
< travel
* .5f
) ? dx
: travel
- dx
;
1024 // Queue the next frame if needed.
1025 if (!QueueAnimatedContentForRefresh(aFrame
->GetContent(), 60)) {
1026 NS_WARNING("Couldn't refresh indeterminate <progress>");
1029 // This is the progress chunk, clip it to the right amount.
1030 double position
= [&] {
1032 auto* meter
= dom::HTMLMeterElement::FromNode(aFrame
->GetContent());
1036 return meter
->Position();
1038 auto* progress
= dom::HTMLProgressElement::FromNode(aFrame
->GetContent());
1042 return progress
->Position();
1045 double clipWidth
= rect
.width
* position
;
1046 clipRect
.width
= clipWidth
;
1047 if (IsFrameRTL(aFrame
)) {
1048 clipRect
.x
+= rect
.width
- clipWidth
;
1051 double clipHeight
= rect
.height
* position
;
1052 clipRect
.height
= clipHeight
;
1053 clipRect
.y
+= rect
.height
- clipHeight
;
1057 auto [backgroundColor
, borderColor
] =
1058 aIsMeter
? ComputeMeterchunkColors(aState
, aColors
)
1059 : ComputeProgressColors(aColors
);
1060 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, rect
, clipRect
,
1061 backgroundColor
, borderColor
,
1062 borderWidth
, radius
, aDpiRatio
);
1065 template <typename PaintBackendData
>
1066 void Theme::PaintButton(nsIFrame
* aFrame
, PaintBackendData
& aPaintData
,
1067 const LayoutDeviceRect
& aRect
,
1068 StyleAppearance aAppearance
, const ElementState
& aState
,
1069 const Colors
& aColors
, DPIRatio aDpiRatio
) {
1070 const CSSCoord radius
= 4.0f
;
1071 auto [backgroundColor
, borderColor
] =
1072 ComputeButtonColors(aState
, aColors
, aFrame
);
1074 if (aAppearance
== StyleAppearance::Toolbarbutton
&&
1075 (!aState
.HasState(ElementState::HOVER
) ||
1076 aState
.HasState(ElementState::DISABLED
))) {
1077 borderColor
= sTransparent
;
1080 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, aRect
, backgroundColor
,
1081 borderColor
, kButtonBorderWidth
,
1084 if (aState
.HasState(ElementState::FOCUSRING
)) {
1085 PaintRoundedFocusRect(aPaintData
, aRect
, aColors
, aDpiRatio
,
1086 radius
+ kButtonBorderWidth
, -kButtonBorderWidth
);
1091 Theme::DrawWidgetBackground(gfxContext
* aContext
, nsIFrame
* aFrame
,
1092 StyleAppearance aAppearance
, const nsRect
& aRect
,
1093 const nsRect
& /* aDirtyRect */,
1094 DrawOverflow aDrawOverflow
) {
1095 if (!DoDrawWidgetBackground(*aContext
->GetDrawTarget(), aFrame
, aAppearance
,
1096 aRect
, aDrawOverflow
)) {
1097 return NS_ERROR_NOT_IMPLEMENTED
;
1102 bool Theme::CreateWebRenderCommandsForWidget(
1103 mozilla::wr::DisplayListBuilder
& aBuilder
,
1104 mozilla::wr::IpcResourceUpdateQueue
& aResources
,
1105 const mozilla::layers::StackingContextHelper
& aSc
,
1106 mozilla::layers::RenderRootStateManager
* aManager
, nsIFrame
* aFrame
,
1107 StyleAppearance aAppearance
, const nsRect
& aRect
) {
1108 if (!StaticPrefs::widget_non_native_theme_webrender()) {
1111 WebRenderBackendData data
{aBuilder
, aResources
, aSc
, aManager
};
1112 return DoDrawWidgetBackground(data
, aFrame
, aAppearance
, aRect
,
1116 static LayoutDeviceRect
ToSnappedRect(const nsRect
& aRect
,
1117 nscoord aTwipsPerPixel
, DrawTarget
& aDt
) {
1118 return LayoutDeviceRect::FromUnknownRect(
1119 NSRectToSnappedRect(aRect
, aTwipsPerPixel
, aDt
));
1122 static LayoutDeviceRect
ToSnappedRect(const nsRect
& aRect
,
1123 nscoord aTwipsPerPixel
,
1124 WebRenderBackendData
& aDt
) {
1125 // TODO: Do we need to do any more snapping here?
1126 return LayoutDeviceRect::FromAppUnits(aRect
, aTwipsPerPixel
);
1129 static ScrollbarDrawing::ScrollbarKind
ComputeScrollbarKind(
1130 nsIFrame
* aFrame
, bool aIsHorizontal
) {
1131 if (aIsHorizontal
) {
1132 return ScrollbarDrawing::ScrollbarKind::Horizontal
;
1134 nsIFrame
* scrollbar
= ScrollbarDrawing::GetParentScrollbarFrame(aFrame
);
1135 if (NS_WARN_IF(!scrollbar
)) {
1136 return ScrollbarDrawing::ScrollbarKind::VerticalRight
;
1138 MOZ_ASSERT(scrollbar
->IsScrollbarFrame());
1139 nsIScrollbarMediator
* sm
=
1140 static_cast<nsScrollbarFrame
*>(scrollbar
)->GetScrollbarMediator();
1141 if (NS_WARN_IF(!sm
)) {
1142 return ScrollbarDrawing::ScrollbarKind::VerticalRight
;
1144 return sm
->IsScrollbarOnRight()
1145 ? ScrollbarDrawing::ScrollbarKind::VerticalRight
1146 : ScrollbarDrawing::ScrollbarKind::VerticalLeft
;
1149 static ScrollbarDrawing::ScrollbarKind
ComputeScrollbarKindForScrollCorner(
1151 nsIScrollableFrame
* sf
= do_QueryFrame(aFrame
->GetParent());
1153 return ScrollbarDrawing::ScrollbarKind::VerticalRight
;
1155 return sf
->IsScrollbarOnRight()
1156 ? ScrollbarDrawing::ScrollbarKind::VerticalRight
1157 : ScrollbarDrawing::ScrollbarKind::VerticalLeft
;
1160 template <typename PaintBackendData
>
1161 bool Theme::DoDrawWidgetBackground(PaintBackendData
& aPaintData
,
1163 StyleAppearance aAppearance
,
1164 const nsRect
& aRect
,
1165 DrawOverflow aDrawOverflow
) {
1166 static_assert(std::is_same_v
<PaintBackendData
, DrawTarget
> ||
1167 std::is_same_v
<PaintBackendData
, WebRenderBackendData
>);
1169 const nsPresContext
* pc
= aFrame
->PresContext();
1170 const nscoord twipsPerPixel
= pc
->AppUnitsPerDevPixel();
1171 const auto devPxRect
= ToSnappedRect(aRect
, twipsPerPixel
, aPaintData
);
1173 const DocumentState docState
= pc
->Document()->State();
1174 ElementState elementState
= GetContentState(aFrame
, aAppearance
);
1175 // Paint the outline iff we're asked to draw overflow and we have
1176 // outline-style: auto.
1177 if (aDrawOverflow
== DrawOverflow::Yes
&&
1178 aFrame
->StyleOutline()->mOutlineStyle
.IsAuto()) {
1179 elementState
|= ElementState::FOCUSRING
;
1181 elementState
&= ~ElementState::FOCUSRING
;
1184 // Hack to avoid skia fuzziness: Add a dummy clip if the widget doesn't
1185 // overflow devPxRect.
1186 Maybe
<AutoClipRect
> maybeClipRect
;
1187 if constexpr (std::is_same_v
<PaintBackendData
, DrawTarget
>) {
1188 if (aAppearance
!= StyleAppearance::FocusOutline
&&
1189 aAppearance
!= StyleAppearance::Range
&&
1190 !elementState
.HasState(ElementState::FOCUSRING
)) {
1191 maybeClipRect
.emplace(aPaintData
, devPxRect
);
1195 const Colors
colors(aFrame
, aAppearance
);
1196 DPIRatio dpiRatio
= GetDPIRatio(aFrame
, aAppearance
);
1198 switch (aAppearance
) {
1199 case StyleAppearance::Radio
: {
1200 auto rect
= CheckBoxRadioRect(devPxRect
);
1201 PaintRadioControl(aPaintData
, rect
, elementState
, colors
, dpiRatio
);
1204 case StyleAppearance::Checkbox
: {
1205 if constexpr (std::is_same_v
<PaintBackendData
, WebRenderBackendData
>) {
1206 // TODO: Need to figure out how to best draw this using WR.
1209 auto rect
= CheckBoxRadioRect(devPxRect
);
1210 PaintCheckboxControl(aPaintData
, rect
, elementState
, colors
, dpiRatio
);
1214 case StyleAppearance::Textarea
:
1215 case StyleAppearance::Textfield
:
1216 case StyleAppearance::NumberInput
:
1217 PaintTextField(aPaintData
, devPxRect
, elementState
, colors
, dpiRatio
);
1219 case StyleAppearance::Listbox
:
1220 PaintListbox(aPaintData
, devPxRect
, elementState
, colors
, dpiRatio
);
1222 case StyleAppearance::MenulistButton
:
1223 case StyleAppearance::Menulist
:
1224 PaintMenulist(aPaintData
, devPxRect
, elementState
, colors
, dpiRatio
);
1226 case StyleAppearance::MozMenulistArrowButton
:
1227 if constexpr (std::is_same_v
<PaintBackendData
, WebRenderBackendData
>) {
1228 // TODO: Need to figure out how to best draw this using WR.
1231 PaintMenulistArrow(aFrame
, aPaintData
, devPxRect
);
1234 case StyleAppearance::Tooltip
: {
1235 const CSSCoord
strokeWidth(1.0f
);
1236 const CSSCoord
strokeRadius(2.0f
);
1237 ThemeDrawing::PaintRoundedRectWithRadius(
1238 aPaintData
, devPxRect
,
1239 colors
.System(StyleSystemColor::Infobackground
),
1240 colors
.System(StyleSystemColor::Infotext
), strokeWidth
, strokeRadius
,
1244 case StyleAppearance::SpinnerUpbutton
:
1245 case StyleAppearance::SpinnerDownbutton
:
1246 if constexpr (std::is_same_v
<PaintBackendData
, WebRenderBackendData
>) {
1247 // TODO: Need to figure out how to best draw this using WR.
1250 PaintSpinnerButton(aFrame
, aPaintData
, devPxRect
, elementState
,
1251 aAppearance
, colors
, dpiRatio
);
1254 case StyleAppearance::Range
:
1255 PaintRange(aFrame
, aPaintData
, devPxRect
, elementState
, colors
, dpiRatio
,
1256 IsRangeHorizontal(aFrame
));
1258 case StyleAppearance::RangeThumb
:
1259 // Painted as part of StyleAppearance::Range.
1261 case StyleAppearance::ProgressBar
:
1262 PaintProgress(aFrame
, aPaintData
, devPxRect
, elementState
, colors
,
1264 /* aIsMeter = */ false);
1266 case StyleAppearance::Progresschunk
:
1267 /* Painted as part of the progress bar */
1269 case StyleAppearance::Meter
:
1270 PaintProgress(aFrame
, aPaintData
, devPxRect
, elementState
, colors
,
1272 /* aIsMeter = */ true);
1274 case StyleAppearance::Meterchunk
:
1275 /* Painted as part of the meter bar */
1277 case StyleAppearance::ScrollbarthumbHorizontal
:
1278 case StyleAppearance::ScrollbarthumbVertical
: {
1280 aAppearance
== StyleAppearance::ScrollbarthumbHorizontal
;
1281 auto kind
= ComputeScrollbarKind(aFrame
, isHorizontal
);
1282 return GetScrollbarDrawing().PaintScrollbarThumb(
1283 aPaintData
, devPxRect
, kind
, aFrame
,
1284 *nsLayoutUtils::StyleForScrollbar(aFrame
), elementState
, docState
,
1287 case StyleAppearance::ScrollbartrackHorizontal
:
1288 case StyleAppearance::ScrollbartrackVertical
: {
1290 aAppearance
== StyleAppearance::ScrollbartrackHorizontal
;
1291 auto kind
= ComputeScrollbarKind(aFrame
, isHorizontal
);
1292 return GetScrollbarDrawing().PaintScrollbarTrack(
1293 aPaintData
, devPxRect
, kind
, aFrame
,
1294 *nsLayoutUtils::StyleForScrollbar(aFrame
), docState
, colors
,
1297 case StyleAppearance::ScrollbarHorizontal
:
1298 case StyleAppearance::ScrollbarVertical
: {
1299 bool isHorizontal
= aAppearance
== StyleAppearance::ScrollbarHorizontal
;
1300 auto kind
= ComputeScrollbarKind(aFrame
, isHorizontal
);
1301 return GetScrollbarDrawing().PaintScrollbar(
1302 aPaintData
, devPxRect
, kind
, aFrame
,
1303 *nsLayoutUtils::StyleForScrollbar(aFrame
), elementState
, docState
,
1306 case StyleAppearance::Scrollcorner
: {
1307 auto kind
= ComputeScrollbarKindForScrollCorner(aFrame
);
1308 return GetScrollbarDrawing().PaintScrollCorner(
1309 aPaintData
, devPxRect
, kind
, aFrame
,
1310 *nsLayoutUtils::StyleForScrollbar(aFrame
), docState
, colors
,
1313 case StyleAppearance::ScrollbarbuttonUp
:
1314 case StyleAppearance::ScrollbarbuttonDown
:
1315 case StyleAppearance::ScrollbarbuttonLeft
:
1316 case StyleAppearance::ScrollbarbuttonRight
: {
1317 // For scrollbar-width:thin, we don't display the buttons.
1318 if (!ScrollbarDrawing::IsScrollbarWidthThin(aFrame
)) {
1319 if constexpr (std::is_same_v
<PaintBackendData
, WebRenderBackendData
>) {
1320 // TODO: Need to figure out how to best draw this using WR.
1324 aAppearance
== StyleAppearance::ScrollbarbuttonLeft
||
1325 aAppearance
== StyleAppearance::ScrollbarbuttonRight
;
1326 auto kind
= ComputeScrollbarKind(aFrame
, isHorizontal
);
1327 GetScrollbarDrawing().PaintScrollbarButton(
1328 aPaintData
, aAppearance
, devPxRect
, kind
, aFrame
,
1329 *nsLayoutUtils::StyleForScrollbar(aFrame
), elementState
, docState
,
1335 case StyleAppearance::Button
:
1336 case StyleAppearance::Toolbarbutton
:
1337 PaintButton(aFrame
, aPaintData
, devPxRect
, aAppearance
, elementState
,
1340 case StyleAppearance::FocusOutline
:
1341 PaintAutoStyleOutline(aFrame
, aPaintData
, devPxRect
, colors
, dpiRatio
);
1344 // Various appearance values are used for XUL elements. Normally these
1345 // will not be available in content documents (and thus in the content
1346 // processes where the native basic theme can be used), but tests are
1347 // run with the remote XUL pref enabled and so we can get in here. So
1348 // we just return an error rather than assert.
1355 template <typename PaintBackendData
>
1356 void Theme::PaintAutoStyleOutline(nsIFrame
* aFrame
,
1357 PaintBackendData
& aPaintData
,
1358 const LayoutDeviceRect
& aRect
,
1359 const Colors
& aColors
, DPIRatio aDpiRatio
) {
1360 const auto& accentColor
= aColors
.Accent();
1361 const bool solid
= StaticPrefs::widget_non_native_theme_solid_outline_style();
1362 LayoutDeviceCoord
strokeWidth(ThemeDrawing::SnapBorderWidth(2.0f
, aDpiRatio
));
1364 LayoutDeviceRect
rect(aRect
);
1365 rect
.Inflate(strokeWidth
);
1367 const nscoord a2d
= aFrame
->PresContext()->AppUnitsPerDevPixel();
1368 nscoord cssOffset
= aFrame
->StyleOutline()->mOutlineOffset
.ToAppUnits();
1369 nscoord cssRadii
[8] = {0};
1370 if (!aFrame
->GetBorderRadii(cssRadii
)) {
1371 const auto twoPixels
= 2 * AppUnitsPerCSSPixel();
1372 const nscoord radius
=
1373 cssOffset
>= 0 ? twoPixels
: std::max(twoPixels
+ cssOffset
, 0);
1374 cssOffset
= -twoPixels
;
1375 for (auto& r
: cssRadii
) {
1380 auto offset
= LayoutDevicePixel::FromAppUnits(cssOffset
, a2d
);
1381 RectCornerRadii innerRadii
;
1382 nsCSSRendering::ComputePixelRadii(cssRadii
, a2d
, &innerRadii
);
1384 // NOTE(emilio): This doesn't use PaintRoundedRectWithRadius because we need
1385 // to support arbitrary radii.
1386 auto DrawRect
= [&](const sRGBColor
& aColor
) {
1387 RectCornerRadii outerRadii
;
1388 if constexpr (std::is_same_v
<PaintBackendData
, WebRenderBackendData
>) {
1389 const Float widths
[4] = {strokeWidth
+ offset
, strokeWidth
+ offset
,
1390 strokeWidth
+ offset
, strokeWidth
+ offset
};
1391 nsCSSBorderRenderer::ComputeOuterRadii(innerRadii
, widths
, &outerRadii
);
1392 const auto dest
= wr::ToLayoutRect(rect
);
1394 wr::ToBorderSide(ToDeviceColor(aColor
), StyleBorderStyle::Solid
);
1395 const wr::BorderSide sides
[4] = {side
, side
, side
, side
};
1396 const bool kBackfaceIsVisible
= true;
1397 const auto wrWidths
= wr::ToBorderWidths(strokeWidth
, strokeWidth
,
1398 strokeWidth
, strokeWidth
);
1399 const auto wrRadius
= wr::ToBorderRadius(outerRadii
);
1400 aPaintData
.mBuilder
.PushBorder(dest
, dest
, kBackfaceIsVisible
, wrWidths
,
1401 {sides
, 4}, wrRadius
);
1403 const LayoutDeviceCoord halfWidth
= strokeWidth
* 0.5f
;
1404 const Float widths
[4] = {halfWidth
+ offset
, halfWidth
+ offset
,
1405 halfWidth
+ offset
, halfWidth
+ offset
};
1406 nsCSSBorderRenderer::ComputeOuterRadii(innerRadii
, widths
, &outerRadii
);
1407 LayoutDeviceRect
dest(rect
);
1408 dest
.Deflate(halfWidth
);
1410 MakePathForRoundedRect(aPaintData
, dest
.ToUnknownRect(), outerRadii
);
1411 aPaintData
.Stroke(path
, ColorPattern(ToDeviceColor(aColor
)),
1412 StrokeOptions(strokeWidth
));
1416 auto primaryColor
= aColors
.HighContrast()
1417 ? aColors
.System(StyleSystemColor::Selecteditem
)
1418 : accentColor
.Get();
1419 DrawRect(primaryColor
);
1425 offset
+= strokeWidth
;
1428 LayoutDeviceCoord(ThemeDrawing::SnapBorderWidth(1.0f
, aDpiRatio
));
1429 rect
.Inflate(strokeWidth
);
1431 auto secondaryColor
= aColors
.HighContrast()
1432 ? aColors
.System(StyleSystemColor::Canvastext
)
1433 : accentColor
.GetForeground();
1434 DrawRect(secondaryColor
);
1437 LayoutDeviceIntMargin
Theme::GetWidgetBorder(nsDeviceContext
* aContext
,
1439 StyleAppearance aAppearance
) {
1440 switch (aAppearance
) {
1441 case StyleAppearance::Textfield
:
1442 case StyleAppearance::Textarea
:
1443 case StyleAppearance::NumberInput
:
1444 case StyleAppearance::Listbox
:
1445 case StyleAppearance::Menulist
:
1446 case StyleAppearance::MenulistButton
:
1447 case StyleAppearance::Button
:
1448 case StyleAppearance::Toolbarbutton
:
1449 // Return the border size from the UA sheet, even though what we paint
1450 // doesn't actually match that. We know this is the UA sheet border
1451 // because we disable native theming when different border widths are
1452 // specified by authors, see Theme::IsWidgetStyled.
1454 // The Rounded() bit is technically redundant, but needed to appease the
1455 // type system, we should always end up with full device pixels due to
1456 // round_border_to_device_pixels at style time.
1457 return LayoutDeviceIntMargin::FromAppUnits(
1458 aFrame
->StyleBorder()->GetComputedBorder(),
1459 aFrame
->PresContext()->AppUnitsPerDevPixel())
1461 case StyleAppearance::Checkbox
:
1462 case StyleAppearance::Radio
: {
1463 DPIRatio dpiRatio
= GetDPIRatio(aFrame
, aAppearance
);
1464 LayoutDeviceIntCoord w
=
1465 ThemeDrawing::SnapBorderWidth(kCheckboxRadioBorderWidth
, dpiRatio
);
1466 return LayoutDeviceIntMargin(w
, w
, w
, w
);
1469 return LayoutDeviceIntMargin();
1473 bool Theme::GetWidgetPadding(nsDeviceContext
* aContext
, nsIFrame
* aFrame
,
1474 StyleAppearance aAppearance
,
1475 LayoutDeviceIntMargin
* aResult
) {
1476 switch (aAppearance
) {
1477 // Radios and checkboxes return a fixed size in GetMinimumWidgetSize
1478 // and have a meaningful baseline, so they can't have
1479 // author-specified padding.
1480 case StyleAppearance::Radio
:
1481 case StyleAppearance::Checkbox
:
1482 aResult
->SizeTo(0, 0, 0, 0);
1490 bool Theme::GetWidgetOverflow(nsDeviceContext
* aContext
, nsIFrame
* aFrame
,
1491 StyleAppearance aAppearance
,
1492 nsRect
* aOverflowRect
) {
1493 CSSIntMargin overflow
;
1494 switch (aAppearance
) {
1495 case StyleAppearance::FocusOutline
: {
1496 // 2px * one segment, or 2px + 1px
1498 StaticPrefs::widget_non_native_theme_solid_outline_style() ? 2 : 3;
1499 overflow
.SizeTo(width
, width
, width
, width
);
1502 case StyleAppearance::Radio
:
1503 case StyleAppearance::Checkbox
:
1504 case StyleAppearance::Range
:
1505 // 2px for each outline segment, plus 1px separation, plus we paint with a
1506 // 1px extra offset, so 6px.
1507 overflow
.SizeTo(6, 6, 6, 6);
1509 case StyleAppearance::Textarea
:
1510 case StyleAppearance::Textfield
:
1511 case StyleAppearance::NumberInput
:
1512 case StyleAppearance::Listbox
:
1513 case StyleAppearance::MenulistButton
:
1514 case StyleAppearance::Menulist
:
1515 case StyleAppearance::Button
:
1516 case StyleAppearance::Toolbarbutton
:
1517 // 2px for each segment, plus 1px separation, but we paint 1px inside
1518 // the border area so 4px overflow.
1519 overflow
.SizeTo(4, 4, 4, 4);
1525 // TODO: This should convert from device pixels to app units, not from CSS
1526 // pixels. And it should take the dpi ratio into account.
1527 // Using CSS pixels can cause the overflow to be too small if the page is
1529 aOverflowRect
->Inflate(CSSPixel::ToAppUnits(overflow
));
1533 LayoutDeviceIntCoord
Theme::GetScrollbarSize(const nsPresContext
* aPresContext
,
1534 StyleScrollbarWidth aWidth
,
1536 return GetScrollbarDrawing().GetScrollbarSize(aPresContext
, aWidth
, aOverlay
);
1539 nscoord
Theme::GetCheckboxRadioPrefSize() {
1540 return CSSPixel::ToAppUnits(kCheckboxRadioContentBoxSize
);
1544 UniquePtr
<ScrollbarDrawing
> Theme::ScrollbarStyle() {
1545 switch (StaticPrefs::widget_non_native_theme_scrollbar_style()) {
1547 return MakeUnique
<ScrollbarDrawingCocoa
>();
1549 return MakeUnique
<ScrollbarDrawingGTK
>();
1551 return MakeUnique
<ScrollbarDrawingAndroid
>();
1553 return MakeUnique
<ScrollbarDrawingWin
>();
1555 return MakeUnique
<ScrollbarDrawingWin11
>();
1559 // Default to native scrollbar style for each platform.
1561 if (IsWin11OrLater()) {
1562 return MakeUnique
<ScrollbarDrawingWin11
>();
1564 return MakeUnique
<ScrollbarDrawingWin
>();
1565 #elif defined(MOZ_WIDGET_COCOA) || defined(MOZ_WIDGET_UIKIT)
1566 return MakeUnique
<ScrollbarDrawingCocoa
>();
1567 #elif MOZ_WIDGET_GTK
1568 return MakeUnique
<ScrollbarDrawingGTK
>();
1570 return MakeUnique
<ScrollbarDrawingAndroid
>();
1572 # error "Unknown platform, need scrollbar implementation."
1576 LayoutDeviceIntSize
Theme::GetMinimumWidgetSize(nsPresContext
* aPresContext
,
1578 StyleAppearance aAppearance
) {
1579 DPIRatio dpiRatio
= GetDPIRatio(aFrame
, aAppearance
);
1581 if (IsWidgetScrollbarPart(aAppearance
)) {
1582 return GetScrollbarDrawing().GetMinimumWidgetSize(aPresContext
, aAppearance
,
1586 LayoutDeviceIntSize result
;
1587 switch (aAppearance
) {
1588 case StyleAppearance::RangeThumb
:
1589 result
.SizeTo((kMinimumRangeThumbSize
* dpiRatio
).Rounded(),
1590 (kMinimumRangeThumbSize
* dpiRatio
).Rounded());
1592 case StyleAppearance::MozMenulistArrowButton
:
1593 result
.width
= (kMinimumDropdownArrowButtonWidth
* dpiRatio
).Rounded();
1595 case StyleAppearance::SpinnerUpbutton
:
1596 case StyleAppearance::SpinnerDownbutton
:
1597 result
.width
= (kMinimumSpinnerButtonWidth
* dpiRatio
).Rounded();
1598 result
.height
= (kMinimumSpinnerButtonHeight
* dpiRatio
).Rounded();
1606 nsITheme::Transparency
Theme::GetWidgetTransparency(
1607 nsIFrame
* aFrame
, StyleAppearance aAppearance
) {
1608 if (auto scrollbar
= GetScrollbarDrawing().GetScrollbarPartTransparency(
1609 aFrame
, aAppearance
)) {
1612 if (aAppearance
== StyleAppearance::Tooltip
) {
1613 // We draw a rounded rect, so we need transparency.
1614 return eTransparent
;
1616 return eUnknownTransparency
;
1620 Theme::WidgetStateChanged(nsIFrame
* aFrame
, StyleAppearance aAppearance
,
1621 nsAtom
* aAttribute
, bool* aShouldRepaint
,
1622 const nsAttrValue
* aOldValue
) {
1624 // Hover/focus/active changed. Always repaint.
1625 *aShouldRepaint
= true;
1627 // Check the attribute to see if it's relevant.
1628 // disabled, checked, dlgtype, default, etc.
1629 *aShouldRepaint
= false;
1630 if (aAttribute
== nsGkAtoms::disabled
|| aAttribute
== nsGkAtoms::checked
||
1631 aAttribute
== nsGkAtoms::selected
||
1632 aAttribute
== nsGkAtoms::visuallyselected
||
1633 aAttribute
== nsGkAtoms::menuactive
||
1634 aAttribute
== nsGkAtoms::sortDirection
||
1635 aAttribute
== nsGkAtoms::focused
|| aAttribute
== nsGkAtoms::_default
||
1636 aAttribute
== nsGkAtoms::open
|| aAttribute
== nsGkAtoms::hover
) {
1637 *aShouldRepaint
= true;
1645 Theme::ThemeChanged() { return NS_OK
; }
1647 bool Theme::WidgetAppearanceDependsOnWindowFocus(StyleAppearance aAppearance
) {
1648 return IsWidgetScrollbarPart(aAppearance
);
1651 nsITheme::ThemeGeometryType
Theme::ThemeGeometryTypeForWidget(
1652 nsIFrame
* aFrame
, StyleAppearance aAppearance
) {
1653 return eThemeGeometryTypeUnknown
;
1656 bool Theme::ThemeSupportsWidget(nsPresContext
* aPresContext
, nsIFrame
* aFrame
,
1657 StyleAppearance aAppearance
) {
1658 switch (aAppearance
) {
1659 case StyleAppearance::Radio
:
1660 case StyleAppearance::Checkbox
:
1661 case StyleAppearance::FocusOutline
:
1662 case StyleAppearance::Textarea
:
1663 case StyleAppearance::Textfield
:
1664 case StyleAppearance::Range
:
1665 case StyleAppearance::RangeThumb
:
1666 case StyleAppearance::ProgressBar
:
1667 case StyleAppearance::Progresschunk
:
1668 case StyleAppearance::Meter
:
1669 case StyleAppearance::Meterchunk
:
1670 case StyleAppearance::ScrollbarbuttonUp
:
1671 case StyleAppearance::ScrollbarbuttonDown
:
1672 case StyleAppearance::ScrollbarbuttonLeft
:
1673 case StyleAppearance::ScrollbarbuttonRight
:
1674 case StyleAppearance::ScrollbarthumbHorizontal
:
1675 case StyleAppearance::ScrollbarthumbVertical
:
1676 case StyleAppearance::ScrollbartrackHorizontal
:
1677 case StyleAppearance::ScrollbartrackVertical
:
1678 case StyleAppearance::ScrollbarHorizontal
:
1679 case StyleAppearance::ScrollbarVertical
:
1680 case StyleAppearance::Scrollcorner
:
1681 case StyleAppearance::Button
:
1682 case StyleAppearance::Toolbarbutton
:
1683 case StyleAppearance::Listbox
:
1684 case StyleAppearance::Menulist
:
1685 case StyleAppearance::MenulistButton
:
1686 case StyleAppearance::NumberInput
:
1687 case StyleAppearance::MozMenulistArrowButton
:
1688 case StyleAppearance::SpinnerUpbutton
:
1689 case StyleAppearance::SpinnerDownbutton
:
1690 case StyleAppearance::Tooltip
:
1691 return !IsWidgetStyled(aPresContext
, aFrame
, aAppearance
);
1697 bool Theme::WidgetIsContainer(StyleAppearance aAppearance
) {
1698 switch (aAppearance
) {
1699 case StyleAppearance::MozMenulistArrowButton
:
1700 case StyleAppearance::Radio
:
1701 case StyleAppearance::Checkbox
:
1708 bool Theme::ThemeDrawsFocusForWidget(nsIFrame
*, StyleAppearance
) {
1712 bool Theme::ThemeNeedsComboboxDropmarker() { return true; }
1714 bool Theme::ThemeSupportsScrollbarButtons() {
1715 return GetScrollbarDrawing().ShouldDrawScrollbarButtons();
1718 } // namespace mozilla::widget