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"
11 using namespace mozilla
;
12 using namespace mozilla::widget
;
14 LayoutDeviceIntSize
ScrollbarDrawingAndroid::GetMinimumWidgetSize(
15 nsPresContext
* aPresContext
, StyleAppearance aAppearance
,
17 MOZ_ASSERT(nsNativeTheme::IsWidgetScrollbarPart(aAppearance
));
20 GetScrollbarSizes(aPresContext
, StyleScrollbarWidth::Auto
, Overlay::Yes
);
21 MOZ_ASSERT(sizes
.mHorizontal
== sizes
.mVertical
);
23 return LayoutDeviceIntSize
{sizes
.mHorizontal
, sizes
.mVertical
};
26 auto ScrollbarDrawingAndroid::GetScrollbarSizes(nsPresContext
* aPresContext
,
27 StyleScrollbarWidth aWidth
,
30 // We force auto-width scrollbars because scrollbars on android are already
32 return ScrollbarDrawing::GetScrollbarSizes(
33 aPresContext
, StyleScrollbarWidth::Auto
, aOverlay
);
36 template <typename PaintBackendData
>
37 void ScrollbarDrawingAndroid::DoPaintScrollbarThumb(
38 PaintBackendData
& aPaintData
, const LayoutDeviceRect
& aRect
,
39 ScrollbarKind aScrollbarKind
, nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
40 const ElementState
& aElementState
, const DocumentState
& aDocumentState
,
41 const Colors
& aColors
, const DPIRatio
& aDpiRatio
) {
42 // TODO(emilio): Maybe do like macOS and draw a stroke?
43 const auto color
= ComputeScrollbarThumbColor(aFrame
, aStyle
, aElementState
,
44 aDocumentState
, aColors
);
45 const bool horizontal
= aScrollbarKind
== ScrollbarKind::Horizontal
;
47 // Draw the thumb rect centered in the scrollbar.
48 LayoutDeviceRect
thumbRect(aRect
);
50 thumbRect
.height
*= 0.5f
;
51 thumbRect
.y
+= thumbRect
.height
* 0.5f
;
53 thumbRect
.width
*= 0.5f
;
54 thumbRect
.x
+= thumbRect
.width
* 0.5f
;
57 const LayoutDeviceCoord radius
=
58 (horizontal
? thumbRect
.height
: thumbRect
.width
) / 2.0f
;
59 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, thumbRect
, color
,
60 sRGBColor::White(0.0f
), 0.0f
,
61 radius
/ aDpiRatio
, aDpiRatio
);
64 bool ScrollbarDrawingAndroid::PaintScrollbarThumb(
65 DrawTarget
& aDt
, const LayoutDeviceRect
& aRect
,
66 ScrollbarKind aScrollbarKind
, nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
67 const ElementState
& aElementState
, const DocumentState
& aDocumentState
,
68 const Colors
& aColors
, const DPIRatio
& aDpiRatio
) {
69 DoPaintScrollbarThumb(aDt
, aRect
, aScrollbarKind
, aFrame
, aStyle
,
70 aElementState
, aDocumentState
, aColors
, aDpiRatio
);
74 bool ScrollbarDrawingAndroid::PaintScrollbarThumb(
75 WebRenderBackendData
& aWrData
, const LayoutDeviceRect
& aRect
,
76 ScrollbarKind aScrollbarKind
, nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
77 const ElementState
& aElementState
, const DocumentState
& aDocumentState
,
78 const Colors
& aColors
, const DPIRatio
& aDpiRatio
) {
79 DoPaintScrollbarThumb(aWrData
, aRect
, aScrollbarKind
, aFrame
, aStyle
,
80 aElementState
, aDocumentState
, aColors
, aDpiRatio
);
84 void ScrollbarDrawingAndroid::RecomputeScrollbarParams() {
85 uint32_t defaultSize
= 6;
86 uint32_t overrideSize
=
87 StaticPrefs::widget_non_native_theme_scrollbar_size_override();
88 if (overrideSize
> 0) {
89 defaultSize
= overrideSize
;
91 mHorizontalScrollbarHeight
= mVerticalScrollbarWidth
= defaultSize
;