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 class nsScrollbarFrame
;
20 namespace mozilla::widget
{
22 class ScrollbarDrawing
{
24 using DPIRatio
= mozilla::CSSToLayoutDeviceScale
;
25 using ElementState
= dom::ElementState
;
26 using DocumentState
= dom::DocumentState
;
27 using DrawTarget
= mozilla::gfx::DrawTarget
;
28 using sRGBColor
= mozilla::gfx::sRGBColor
;
29 using Colors
= ThemeColors
;
30 using Overlay
= nsITheme::Overlay
;
31 using WebRenderBackendData
= mozilla::widget::WebRenderBackendData
;
33 enum class Kind
: uint8_t {
41 explicit ScrollbarDrawing(Kind aKind
) : mKind(aKind
) {}
44 virtual ~ScrollbarDrawing() = default;
46 enum class ScrollbarKind
: uint8_t {
52 DPIRatio
GetDPIRatioForScrollbarPart(const nsPresContext
*);
54 static nsScrollbarFrame
* GetParentScrollbarFrame(nsIFrame
* aFrame
);
55 static bool IsParentScrollbarRolledOver(nsIFrame
* aFrame
);
56 static bool IsParentScrollbarHoveredOrActive(nsIFrame
* aFrame
);
58 static bool IsScrollbarWidthThin(const ComputedStyle
& aStyle
);
59 static bool IsScrollbarWidthThin(nsIFrame
* aFrame
);
61 CSSIntCoord
GetCSSScrollbarSize(StyleScrollbarWidth
, Overlay
) const;
62 LayoutDeviceIntCoord
GetScrollbarSize(const nsPresContext
*,
63 StyleScrollbarWidth
, Overlay
);
64 LayoutDeviceIntCoord
GetScrollbarSize(const nsPresContext
*, nsIFrame
*);
66 virtual LayoutDeviceIntSize
GetMinimumWidgetSize(nsPresContext
*,
67 StyleAppearance aAppearance
,
68 nsIFrame
* aFrame
) = 0;
69 virtual Maybe
<nsITheme::Transparency
> GetScrollbarPartTransparency(
70 nsIFrame
* aFrame
, StyleAppearance aAppearance
) {
74 bool IsScrollbarTrackOpaque(nsIFrame
*);
75 virtual sRGBColor
ComputeScrollbarTrackColor(nsIFrame
*, const ComputedStyle
&,
78 virtual sRGBColor
ComputeScrollbarThumbColor(nsIFrame
*, const ComputedStyle
&,
83 nscolor
GetScrollbarButtonColor(nscolor aTrackColor
, ElementState
);
84 Maybe
<nscolor
> GetScrollbarArrowColor(nscolor aButtonColor
);
86 // Returned colors are button, arrow.
87 virtual std::pair
<sRGBColor
, sRGBColor
> ComputeScrollbarButtonColors(
88 nsIFrame
*, StyleAppearance
, const ComputedStyle
&, const ElementState
&,
89 const DocumentState
&, const Colors
&);
91 virtual bool PaintScrollbarButton(DrawTarget
&, StyleAppearance
,
92 const LayoutDeviceRect
&, ScrollbarKind
,
93 nsIFrame
*, const ComputedStyle
&,
94 const ElementState
&, const DocumentState
&,
95 const Colors
&, const DPIRatio
&);
97 virtual bool PaintScrollbarThumb(DrawTarget
&, const LayoutDeviceRect
&,
98 ScrollbarKind
, nsIFrame
*,
99 const ComputedStyle
&, const ElementState
&,
100 const DocumentState
&, const Colors
&,
101 const DPIRatio
&) = 0;
102 virtual bool PaintScrollbarThumb(WebRenderBackendData
&,
103 const LayoutDeviceRect
&, ScrollbarKind
,
104 nsIFrame
*, const ComputedStyle
&,
105 const ElementState
&, const DocumentState
&,
106 const Colors
&, const DPIRatio
&) = 0;
108 template <typename PaintBackendData
>
109 bool DoPaintDefaultScrollbar(PaintBackendData
&, const LayoutDeviceRect
&,
110 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
111 const ElementState
&, const DocumentState
&,
112 const Colors
&, const DPIRatio
&);
113 virtual bool PaintScrollbar(DrawTarget
&, const LayoutDeviceRect
&,
114 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
115 const ElementState
&, const DocumentState
&,
116 const Colors
&, const DPIRatio
&);
117 virtual bool PaintScrollbar(WebRenderBackendData
&, const LayoutDeviceRect
&,
118 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
119 const ElementState
&, const DocumentState
&,
120 const Colors
&, const DPIRatio
&);
122 template <typename PaintBackendData
>
123 bool DoPaintDefaultScrollCorner(PaintBackendData
&, const LayoutDeviceRect
&,
124 ScrollbarKind
, nsIFrame
*,
125 const ComputedStyle
&, const DocumentState
&,
126 const Colors
&, const DPIRatio
&);
127 virtual bool PaintScrollCorner(DrawTarget
&, const LayoutDeviceRect
&,
128 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
129 const DocumentState
&, const Colors
&,
131 virtual bool PaintScrollCorner(WebRenderBackendData
&, const LayoutDeviceRect
&,
132 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
133 const DocumentState
&, const Colors
&,
136 virtual void RecomputeScrollbarParams() = 0;
138 virtual bool ShouldDrawScrollbarButtons() { return true; }
141 // The scrollbar sizes for all our scrollbars. Indices are overlay or not,
142 // then thin or not. Should be configured via ConfigureScrollbarSize.
143 CSSIntCoord mScrollbarSize
[2][2]{};
146 // For some kind of style differences a full virtual method is overkill, so we
147 // store the kind here so we can branch on it if necessary.
150 // Configures the scrollbar sizes based on a single size.
151 void ConfigureScrollbarSize(CSSIntCoord
);
153 // Configures a particular scrollbar size.
154 void ConfigureScrollbarSize(StyleScrollbarWidth
, Overlay
, CSSIntCoord
);
157 } // namespace mozilla::widget