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 {
40 explicit ScrollbarDrawing(Kind aKind
) : mKind(aKind
) {}
41 virtual ~ScrollbarDrawing() = default;
43 static DPIRatio
GetDPIRatioForScrollbarPart(nsPresContext
*);
45 static nsIFrame
* GetParentScrollbarFrame(nsIFrame
* aFrame
);
46 static bool IsParentScrollbarRolledOver(nsIFrame
* aFrame
);
47 static bool IsParentScrollbarHoveredOrActive(nsIFrame
* aFrame
);
49 static bool IsScrollbarWidthThin(const ComputedStyle
& aStyle
);
50 static bool IsScrollbarWidthThin(nsIFrame
* aFrame
);
52 virtual ScrollbarSizes
GetScrollbarSizes(nsPresContext
*, StyleScrollbarWidth
,
54 ScrollbarSizes
GetScrollbarSizes(nsPresContext
*, nsIFrame
*);
55 virtual LayoutDeviceIntSize
GetMinimumWidgetSize(nsPresContext
*,
56 StyleAppearance aAppearance
,
57 nsIFrame
* aFrame
) = 0;
58 virtual Maybe
<nsITheme::Transparency
> GetScrollbarPartTransparency(
59 nsIFrame
* aFrame
, StyleAppearance aAppearance
) {
63 bool IsScrollbarTrackOpaque(nsIFrame
*);
64 virtual sRGBColor
ComputeScrollbarTrackColor(
65 nsIFrame
*, const ComputedStyle
&, const EventStates
& aDocumentState
,
67 virtual sRGBColor
ComputeScrollbarThumbColor(
68 nsIFrame
*, const ComputedStyle
&, const EventStates
& aElementState
,
69 const EventStates
& aDocumentState
, const Colors
&);
71 nscolor
GetScrollbarButtonColor(nscolor aTrackColor
, EventStates
);
72 Maybe
<nscolor
> GetScrollbarArrowColor(nscolor aButtonColor
);
74 // Returned colors are button, arrow.
75 virtual std::pair
<sRGBColor
, sRGBColor
> ComputeScrollbarButtonColors(
76 nsIFrame
*, StyleAppearance
, const ComputedStyle
&,
77 const EventStates
& aElementState
, const EventStates
& aDocumentState
,
80 virtual bool PaintScrollbarButton(DrawTarget
&, StyleAppearance
,
81 const LayoutDeviceRect
&, nsIFrame
*,
83 const EventStates
& aElementState
,
84 const EventStates
& aDocumentState
,
85 const Colors
&, const DPIRatio
&);
87 virtual bool PaintScrollbarThumb(DrawTarget
&, const LayoutDeviceRect
&,
88 bool aHorizontal
, nsIFrame
*,
90 const EventStates
& aElementState
,
91 const EventStates
& aDocumentState
,
92 const Colors
&, const DPIRatio
&) = 0;
93 virtual bool PaintScrollbarThumb(WebRenderBackendData
&,
94 const LayoutDeviceRect
&, bool aHorizontal
,
95 nsIFrame
*, const ComputedStyle
&,
96 const EventStates
& aElementState
,
97 const EventStates
& aDocumentState
,
98 const Colors
&, const DPIRatio
&) = 0;
100 template <typename PaintBackendData
>
101 bool DoPaintDefaultScrollbar(PaintBackendData
&, const LayoutDeviceRect
&,
102 bool aHorizontal
, nsIFrame
*,
103 const ComputedStyle
&,
104 const EventStates
& aElementState
,
105 const EventStates
& aDocumentState
, const Colors
&,
107 bool PaintScrollbar(DrawTarget
&, const LayoutDeviceRect
&, bool aHorizontal
,
108 nsIFrame
*, const ComputedStyle
&,
109 const EventStates
& aElementState
,
110 const EventStates
& aDocumentState
, const Colors
&,
112 bool PaintScrollbar(WebRenderBackendData
&, const LayoutDeviceRect
&,
113 bool aHorizontal
, nsIFrame
*, const ComputedStyle
&,
114 const EventStates
& aElementState
,
115 const EventStates
& aDocumentState
, const Colors
&,
118 virtual bool PaintScrollbarTrack(DrawTarget
&, const LayoutDeviceRect
&,
119 bool aHorizontal
, nsIFrame
*,
120 const ComputedStyle
&,
121 const EventStates
& aDocumentState
,
122 const Colors
&, const DPIRatio
&) {
123 // Draw nothing by default. Subclasses can override this.
126 virtual bool PaintScrollbarTrack(WebRenderBackendData
&,
127 const LayoutDeviceRect
&, bool aHorizontal
,
128 nsIFrame
*, const ComputedStyle
&,
129 const EventStates
& aDocumentState
,
130 const Colors
&, const DPIRatio
&) {
131 // Draw nothing by default. Subclasses can override this.
135 template <typename PaintBackendData
>
136 bool DoPaintDefaultScrollCorner(PaintBackendData
&, const LayoutDeviceRect
&,
137 nsIFrame
*, const ComputedStyle
&,
138 const EventStates
& aDocumentState
,
139 const Colors
&, const DPIRatio
&);
140 virtual bool PaintScrollCorner(DrawTarget
&, const LayoutDeviceRect
&,
141 nsIFrame
*, const ComputedStyle
&,
142 const EventStates
& aDocumentState
,
143 const Colors
&, const DPIRatio
&);
144 virtual bool PaintScrollCorner(WebRenderBackendData
&, const LayoutDeviceRect
&,
145 nsIFrame
*, const ComputedStyle
&,
146 const EventStates
& aDocumentState
,
147 const Colors
&, const DPIRatio
&);
149 virtual void RecomputeScrollbarParams() = 0;
151 virtual bool ShouldDrawScrollbarButtons() { return true; }
153 uint32_t GetHorizontalScrollbarHeight() const {
154 return mHorizontalScrollbarHeight
;
156 uint32_t GetVerticalScrollbarWidth() const { return mVerticalScrollbarWidth
; }
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.
162 uint32_t mHorizontalScrollbarHeight
= 0;
163 uint32_t mVerticalScrollbarWidth
= 0;
166 } // namespace mozilla::widget