Bug 1942006 - Upstream a variety of Servo-specific code from Servo's downstream fork...
[gecko.git] / widget / ScrollbarDrawing.h
blob686acbf9f2d35a61ebf4a7e914a47ae0aa32af18
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"
12 #include "nsColor.h"
13 #include "nsITheme.h"
14 #include "ThemeColors.h"
15 #include "ThemeDrawing.h"
16 #include "Units.h"
18 class nsScrollbarFrame;
20 namespace mozilla::widget {
22 class ScrollbarDrawing {
23 protected:
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 {
34 Android,
35 Cocoa,
36 Gtk,
37 Win10,
38 Win11,
41 explicit ScrollbarDrawing(Kind aKind) : mKind(aKind) {}
43 public:
44 virtual ~ScrollbarDrawing() = default;
46 enum class ScrollbarKind : uint8_t {
47 Horizontal,
48 VerticalLeft,
49 VerticalRight,
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) {
71 return Nothing();
74 bool IsScrollbarTrackOpaque(nsIFrame*);
75 virtual sRGBColor ComputeScrollbarTrackColor(nsIFrame*, const ComputedStyle&,
76 const DocumentState&,
77 const Colors&);
78 virtual sRGBColor ComputeScrollbarThumbColor(nsIFrame*, const ComputedStyle&,
79 const ElementState&,
80 const DocumentState&,
81 const Colors&);
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&,
130 const DPIRatio&);
131 virtual bool PaintScrollCorner(WebRenderBackendData&, const LayoutDeviceRect&,
132 ScrollbarKind, nsIFrame*, const ComputedStyle&,
133 const DocumentState&, const Colors&,
134 const DPIRatio&);
136 virtual void RecomputeScrollbarParams() = 0;
138 virtual bool ShouldDrawScrollbarButtons() { return true; }
140 private:
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]{};
145 protected:
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.
148 Kind mKind;
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
159 #endif