mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-23 16:48:53 +00:00
AppKit: Size vertical scrollers by scroller style in CPScrollView
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.
This commit is contained in:
1 parent
99b47c9a29
commit
203bf38b21
2 files changed
+45
-2
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user