1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "ScrollbarDrawingGTK.h"
8 #include "mozilla/gfx/Helpers.h"
9 #include "mozilla/StaticPrefs_widget.h"
10 #include "nsLayoutUtils.h"
11 #include "nsNativeTheme.h"
13 using namespace mozilla
;
14 using namespace mozilla::gfx
;
15 using namespace mozilla::widget
;
17 LayoutDeviceIntSize
ScrollbarDrawingGTK::GetMinimumWidgetSize(
18 nsPresContext
* aPresContext
, StyleAppearance aAppearance
,
20 MOZ_ASSERT(nsNativeTheme::IsWidgetScrollbarPart(aAppearance
));
21 auto sizes
= GetScrollbarSizes(aPresContext
, aFrame
);
22 MOZ_ASSERT(sizes
.mHorizontal
== sizes
.mVertical
);
23 LayoutDeviceIntSize size
{sizes
.mHorizontal
, sizes
.mVertical
};
24 if (aAppearance
== StyleAppearance::ScrollbarHorizontal
||
25 aAppearance
== StyleAppearance::ScrollbarVertical
||
26 aAppearance
== StyleAppearance::ScrollbarthumbHorizontal
||
27 aAppearance
== StyleAppearance::ScrollbarthumbVertical
) {
29 StaticPrefs::widget_non_native_theme_gtk_scrollbar_thumb_cross_size());
30 const bool isVertical
=
31 aAppearance
== StyleAppearance::ScrollbarVertical
||
32 aAppearance
== StyleAppearance::ScrollbarthumbVertical
;
33 auto dpi
= GetDPIRatioForScrollbarPart(aPresContext
);
35 size
.height
= thumbSize
* dpi
;
37 size
.width
= thumbSize
* dpi
;
43 Maybe
<nsITheme::Transparency
> ScrollbarDrawingGTK::GetScrollbarPartTransparency(
44 nsIFrame
* aFrame
, StyleAppearance aAppearance
) {
45 if (!aFrame
->PresContext()->UseOverlayScrollbars() &&
46 (aAppearance
== StyleAppearance::ScrollbarVertical
||
47 aAppearance
== StyleAppearance::ScrollbarHorizontal
) &&
48 IsScrollbarTrackOpaque(aFrame
)) {
49 return Some(nsITheme::eOpaque
);
55 template <typename PaintBackendData
>
56 bool ScrollbarDrawingGTK::DoPaintScrollbarThumb(
57 PaintBackendData
& aPaintData
, const LayoutDeviceRect
& aRect
,
58 ScrollbarKind aScrollbarKind
, nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
59 const ElementState
& aElementState
, const DocumentState
& aDocumentState
,
60 const Colors
& aColors
, const DPIRatio
& aDpiRatio
) {
61 sRGBColor thumbColor
= ComputeScrollbarThumbColor(
62 aFrame
, aStyle
, aElementState
, aDocumentState
, aColors
);
64 LayoutDeviceRect
thumbRect(aRect
);
66 const bool horizontal
= aScrollbarKind
== ScrollbarKind::Horizontal
;
67 if (aFrame
->PresContext()->UseOverlayScrollbars() &&
68 !ScrollbarDrawing::IsParentScrollbarHoveredOrActive(aFrame
)) {
70 thumbRect
.height
*= 0.5;
71 thumbRect
.y
+= thumbRect
.height
;
73 thumbRect
.width
*= 0.5;
74 if (aScrollbarKind
== ScrollbarKind::VerticalRight
) {
75 thumbRect
.x
+= thumbRect
.width
;
81 float factor
= std::max(
83 1.0f
- StaticPrefs::widget_non_native_theme_gtk_scrollbar_thumb_size());
84 thumbRect
.Deflate((horizontal
? thumbRect
.height
: thumbRect
.width
) *
88 LayoutDeviceCoord radius
=
89 StaticPrefs::widget_non_native_theme_gtk_scrollbar_round_thumb()
90 ? (horizontal
? thumbRect
.height
: thumbRect
.width
) / 2.0f
93 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, thumbRect
, thumbColor
,
94 sRGBColor(), 0, radius
/ aDpiRatio
,
99 bool ScrollbarDrawingGTK::PaintScrollbarThumb(
100 DrawTarget
& aDrawTarget
, const LayoutDeviceRect
& aRect
,
101 ScrollbarKind aScrollbarKind
, nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
102 const ElementState
& aElementState
, const DocumentState
& aDocumentState
,
103 const Colors
& aColors
, const DPIRatio
& aDpiRatio
) {
104 return DoPaintScrollbarThumb(aDrawTarget
, aRect
, aScrollbarKind
, aFrame
,
105 aStyle
, aElementState
, aDocumentState
, aColors
,
109 bool ScrollbarDrawingGTK::PaintScrollbarThumb(
110 WebRenderBackendData
& aWrData
, const LayoutDeviceRect
& aRect
,
111 ScrollbarKind aScrollbarKind
, nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
112 const ElementState
& aElementState
, const DocumentState
& aDocumentState
,
113 const Colors
& aColors
, const DPIRatio
& aDpiRatio
) {
114 return DoPaintScrollbarThumb(aWrData
, aRect
, aScrollbarKind
, aFrame
, aStyle
,
115 aElementState
, aDocumentState
, aColors
,
119 bool ScrollbarDrawingGTK::ShouldDrawScrollbarButtons() {
120 if (StaticPrefs::widget_non_native_theme_enabled()) {
121 return StaticPrefs::widget_non_native_theme_gtk_scrollbar_allow_buttons();
126 void ScrollbarDrawingGTK::RecomputeScrollbarParams() {
127 uint32_t defaultSize
= 12;
128 uint32_t overrideSize
=
129 StaticPrefs::widget_non_native_theme_scrollbar_size_override();
130 if (overrideSize
> 0) {
131 defaultSize
= overrideSize
;
133 mHorizontalScrollbarHeight
= mVerticalScrollbarWidth
= defaultSize
;