Bug 1755924 [wpt PR 32876] - Handle resumed blocks that get sliced by floats correctl...
[gecko.git] / widget / ScrollbarDrawing.h
blob260c6d97ae5d39b8844f36d34406e75f88f96237
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"
12 #include "nsColor.h"
13 #include "nsITheme.h"
14 #include "ThemeColors.h"
15 #include "ThemeDrawing.h"
16 #include "Units.h"
18 namespace mozilla::widget {
20 class ScrollbarDrawing {
21 protected:
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 {
32 Android,
33 Cocoa,
34 Gtk,
35 Win10,
36 Win11,
39 public:
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,
53 Overlay);
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) {
60 return Nothing();
63 bool IsScrollbarTrackOpaque(nsIFrame*);
64 virtual sRGBColor ComputeScrollbarTrackColor(
65 nsIFrame*, const ComputedStyle&, const EventStates& aDocumentState,
66 const Colors&);
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,
78 const Colors&);
80 virtual bool PaintScrollbarButton(DrawTarget&, StyleAppearance,
81 const LayoutDeviceRect&, nsIFrame*,
82 const ComputedStyle&,
83 const EventStates& aElementState,
84 const EventStates& aDocumentState,
85 const Colors&, const DPIRatio&);
87 virtual bool PaintScrollbarThumb(DrawTarget&, const LayoutDeviceRect&,
88 bool aHorizontal, nsIFrame*,
89 const ComputedStyle&,
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&,
106 const DPIRatio&);
107 bool PaintScrollbar(DrawTarget&, const LayoutDeviceRect&, bool aHorizontal,
108 nsIFrame*, const ComputedStyle&,
109 const EventStates& aElementState,
110 const EventStates& aDocumentState, const Colors&,
111 const DPIRatio&);
112 bool PaintScrollbar(WebRenderBackendData&, const LayoutDeviceRect&,
113 bool aHorizontal, nsIFrame*, const ComputedStyle&,
114 const EventStates& aElementState,
115 const EventStates& aDocumentState, const Colors&,
116 const DPIRatio&);
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.
124 return true;
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.
132 return true;
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; }
158 protected:
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.
161 Kind mKind;
162 uint32_t mHorizontalScrollbarHeight = 0;
163 uint32_t mVerticalScrollbarWidth = 0;
166 } // namespace mozilla::widget
168 #endif