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 "ScrollbarDrawingAndroid.h"
9 #include "nsNativeTheme.h"
10 #include "mozilla/StaticPrefs_widget.h"
12 using namespace mozilla
;
13 using namespace mozilla::widget
;
15 LayoutDeviceIntSize
ScrollbarDrawingAndroid::GetMinimumWidgetSize(
16 nsPresContext
* aPresContext
, StyleAppearance aAppearance
,
18 MOZ_ASSERT(nsNativeTheme::IsWidgetScrollbarPart(aAppearance
));
20 GetScrollbarSize(aPresContext
, StyleScrollbarWidth::Auto
, Overlay::Yes
);
21 return LayoutDeviceIntSize
{size
, size
};
24 template <typename PaintBackendData
>
25 void ScrollbarDrawingAndroid::DoPaintScrollbarThumb(
26 PaintBackendData
& aPaintData
, const LayoutDeviceRect
& aRect
,
27 ScrollbarKind aScrollbarKind
, nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
28 const ElementState
& aElementState
, const DocumentState
& aDocumentState
,
29 const Colors
& aColors
, const DPIRatio
& aDpiRatio
) {
30 // TODO(emilio): Maybe do like macOS and draw a stroke?
31 const auto color
= ComputeScrollbarThumbColor(aFrame
, aStyle
, aElementState
,
32 aDocumentState
, aColors
);
33 const bool horizontal
= aScrollbarKind
== ScrollbarKind::Horizontal
;
35 // Draw the thumb rect centered in the scrollbar.
36 LayoutDeviceRect
thumbRect(aRect
);
38 thumbRect
.height
*= 0.5f
;
39 thumbRect
.y
+= thumbRect
.height
* 0.5f
;
41 thumbRect
.width
*= 0.5f
;
42 thumbRect
.x
+= thumbRect
.width
* 0.5f
;
45 const LayoutDeviceCoord radius
=
46 (horizontal
? thumbRect
.height
: thumbRect
.width
) / 2.0f
;
47 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, thumbRect
, color
,
48 sRGBColor::White(0.0f
), 0.0f
,
49 radius
/ aDpiRatio
, aDpiRatio
);
52 bool ScrollbarDrawingAndroid::PaintScrollbarThumb(
53 DrawTarget
& aDt
, const LayoutDeviceRect
& aRect
,
54 ScrollbarKind aScrollbarKind
, nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
55 const ElementState
& aElementState
, const DocumentState
& aDocumentState
,
56 const Colors
& aColors
, const DPIRatio
& aDpiRatio
) {
57 DoPaintScrollbarThumb(aDt
, aRect
, aScrollbarKind
, aFrame
, aStyle
,
58 aElementState
, aDocumentState
, aColors
, aDpiRatio
);
62 bool ScrollbarDrawingAndroid::PaintScrollbarThumb(
63 WebRenderBackendData
& aWrData
, const LayoutDeviceRect
& aRect
,
64 ScrollbarKind aScrollbarKind
, nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
65 const ElementState
& aElementState
, const DocumentState
& aDocumentState
,
66 const Colors
& aColors
, const DPIRatio
& aDpiRatio
) {
67 DoPaintScrollbarThumb(aWrData
, aRect
, aScrollbarKind
, aFrame
, aStyle
,
68 aElementState
, aDocumentState
, aColors
, aDpiRatio
);
72 void ScrollbarDrawingAndroid::RecomputeScrollbarParams() {
73 uint32_t defaultSize
= 6;
74 uint32_t overrideSize
=
75 StaticPrefs::widget_non_native_theme_scrollbar_size_override();
76 if (overrideSize
> 0) {
77 defaultSize
= overrideSize
;
79 ConfigureScrollbarSize(defaultSize
);
80 // We make thin scrollbars as wide as auto ones because auto scrollbars on
81 // android are already thin enough.
82 ConfigureScrollbarSize(StyleScrollbarWidth::Thin
, Overlay::Yes
, defaultSize
);
83 ConfigureScrollbarSize(StyleScrollbarWidth::Thin
, Overlay::No
, defaultSize
);