From 203bf38b210cc2782812ca61ba91f71ac7d149f2 Mon Sep 17 00:00:00 2001 From: David Richardson Date: Thu, 22 Oct 2026 12:36:32 -0600 Subject: [PATCH] AppKit: Size vertical scrollers by scroller style in CPScrollView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CPScrollView's frame and content size calculations sized the vertical scroller with scrollerWidthForControlSize:, passing a scroller style, so it always took the legacy width. * CPScrollView: Use scrollerWidthInStyle: for the vertical scroller in +contentSizeForFrameSize:… and +frameSizeForContentSize:…. * CPScrollViewTest: Add tests for both methods with a scroller whose widths differ by style. --- AppKit/CPScrollView.j | 4 +-- Tests/AppKit/CPScrollViewTest.j | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/AppKit/CPScrollView.j b/AppKit/CPScrollView.j index 45f98d5f0..716d34550 100644 --- a/AppKit/CPScrollView.j +++ b/AppKit/CPScrollView.j @@ -207,7 +207,7 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay, bounds.size.height -= [horizontalScrollerClass scrollerWidthInStyle:scrollerStyle]; if (verticalScrollerClass) - bounds.size.width -= [verticalScrollerClass scrollerWidthForControlSize:scrollerStyle]; + bounds.size.width -= [verticalScrollerClass scrollerWidthInStyle:scrollerStyle]; return bounds.size; } @@ -240,7 +240,7 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay, frameSize.height += [horizontalScrollerClass scrollerWidthInStyle:scrollerStyle]; if (verticalScrollerClass) - frameSize.width += [verticalScrollerClass scrollerWidthForControlSize:scrollerStyle]; + frameSize.width += [verticalScrollerClass scrollerWidthInStyle:scrollerStyle]; return frameSize; } diff --git a/Tests/AppKit/CPScrollViewTest.j b/Tests/AppKit/CPScrollViewTest.j index be937a1c9..15ee3ec5c 100644 --- a/Tests/AppKit/CPScrollViewTest.j +++ b/Tests/AppKit/CPScrollViewTest.j @@ -379,5 +379,48 @@ [self assertSize:expected.size equals:actual.size message:message] } +- (void)testFrameSizeForContentSizeUsesScrollerStyleForBothScrollers +{ + var frameSize = [CPScrollView frameSizeForContentSize:CGSizeMake(100.0, 100.0) + horizontalScrollerClass:[_CPScrollViewTestScroller class] + verticalScrollerClass:[_CPScrollViewTestScroller class] + borderType:CPNoBorder + controlSize:CPRegularControlSize + scrollerStyle:CPScrollerStyleOverlay]; + + [self assertSize:CGSizeMake(105.0, 105.0) equals:frameSize message:@"both scroller widths come from scrollerWidthInStyle:"]; +} + +- (void)testContentSizeForFrameSizeUsesScrollerStyleForBothScrollers +{ + var contentSize = [CPScrollView contentSizeForFrameSize:CGSizeMake(100.0, 100.0) + horizontalScrollerClass:[_CPScrollViewTestScroller class] + verticalScrollerClass:[_CPScrollViewTestScroller class] + borderType:CPNoBorder + controlSize:CPRegularControlSize + scrollerStyle:CPScrollerStyleOverlay]; + + [self assertSize:CGSizeMake(95.0, 95.0) equals:contentSize message:@"both scroller widths come from scrollerWidthInStyle:"]; +} + @end + +/*! + A scroller whose widths differ by style, and whose control-size width differs + from both, so a size calculation that uses the wrong method is detectable + regardless of the theme. +*/ +@implementation _CPScrollViewTestScroller : CPScroller + ++ (float)scrollerWidthInStyle:(CPScrollerStyle)aStyle +{ + return aStyle === CPScrollerStyleOverlay ? 5.0 : 20.0; +} + ++ (float)scrollerWidthForControlSize:(CPControlSize)aControlSize +{ + return 99.0; +} + +@end