1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_widget_ScrollbarDrawing_h
8 #define mozilla_widget_ScrollbarDrawing_h
10 #include "mozilla/dom/RustTypes.h"
11 #include "mozilla/gfx/2D.h"
14 #include "ThemeColors.h"
15 #include "ThemeDrawing.h"
18 namespace mozilla::widget
{
20 class ScrollbarDrawing
{
22 using DPIRatio
= mozilla::CSSToLayoutDeviceScale
;
23 using ElementState
= dom::ElementState
;
24 using DocumentState
= dom::DocumentState
;
25 using DrawTarget
= mozilla::gfx::DrawTarget
;
26 using sRGBColor
= mozilla::gfx::sRGBColor
;
27 using Colors
= ThemeColors
;
28 using Overlay
= nsITheme::Overlay
;
29 using WebRenderBackendData
= mozilla::widget::WebRenderBackendData
;
31 enum class Kind
: uint8_t {
39 explicit ScrollbarDrawing(Kind aKind
) : mKind(aKind
) {}
42 virtual ~ScrollbarDrawing() = default;
44 enum class ScrollbarKind
: uint8_t {
50 DPIRatio
GetDPIRatioForScrollbarPart(const nsPresContext
*);
52 static nsIFrame
* GetParentScrollbarFrame(nsIFrame
* aFrame
);
53 static bool IsParentScrollbarRolledOver(nsIFrame
* aFrame
);
54 static bool IsParentScrollbarHoveredOrActive(nsIFrame
* aFrame
);
56 static bool IsScrollbarWidthThin(const ComputedStyle
& aStyle
);
57 static bool IsScrollbarWidthThin(nsIFrame
* aFrame
);
59 CSSIntCoord
GetCSSScrollbarSize(StyleScrollbarWidth
, Overlay
) const;
60 LayoutDeviceIntCoord
GetScrollbarSize(const nsPresContext
*,
61 StyleScrollbarWidth
, Overlay
);
62 LayoutDeviceIntCoord
GetScrollbarSize(const nsPresContext
*, nsIFrame
*);
64 virtual LayoutDeviceIntSize
GetMinimumWidgetSize(nsPresContext
*,
65 StyleAppearance aAppearance
,
66 nsIFrame
* aFrame
) = 0;
67 virtual Maybe
<nsITheme::Transparency
> GetScrollbarPartTransparency(
68 nsIFrame
* aFrame
, StyleAppearance aAppearance
) {
72 bool IsScrollbarTrackOpaque(nsIFrame
*);
73 virtual sRGBColor
ComputeScrollbarTrackColor(nsIFrame
*, const ComputedStyle
&,
76 virtual sRGBColor
ComputeScrollbarThumbColor(nsIFrame
*, const ComputedStyle
&,
81 nscolor
GetScrollbarButtonColor(nscolor aTrackColor
, ElementState
);
82 Maybe
<nscolor
> GetScrollbarArrowColor(nscolor aButtonColor
);
84 // Returned colors are button, arrow.
85 virtual std::pair
<sRGBColor
, sRGBColor
> ComputeScrollbarButtonColors(
86 nsIFrame
*, StyleAppearance
, const ComputedStyle
&, const ElementState
&,
87 const DocumentState
&, const Colors
&);
89 virtual bool PaintScrollbarButton(DrawTarget
&, StyleAppearance
,
90 const LayoutDeviceRect
&, ScrollbarKind
,
91 nsIFrame
*, const ComputedStyle
&,
92 const ElementState
&, const DocumentState
&,
93 const Colors
&, const DPIRatio
&);
95 virtual bool PaintScrollbarThumb(DrawTarget
&, const LayoutDeviceRect
&,
96 ScrollbarKind
, nsIFrame
*,
97 const ComputedStyle
&, const ElementState
&,
98 const DocumentState
&, const Colors
&,
100 virtual bool PaintScrollbarThumb(WebRenderBackendData
&,
101 const LayoutDeviceRect
&, ScrollbarKind
,
102 nsIFrame
*, const ComputedStyle
&,
103 const ElementState
&, const DocumentState
&,
104 const Colors
&, const DPIRatio
&) = 0;
106 template <typename PaintBackendData
>
107 bool DoPaintDefaultScrollbar(PaintBackendData
&, const LayoutDeviceRect
&,
108 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
109 const ElementState
&, const DocumentState
&,
110 const Colors
&, const DPIRatio
&);
111 bool PaintScrollbar(DrawTarget
&, const LayoutDeviceRect
&, ScrollbarKind
,
112 nsIFrame
*, const ComputedStyle
&, const ElementState
&,
113 const DocumentState
&, const Colors
&, const DPIRatio
&);
114 bool PaintScrollbar(WebRenderBackendData
&, const LayoutDeviceRect
&,
115 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
116 const ElementState
&, const DocumentState
&, const Colors
&,
119 virtual bool PaintScrollbarTrack(DrawTarget
&, const LayoutDeviceRect
&,
120 ScrollbarKind
, nsIFrame
*,
121 const ComputedStyle
&, const DocumentState
&,
122 const Colors
&, const DPIRatio
&) {
123 // Draw nothing by default. Subclasses can override this.
126 virtual bool PaintScrollbarTrack(WebRenderBackendData
&,
127 const LayoutDeviceRect
&, ScrollbarKind
,
128 nsIFrame
*, const ComputedStyle
&,
129 const DocumentState
&, const Colors
&,
131 // Draw nothing by default. Subclasses can override this.
135 template <typename PaintBackendData
>
136 bool DoPaintDefaultScrollCorner(PaintBackendData
&, const LayoutDeviceRect
&,
137 ScrollbarKind
, nsIFrame
*,
138 const ComputedStyle
&, const DocumentState
&,
139 const Colors
&, const DPIRatio
&);
140 virtual bool PaintScrollCorner(DrawTarget
&, const LayoutDeviceRect
&,
141 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
142 const DocumentState
&, const Colors
&,
144 virtual bool PaintScrollCorner(WebRenderBackendData
&, const LayoutDeviceRect
&,
145 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
146 const DocumentState
&, const Colors
&,
149 virtual void RecomputeScrollbarParams() = 0;
151 virtual bool ShouldDrawScrollbarButtons() { return true; }
154 // The scrollbar sizes for all our scrollbars. Indices are overlay or not,
155 // then thin or not. Should be configured via ConfigureScrollbarSize.
156 CSSIntCoord mScrollbarSize
[2][2]{};
159 // For some kind of style differences a full virtual method is overkill, so we
160 // store the kind here so we can branch on it if necessary.
163 // Configures the scrollbar sizes based on a single size.
164 void ConfigureScrollbarSize(CSSIntCoord
);
166 // Configures a particular scrollbar size.
167 void ConfigureScrollbarSize(StyleScrollbarWidth
, Overlay
, CSSIntCoord
);
170 } // namespace mozilla::widget