From 4d39466f147d25f2094de5f3cb2c8ac4976365e9 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Mon, 6 Oct 2008 17:37:27 -0700 Subject: [PATCH] Fix for CPScrollView performance issue. [#93 state:resolved] Reviewed by ross. --- AppKit/CPClipView.j | 21 +++++++++++++++------ AppKit/CPScrollView.j | 24 ------------------------ 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/AppKit/CPClipView.j b/AppKit/CPClipView.j index 979dd6b4f..a8977f2ac 100644 --- a/AppKit/CPClipView.j +++ b/AppKit/CPClipView.j @@ -137,10 +137,7 @@ import "CPView.j" */ - (void)viewBoundsChanged:(CPNotification)aNotification { - var superview = [self superview]; - - if([superview isKindOfClass:[CPScrollView class]]) - [superview reflectScrolledClipView:self]; + [self viewFrameChanged:aNotification]; } /* @@ -149,9 +146,21 @@ import "CPView.j" */ - (void)viewFrameChanged:(CPNotification)aNotification { - var superview = [self superview]; + var oldScrollPoint = [self bounds].origin; + + // Call scrollToPoint: because the current scroll point may no longer make + // sense given the new frame of the document view. + [self scrollToPoint:oldScrollPoint]; + + // scrollToPoint: takes care of reflectScrollClipView: for us, so bail if + // the scroll points are not equal (meaning scrollToPoint: didn't early bail). + if (!CGPointEqualToPoint(oldScrollPoint, [self bounds].origin)) + return; - if([superview isKindOfClass:[CPScrollView class]]) + // ... and we're in a scroll view of course. + var superview = [self superview]; + + if ([superview isKindOfClass:[CPScrollView class]]) [superview reflectScrolledClipView:self]; } diff --git a/AppKit/CPScrollView.j b/AppKit/CPScrollView.j index e03543076..7ba13f4df 100644 --- a/AppKit/CPScrollView.j +++ b/AppKit/CPScrollView.j @@ -227,30 +227,6 @@ import "CPScroller.j" [_contentView setFrame:contentViewFrame]; - // The reason we have to do this is because this is called on a frame size change, so when the frame changes, - // so does the the float value, so we have to update the clip view accordingly. - if (_hasVerticalScroller && (shouldShowVerticalScroller || wasShowingVerticalScroller)) - { - //[self _verticalScrollerDidScroll:_verticalScroller]; - var value = [_verticalScroller floatValue], - contentBounds = [_contentView bounds]; - - contentBounds.origin.y = value * (_CGRectGetHeight([documentView frame]) - _CGRectGetHeight(contentBounds)); - - [_contentView scrollToPoint:contentBounds.origin]; - } - if (_hasHorizontalScroller && (shouldShowHorizontalScroller || wasShowingHorizontalScroller)) - { - //[self _horizontalScrollerDidScroll:_horizontalScroller]; - - var value = [_horizontalScroller floatValue], - contentBounds = [_contentView bounds]; - - contentBounds.origin.x = value * (_CGRectGetWidth([documentView frame]) - _CGRectGetWidth(contentBounds)); - - [_contentView scrollToPoint:contentBounds.origin]; - } - --_recursionCount; }