Changeset 3606

Show
Ignore:
Timestamp:
03/09/07 03:07:48 (2 years ago)
Author:
timothy
Message:

Fixes the scrollbar jumping to the top of the transcript when scrolled in the middle. Also prevents removing messages from the top when you are scrolled. Other clean up

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Resources/Styles/Bland.colloquyStyle/Contents/Resources/genericTemplate.html

    r3372 r3606  
    1717        bottomAlignChat(); 
    1818</script> 
     19<div id="contents"></div> 
  • trunk/Resources/Styles/Fiat.colloquyStyle/Contents/Resources/genericTemplate.html

    r3370 r3606  
    44        } 
    55</script> 
     6<div id="contents"></div> 
  • trunk/Resources/Styles/Standard.colloquyStyle/Contents/Resources/genericTemplate.html

    r3375 r3606  
    3737        } 
    3838</script> 
     39<div id="contents"></div> 
  • trunk/Resources/template.html

    r3560 r3606  
    1515        <base href="%@" /> 
    1616</head> 
    17 <body> 
    18 %@ 
    19 </body> 
     17<body>%@</body> 
    2018</html> 
  • trunk/Views/JVStyleView.m

    r3605 r3606  
    2828@end 
    2929 
     30#pragma mark - 
     31 
    3032@interface WebView (WebViewPrivate) 
    3133- (WebFrame *) _frameForCurrentSelection; 
    3234@end 
     35 
     36#pragma mark - 
    3337 
    3438@interface DOMHTMLElement (DOMHTMLElementLeopard) 
     
    4246@interface NSScrollView (NSScrollViewWebKitPrivate) 
    4347- (void) setAllowsHorizontalScrolling:(BOOL) allow; 
     48@end 
     49 
     50#pragma mark - 
     51 
     52@interface DOMHTMLElement (DOMHTMLElementExtras) 
     53- (unsigned) childElementLength; 
     54- (DOMNode *) childElementAtIndex:(unsigned) index; 
     55@end 
     56 
     57#pragma mark - 
     58 
     59@implementation DOMHTMLElement (DOMHTMLElementExtras) 
     60- (unsigned) childElementLength { 
     61        unsigned length = 0; 
     62 
     63        DOMNode *node = [self firstChild]; 
     64        while (node) { 
     65                if( [node nodeType] == DOM_ELEMENT_NODE ) ++length; 
     66                node = [node nextSibling]; 
     67        } 
     68 
     69        return length; 
     70} 
     71 
     72- (DOMNode *) childElementAtIndex:(unsigned) index { 
     73        unsigned count = 0; 
     74        DOMNode *node = [self firstChild]; 
     75        while (node) { 
     76                if( [node nodeType] == DOM_ELEMENT_NODE && count++ == index ) 
     77                        return node; 
     78                node = [node nextSibling]; 
     79        } 
     80 
     81        return nil; 
     82} 
    4483@end 
    4584 
     
    589628                long shift = [scroller shiftAmountToCenterAlign]; 
    590629                [scroller setLocationOfCurrentMark:loc]; 
    591                 [_body setValue:[NSNumber numberWithUnsignedLong:( loc - shift )] forKey:@"scrollTop"]; 
     630                [[_domDocument body] setValue:[NSNumber numberWithUnsignedLong:( loc - shift )] forKey:@"scrollTop"]; 
    592631        } 
    593632} 
     
    599638        } 
    600639 
    601         if( [_body respondsToSelector:@selector( scrollHeight )] ) 
    602                 [_body setValue:[NSNumber numberWithUnsignedInt:[_body scrollHeight]] forKey:@"scrollTop"]; 
    603         else [_body setValue:[_body valueForKey:@"scrollHeight"] forKey:@"scrollTop"]; 
     640        DOMHTMLElement *body = [_domDocument body]; 
     641        if( [body respondsToSelector:@selector( scrollHeight )] ) 
     642                [body setValue:[NSNumber numberWithUnsignedInt:[body scrollHeight]] forKey:@"scrollTop"]; 
     643        else [body setValue:[body valueForKey:@"scrollHeight"] forKey:@"scrollTop"]; 
    604644} 
    605645 
     
    613653 
    614654        unsigned int scrollHeight = 0; 
    615         if( [_body respondsToSelector:@selector( scrollHeight )] ) 
    616                 scrollHeight = [_body scrollHeight]; 
    617         else scrollHeight = [[_body valueForKey:@"scrollHeight"] unsignedIntValue]; 
    618  
    619         unsigned int scrollTop = [[_body valueForKey:@"scrollTop"] unsignedIntValue]; 
     655        DOMHTMLElement *body = [_domDocument body]; 
     656        if( [body respondsToSelector:@selector( scrollHeight )] ) 
     657                scrollHeight = [body scrollHeight]; 
     658        else scrollHeight = [[body valueForKey:@"scrollHeight"] unsignedIntValue]; 
     659 
     660        unsigned int scrollTop = [[body valueForKey:@"scrollTop"] unsignedIntValue]; 
    620661 
    621662        // check if we are near the bottom 10 pixels of the chat area 
     
    661702        _contentFrameReady = NO; 
    662703        if( _rememberScrollPosition ) { 
    663                 _lastScrollPosition = [[_body valueForKey:@"scrollTop"] longValue]; 
     704                _lastScrollPosition = [[[_domDocument body] valueForKey:@"scrollTop"] longValue]; 
    664705        } else _lastScrollPosition = 0; 
    665706 
     
    736777        if( _rememberScrollPosition ) { 
    737778                _rememberScrollPosition = NO; 
    738                 [_body setValue:[NSNumber numberWithUnsignedLong:_lastScrollPosition] forKey:@"scrollTop"]; 
     779                [[_domDocument body] setValue:[NSNumber numberWithUnsignedLong:_lastScrollPosition] forKey:@"scrollTop"]; 
    739780        } 
    740781} 
     
    743784        if( ! _body ) return; 
    744785 
    745         long shiftAmount = 0; 
    746786        unsigned int messageCount = [self _visibleMessageCount] + 1; 
    747787        unsigned int scrollbackLimit = [self scrollbackLimit]; 
     
    751791 
    752792        // check if we are near the bottom of the chat area, and if we should scroll down later 
    753         BOOL scrollNeeded = [self scrolledNearBottom]; 
    754  
    755         // check how much we need to shift the scrollbar marks 
    756         if( ! consecutive && messageCount > scrollbackLimit ) { 
    757                 shiftAmount = [self _locationOfElementAtIndex:( messageCount - scrollbackLimit )]; 
    758                 if( shiftAmount > 0 && shiftAmount != NSNotFound ) 
    759                         [scroller shiftMarksAndShadedAreasBy:( shiftAmount * -1 )]; 
    760         } 
     793        BOOL scrollToBottomNeeded = [self scrolledNearBottom]; 
    761794 
    762795        NSMutableString *transformedMessage = [message mutableCopyWithZone:nil]; 
     
    782815        transformedMessage = nil; 
    783816 
     817        long shiftAmount = 0; 
     818        // check how much we need to shift the scrollbar marks 
     819        if( ! consecutive && messageCount > scrollbackLimit ) 
     820                shiftAmount = [self _locationOfElementAtIndex:( messageCount - scrollbackLimit )]; 
     821 
    784822        // enforce the scrollback limit 
    785         if( scrollbackLimit > 0 && messageCount > scrollbackLimit ) { 
     823        if( scrollToBottomNeeded && scrollbackLimit > 0 && messageCount > scrollbackLimit ) { 
    786824                for( unsigned int i = 0; messageCount > scrollbackLimit && i < ( messageCount - scrollbackLimit ); i++ ) { 
    787825                        [_body removeChild:[_body firstChild]]; 
     
    790828        } 
    791829 
    792         if( ! scrollNeeded && shiftAmount > 0 ) { 
    793                 unsigned long scrollTop = [[_body valueForKey:@"scrollTop"] longValue]; 
    794                 [_body setValue:[NSNumber numberWithUnsignedLong:( scrollTop - shiftAmount )] forKey:@"scrollTop"]; 
     830        if( scrollToBottomNeeded && shiftAmount > 0 && shiftAmount != NSNotFound ) { 
     831                DOMHTMLElement *body = [_domDocument body]; 
     832                unsigned long scrollTop = [[body valueForKey:@"scrollTop"] longValue]; 
     833                [body setValue:[NSNumber numberWithUnsignedLong:( scrollTop - shiftAmount )] forKey:@"scrollTop"]; 
     834                [scroller shiftMarksAndShadedAreasBy:( shiftAmount * -1 )]; 
    795835        } 
    796836 
    797837        [[self verticalMarkedScroller] setNeedsDisplay:YES]; 
    798838 
    799         if( scrollNeeded ) [self scrollToBottom]; 
     839        if( scrollToBottomNeeded ) [self scrollToBottom]; 
    800840} 
    801841 
     
    906946 
    907947- (long) _locationOfElementAtIndex:(unsigned long) index { 
    908         if( ! _contentFrameReady || index >= [[_body childNodes] length]
     948        if( ! _contentFrameReady
    909949                return NSNotFound; 
    910         DOMNode *node = [[_body childNodes] item:index]; 
    911         if( ! [node isKindOfClass:[DOMHTMLElement class]] ) 
     950        DOMNode *node = [_body childElementAtIndex:index]; 
     951        if( ! node || ! [node isKindOfClass:[DOMHTMLElement class]] ) 
    912952                return NSNotFound; 
    913953        if( [node respondsToSelector:@selector( offsetTop )] ) 
     
    921961- (unsigned long) _visibleMessageCount { 
    922962        if( ! _contentFrameReady ) return 0; 
    923         return [[_body childNodes] length]; 
    924 } 
    925 @end 
     963        return [_body childElementLength]; 
     964} 
     965@end