Bug 1918802 - Simplify scrollbar track drawing. r=mstange,mac-reviewers

This was caught by Markus. When you hover over an overlay scrollbar on
macOS, you'd hit this the PaintScrollbar() code-path (or rather, you
won't bail out from the if (overlay && !hovered)), but macOS draws the
track in PaintScrollbarTrack().

Android doesn't hit this because android scrollbars can't ever be
hovered (they have pointer-events: none). This is a better fix than
D222172, which didn't paint the background for the non-overlay
scrollbars...

This doesn't change behavior since scrollbar and the track have the same
size (as cocoa scrollbars can never have buttons). Removing
nsSliderFrame is a refactor for another day if ever.

Differential Revision: https://phabricator.services.mozilla.com/D222194
This commit is contained in:
Emilio Cobos Álvarez 2024-09-17 15:59:43 +00:00
parent 2fcdf37091
commit bb17d77850
8 changed files with 51 additions and 91 deletions

View File

@ -176,15 +176,6 @@ scrollbar[root] {
}
}
slider {
appearance: auto;
-moz-default-appearance: scrollbartrack-horizontal;
}
slider[orient="vertical"] {
-moz-default-appearance: scrollbartrack-vertical;
}
scrollbarbutton {
appearance: auto;
-moz-default-appearance: scrollbarbutton-right;

View File

@ -1534,11 +1534,6 @@ pub enum Appearance {
ScrollbarthumbHorizontal,
#[parse(condition = "ParserContext::chrome_rules_enabled")]
ScrollbarthumbVertical,
/// The scrollbar track.
#[parse(condition = "ParserContext::chrome_rules_enabled")]
ScrollbartrackHorizontal,
#[parse(condition = "ParserContext::chrome_rules_enabled")]
ScrollbartrackVertical,
/// The scroll corner
#[parse(condition = "ParserContext::chrome_rules_enabled")]
Scrollcorner,

View File

@ -120,7 +120,7 @@ bool ScrollbarDrawing::IsScrollbarTrackOpaque(nsIFrame* aFrame) {
auto trackColor = ComputeScrollbarTrackColor(
aFrame, *nsLayoutUtils::StyleForScrollbar(aFrame),
aFrame->PresContext()->Document()->State(),
Colors(aFrame, StyleAppearance::ScrollbartrackVertical));
Colors(aFrame, StyleAppearance::ScrollbarVertical));
return trackColor.a == 1.0f;
}

View File

@ -110,29 +110,14 @@ class ScrollbarDrawing {
ScrollbarKind, nsIFrame*, const ComputedStyle&,
const ElementState&, const DocumentState&,
const Colors&, const DPIRatio&);
bool PaintScrollbar(DrawTarget&, const LayoutDeviceRect&, ScrollbarKind,
nsIFrame*, const ComputedStyle&, const ElementState&,
const DocumentState&, const Colors&, const DPIRatio&);
bool PaintScrollbar(WebRenderBackendData&, const LayoutDeviceRect&,
ScrollbarKind, nsIFrame*, const ComputedStyle&,
const ElementState&, const DocumentState&, const Colors&,
const DPIRatio&);
virtual bool PaintScrollbarTrack(DrawTarget&, const LayoutDeviceRect&,
ScrollbarKind, nsIFrame*,
const ComputedStyle&, const DocumentState&,
const Colors&, const DPIRatio&) {
// Draw nothing by default. Subclasses can override this.
return true;
}
virtual bool PaintScrollbarTrack(WebRenderBackendData&,
const LayoutDeviceRect&, ScrollbarKind,
nsIFrame*, const ComputedStyle&,
const DocumentState&, const Colors&,
const DPIRatio&) {
// Draw nothing by default. Subclasses can override this.
return true;
}
virtual bool PaintScrollbar(DrawTarget&, const LayoutDeviceRect&,
ScrollbarKind, nsIFrame*, const ComputedStyle&,
const ElementState&, const DocumentState&,
const Colors&, const DPIRatio&);
virtual bool PaintScrollbar(WebRenderBackendData&, const LayoutDeviceRect&,
ScrollbarKind, nsIFrame*, const ComputedStyle&,
const ElementState&, const DocumentState&,
const Colors&, const DPIRatio&);
template <typename PaintBackendData>
bool DoPaintDefaultScrollCorner(PaintBackendData&, const LayoutDeviceRect&,

View File

@ -83,9 +83,7 @@ LayoutDeviceIntSize ScrollbarDrawingCocoa::GetMinimumWidgetSize(
case StyleAppearance::ScrollbarthumbVertical:
return {0, 26};
case StyleAppearance::ScrollbarVertical:
case StyleAppearance::ScrollbarHorizontal:
case StyleAppearance::ScrollbartrackVertical:
case StyleAppearance::ScrollbartrackHorizontal: {
case StyleAppearance::ScrollbarHorizontal: {
ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame);
auto scrollbarWidth = style->StyleUIReset()->ScrollbarWidth();
auto size = GetCSSScrollbarSize(
@ -212,11 +210,6 @@ static ScrollbarTrackDecorationColors ComputeScrollbarTrackDecorationColors(
static bool GetScrollbarTrackRects(const LayoutDeviceRect& aRect,
const ScrollbarParams& aParams, float aScale,
ScrollbarTrackRects& aRects) {
if (aParams.isOverlay && !aParams.isRolledOver) {
// Non-hovered overlay scrollbars don't have a track. Draw nothing.
return false;
}
nscolor trackColor;
if (aParams.isCustom) {
trackColor = aParams.trackColor;
@ -388,39 +381,49 @@ bool ScrollbarDrawingCocoa::PaintScrollbarThumb(
}
template <typename PaintBackendData>
void ScrollbarDrawingCocoa::DoPaintScrollbarTrack(
void ScrollbarDrawingCocoa::DoPaintScrollbar(
PaintBackendData& aPaintData, const LayoutDeviceRect& aRect,
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
const DocumentState& aDocumentState, const Colors& aColors,
const DPIRatio& aDpiRatio) {
const ElementState& aElementState, const DocumentState& aDocumentState,
const Colors& aColors, const DPIRatio& aDpiRatio) {
ScrollbarParams params =
ComputeScrollbarParams(aFrame, aStyle, aColors, aScrollbarKind);
if (params.isOverlay && !params.isRolledOver) {
// Non-hovered overlay scrollbars don't have a track. Draw nothing.
return;
}
// Paint our track.
const auto color =
ComputeScrollbarTrackColor(aFrame, aStyle, aDocumentState, aColors);
ThemeDrawing::FillRect(aPaintData, aRect, color);
// Paint our decorations.
ScrollbarTrackRects rects;
if (GetScrollbarTrackRects(aRect, params, aDpiRatio.scale, rects)) {
for (const auto& rect : rects) {
ThemeDrawing::FillRect(aPaintData, rect.mRect,
sRGBColor::FromABGR(rect.mColor));
}
GetScrollbarTrackRects(aRect, params, aDpiRatio.scale, rects);
for (const auto& rect : rects) {
ThemeDrawing::FillRect(aPaintData, rect.mRect,
sRGBColor::FromABGR(rect.mColor));
}
}
bool ScrollbarDrawingCocoa::PaintScrollbarTrack(
DrawTarget& aDt, const LayoutDeviceRect& aRect,
bool ScrollbarDrawingCocoa::PaintScrollbar(
DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect,
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
const DocumentState& aDocumentState, const Colors& aColors,
const DPIRatio& aDpiRatio) {
DoPaintScrollbarTrack(aDt, aRect, aScrollbarKind, aFrame, aStyle,
aDocumentState, aColors, aDpiRatio);
const ElementState& aElementState, const DocumentState& aDocumentState,
const Colors& aColors, const DPIRatio& aDpiRatio) {
DoPaintScrollbar(aDrawTarget, aRect, aScrollbarKind, aFrame, aStyle,
aElementState, aDocumentState, aColors, aDpiRatio);
return true;
}
bool ScrollbarDrawingCocoa::PaintScrollbarTrack(
bool ScrollbarDrawingCocoa::PaintScrollbar(
WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect,
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
const DocumentState& aDocumentState, const Colors& aColors,
const DPIRatio& aDpiRatio) {
DoPaintScrollbarTrack(aWrData, aRect, aScrollbarKind, aFrame, aStyle,
aDocumentState, aColors, aDpiRatio);
const ElementState& aElementState, const DocumentState& aDocumentState,
const Colors& aColors, const DPIRatio& aDpiRatio) {
DoPaintScrollbar(aWrData, aRect, aScrollbarKind, aFrame, aStyle,
aElementState, aDocumentState, aColors, aDpiRatio);
return true;
}

View File

@ -40,18 +40,18 @@ class ScrollbarDrawingCocoa final : public ScrollbarDrawing {
const Colors&, const DPIRatio&) override;
template <typename PaintBackendData>
void DoPaintScrollbarTrack(PaintBackendData&, const LayoutDeviceRect&,
ScrollbarKind, nsIFrame*, const ComputedStyle&,
const DocumentState&, const Colors&,
const DPIRatio&);
bool PaintScrollbarTrack(DrawTarget&, const LayoutDeviceRect& aRect,
ScrollbarKind, nsIFrame* aFrame,
const ComputedStyle& aStyle, const DocumentState&,
const Colors&, const DPIRatio&) override;
bool PaintScrollbarTrack(WebRenderBackendData&, const LayoutDeviceRect& aRect,
ScrollbarKind, nsIFrame* aFrame,
const ComputedStyle& aStyle, const DocumentState&,
const Colors&, const DPIRatio&) override;
void DoPaintScrollbar(PaintBackendData&, const LayoutDeviceRect&,
ScrollbarKind, nsIFrame*, const ComputedStyle&,
const ElementState&, const DocumentState&,
const Colors&, const DPIRatio&);
bool PaintScrollbar(DrawTarget&, const LayoutDeviceRect&, ScrollbarKind,
nsIFrame*, const ComputedStyle&, const ElementState&,
const DocumentState&, const Colors&,
const DPIRatio&) override;
bool PaintScrollbar(WebRenderBackendData&, const LayoutDeviceRect&,
ScrollbarKind, nsIFrame*, const ComputedStyle&,
const ElementState&, const DocumentState&, const Colors&,
const DPIRatio&) override;
template <typename PaintBackendData>
void DoPaintScrollCorner(PaintBackendData&, const LayoutDeviceRect&,

View File

@ -1310,16 +1310,6 @@ bool Theme::DoDrawWidgetBackground(PaintBackendData& aPaintData,
*nsLayoutUtils::StyleForScrollbar(aFrame), elementState, docState,
colors, dpiRatio);
}
case StyleAppearance::ScrollbartrackHorizontal:
case StyleAppearance::ScrollbartrackVertical: {
bool isHorizontal =
aAppearance == StyleAppearance::ScrollbartrackHorizontal;
auto kind = ComputeScrollbarKind(aFrame, isHorizontal);
return GetScrollbarDrawing().PaintScrollbarTrack(
aPaintData, devPxRect, kind, aFrame,
*nsLayoutUtils::StyleForScrollbar(aFrame), docState, colors,
dpiRatio);
}
case StyleAppearance::ScrollbarHorizontal:
case StyleAppearance::ScrollbarVertical: {
bool isHorizontal = aAppearance == StyleAppearance::ScrollbarHorizontal;
@ -1678,8 +1668,6 @@ bool Theme::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFrame,
case StyleAppearance::ScrollbarbuttonRight:
case StyleAppearance::ScrollbarthumbHorizontal:
case StyleAppearance::ScrollbarthumbVertical:
case StyleAppearance::ScrollbartrackHorizontal:
case StyleAppearance::ScrollbartrackVertical:
case StyleAppearance::ScrollbarHorizontal:
case StyleAppearance::ScrollbarVertical:
case StyleAppearance::Scrollcorner:

View File

@ -569,8 +569,6 @@ bool nsNativeTheme::IsWidgetScrollbarPart(StyleAppearance aAppearance) {
case StyleAppearance::ScrollbarbuttonRight:
case StyleAppearance::ScrollbarthumbVertical:
case StyleAppearance::ScrollbarthumbHorizontal:
case StyleAppearance::ScrollbartrackHorizontal:
case StyleAppearance::ScrollbartrackVertical:
case StyleAppearance::Scrollcorner:
return true;
default: