2020-07-30 17:02:02 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2021-11-15 12:39:38 +00:00
|
|
|
#include "ScrollbarDrawingAndroid.h"
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2021-09-28 17:04:34 +00:00
|
|
|
#include "nsIFrame.h"
|
2021-11-15 12:39:38 +00:00
|
|
|
#include "nsNativeTheme.h"
|
2021-09-28 17:04:34 +00:00
|
|
|
|
2021-11-15 12:39:38 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::widget;
|
2021-09-28 17:04:34 +00:00
|
|
|
|
2021-11-15 12:39:38 +00:00
|
|
|
LayoutDeviceIntSize ScrollbarDrawingAndroid::GetMinimumWidgetSize(
|
|
|
|
nsPresContext* aPresContext, StyleAppearance aAppearance,
|
|
|
|
nsIFrame* aFrame) {
|
|
|
|
MOZ_ASSERT(nsNativeTheme::IsWidgetScrollbarPart(aAppearance));
|
2021-09-28 17:04:34 +00:00
|
|
|
|
|
|
|
auto sizes =
|
|
|
|
GetScrollbarSizes(aPresContext, StyleScrollbarWidth::Auto, Overlay::Yes);
|
|
|
|
MOZ_ASSERT(sizes.mHorizontal == sizes.mVertical);
|
|
|
|
|
2021-11-15 12:39:38 +00:00
|
|
|
return LayoutDeviceIntSize{sizes.mHorizontal, sizes.mVertical};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ScrollbarDrawingAndroid::GetScrollbarSizes(nsPresContext* aPresContext,
|
|
|
|
StyleScrollbarWidth aWidth,
|
|
|
|
Overlay aOverlay)
|
|
|
|
-> ScrollbarSizes {
|
|
|
|
// We force auto-width scrollbars because scrollbars on android are already
|
|
|
|
// thin enough.
|
|
|
|
return ScrollbarDrawing::GetScrollbarSizes(
|
|
|
|
aPresContext, StyleScrollbarWidth::Auto, aOverlay);
|
2021-09-28 17:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename PaintBackendData>
|
2021-11-15 12:39:38 +00:00
|
|
|
void ScrollbarDrawingAndroid::DoPaintScrollbarThumb(
|
2021-09-28 17:04:34 +00:00
|
|
|
PaintBackendData& aPaintData, const LayoutDeviceRect& aRect,
|
2022-05-09 17:09:24 +00:00
|
|
|
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState& aElementState, const DocumentState& aDocumentState,
|
2021-11-15 12:39:38 +00:00
|
|
|
const Colors& aColors, const DPIRatio& aDpiRatio) {
|
2021-09-28 17:04:34 +00:00
|
|
|
// TODO(emilio): Maybe do like macOS and draw a stroke?
|
2021-10-05 09:40:00 +00:00
|
|
|
const auto color = ComputeScrollbarThumbColor(aFrame, aStyle, aElementState,
|
|
|
|
aDocumentState, aColors);
|
2022-05-09 17:09:24 +00:00
|
|
|
const bool horizontal = aScrollbarKind == ScrollbarKind::Horizontal;
|
2021-09-28 17:04:34 +00:00
|
|
|
|
|
|
|
// Draw the thumb rect centered in the scrollbar.
|
|
|
|
LayoutDeviceRect thumbRect(aRect);
|
2022-05-09 17:09:24 +00:00
|
|
|
if (horizontal) {
|
2021-09-28 17:04:34 +00:00
|
|
|
thumbRect.height *= 0.5f;
|
|
|
|
thumbRect.y += thumbRect.height * 0.5f;
|
|
|
|
} else {
|
|
|
|
thumbRect.width *= 0.5f;
|
|
|
|
thumbRect.x += thumbRect.width * 0.5f;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LayoutDeviceCoord radius =
|
2022-05-09 17:09:24 +00:00
|
|
|
(horizontal ? thumbRect.height : thumbRect.width) / 2.0f;
|
2021-11-15 12:39:38 +00:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, thumbRect, color,
|
|
|
|
sRGBColor::White(0.0f), 0.0f,
|
|
|
|
radius / aDpiRatio, aDpiRatio);
|
2021-09-28 17:04:34 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 12:39:38 +00:00
|
|
|
bool ScrollbarDrawingAndroid::PaintScrollbarThumb(
|
2022-05-10 03:47:37 +00:00
|
|
|
DrawTarget& aDt, const LayoutDeviceRect& aRect,
|
|
|
|
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState& aElementState, const DocumentState& aDocumentState,
|
2021-11-15 12:39:38 +00:00
|
|
|
const Colors& aColors, const DPIRatio& aDpiRatio) {
|
2022-05-10 03:47:37 +00:00
|
|
|
DoPaintScrollbarThumb(aDt, aRect, aScrollbarKind, aFrame, aStyle,
|
|
|
|
aElementState, aDocumentState, aColors, aDpiRatio);
|
2021-09-28 17:04:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-15 12:39:38 +00:00
|
|
|
bool ScrollbarDrawingAndroid::PaintScrollbarThumb(
|
2021-09-28 17:04:34 +00:00
|
|
|
WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect,
|
2022-05-09 17:09:24 +00:00
|
|
|
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState& aElementState, const DocumentState& aDocumentState,
|
2021-11-15 12:39:38 +00:00
|
|
|
const Colors& aColors, const DPIRatio& aDpiRatio) {
|
2022-05-09 17:09:24 +00:00
|
|
|
DoPaintScrollbarThumb(aWrData, aRect, aScrollbarKind, aFrame, aStyle,
|
2021-10-05 09:40:00 +00:00
|
|
|
aElementState, aDocumentState, aColors, aDpiRatio);
|
2021-09-28 17:04:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-11-15 12:39:39 +00:00
|
|
|
|
|
|
|
void ScrollbarDrawingAndroid::RecomputeScrollbarParams() {
|
|
|
|
uint32_t defaultSize = 6;
|
|
|
|
uint32_t overrideSize =
|
|
|
|
StaticPrefs::widget_non_native_theme_scrollbar_size_override();
|
|
|
|
if (overrideSize > 0) {
|
|
|
|
defaultSize = overrideSize;
|
|
|
|
}
|
|
|
|
mHorizontalScrollbarHeight = mVerticalScrollbarWidth = defaultSize;
|
|
|
|
}
|