Bug 1837494 [wpt PR 40457] - Ignore urllib3's warnings when run on LibreSSL, a=testonly
[gecko.git] / widget / Theme.cpp
blob1fb9dd854271771eb93a673bea62152019a151de
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/. */
6 #include "Theme.h"
7 #include <utility>
8 #include "ThemeCocoa.h"
10 #include "ThemeDrawing.h"
11 #include "Units.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"
38 #ifdef XP_WIN
39 # include "mozilla/WindowsVersion.h"
40 #endif
42 using namespace mozilla;
43 using namespace mozilla::dom;
44 using namespace mozilla::gfx;
45 using namespace mozilla::widget;
47 namespace {
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
101 // the clips.
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(); }
111 private:
112 DrawTarget& mDt;
115 static StaticRefPtr<Theme> gNativeInstance;
116 static StaticRefPtr<Theme> gNonNativeInstance;
117 static StaticRefPtr<Theme> gRDMInstance;
119 } // namespace
121 #ifdef ANDROID
122 already_AddRefed<Theme> do_CreateNativeThemeDoNotUseDirectly() {
123 // Android doesn't have a native theme.
124 return do_AddRef(new Theme(Theme::ScrollbarStyle()));
126 #endif
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));
133 #else
134 gNonNativeInstance = new Theme(std::move(scrollbarDrawing));
135 #endif
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,
168 void Theme::Init() {
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);
181 /* static */
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)
193 -> DPIRatio {
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)
202 -> DPIRatio {
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) {
227 if (isDisabled) {
228 auto bg = ComputeBorderColor(aState, aColors, OutlineCoversBorder::No);
229 auto fg = aColors.HighContrast()
230 ? aColors.System(StyleSystemColor::Graytext)
231 : sRGBColor::White(.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);
241 bool isActive =
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);
251 auto [bg, border] =
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);
265 bool isActive =
266 aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE);
267 bool isHovered = aState.HasState(ElementState::HOVER);
268 bool isFocused = aState.HasState(ElementState::FOCUSRING);
269 if (isDisabled) {
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.
279 return sTransparent;
281 bool dark = aColors.IsDark();
282 if (isActive) {
283 return dark ? sColorGrey20 : sColorGrey60;
285 if (isHovered) {
286 return dark ? sColorGrey30 : sColorGrey50;
288 return sColorGrey40;
291 std::pair<sRGBColor, sRGBColor> Theme::ComputeButtonColors(
292 const ElementState& aState, const Colors& aColors, nsIFrame* aFrame) {
293 bool isActive =
294 aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE);
295 bool isDisabled = aState.HasState(ElementState::DISABLED);
296 bool isHovered = aState.HasState(ElementState::HOVER);
298 nscolor backgroundColor = [&] {
299 if (isDisabled) {
300 return aColors.SystemNs(StyleSystemColor::MozButtondisabledface);
302 if (isActive) {
303 return aColors.SystemNs(StyleSystemColor::MozButtonactiveface);
305 if (isHovered) {
306 return aColors.SystemNs(StyleSystemColor::MozButtonhoverface);
308 return aColors.SystemNs(StyleSystemColor::Buttonface);
309 }();
311 if (aState.HasState(ElementState::AUTOFILL)) {
312 backgroundColor = NS_ComposeColors(
313 backgroundColor,
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);
330 }();
332 if (aState.HasState(ElementState::AUTOFILL)) {
333 backgroundColor = NS_ComposeColors(
334 backgroundColor,
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);
350 bool isActive =
351 aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE);
352 bool isDisabled = aState.HasState(ElementState::DISABLED);
353 bool isHovered = aState.HasState(ElementState::HOVER);
355 if (isDisabled) {
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);
371 bool isActive =
372 aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE);
373 bool isDisabled = aState.HasState(ElementState::DISABLED);
374 bool isHovered = aState.HasState(ElementState::HOVER);
376 if (isDisabled) {
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);
392 bool isActive =
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 = [&] {
398 if (isDisabled) {
399 return sColorGrey40;
401 if (isActive) {
402 return aColors.Accent().Get();
404 if (isHovered) {
405 return sColorGrey60;
407 return sColorGrey50;
408 }();
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
477 // red">Foobar</div>
479 // But some controls might provide a negative offset to cover the border, if
480 // necessary.
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);
492 strokeWidthDevPx =
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);
502 strokeWidthDevPx =
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) {
522 borderWidth = 0.0f;
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);
554 const float scale =
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);
560 builder->MoveTo(p);
561 for (int32_t i = 1; i < checkNumPoints; i++) {
562 p = center + Point(checkPolygonX[i] * scale, checkPolygonY[i] * scale);
563 builder->LineTo(p);
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;
574 const float scale =
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,
596 aDpiRatio);
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);
633 if (!blurFilter) {
634 return;
637 blurFilter->SetAttribute(ATT_GAUSSIAN_BLUR_STD_DEVIATION, stdDev);
639 IntSize inflation =
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);
651 if (!ellipseDT) {
652 return;
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) {
679 borderWidth = 0.0f;
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));
689 rect.Deflate(width);
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,
712 radius, aDpiRatio);
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,
732 radius, aDpiRatio);
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,
750 radius, aDpiRatio);
752 if (aState.HasState(ElementState::FOCUSRING)) {
753 PaintRoundedFocusRect(aDrawTarget, aRect, aColors, aDpiRatio,
754 radius + kMenulistBorderWidth, -kMenulistBorderWidth);
758 void Theme::PaintMenulistArrowButton(nsIFrame* aFrame, DrawTarget& aDrawTarget,
759 const LayoutDeviceRect& aRect,
760 const ElementState& aState) {
761 // not const: these may be negated in-place below
762 float polygonX[] = {-4.0f, -0.5f, 0.5f, 4.0f, 4.0f,
763 3.0f, 0.0f, 0.0f, -3.0f, -4.0f};
764 float polygonY[] = {-1, 3.0f, 3.0f, -1.0f, -2.0f,
765 -2.0f, 1.5f, 1.5f, -2.0f, -2.0f};
767 const float kPolygonSize = kMinimumDropdownArrowButtonWidth;
769 auto const [xs, ys] = [&] {
770 using Pair = std::pair<const float*, const float*>;
771 switch (aFrame->GetWritingMode().GetBlockDir()) {
772 case WritingMode::BlockDir::eBlockRL:
773 // rotate 90°: [[0,1],[-1,0]]
774 for (float& f : polygonY) {
775 f = -f;
777 return Pair(polygonY, polygonX);
779 case WritingMode::BlockDir::eBlockLR:
780 // rotate 270°: [[0,-1],[1,0]]
781 for (float& f : polygonX) {
782 f = -f;
784 return Pair(polygonY, polygonX);
786 case WritingMode::BlockDir::eBlockTB:
787 // rotate 0°: [[1,0],[0,1]]
788 return Pair(polygonX, polygonY);
790 MOZ_ASSERT_UNREACHABLE("unhandled BlockDir");
791 return Pair(polygonX, polygonY);
792 }();
794 const auto arrowColor = sRGBColor::FromABGR(
795 nsLayoutUtils::GetColor(aFrame, &nsStyleText::mWebkitTextFillColor));
796 ThemeDrawing::PaintArrow(aDrawTarget, aRect, xs, ys, kPolygonSize,
797 ArrayLength(polygonX), arrowColor);
800 void Theme::PaintSpinnerButton(nsIFrame* aFrame, DrawTarget& aDrawTarget,
801 const LayoutDeviceRect& aRect,
802 const ElementState& aState,
803 StyleAppearance aAppearance,
804 const Colors& aColors, DPIRatio aDpiRatio) {
805 auto [backgroundColor, borderColor] = ComputeButtonColors(aState, aColors);
807 aDrawTarget.FillRect(aRect.ToUnknownRect(),
808 ColorPattern(ToDeviceColor(backgroundColor)));
810 const float kPolygonX[] = {-3.5f, -0.5f, 0.5f, 3.5f, 3.5f,
811 2.5f, 0.0f, 0.0f, -2.5f, -3.5f};
812 float polygonY[] = {-1.5f, 1.5f, 1.5f, -1.5f, -2.5f,
813 -2.5f, 0.0f, 0.0f, -2.5f, -2.5f};
815 const float kPolygonSize = kMinimumSpinnerButtonHeight;
816 if (aAppearance == StyleAppearance::SpinnerUpbutton) {
817 for (auto& coord : polygonY) {
818 coord = -coord;
822 ThemeDrawing::PaintArrow(aDrawTarget, aRect, kPolygonX, polygonY,
823 kPolygonSize, ArrayLength(kPolygonX), borderColor);
826 template <typename PaintBackendData>
827 void Theme::PaintRange(nsIFrame* aFrame, PaintBackendData& aPaintData,
828 const LayoutDeviceRect& aRect,
829 const ElementState& aState, const Colors& aColors,
830 DPIRatio aDpiRatio, bool aHorizontal) {
831 nsRangeFrame* rangeFrame = do_QueryFrame(aFrame);
832 if (!rangeFrame) {
833 return;
836 auto tickMarks = rangeFrame->TickMarks();
837 double progress = rangeFrame->GetValueAsFractionOfRange();
838 auto rect = aRect;
839 LayoutDeviceRect thumbRect(0, 0, kMinimumRangeThumbSize * aDpiRatio,
840 kMinimumRangeThumbSize * aDpiRatio);
841 LayoutDeviceRect progressClipRect(aRect);
842 LayoutDeviceRect trackClipRect(aRect);
843 const LayoutDeviceCoord verticalSize = kRangeHeight * aDpiRatio;
844 const LayoutDeviceCoord tickMarkWidth(
845 ThemeDrawing::SnapBorderWidth(1.0f, aDpiRatio));
846 const LayoutDeviceCoord tickMarkHeight(
847 ThemeDrawing::SnapBorderWidth(5.0f, aDpiRatio));
848 LayoutDevicePoint tickMarkOrigin, tickMarkDirection;
849 LayoutDeviceSize tickMarkSize;
850 if (aHorizontal) {
851 rect.height = verticalSize;
852 rect.y = aRect.y + (aRect.height - rect.height) / 2;
853 tickMarkSize = LayoutDeviceSize(tickMarkWidth, tickMarkHeight);
854 thumbRect.y = aRect.y + (aRect.height - thumbRect.height) / 2;
856 if (IsFrameRTL(aFrame)) {
857 tickMarkOrigin =
858 LayoutDevicePoint(aRect.XMost() - thumbRect.width / 2, aRect.YMost());
859 tickMarkDirection = LayoutDevicePoint(-1.0f, 0.0f);
860 thumbRect.x =
861 aRect.x + (aRect.width - thumbRect.width) * (1.0 - progress);
862 float midPoint = thumbRect.Center().X();
863 trackClipRect.SetBoxX(aRect.X(), midPoint);
864 progressClipRect.SetBoxX(midPoint, aRect.XMost());
865 } else {
866 tickMarkOrigin =
867 LayoutDevicePoint(aRect.x + thumbRect.width / 2, aRect.YMost());
868 tickMarkDirection = LayoutDevicePoint(1.0, 0.0f);
869 thumbRect.x = aRect.x + (aRect.width - thumbRect.width) * progress;
870 float midPoint = thumbRect.Center().X();
871 progressClipRect.SetBoxX(aRect.X(), midPoint);
872 trackClipRect.SetBoxX(midPoint, aRect.XMost());
874 } else {
875 rect.width = verticalSize;
876 rect.x = aRect.x + (aRect.width - rect.width) / 2;
877 tickMarkOrigin = LayoutDevicePoint(aRect.XMost() - tickMarkHeight / 4,
878 aRect.YMost() - thumbRect.width / 2);
879 tickMarkDirection = LayoutDevicePoint(0.0f, -1.0f);
880 tickMarkSize = LayoutDeviceSize(tickMarkHeight, tickMarkWidth);
881 thumbRect.x = aRect.x + (aRect.width - thumbRect.width) / 2;
883 thumbRect.y =
884 aRect.y + (aRect.height - thumbRect.height) * (1.0 - progress);
885 float midPoint = thumbRect.Center().Y();
886 trackClipRect.SetBoxY(aRect.Y(), midPoint);
887 progressClipRect.SetBoxY(midPoint, aRect.YMost());
890 const CSSCoord borderWidth = 1.0f;
891 const CSSCoord radius = 3.0f;
893 auto [progressColor, progressBorderColor] =
894 ComputeRangeProgressColors(aState, aColors);
895 auto [trackColor, trackBorderColor] =
896 ComputeRangeTrackColors(aState, aColors);
897 auto tickMarkColor = trackBorderColor;
899 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, rect, progressClipRect,
900 progressColor, progressBorderColor,
901 borderWidth, radius, aDpiRatio);
903 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, rect, trackClipRect,
904 trackColor, trackBorderColor,
905 borderWidth, radius, aDpiRatio);
907 if (!aState.HasState(ElementState::DISABLED)) {
908 // Ensure the shadow doesn't expand outside of our overflow rect declared in
909 // GetWidgetOverflow().
910 auto overflowRect = aRect;
911 overflowRect.Inflate(CSSCoord(6.0f) * aDpiRatio);
912 // Thumb shadow
913 PaintCircleShadow(aPaintData, thumbRect, overflowRect, 0.3f,
914 CSSPoint(0.0f, 2.0f), 2.0f, aDpiRatio);
917 tickMarkDirection.x *= aRect.width - thumbRect.width;
918 tickMarkDirection.y *= aRect.height - thumbRect.height;
919 tickMarkOrigin -=
920 LayoutDevicePoint(tickMarkSize.width, tickMarkSize.height) / 2;
921 auto tickMarkRect = LayoutDeviceRect(tickMarkOrigin, tickMarkSize);
922 for (auto tickMark : tickMarks) {
923 auto tickMarkOffset =
924 tickMarkDirection *
925 float(rangeFrame->GetDoubleAsFractionOfRange(tickMark));
926 ThemeDrawing::FillRect(aPaintData, tickMarkRect + tickMarkOffset,
927 tickMarkColor);
930 // Draw the thumb on top.
931 const CSSCoord thumbBorderWidth = 2.0f;
932 auto [thumbColor, thumbBorderColor] =
933 ComputeRangeThumbColors(aState, aColors);
935 PaintStrokedCircle(aPaintData, thumbRect, thumbColor, thumbBorderColor,
936 thumbBorderWidth, aDpiRatio);
938 if (aState.HasState(ElementState::FOCUSRING)) {
939 PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio, radius, 1.0f);
943 template <typename PaintBackendData>
944 void Theme::PaintProgress(nsIFrame* aFrame, PaintBackendData& aPaintData,
945 const LayoutDeviceRect& aRect,
946 const ElementState& aState, const Colors& aColors,
947 DPIRatio aDpiRatio, bool aIsMeter) {
948 const CSSCoord borderWidth = 1.0f;
949 const CSSCoord radius = aIsMeter ? 6.0f : 3.0f;
951 LayoutDeviceRect rect(aRect);
952 const LayoutDeviceCoord thickness =
953 (aIsMeter ? kMeterHeight : kProgressbarHeight) * aDpiRatio;
955 const bool isHorizontal = !nsNativeTheme::IsVerticalProgress(aFrame);
956 if (isHorizontal) {
957 // Center it vertically.
958 rect.y += (rect.height - thickness) / 2;
959 rect.height = thickness;
960 } else {
961 // Center it horizontally.
962 rect.x += (rect.width - thickness) / 2;
963 rect.width = thickness;
967 // Paint the track, unclipped.
968 auto [backgroundColor, borderColor] = ComputeProgressTrackColors(aColors);
969 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, rect, rect,
970 backgroundColor, borderColor,
971 borderWidth, radius, aDpiRatio);
974 // Now paint the chunk, clipped as needed.
975 LayoutDeviceRect clipRect = rect;
976 if (aState.HasState(ElementState::INDETERMINATE)) {
977 // For indeterminate progress, we paint an animated chunk of 1/3 of the
978 // progress size.
980 // Animation speed and math borrowed from GTK.
981 const LayoutDeviceCoord size = isHorizontal ? rect.width : rect.height;
982 const LayoutDeviceCoord barSize = size * 0.3333f;
983 const LayoutDeviceCoord travel = 2.0f * (size - barSize);
985 // Period equals to travel / pixelsPerMillisecond where pixelsPerMillisecond
986 // equals progressSize / 1000.0. This is equivalent to 1600.
987 const unsigned kPeriod = 1600;
989 const int t = PR_IntervalToMilliseconds(PR_IntervalNow()) % kPeriod;
990 const LayoutDeviceCoord dx = travel * float(t) / float(kPeriod);
991 if (isHorizontal) {
992 rect.width = barSize;
993 rect.x += (dx < travel * .5f) ? dx : travel - dx;
994 } else {
995 rect.height = barSize;
996 rect.y += (dx < travel * .5f) ? dx : travel - dx;
998 clipRect = rect;
999 // Queue the next frame if needed.
1000 if (!QueueAnimatedContentForRefresh(aFrame->GetContent(), 60)) {
1001 NS_WARNING("Couldn't refresh indeterminate <progress>");
1003 } else {
1004 // This is the progress chunk, clip it to the right amount.
1005 double position = [&] {
1006 if (aIsMeter) {
1007 auto* meter = dom::HTMLMeterElement::FromNode(aFrame->GetContent());
1008 if (!meter) {
1009 return 0.0;
1011 return meter->Position();
1013 auto* progress = dom::HTMLProgressElement::FromNode(aFrame->GetContent());
1014 if (!progress) {
1015 return 0.0;
1017 return progress->Position();
1018 }();
1019 if (isHorizontal) {
1020 double clipWidth = rect.width * position;
1021 clipRect.width = clipWidth;
1022 if (IsFrameRTL(aFrame)) {
1023 clipRect.x += rect.width - clipWidth;
1025 } else {
1026 double clipHeight = rect.height * position;
1027 clipRect.height = clipHeight;
1028 clipRect.y += rect.height - clipHeight;
1032 auto [backgroundColor, borderColor] =
1033 aIsMeter ? ComputeMeterchunkColors(aState, aColors)
1034 : ComputeProgressColors(aColors);
1035 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, rect, clipRect,
1036 backgroundColor, borderColor,
1037 borderWidth, radius, aDpiRatio);
1040 template <typename PaintBackendData>
1041 void Theme::PaintButton(nsIFrame* aFrame, PaintBackendData& aPaintData,
1042 const LayoutDeviceRect& aRect,
1043 const ElementState& aState, const Colors& aColors,
1044 DPIRatio aDpiRatio) {
1045 const CSSCoord radius = 4.0f;
1046 auto [backgroundColor, borderColor] =
1047 ComputeButtonColors(aState, aColors, aFrame);
1049 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, aRect, backgroundColor,
1050 borderColor, kButtonBorderWidth,
1051 radius, aDpiRatio);
1053 if (aState.HasState(ElementState::FOCUSRING)) {
1054 PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio,
1055 radius + kButtonBorderWidth, -kButtonBorderWidth);
1059 NS_IMETHODIMP
1060 Theme::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
1061 StyleAppearance aAppearance, const nsRect& aRect,
1062 const nsRect& /* aDirtyRect */,
1063 DrawOverflow aDrawOverflow) {
1064 if (!DoDrawWidgetBackground(*aContext->GetDrawTarget(), aFrame, aAppearance,
1065 aRect, aDrawOverflow)) {
1066 return NS_ERROR_NOT_IMPLEMENTED;
1068 return NS_OK;
1071 bool Theme::CreateWebRenderCommandsForWidget(
1072 mozilla::wr::DisplayListBuilder& aBuilder,
1073 mozilla::wr::IpcResourceUpdateQueue& aResources,
1074 const mozilla::layers::StackingContextHelper& aSc,
1075 mozilla::layers::RenderRootStateManager* aManager, nsIFrame* aFrame,
1076 StyleAppearance aAppearance, const nsRect& aRect) {
1077 if (!StaticPrefs::widget_non_native_theme_webrender()) {
1078 return false;
1080 WebRenderBackendData data{aBuilder, aResources, aSc, aManager};
1081 return DoDrawWidgetBackground(data, aFrame, aAppearance, aRect,
1082 DrawOverflow::Yes);
1085 static LayoutDeviceRect ToSnappedRect(const nsRect& aRect,
1086 nscoord aTwipsPerPixel, DrawTarget& aDt) {
1087 return LayoutDeviceRect::FromUnknownRect(
1088 NSRectToSnappedRect(aRect, aTwipsPerPixel, aDt));
1091 static LayoutDeviceRect ToSnappedRect(const nsRect& aRect,
1092 nscoord aTwipsPerPixel,
1093 WebRenderBackendData& aDt) {
1094 // TODO: Do we need to do any more snapping here?
1095 return LayoutDeviceRect::FromAppUnits(aRect, aTwipsPerPixel);
1098 static ScrollbarDrawing::ScrollbarKind ComputeScrollbarKind(
1099 nsIFrame* aFrame, bool aIsHorizontal) {
1100 if (aIsHorizontal) {
1101 return ScrollbarDrawing::ScrollbarKind::Horizontal;
1103 nsIFrame* scrollbar = ScrollbarDrawing::GetParentScrollbarFrame(aFrame);
1104 if (NS_WARN_IF(!scrollbar)) {
1105 return ScrollbarDrawing::ScrollbarKind::VerticalRight;
1107 MOZ_ASSERT(scrollbar->IsScrollbarFrame());
1108 nsIScrollbarMediator* sm =
1109 static_cast<nsScrollbarFrame*>(scrollbar)->GetScrollbarMediator();
1110 if (NS_WARN_IF(!sm)) {
1111 return ScrollbarDrawing::ScrollbarKind::VerticalRight;
1113 return sm->IsScrollbarOnRight()
1114 ? ScrollbarDrawing::ScrollbarKind::VerticalRight
1115 : ScrollbarDrawing::ScrollbarKind::VerticalLeft;
1118 static ScrollbarDrawing::ScrollbarKind ComputeScrollbarKindForScrollCorner(
1119 nsIFrame* aFrame) {
1120 nsIScrollableFrame* sf = do_QueryFrame(aFrame->GetParent());
1121 if (!sf) {
1122 return ScrollbarDrawing::ScrollbarKind::VerticalRight;
1124 return sf->IsScrollbarOnRight()
1125 ? ScrollbarDrawing::ScrollbarKind::VerticalRight
1126 : ScrollbarDrawing::ScrollbarKind::VerticalLeft;
1129 template <typename PaintBackendData>
1130 bool Theme::DoDrawWidgetBackground(PaintBackendData& aPaintData,
1131 nsIFrame* aFrame,
1132 StyleAppearance aAppearance,
1133 const nsRect& aRect,
1134 DrawOverflow aDrawOverflow) {
1135 static_assert(std::is_same_v<PaintBackendData, DrawTarget> ||
1136 std::is_same_v<PaintBackendData, WebRenderBackendData>);
1138 const nsPresContext* pc = aFrame->PresContext();
1139 const nscoord twipsPerPixel = pc->AppUnitsPerDevPixel();
1140 const auto devPxRect = ToSnappedRect(aRect, twipsPerPixel, aPaintData);
1142 const DocumentState docState = pc->Document()->GetDocumentState();
1143 ElementState elementState = GetContentState(aFrame, aAppearance);
1144 if (aAppearance == StyleAppearance::MozMenulistArrowButton) {
1145 // HTML select and XUL menulist dropdown buttons get state from the
1146 // parent.
1147 nsIFrame* parentFrame = aFrame->GetParent();
1148 aFrame = parentFrame;
1149 elementState = GetContentState(parentFrame, aAppearance);
1152 // Paint the outline iff we're asked to draw overflow and we have
1153 // outline-style: auto.
1154 if (aDrawOverflow == DrawOverflow::Yes &&
1155 aFrame->StyleOutline()->mOutlineStyle.IsAuto()) {
1156 elementState |= ElementState::FOCUSRING;
1157 } else {
1158 elementState &= ~ElementState::FOCUSRING;
1161 // Hack to avoid skia fuzziness: Add a dummy clip if the widget doesn't
1162 // overflow devPxRect.
1163 Maybe<AutoClipRect> maybeClipRect;
1164 if constexpr (std::is_same_v<PaintBackendData, DrawTarget>) {
1165 if (aAppearance != StyleAppearance::FocusOutline &&
1166 aAppearance != StyleAppearance::Range &&
1167 !elementState.HasState(ElementState::FOCUSRING)) {
1168 maybeClipRect.emplace(aPaintData, devPxRect);
1172 const Colors colors(aFrame, aAppearance);
1173 DPIRatio dpiRatio = GetDPIRatio(aFrame, aAppearance);
1175 switch (aAppearance) {
1176 case StyleAppearance::Radio: {
1177 auto rect = CheckBoxRadioRect(devPxRect);
1178 PaintRadioControl(aPaintData, rect, elementState, colors, dpiRatio);
1179 break;
1181 case StyleAppearance::Checkbox: {
1182 if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
1183 // TODO: Need to figure out how to best draw this using WR.
1184 return false;
1185 } else {
1186 auto rect = CheckBoxRadioRect(devPxRect);
1187 PaintCheckboxControl(aPaintData, rect, elementState, colors, dpiRatio);
1189 break;
1191 case StyleAppearance::Textarea:
1192 case StyleAppearance::Textfield:
1193 case StyleAppearance::NumberInput:
1194 PaintTextField(aPaintData, devPxRect, elementState, colors, dpiRatio);
1195 break;
1196 case StyleAppearance::Listbox:
1197 PaintListbox(aPaintData, devPxRect, elementState, colors, dpiRatio);
1198 break;
1199 case StyleAppearance::MenulistButton:
1200 case StyleAppearance::Menulist:
1201 PaintMenulist(aPaintData, devPxRect, elementState, colors, dpiRatio);
1202 break;
1203 case StyleAppearance::MozMenulistArrowButton:
1204 if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
1205 // TODO: Need to figure out how to best draw this using WR.
1206 return false;
1207 } else {
1208 PaintMenulistArrowButton(aFrame, aPaintData, devPxRect, elementState);
1210 break;
1211 case StyleAppearance::Tooltip: {
1212 const CSSCoord strokeWidth(1.0f);
1213 const CSSCoord strokeRadius(2.0f);
1214 ThemeDrawing::PaintRoundedRectWithRadius(
1215 aPaintData, devPxRect,
1216 colors.System(StyleSystemColor::Infobackground),
1217 colors.System(StyleSystemColor::Infotext), strokeWidth, strokeRadius,
1218 dpiRatio);
1219 break;
1221 case StyleAppearance::Menuitem: {
1222 ThemeDrawing::FillRect(aPaintData, devPxRect, [&] {
1223 if (CheckBooleanAttr(aFrame, nsGkAtoms::menuactive)) {
1224 if (elementState.HasState(ElementState::DISABLED)) {
1225 return colors.System(StyleSystemColor::MozMenuhoverdisabled);
1227 return colors.System(StyleSystemColor::MozMenuhover);
1229 return sTransparent;
1230 }());
1231 break;
1233 case StyleAppearance::SpinnerUpbutton:
1234 case StyleAppearance::SpinnerDownbutton:
1235 if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
1236 // TODO: Need to figure out how to best draw this using WR.
1237 return false;
1238 } else {
1239 PaintSpinnerButton(aFrame, aPaintData, devPxRect, elementState,
1240 aAppearance, colors, dpiRatio);
1242 break;
1243 case StyleAppearance::Range:
1244 PaintRange(aFrame, aPaintData, devPxRect, elementState, colors, dpiRatio,
1245 IsRangeHorizontal(aFrame));
1246 break;
1247 case StyleAppearance::RangeThumb:
1248 // Painted as part of StyleAppearance::Range.
1249 break;
1250 case StyleAppearance::ProgressBar:
1251 PaintProgress(aFrame, aPaintData, devPxRect, elementState, colors,
1252 dpiRatio,
1253 /* aIsMeter = */ false);
1254 break;
1255 case StyleAppearance::Progresschunk:
1256 /* Painted as part of the progress bar */
1257 break;
1258 case StyleAppearance::Meter:
1259 PaintProgress(aFrame, aPaintData, devPxRect, elementState, colors,
1260 dpiRatio,
1261 /* aIsMeter = */ true);
1262 break;
1263 case StyleAppearance::Meterchunk:
1264 /* Painted as part of the meter bar */
1265 break;
1266 case StyleAppearance::ScrollbarthumbHorizontal:
1267 case StyleAppearance::ScrollbarthumbVertical: {
1268 bool isHorizontal =
1269 aAppearance == StyleAppearance::ScrollbarthumbHorizontal;
1270 auto kind = ComputeScrollbarKind(aFrame, isHorizontal);
1271 return GetScrollbarDrawing().PaintScrollbarThumb(
1272 aPaintData, devPxRect, kind, aFrame,
1273 *nsLayoutUtils::StyleForScrollbar(aFrame), elementState, docState,
1274 colors, dpiRatio);
1276 case StyleAppearance::ScrollbartrackHorizontal:
1277 case StyleAppearance::ScrollbartrackVertical: {
1278 bool isHorizontal =
1279 aAppearance == StyleAppearance::ScrollbartrackHorizontal;
1280 auto kind = ComputeScrollbarKind(aFrame, isHorizontal);
1281 return GetScrollbarDrawing().PaintScrollbarTrack(
1282 aPaintData, devPxRect, kind, aFrame,
1283 *nsLayoutUtils::StyleForScrollbar(aFrame), docState, colors,
1284 dpiRatio);
1286 case StyleAppearance::ScrollbarHorizontal:
1287 case StyleAppearance::ScrollbarVertical: {
1288 bool isHorizontal = aAppearance == StyleAppearance::ScrollbarHorizontal;
1289 auto kind = ComputeScrollbarKind(aFrame, isHorizontal);
1290 return GetScrollbarDrawing().PaintScrollbar(
1291 aPaintData, devPxRect, kind, aFrame,
1292 *nsLayoutUtils::StyleForScrollbar(aFrame), elementState, docState,
1293 colors, dpiRatio);
1295 case StyleAppearance::Scrollcorner: {
1296 auto kind = ComputeScrollbarKindForScrollCorner(aFrame);
1297 return GetScrollbarDrawing().PaintScrollCorner(
1298 aPaintData, devPxRect, kind, aFrame,
1299 *nsLayoutUtils::StyleForScrollbar(aFrame), docState, colors,
1300 dpiRatio);
1302 case StyleAppearance::ScrollbarbuttonUp:
1303 case StyleAppearance::ScrollbarbuttonDown:
1304 case StyleAppearance::ScrollbarbuttonLeft:
1305 case StyleAppearance::ScrollbarbuttonRight: {
1306 // For scrollbar-width:thin, we don't display the buttons.
1307 if (!ScrollbarDrawing::IsScrollbarWidthThin(aFrame)) {
1308 if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
1309 // TODO: Need to figure out how to best draw this using WR.
1310 return false;
1311 } else {
1312 bool isHorizontal =
1313 aAppearance == StyleAppearance::ScrollbarbuttonLeft ||
1314 aAppearance == StyleAppearance::ScrollbarbuttonRight;
1315 auto kind = ComputeScrollbarKind(aFrame, isHorizontal);
1316 GetScrollbarDrawing().PaintScrollbarButton(
1317 aPaintData, aAppearance, devPxRect, kind, aFrame,
1318 *nsLayoutUtils::StyleForScrollbar(aFrame), elementState, docState,
1319 colors, dpiRatio);
1322 break;
1324 case StyleAppearance::Button:
1325 PaintButton(aFrame, aPaintData, devPxRect, elementState, colors,
1326 dpiRatio);
1327 break;
1328 case StyleAppearance::FocusOutline:
1329 PaintAutoStyleOutline(aFrame, aPaintData, devPxRect, colors, dpiRatio);
1330 break;
1331 default:
1332 // Various appearance values are used for XUL elements. Normally these
1333 // will not be available in content documents (and thus in the content
1334 // processes where the native basic theme can be used), but tests are
1335 // run with the remote XUL pref enabled and so we can get in here. So
1336 // we just return an error rather than assert.
1337 return false;
1340 return true;
1343 template <typename PaintBackendData>
1344 void Theme::PaintAutoStyleOutline(nsIFrame* aFrame,
1345 PaintBackendData& aPaintData,
1346 const LayoutDeviceRect& aRect,
1347 const Colors& aColors, DPIRatio aDpiRatio) {
1348 const auto& accentColor = aColors.Accent();
1349 const bool solid = StaticPrefs::widget_non_native_theme_solid_outline_style();
1350 LayoutDeviceCoord strokeWidth(ThemeDrawing::SnapBorderWidth(2.0f, aDpiRatio));
1352 LayoutDeviceRect rect(aRect);
1353 rect.Inflate(strokeWidth);
1355 const nscoord a2d = aFrame->PresContext()->AppUnitsPerDevPixel();
1356 nscoord cssOffset = aFrame->StyleOutline()->mOutlineOffset.ToAppUnits();
1357 nscoord cssRadii[8] = {0};
1358 if (!aFrame->GetBorderRadii(cssRadii)) {
1359 const auto twoPixels = 2 * AppUnitsPerCSSPixel();
1360 const nscoord radius =
1361 cssOffset >= 0 ? twoPixels : std::max(twoPixels + cssOffset, 0);
1362 cssOffset = -twoPixels;
1363 for (auto& r : cssRadii) {
1364 r = radius;
1368 auto offset = LayoutDevicePixel::FromAppUnits(cssOffset, a2d);
1369 RectCornerRadii innerRadii;
1370 nsCSSRendering::ComputePixelRadii(cssRadii, a2d, &innerRadii);
1372 // NOTE(emilio): This doesn't use PaintRoundedRectWithRadius because we need
1373 // to support arbitrary radii.
1374 auto DrawRect = [&](const sRGBColor& aColor) {
1375 RectCornerRadii outerRadii;
1376 if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
1377 const Float widths[4] = {strokeWidth + offset, strokeWidth + offset,
1378 strokeWidth + offset, strokeWidth + offset};
1379 nsCSSBorderRenderer::ComputeOuterRadii(innerRadii, widths, &outerRadii);
1380 const auto dest = wr::ToLayoutRect(rect);
1381 const auto side =
1382 wr::ToBorderSide(ToDeviceColor(aColor), StyleBorderStyle::Solid);
1383 const wr::BorderSide sides[4] = {side, side, side, side};
1384 const bool kBackfaceIsVisible = true;
1385 const auto wrWidths = wr::ToBorderWidths(strokeWidth, strokeWidth,
1386 strokeWidth, strokeWidth);
1387 const auto wrRadius = wr::ToBorderRadius(outerRadii);
1388 aPaintData.mBuilder.PushBorder(dest, dest, kBackfaceIsVisible, wrWidths,
1389 {sides, 4}, wrRadius);
1390 } else {
1391 const LayoutDeviceCoord halfWidth = strokeWidth * 0.5f;
1392 const Float widths[4] = {halfWidth + offset, halfWidth + offset,
1393 halfWidth + offset, halfWidth + offset};
1394 nsCSSBorderRenderer::ComputeOuterRadii(innerRadii, widths, &outerRadii);
1395 LayoutDeviceRect dest(rect);
1396 dest.Deflate(halfWidth);
1397 RefPtr<Path> path =
1398 MakePathForRoundedRect(aPaintData, dest.ToUnknownRect(), outerRadii);
1399 aPaintData.Stroke(path, ColorPattern(ToDeviceColor(aColor)),
1400 StrokeOptions(strokeWidth));
1404 DrawRect(accentColor.Get());
1406 if (solid) {
1407 return;
1410 offset += strokeWidth;
1412 strokeWidth =
1413 LayoutDeviceCoord(ThemeDrawing::SnapBorderWidth(1.0f, aDpiRatio));
1414 rect.Inflate(strokeWidth);
1416 DrawRect(accentColor.GetForeground());
1419 LayoutDeviceIntMargin Theme::GetWidgetBorder(nsDeviceContext* aContext,
1420 nsIFrame* aFrame,
1421 StyleAppearance aAppearance) {
1422 switch (aAppearance) {
1423 case StyleAppearance::Textfield:
1424 case StyleAppearance::Textarea:
1425 case StyleAppearance::NumberInput:
1426 case StyleAppearance::Listbox:
1427 case StyleAppearance::Menulist:
1428 case StyleAppearance::MenulistButton:
1429 case StyleAppearance::Button:
1430 // Return the border size from the UA sheet, even though what we paint
1431 // doesn't actually match that. We know this is the UA sheet border
1432 // because we disable native theming when different border widths are
1433 // specified by authors, see Theme::IsWidgetStyled.
1435 // The Rounded() bit is technically redundant, but needed to appease the
1436 // type system, we should always end up with full device pixels due to
1437 // round_border_to_device_pixels at style time.
1438 return LayoutDeviceIntMargin::FromAppUnits(
1439 aFrame->StyleBorder()->GetComputedBorder(),
1440 aFrame->PresContext()->AppUnitsPerDevPixel())
1441 .Rounded();
1442 case StyleAppearance::Checkbox:
1443 case StyleAppearance::Radio: {
1444 DPIRatio dpiRatio = GetDPIRatio(aFrame, aAppearance);
1445 LayoutDeviceIntCoord w =
1446 ThemeDrawing::SnapBorderWidth(kCheckboxRadioBorderWidth, dpiRatio);
1447 return LayoutDeviceIntMargin(w, w, w, w);
1449 default:
1450 return LayoutDeviceIntMargin();
1454 bool Theme::GetWidgetPadding(nsDeviceContext* aContext, nsIFrame* aFrame,
1455 StyleAppearance aAppearance,
1456 LayoutDeviceIntMargin* aResult) {
1457 switch (aAppearance) {
1458 // Radios and checkboxes return a fixed size in GetMinimumWidgetSize
1459 // and have a meaningful baseline, so they can't have
1460 // author-specified padding.
1461 case StyleAppearance::Radio:
1462 case StyleAppearance::Checkbox:
1463 aResult->SizeTo(0, 0, 0, 0);
1464 return true;
1465 default:
1466 break;
1468 return false;
1471 bool Theme::GetWidgetOverflow(nsDeviceContext* aContext, nsIFrame* aFrame,
1472 StyleAppearance aAppearance,
1473 nsRect* aOverflowRect) {
1474 CSSIntMargin overflow;
1475 switch (aAppearance) {
1476 case StyleAppearance::FocusOutline: {
1477 // 2px * one segment, or 2px + 1px
1478 const auto width =
1479 StaticPrefs::widget_non_native_theme_solid_outline_style() ? 2 : 3;
1480 overflow.SizeTo(width, width, width, width);
1481 break;
1483 case StyleAppearance::Radio:
1484 case StyleAppearance::Checkbox:
1485 case StyleAppearance::Range:
1486 // 2px for each outline segment, plus 1px separation, plus we paint with a
1487 // 1px extra offset, so 6px.
1488 overflow.SizeTo(6, 6, 6, 6);
1489 break;
1490 case StyleAppearance::Textarea:
1491 case StyleAppearance::Textfield:
1492 case StyleAppearance::NumberInput:
1493 case StyleAppearance::Listbox:
1494 case StyleAppearance::MenulistButton:
1495 case StyleAppearance::Menulist:
1496 case StyleAppearance::Button:
1497 // 2px for each segment, plus 1px separation, but we paint 1px inside
1498 // the border area so 4px overflow.
1499 overflow.SizeTo(4, 4, 4, 4);
1500 break;
1501 default:
1502 return false;
1505 // TODO: This should convert from device pixels to app units, not from CSS
1506 // pixels. And it should take the dpi ratio into account.
1507 // Using CSS pixels can cause the overflow to be too small if the page is
1508 // zoomed out.
1509 aOverflowRect->Inflate(CSSPixel::ToAppUnits(overflow));
1510 return true;
1513 LayoutDeviceIntCoord Theme::GetScrollbarSize(const nsPresContext* aPresContext,
1514 StyleScrollbarWidth aWidth,
1515 Overlay aOverlay) {
1516 return GetScrollbarDrawing().GetScrollbarSize(aPresContext, aWidth, aOverlay);
1519 nscoord Theme::GetCheckboxRadioPrefSize() {
1520 return CSSPixel::ToAppUnits(kCheckboxRadioContentBoxSize);
1523 /* static */
1524 UniquePtr<ScrollbarDrawing> Theme::ScrollbarStyle() {
1525 switch (StaticPrefs::widget_non_native_theme_scrollbar_style()) {
1526 case 1:
1527 return MakeUnique<ScrollbarDrawingCocoa>();
1528 case 2:
1529 return MakeUnique<ScrollbarDrawingGTK>();
1530 case 3:
1531 return MakeUnique<ScrollbarDrawingAndroid>();
1532 case 4:
1533 return MakeUnique<ScrollbarDrawingWin>();
1534 case 5:
1535 return MakeUnique<ScrollbarDrawingWin11>();
1536 default:
1537 break;
1539 // Default to native scrollbar style for each platform.
1540 #ifdef XP_WIN
1541 if (IsWin11OrLater()) {
1542 return MakeUnique<ScrollbarDrawingWin11>();
1544 return MakeUnique<ScrollbarDrawingWin>();
1545 #elif MOZ_WIDGET_COCOA
1546 return MakeUnique<ScrollbarDrawingCocoa>();
1547 #elif MOZ_WIDGET_GTK
1548 return MakeUnique<ScrollbarDrawingGTK>();
1549 #elif ANDROID
1550 return MakeUnique<ScrollbarDrawingAndroid>();
1551 #else
1552 # error "Unknown platform, need scrollbar implementation."
1553 #endif
1556 LayoutDeviceIntSize Theme::GetMinimumWidgetSize(nsPresContext* aPresContext,
1557 nsIFrame* aFrame,
1558 StyleAppearance aAppearance) {
1559 DPIRatio dpiRatio = GetDPIRatio(aFrame, aAppearance);
1561 if (IsWidgetScrollbarPart(aAppearance)) {
1562 return GetScrollbarDrawing().GetMinimumWidgetSize(aPresContext, aAppearance,
1563 aFrame);
1566 LayoutDeviceIntSize result;
1567 switch (aAppearance) {
1568 case StyleAppearance::RangeThumb:
1569 result.SizeTo((kMinimumRangeThumbSize * dpiRatio).Rounded(),
1570 (kMinimumRangeThumbSize * dpiRatio).Rounded());
1571 break;
1572 case StyleAppearance::MozMenulistArrowButton:
1573 result.width = (kMinimumDropdownArrowButtonWidth * dpiRatio).Rounded();
1574 break;
1575 case StyleAppearance::SpinnerUpbutton:
1576 case StyleAppearance::SpinnerDownbutton:
1577 result.width = (kMinimumSpinnerButtonWidth * dpiRatio).Rounded();
1578 result.height = (kMinimumSpinnerButtonHeight * dpiRatio).Rounded();
1579 break;
1580 default:
1581 break;
1583 return result;
1586 nsITheme::Transparency Theme::GetWidgetTransparency(
1587 nsIFrame* aFrame, StyleAppearance aAppearance) {
1588 if (auto scrollbar = GetScrollbarDrawing().GetScrollbarPartTransparency(
1589 aFrame, aAppearance)) {
1590 return *scrollbar;
1592 if (aAppearance == StyleAppearance::Tooltip) {
1593 // We draw a rounded rect, so we need transparency.
1594 return eTransparent;
1596 return eUnknownTransparency;
1599 NS_IMETHODIMP
1600 Theme::WidgetStateChanged(nsIFrame* aFrame, StyleAppearance aAppearance,
1601 nsAtom* aAttribute, bool* aShouldRepaint,
1602 const nsAttrValue* aOldValue) {
1603 if (!aAttribute) {
1604 // Hover/focus/active changed. Always repaint.
1605 *aShouldRepaint = true;
1606 } else {
1607 // Check the attribute to see if it's relevant.
1608 // disabled, checked, dlgtype, default, etc.
1609 *aShouldRepaint = false;
1610 if (aAttribute == nsGkAtoms::disabled || aAttribute == nsGkAtoms::checked ||
1611 aAttribute == nsGkAtoms::selected ||
1612 aAttribute == nsGkAtoms::visuallyselected ||
1613 aAttribute == nsGkAtoms::menuactive ||
1614 aAttribute == nsGkAtoms::sortDirection ||
1615 aAttribute == nsGkAtoms::focused || aAttribute == nsGkAtoms::_default ||
1616 aAttribute == nsGkAtoms::open || aAttribute == nsGkAtoms::hover) {
1617 *aShouldRepaint = true;
1621 return NS_OK;
1624 NS_IMETHODIMP
1625 Theme::ThemeChanged() { return NS_OK; }
1627 bool Theme::WidgetAppearanceDependsOnWindowFocus(StyleAppearance aAppearance) {
1628 return IsWidgetScrollbarPart(aAppearance);
1631 nsITheme::ThemeGeometryType Theme::ThemeGeometryTypeForWidget(
1632 nsIFrame* aFrame, StyleAppearance aAppearance) {
1633 return eThemeGeometryTypeUnknown;
1636 bool Theme::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFrame,
1637 StyleAppearance aAppearance) {
1638 switch (aAppearance) {
1639 case StyleAppearance::Radio:
1640 case StyleAppearance::Checkbox:
1641 case StyleAppearance::FocusOutline:
1642 case StyleAppearance::Textarea:
1643 case StyleAppearance::Textfield:
1644 case StyleAppearance::Range:
1645 case StyleAppearance::RangeThumb:
1646 case StyleAppearance::ProgressBar:
1647 case StyleAppearance::Progresschunk:
1648 case StyleAppearance::Meter:
1649 case StyleAppearance::Meterchunk:
1650 case StyleAppearance::ScrollbarbuttonUp:
1651 case StyleAppearance::ScrollbarbuttonDown:
1652 case StyleAppearance::ScrollbarbuttonLeft:
1653 case StyleAppearance::ScrollbarbuttonRight:
1654 case StyleAppearance::ScrollbarthumbHorizontal:
1655 case StyleAppearance::ScrollbarthumbVertical:
1656 case StyleAppearance::ScrollbartrackHorizontal:
1657 case StyleAppearance::ScrollbartrackVertical:
1658 case StyleAppearance::ScrollbarHorizontal:
1659 case StyleAppearance::ScrollbarVertical:
1660 case StyleAppearance::Scrollcorner:
1661 case StyleAppearance::Button:
1662 case StyleAppearance::Listbox:
1663 case StyleAppearance::Menulist:
1664 case StyleAppearance::MenulistButton:
1665 case StyleAppearance::NumberInput:
1666 case StyleAppearance::MozMenulistArrowButton:
1667 case StyleAppearance::SpinnerUpbutton:
1668 case StyleAppearance::SpinnerDownbutton:
1669 case StyleAppearance::Menuitem:
1670 case StyleAppearance::Tooltip:
1671 return !IsWidgetStyled(aPresContext, aFrame, aAppearance);
1672 default:
1673 return false;
1677 bool Theme::WidgetIsContainer(StyleAppearance aAppearance) {
1678 switch (aAppearance) {
1679 case StyleAppearance::MozMenulistArrowButton:
1680 case StyleAppearance::Radio:
1681 case StyleAppearance::Checkbox:
1682 return false;
1683 default:
1684 return true;
1688 bool Theme::ThemeDrawsFocusForWidget(nsIFrame*, StyleAppearance) {
1689 return true;
1692 bool Theme::ThemeNeedsComboboxDropmarker() { return true; }
1694 bool Theme::ThemeSupportsScrollbarButtons() {
1695 return GetScrollbarDrawing().ShouldDrawScrollbarButtons();
1698 } // namespace mozilla::widget