Bug 1732409 make getUserMedia() permission prompt requirement independent of "media...
[gecko.git] / widget / ScrollbarDrawing.h
blob115a01ed0906bfc2bd0686ab8b082e3ab405b88a
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 static constexpr gfx::sRGBColor sScrollbarColor(
21 gfx::sRGBColor::UnusualFromARGB(0xfff0f0f0));
22 static constexpr gfx::sRGBColor sScrollbarThumbColor(
23 gfx::sRGBColor::UnusualFromARGB(0xffcdcdcd));
25 class ScrollbarDrawing {
26 protected:
27 using DPIRatio = mozilla::CSSToLayoutDeviceScale;
28 using EventStates = mozilla::EventStates;
29 using DrawTarget = mozilla::gfx::DrawTarget;
30 using sRGBColor = mozilla::gfx::sRGBColor;
31 using Colors = ThemeColors;
32 using ScrollbarSizes = nsITheme::ScrollbarSizes;
33 using Overlay = nsITheme::Overlay;
34 using WebRenderBackendData = mozilla::widget::WebRenderBackendData;
36 public:
37 ScrollbarDrawing() = default;
38 virtual ~ScrollbarDrawing() = default;
40 struct ScrollbarParams {
41 bool isOverlay = false;
42 bool isRolledOver = false;
43 bool isSmall = false;
44 bool isHorizontal = false;
45 bool isRtl = false;
46 bool isOnDarkBackground = false;
47 bool isCustom = false;
48 // Two colors only used when custom is true.
49 nscolor trackColor = NS_RGBA(0, 0, 0, 0);
50 nscolor faceColor = NS_RGBA(0, 0, 0, 0);
53 static DPIRatio GetDPIRatioForScrollbarPart(nsPresContext*);
55 static nsIFrame* GetParentScrollbarFrame(nsIFrame* aFrame);
56 static bool IsParentScrollbarRolledOver(nsIFrame* aFrame);
57 static bool IsParentScrollbarHoveredOrActive(nsIFrame* aFrame);
59 static bool IsScrollbarWidthThin(const ComputedStyle& aStyle);
60 static bool IsScrollbarWidthThin(nsIFrame* aFrame);
62 virtual ScrollbarSizes GetScrollbarSizes(nsPresContext*, StyleScrollbarWidth,
63 Overlay);
64 virtual LayoutDeviceIntSize GetMinimumWidgetSize(nsPresContext*,
65 StyleAppearance aAppearance,
66 nsIFrame* aFrame) = 0;
67 virtual Maybe<nsITheme::Transparency> GetScrollbarPartTransparency(
68 nsIFrame* aFrame, StyleAppearance aAppearance) {
69 return Nothing();
72 bool IsScrollbarTrackOpaque(nsIFrame*);
73 virtual sRGBColor ComputeScrollbarTrackColor(
74 nsIFrame*, const ComputedStyle&, const EventStates& aDocumentState,
75 const Colors&);
76 virtual sRGBColor ComputeScrollbarThumbColor(
77 nsIFrame*, const ComputedStyle&, const EventStates& aElementState,
78 const EventStates& aDocumentState, const Colors&);
80 static ScrollbarParams ComputeScrollbarParams(nsIFrame* aFrame,
81 const ComputedStyle& aStyle,
82 bool aIsHorizontal);
83 static bool ShouldUseDarkScrollbar(nsIFrame*, const ComputedStyle&);
85 nscolor GetScrollbarButtonColor(nscolor aTrackColor, EventStates);
86 Maybe<nscolor> GetScrollbarArrowColor(nscolor aButtonColor);
88 // Returned colors are button, arrow.
89 virtual std::pair<sRGBColor, sRGBColor> ComputeScrollbarButtonColors(
90 nsIFrame*, StyleAppearance, const ComputedStyle&,
91 const EventStates& aElementState, const EventStates& aDocumentState,
92 const Colors&);
94 virtual bool PaintScrollbarButton(DrawTarget&, StyleAppearance,
95 const LayoutDeviceRect&, nsIFrame*,
96 const ComputedStyle&,
97 const EventStates& aElementState,
98 const EventStates& aDocumentState,
99 const Colors&);
101 virtual bool PaintScrollbarThumb(DrawTarget&, const LayoutDeviceRect&,
102 bool aHorizontal, nsIFrame*,
103 const ComputedStyle&,
104 const EventStates& aElementState,
105 const EventStates& aDocumentState,
106 const Colors&, const DPIRatio&) = 0;
107 virtual bool PaintScrollbarThumb(WebRenderBackendData&,
108 const LayoutDeviceRect&, bool aHorizontal,
109 nsIFrame*, const ComputedStyle&,
110 const EventStates& aElementState,
111 const EventStates& aDocumentState,
112 const Colors&, const DPIRatio&) = 0;
114 template <typename PaintBackendData>
115 bool DoPaintDefaultScrollbar(PaintBackendData&, const LayoutDeviceRect&,
116 bool aHorizontal, nsIFrame*,
117 const ComputedStyle&,
118 const EventStates& aElementState,
119 const EventStates& aDocumentState, const Colors&,
120 const DPIRatio&);
121 virtual bool PaintScrollbar(DrawTarget&, const LayoutDeviceRect&,
122 bool aHorizontal, nsIFrame*, const ComputedStyle&,
123 const EventStates& aElementState,
124 const EventStates& aDocumentState, const Colors&,
125 const DPIRatio&);
126 virtual bool PaintScrollbar(WebRenderBackendData&, const LayoutDeviceRect&,
127 bool aHorizontal, nsIFrame*, const ComputedStyle&,
128 const EventStates& aElementState,
129 const EventStates& aDocumentState, const Colors&,
130 const DPIRatio&);
132 virtual bool PaintScrollbarTrack(DrawTarget&, const LayoutDeviceRect&,
133 bool aHorizontal, nsIFrame*,
134 const ComputedStyle&,
135 const EventStates& aDocumentState,
136 const Colors&, const DPIRatio&) {
137 // Draw nothing by default. Subclasses can override this.
138 return true;
140 virtual bool PaintScrollbarTrack(WebRenderBackendData&,
141 const LayoutDeviceRect&, bool aHorizontal,
142 nsIFrame*, const ComputedStyle&,
143 const EventStates& aDocumentState,
144 const Colors&, const DPIRatio&) {
145 // Draw nothing by default. Subclasses can override this.
146 return true;
149 template <typename PaintBackendData>
150 bool DoPaintDefaultScrollCorner(PaintBackendData&, const LayoutDeviceRect&,
151 nsIFrame*, const ComputedStyle&,
152 const EventStates& aDocumentState,
153 const Colors&, const DPIRatio&);
154 virtual bool PaintScrollCorner(DrawTarget&, const LayoutDeviceRect&,
155 nsIFrame*, const ComputedStyle&,
156 const EventStates& aDocumentState,
157 const Colors&, const DPIRatio&);
158 virtual bool PaintScrollCorner(WebRenderBackendData&, const LayoutDeviceRect&,
159 nsIFrame*, const ComputedStyle&,
160 const EventStates& aDocumentState,
161 const Colors&, const DPIRatio&);
163 virtual void RecomputeScrollbarParams() = 0;
165 virtual bool ShouldDrawScrollbarButtons() { return true; }
167 uint32_t GetHorizontalScrollbarHeight() const {
168 return mHorizontalScrollbarHeight;
170 uint32_t GetVerticalScrollbarWidth() const { return mVerticalScrollbarWidth; }
172 protected:
173 uint32_t mHorizontalScrollbarHeight = 0;
174 uint32_t mVerticalScrollbarWidth = 0;
177 } // namespace mozilla::widget
179 #endif