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/EventStates.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 EventStates
= mozilla::EventStates
;
24 using DrawTarget
= mozilla::gfx::DrawTarget
;
25 using sRGBColor
= mozilla::gfx::sRGBColor
;
26 using Colors
= ThemeColors
;
27 using ScrollbarSizes
= nsITheme::ScrollbarSizes
;
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 static DPIRatio
GetDPIRatioForScrollbarPart(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 virtual ScrollbarSizes
GetScrollbarSizes(nsPresContext
*, StyleScrollbarWidth
,
61 ScrollbarSizes
GetScrollbarSizes(nsPresContext
*, nsIFrame
*);
62 virtual LayoutDeviceIntSize
GetMinimumWidgetSize(nsPresContext
*,
63 StyleAppearance aAppearance
,
64 nsIFrame
* aFrame
) = 0;
65 virtual Maybe
<nsITheme::Transparency
> GetScrollbarPartTransparency(
66 nsIFrame
* aFrame
, StyleAppearance aAppearance
) {
70 bool IsScrollbarTrackOpaque(nsIFrame
*);
71 virtual sRGBColor
ComputeScrollbarTrackColor(
72 nsIFrame
*, const ComputedStyle
&, const EventStates
& aDocumentState
,
74 virtual sRGBColor
ComputeScrollbarThumbColor(
75 nsIFrame
*, const ComputedStyle
&, const EventStates
& aElementState
,
76 const EventStates
& aDocumentState
, const Colors
&);
78 nscolor
GetScrollbarButtonColor(nscolor aTrackColor
, EventStates
);
79 Maybe
<nscolor
> GetScrollbarArrowColor(nscolor aButtonColor
);
81 // Returned colors are button, arrow.
82 virtual std::pair
<sRGBColor
, sRGBColor
> ComputeScrollbarButtonColors(
83 nsIFrame
*, StyleAppearance
, const ComputedStyle
&,
84 const EventStates
& aElementState
, const EventStates
& aDocumentState
,
87 virtual bool PaintScrollbarButton(DrawTarget
&, StyleAppearance
,
88 const LayoutDeviceRect
&, ScrollbarKind
,
89 nsIFrame
*, const ComputedStyle
&,
90 const EventStates
& aElementState
,
91 const EventStates
& aDocumentState
,
92 const Colors
&, const DPIRatio
&);
94 virtual bool PaintScrollbarThumb(DrawTarget
&, const LayoutDeviceRect
&,
95 ScrollbarKind
, nsIFrame
*,
97 const EventStates
& aElementState
,
98 const EventStates
& aDocumentState
,
99 const Colors
&, const DPIRatio
&) = 0;
100 virtual bool PaintScrollbarThumb(WebRenderBackendData
&,
101 const LayoutDeviceRect
&, ScrollbarKind
,
102 nsIFrame
*, const ComputedStyle
&,
103 const EventStates
& aElementState
,
104 const EventStates
& aDocumentState
,
105 const Colors
&, const DPIRatio
&) = 0;
107 template <typename PaintBackendData
>
108 bool DoPaintDefaultScrollbar(PaintBackendData
&, const LayoutDeviceRect
&,
109 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
110 const EventStates
& aElementState
,
111 const EventStates
& aDocumentState
, const Colors
&,
113 bool PaintScrollbar(DrawTarget
&, const LayoutDeviceRect
&, ScrollbarKind
,
114 nsIFrame
*, const ComputedStyle
&,
115 const EventStates
& aElementState
,
116 const EventStates
& aDocumentState
, const Colors
&,
118 bool PaintScrollbar(WebRenderBackendData
&, const LayoutDeviceRect
&,
119 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
120 const EventStates
& aElementState
,
121 const EventStates
& aDocumentState
, const Colors
&,
124 virtual bool PaintScrollbarTrack(DrawTarget
&, const LayoutDeviceRect
&,
125 ScrollbarKind
, nsIFrame
*,
126 const ComputedStyle
&,
127 const EventStates
& aDocumentState
,
128 const Colors
&, const DPIRatio
&) {
129 // Draw nothing by default. Subclasses can override this.
132 virtual bool PaintScrollbarTrack(WebRenderBackendData
&,
133 const LayoutDeviceRect
&, ScrollbarKind
,
134 nsIFrame
*, const ComputedStyle
&,
135 const EventStates
& aDocumentState
,
136 const Colors
&, const DPIRatio
&) {
137 // Draw nothing by default. Subclasses can override this.
141 template <typename PaintBackendData
>
142 bool DoPaintDefaultScrollCorner(PaintBackendData
&, const LayoutDeviceRect
&,
143 ScrollbarKind
, nsIFrame
*,
144 const ComputedStyle
&,
145 const EventStates
& aDocumentState
,
146 const Colors
&, const DPIRatio
&);
147 virtual bool PaintScrollCorner(DrawTarget
&, const LayoutDeviceRect
&,
148 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
149 const EventStates
& aDocumentState
,
150 const Colors
&, const DPIRatio
&);
151 virtual bool PaintScrollCorner(WebRenderBackendData
&, const LayoutDeviceRect
&,
152 ScrollbarKind
, nsIFrame
*, const ComputedStyle
&,
153 const EventStates
& aDocumentState
,
154 const Colors
&, const DPIRatio
&);
156 virtual void RecomputeScrollbarParams() = 0;
158 virtual bool ShouldDrawScrollbarButtons() { return true; }
160 uint32_t GetHorizontalScrollbarHeight() const {
161 return mHorizontalScrollbarHeight
;
163 uint32_t GetVerticalScrollbarWidth() const { return mVerticalScrollbarWidth
; }
166 // For some kind of style differences a full virtual method is overkill, so we
167 // store the kind here so we can branch on it if necessary.
169 uint32_t mHorizontalScrollbarHeight
= 0;
170 uint32_t mVerticalScrollbarWidth
= 0;
173 } // namespace mozilla::widget