Issue #1705 - Part 9: Implement scrollbar-width:thin on Mac (cocoa).

This commit is contained in:
Moonchild 2021-01-09 23:21:36 +00:00 • committed by roytam1
commit b523c3be80

View file

@ -2279,6 +2279,12 @@ IsHiDPIContext(nsPresContext* aContext)
2 * aContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom(); 2 * aContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
} }
static bool
IsScrollbarWidthThin(nsIFrame* aFrame)
{
return aFrame->StyleUserInterface()->mScrollbarWidth == StyleScrollbarWidth::Thin;
}
NS_IMETHODIMP NS_IMETHODIMP
nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext, nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
nsIFrame* aFrame, nsIFrame* aFrame,
@ -3392,13 +3398,24 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
// Find our parent scrollbar frame in order to find out whether we're in // Find our parent scrollbar frame in order to find out whether we're in
// a small or a large scrollbar. // a small or a large scrollbar.
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame); nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
if (!scrollbarFrame) if (!scrollbarFrame) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
}
bool isSmall = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL); bool isSmall = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL);
bool isHorizontal = (aWidgetType == NS_THEME_SCROLLBARTHUMB_HORIZONTAL); bool isHorizontal = (aWidgetType == NS_THEME_SCROLLBARTHUMB_HORIZONTAL);
int32_t& minSize = isHorizontal ? aResult->width : aResult->height; int32_t& minSize = isSmall ? kSmallScrollbarThumbMinSize : kRegularScrollbarThumbMinSize;
minSize = isSmall ? kSmallScrollbarThumbMinSize : kRegularScrollbarThumbMinSize; if (IsScrollbarWidthThin(aFrame)) {
minSize /= 2;
}
if (isHorizontal) {
aResult->width = kRegularScrollbarThumbMinSize;
aResult->height = minSize;
} else {
aResult->width = minSize;
aResult->height = kRegularScrollbarThumbMinSize;
}
break; break;
} }
@ -3419,6 +3436,9 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
else { else {
aResult->SizeTo(16, 16); aResult->SizeTo(16, 16);
} }
if (IsScrollbarWidthThin(aFrame)) {
aResult->SizeTo(8, 8);
}
break; break;
} }
@ -3435,6 +3455,9 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
kThemeMetricScrollBarWidth; kThemeMetricScrollBarWidth;
SInt32 scrollbarWidth = 0; SInt32 scrollbarWidth = 0;
::GetThemeMetric(themeMetric, &scrollbarWidth); ::GetThemeMetric(themeMetric, &scrollbarWidth);
if (IsScrollbarWidthThin(aFrame)) {
scrollbarWidth /= 2;
}
aResult->SizeTo(scrollbarWidth, scrollbarWidth); aResult->SizeTo(scrollbarWidth, scrollbarWidth);
break; break;
} }
@ -3467,22 +3490,26 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
case NS_THEME_SCROLLBARBUTTON_LEFT: case NS_THEME_SCROLLBARBUTTON_LEFT:
case NS_THEME_SCROLLBARBUTTON_RIGHT: case NS_THEME_SCROLLBARBUTTON_RIGHT:
{ {
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame); if (!IsScrollbarWidthThin(aFrame)) {
if (!scrollbarFrame) return NS_ERROR_FAILURE; // Get scrollbar button metrics from the system, except in the case of
// thin scrollbars, where we leave them at 0 (collapse)
// Since there is no NS_THEME_SCROLLBARBUTTON_UP_SMALL we need to ask the parent what appearance style it has. nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
int32_t themeMetric = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL) ? if (!scrollbarFrame) return NS_ERROR_FAILURE;
kThemeMetricSmallScrollBarWidth :
kThemeMetricScrollBarWidth;
SInt32 scrollbarWidth = 0;
::GetThemeMetric(themeMetric, &scrollbarWidth);
// It seems that for both sizes of scrollbar, the buttons are one pixel "longer". // Since there is no NS_THEME_SCROLLBARBUTTON_UP_SMALL we need to ask the parent what appearance style it has.
if (aWidgetType == NS_THEME_SCROLLBARBUTTON_LEFT || aWidgetType == NS_THEME_SCROLLBARBUTTON_RIGHT) int32_t themeMetric = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL) ?
aResult->SizeTo(scrollbarWidth+1, scrollbarWidth); kThemeMetricSmallScrollBarWidth :
else kThemeMetricScrollBarWidth;
aResult->SizeTo(scrollbarWidth, scrollbarWidth+1); SInt32 scrollbarWidth = 0;
::GetThemeMetric(themeMetric, &scrollbarWidth);
// It seems that for both sizes of scrollbar, the buttons are one pixel "longer".
if (aWidgetType == NS_THEME_SCROLLBARBUTTON_LEFT || aWidgetType == NS_THEME_SCROLLBARBUTTON_RIGHT)
aResult->SizeTo(scrollbarWidth+1, scrollbarWidth);
else
aResult->SizeTo(scrollbarWidth, scrollbarWidth+1);
}
*aIsOverridable = false; *aIsOverridable = false;
break; break;
} }