summaryrefslogtreecommitdiff
path: root/widget/cocoa
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2021-01-09 23:21:36 +0000
committerMoonchild <moonchild@palemoon.org>2021-01-09 23:21:36 +0000
commit59ef3f4eda3c4959dc4a7cf48f59c1f3dfbc2757 (patch)
treef4798c9ce4be71583229ac03ef5c337901a962ca /widget/cocoa
parentecc771848fe6e1f400b5c3622cf87a4e476950c6 (diff)
downloaduxp-59ef3f4eda3c4959dc4a7cf48f59c1f3dfbc2757.tar.gz
Issue #1705 - Part 9: Implement scrollbar-width:thin on Mac (cocoa).
Diffstat (limited to 'widget/cocoa')
-rw-r--r--widget/cocoa/nsNativeThemeCocoa.mm67
1 files changed, 47 insertions, 20 deletions
diff --git a/widget/cocoa/nsNativeThemeCocoa.mm b/widget/cocoa/nsNativeThemeCocoa.mm
index f93e40f7b5..ce87d1996c 100644
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -2279,6 +2279,12 @@ IsHiDPIContext(nsPresContext* aContext)
2 * aContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
}
+static bool
+IsScrollbarWidthThin(nsIFrame* aFrame)
+{
+ return aFrame->StyleUserInterface()->mScrollbarWidth == StyleScrollbarWidth::Thin;
+}
+
NS_IMETHODIMP
nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
nsIFrame* aFrame,
@@ -3392,13 +3398,24 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
// Find our parent scrollbar frame in order to find out whether we're in
// a small or a large scrollbar.
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
- if (!scrollbarFrame)
+ if (!scrollbarFrame) {
return NS_ERROR_FAILURE;
-
+ }
+
bool isSmall = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL);
bool isHorizontal = (aWidgetType == NS_THEME_SCROLLBARTHUMB_HORIZONTAL);
- int32_t& minSize = isHorizontal ? aResult->width : aResult->height;
- minSize = isSmall ? kSmallScrollbarThumbMinSize : kRegularScrollbarThumbMinSize;
+ int32_t& 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;
}
@@ -3419,6 +3436,9 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
else {
aResult->SizeTo(16, 16);
}
+ if (IsScrollbarWidthThin(aFrame)) {
+ aResult->SizeTo(8, 8);
+ }
break;
}
@@ -3435,6 +3455,9 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
kThemeMetricScrollBarWidth;
SInt32 scrollbarWidth = 0;
::GetThemeMetric(themeMetric, &scrollbarWidth);
+ if (IsScrollbarWidthThin(aFrame)) {
+ scrollbarWidth /= 2;
+ }
aResult->SizeTo(scrollbarWidth, scrollbarWidth);
break;
}
@@ -3467,22 +3490,26 @@ nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
case NS_THEME_SCROLLBARBUTTON_LEFT:
case NS_THEME_SCROLLBARBUTTON_RIGHT:
{
- nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
- if (!scrollbarFrame) return NS_ERROR_FAILURE;
-
- // Since there is no NS_THEME_SCROLLBARBUTTON_UP_SMALL we need to ask the parent what appearance style it has.
- int32_t themeMetric = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL) ?
- kThemeMetricSmallScrollBarWidth :
- kThemeMetricScrollBarWidth;
- 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);
-
+ if (!IsScrollbarWidthThin(aFrame)) {
+ // Get scrollbar button metrics from the system, except in the case of
+ // thin scrollbars, where we leave them at 0 (collapse)
+
+ nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
+ if (!scrollbarFrame) return NS_ERROR_FAILURE;
+
+ // Since there is no NS_THEME_SCROLLBARBUTTON_UP_SMALL we need to ask the parent what appearance style it has.
+ int32_t themeMetric = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL) ?
+ kThemeMetricSmallScrollBarWidth :
+ kThemeMetricScrollBarWidth;
+ 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;
break;
}