mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 01:42:03 +00:00
Fixes #1450: a scroll view with non hiding legacy scrollbars would crash if the document view had a size of 0 pixels in either dimension.
This commit is contained in:
1 parent
c9d4089b9a
commit
fe70a5541e
2 files changed
+21
-2
No files matched your search
@@ -1138,8 +1138,9 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
|
||||
if (_scrollerStyle === CPScrollerStyleOverlay && hasHorizontalScroll)
|
||||
verticalScrollerHeight -= horizontalScrollerHeight;
|
||||
|
||||
var documentHeight = _CGRectGetHeight(documentFrame);
|
||||
[_verticalScroller setFloatValue:(difference.height <= 0.0) ? 0.0 : scrollPoint.y / difference.height];
|
||||
[_verticalScroller setKnobProportion:_CGRectGetHeight(contentFrame) / _CGRectGetHeight(documentFrame)];
|
||||
[_verticalScroller setKnobProportion:documentHeight > 0 ? _CGRectGetHeight(contentFrame) / documentHeight : 1.0];
|
||||
[_verticalScroller setFrame:_CGRectMake(_CGRectGetMaxX(contentFrame) - overlay, verticalScrollerY, verticalScrollerWidth, verticalScrollerHeight)];
|
||||
}
|
||||
else if (wasShowingVerticalScroller)
|
||||
@@ -1155,8 +1156,10 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
|
||||
if (_scrollerStyle === CPScrollerStyleOverlay && hasVerticalScroll)
|
||||
horizontalScrollerWidth -= verticalScrollerWidth;
|
||||
|
||||
var documentWidth = _CGRectGetWidth(documentFrame);
|
||||
|
||||
[_horizontalScroller setFloatValue:(difference.width <= 0.0) ? 0.0 : scrollPoint.x / difference.width];
|
||||
[_horizontalScroller setKnobProportion:_CGRectGetWidth(contentFrame) / _CGRectGetWidth(documentFrame)];
|
||||
[_horizontalScroller setKnobProportion:documentWidth > 0 ? _CGRectGetWidth(contentFrame) / documentWidth : 1.0];
|
||||
[_horizontalScroller setFrame:_CGRectMake(_CGRectGetMinX(contentFrame), _CGRectGetMaxY(contentFrame) - overlay, horizontalScrollerWidth, horizontalScrollerHeight)];
|
||||
}
|
||||
else if (wasShowingHorizontalScroller)
|
||||
|
||||
@@ -4,6 +4,21 @@
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
Test that scroll views don't generate bad layouts when very small.
|
||||
*/
|
||||
- (void)testZeroSize
|
||||
{
|
||||
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMakeZero()],
|
||||
documentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
|
||||
[scrollView setAutohidesScrollers:NO];
|
||||
[scrollView setDocumentView:documentView];
|
||||
[scrollView setScrollerStyle:CPScrollerStyleLegacy];
|
||||
// If the layout operation leads to setKnobProportion:0/0 this will crash.
|
||||
[[scrollView horizontalScroller] layoutSubviews];
|
||||
[[scrollView verticalScroller] layoutSubviews];
|
||||
}
|
||||
|
||||
- (void)testBothScrollersVisible
|
||||
{
|
||||
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
|
||||
@@ -200,3 +215,4 @@
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in new issue
Block a user