Bug 1671704 - Unify some calls to ComputeScrollbarParams and call nsLayoutUtils::StyleForScrollbar in the caller. r=spohl

Differential Revision: https://phabricator.services.mozilla.com/D95076
This commit is contained in:
Markus Stange 2020-11-02 17:08:56 +00:00
parent 30cc69eb90
commit aa21c0548f
3 changed files with 29 additions and 19 deletions

View File

@ -91,26 +91,25 @@ LayoutDeviceIntSize ScrollbarDrawingMac::GetMinimumWidgetSize(
}
ScrollbarParams ScrollbarDrawingMac::ComputeScrollbarParams(
nsIFrame* aFrame, bool aIsHorizontal) {
ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame);
nsIFrame* aFrame, const ComputedStyle& aStyle, bool aIsHorizontal) {
ScrollbarParams params;
params.overlay =
nsLookAndFeel::GetInt(LookAndFeel::IntID::UseOverlayScrollbars) != 0;
params.rolledOver = IsParentScrollbarRolledOver(aFrame);
params.small =
style->StyleUIReset()->mScrollbarWidth == StyleScrollbarWidth::Thin;
aStyle.StyleUIReset()->mScrollbarWidth == StyleScrollbarWidth::Thin;
params.rtl = nsNativeTheme::IsFrameRTL(aFrame);
params.horizontal = aIsHorizontal;
params.onDarkBackground = nsNativeTheme::IsDarkBackground(aFrame);
// Don't use custom scrollbars for overlay scrollbars since they are
// generally good enough for use cases of custom scrollbars.
if (!params.overlay) {
const nsStyleUI* ui = style->StyleUI();
const nsStyleUI* ui = aStyle.StyleUI();
if (ui->HasCustomScrollbars()) {
const auto& colors = ui->mScrollbarColor.AsColors();
params.custom = true;
params.trackColor = colors.track.CalcColor(*style);
params.faceColor = colors.thumb.CalcColor(*style);
params.trackColor = colors.track.CalcColor(aStyle);
params.faceColor = colors.thumb.CalcColor(aStyle);
}
}

View File

@ -33,6 +33,7 @@ class ScrollbarDrawingMac final {
nsIFrame* aFrame,
float aDpiRatio);
static ScrollbarParams ComputeScrollbarParams(nsIFrame* aFrame,
const ComputedStyle& aStyle,
bool aIsHorizontal);
static void DrawScrollbarThumb(gfx::DrawTarget& aDT, const gfx::Rect& aRect,
const ScrollbarParams& aParams);

View File

@ -2706,26 +2706,35 @@ Maybe<nsNativeThemeCocoa::WidgetInfo> nsNativeThemeCocoa::ComputeWidgetInfo(
case StyleAppearance::ScrollbarHorizontal:
case StyleAppearance::ScrollbarVertical:
break;
case StyleAppearance::ScrollbarthumbVertical:
case StyleAppearance::ScrollbarthumbHorizontal:
return Some(WidgetInfo::ScrollbarThumb(ScrollbarDrawingMac::ComputeScrollbarParams(
aFrame, aAppearance == StyleAppearance::ScrollbarthumbHorizontal)));
case StyleAppearance::ScrollbarbuttonUp:
case StyleAppearance::ScrollbarbuttonLeft:
case StyleAppearance::ScrollbarbuttonDown:
case StyleAppearance::ScrollbarbuttonRight:
break;
case StyleAppearance::ScrollbarthumbVertical:
case StyleAppearance::ScrollbarthumbHorizontal:
case StyleAppearance::ScrollbartrackHorizontal:
case StyleAppearance::ScrollbartrackVertical:
return Some(WidgetInfo::ScrollbarTrack(ScrollbarDrawingMac::ComputeScrollbarParams(
aFrame, aAppearance == StyleAppearance::ScrollbartrackHorizontal)));
case StyleAppearance::Scrollcorner:
return Some(
WidgetInfo::ScrollCorner(ScrollbarDrawingMac::ComputeScrollbarParams(aFrame, false)));
case StyleAppearance::Scrollcorner: {
bool isHorizontal = aAppearance == StyleAppearance::ScrollbarthumbHorizontal ||
aAppearance == StyleAppearance::ScrollbartrackHorizontal;
ScrollbarParams params = ScrollbarDrawingMac::ComputeScrollbarParams(
aFrame, *nsLayoutUtils::StyleForScrollbar(aFrame), isHorizontal);
switch (aAppearance) {
case StyleAppearance::ScrollbarthumbVertical:
case StyleAppearance::ScrollbarthumbHorizontal:
return Some(WidgetInfo::ScrollbarThumb(params));
case StyleAppearance::ScrollbartrackHorizontal:
case StyleAppearance::ScrollbartrackVertical:
return Some(WidgetInfo::ScrollbarTrack(params));
case StyleAppearance::Scrollcorner:
return Some(WidgetInfo::ScrollCorner(params));
default:
MOZ_CRASH("unexpected aAppearance");
}
break;
}
case StyleAppearance::Textarea:
return Some(WidgetInfo::MultilineTextField(eventState.HasState(NS_EVENT_STATE_FOCUS)));
@ -3092,8 +3101,9 @@ bool nsNativeThemeCocoa::CreateWebRenderCommandsForWidget(
case StyleAppearance::Scrollcorner:
case StyleAppearance::ScrollbartrackHorizontal:
case StyleAppearance::ScrollbartrackVertical: {
const ComputedStyle& style = *nsLayoutUtils::StyleForScrollbar(aFrame);
ScrollbarParams params = ScrollbarDrawingMac::ComputeScrollbarParams(
aFrame, aAppearance == StyleAppearance::ScrollbartrackHorizontal);
aFrame, style, aAppearance == StyleAppearance::ScrollbartrackHorizontal);
if (params.overlay && !params.rolledOver) {
// There is no scrollbar track, draw nothing and return true.
return true;