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 bool aHorizontal
, nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
40 const EventStates
& aElementState
, const EventStates
& 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
);
46 // Draw the thumb rect centered in the scrollbar.
47 LayoutDeviceRect
thumbRect(aRect
);
49 thumbRect
.height
*= 0.5f
;
50 thumbRect
.y
+= thumbRect
.height
* 0.5f
;
52 thumbRect
.width
*= 0.5f
;
53 thumbRect
.x
+= thumbRect
.width
* 0.5f
;
56 const LayoutDeviceCoord radius
=
57 (aHorizontal
? thumbRect
.height
: thumbRect
.width
) / 2.0f
;
58 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData
, thumbRect
, color
,
59 sRGBColor::White(0.0f
), 0.0f
,
60 radius
/ aDpiRatio
, aDpiRatio
);
63 bool ScrollbarDrawingAndroid::PaintScrollbarThumb(
64 DrawTarget
& aDt
, const LayoutDeviceRect
& aRect
, bool aHorizontal
,
65 nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
66 const EventStates
& aElementState
, const EventStates
& aDocumentState
,
67 const Colors
& aColors
, const DPIRatio
& aDpiRatio
) {
68 DoPaintScrollbarThumb(aDt
, aRect
, aHorizontal
, aFrame
, aStyle
, aElementState
,
69 aDocumentState
, aColors
, aDpiRatio
);
73 bool ScrollbarDrawingAndroid::PaintScrollbarThumb(
74 WebRenderBackendData
& aWrData
, const LayoutDeviceRect
& aRect
,
75 bool aHorizontal
, nsIFrame
* aFrame
, const ComputedStyle
& aStyle
,
76 const EventStates
& aElementState
, const EventStates
& aDocumentState
,
77 const Colors
& aColors
, const DPIRatio
& aDpiRatio
) {
78 DoPaintScrollbarThumb(aWrData
, aRect
, aHorizontal
, aFrame
, aStyle
,
79 aElementState
, aDocumentState
, aColors
, aDpiRatio
);
83 void ScrollbarDrawingAndroid::RecomputeScrollbarParams() {
84 uint32_t defaultSize
= 6;
85 uint32_t overrideSize
=
86 StaticPrefs::widget_non_native_theme_scrollbar_size_override();
87 if (overrideSize
> 0) {
88 defaultSize
= overrideSize
;
90 mHorizontalScrollbarHeight
= mVerticalScrollbarWidth
= defaultSize
;