Bug 1758713 [wpt PR 33128] - Clarify the status of the CSS build system, a=testonly
[gecko.git] / widget / ScrollbarDrawingAndroid.cpp
blob8955531725e842f839e4396d4d54a26fbf9ff41e
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"
8 #include "nsIFrame.h"
9 #include "nsNativeTheme.h"
11 using namespace mozilla;
12 using namespace mozilla::widget;
14 LayoutDeviceIntSize ScrollbarDrawingAndroid::GetMinimumWidgetSize(
15 nsPresContext* aPresContext, StyleAppearance aAppearance,
16 nsIFrame* aFrame) {
17 MOZ_ASSERT(nsNativeTheme::IsWidgetScrollbarPart(aAppearance));
19 auto sizes =
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,
28 Overlay aOverlay)
29 -> ScrollbarSizes {
30 // We force auto-width scrollbars because scrollbars on android are already
31 // thin enough.
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);
48 if (aHorizontal) {
49 thumbRect.height *= 0.5f;
50 thumbRect.y += thumbRect.height * 0.5f;
51 } else {
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);
70 return true;
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);
80 return true;
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;