Changeset 3333

Show
Ignore:
Timestamp:
08/19/06 23:42:01 (2 years ago)
Author:
timothy
Message:

Improved style loading. Uses WebKit?'s loadRequest to load the mian file now, might help the blank chat room bug. Also adjusts the scroll to bottom logic, fixing #468.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Colloquy.xcodeproj/project.pbxproj

    r3332 r3333  
    19111911                        isa = PBXProject; 
    19121912                        buildConfigurationList = 1C041A700854E97700A5A5BA /* Build configuration list for PBXProject "Colloquy" */; 
     1913                        compatibilityVersion = "Xcode 2.4"; 
    19131914                        hasScannedForEncodings = 1; 
    19141915                        knownRegions = ( 
     
    19601961                        ); 
    19611962                        projectRoot = ""; 
     1963                        shouldCheckCompatibility = 1; 
    19621964                        targets = ( 
    19631965                                1CB2CCF5052DDC560094AAA4 /* Colloquy (Application) */, 
  • trunk/Panels/JVChatTranscriptPanel.m

    r3252 r3333  
    670670} 
    671671 
    672 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 
    673 #define NSWorkspaceLaunchWithoutActivation 0x00000200 
    674 #endif 
    675  
    676672- (void) webView:(WebView *) sender decidePolicyForNavigationAction:(NSDictionary *) actionInformation request:(NSURLRequest *) request frame:(WebFrame *) frame decisionListener:(id <WebPolicyDecisionListener>) listener { 
    677673        NSURL *url = [actionInformation objectForKey:WebActionOriginalURLKey]; 
     
    680676                if( [[[url standardizedURL] path] length] ) [listener ignore]; 
    681677                else [listener use]; 
     678        } else if( [url isFileURL] && [[url path] hasPrefix:[[NSBundle mainBundle] resourcePath]] ) { 
     679                [listener use]; 
    682680        } else if( [[url scheme] isEqualToString:@"self"] ) { 
    683681                NSString *resource = [url resourceSpecifier]; 
  • trunk/Preferences/JVAppearancePreferences.m

    r3072 r3333  
    312312 
    313313- (void) webView:(WebView *) sender decidePolicyForNavigationAction:(NSDictionary *) actionInformation request:(NSURLRequest *) request frame:(WebFrame *) frame decisionListener:(id <WebPolicyDecisionListener>) listener { 
    314         if( [[[actionInformation objectForKey:WebActionOriginalURLKey] scheme] isEqualToString:@"about"]  ) { 
     314        NSURL *url = [actionInformation objectForKey:WebActionOriginalURLKey]; 
     315 
     316        if( [[url scheme] isEqualToString:@"about"] ) { 
     317                if( [[[url standardizedURL] path] length] ) [listener ignore]; 
     318                else [listener use]; 
     319        } else if( [url isFileURL] && [[url path] hasPrefix:[[NSBundle mainBundle] resourcePath]] ) { 
    315320                [listener use]; 
    316321        } else { 
    317                 NSURL *url = [actionInformation objectForKey:WebActionOriginalURLKey]; 
    318322                [[NSWorkspace sharedWorkspace] openURL:url]; 
    319323                [listener ignore]; 
  • trunk/Resources/base.html

    r3152 r3333  
    44<head> 
    55        <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    6         <title>%@</title> 
    7         <base href="%@" /> 
    86        <script type="text/ecmascript" defer="defer" encoding="utf-8" src="roomTopicBanner.js" /> 
    97        <style type="text/css"> 
  • trunk/Resources/template.html

    r3014 r3333  
    44<head> 
    55        <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    6         <meta name="generator" content="Colloquy 2.0.1" /> 
     6        <meta name="generator" content="Colloquy 2.1" /> 
    77        <meta name="formatter" content="libxslt 1.1.11" /> 
    88        <title>%@</title> 
    99        %@ 
    10         <script id="defaultScript" type="text/ecmascript" defer="defer" src="%@/default.js" encoding="utf-8" /
    11         <link id="defaultStyle" rel="stylesheet" type="text/css" href="%3$@/default.css" /> 
     10        <script id="defaultScript" type="text/ecmascript" defer="defer" src="default.js" encoding="utf-8"></script
     11        <link id="defaultStyle" rel="stylesheet" type="text/css" href="default.css" /> 
    1212        <link id="emoticonStyle" rel="stylesheet" type="text/css" href="%@" /> 
    1313        <link id="mainStyle" rel="stylesheet" type="text/css" href="%@" /> 
    1414        <link id="variantStyle" rel="stylesheet" type="text/css" href="%@" /> 
    15         <base href="%@" /> 
    1615</head> 
    1716<body> 
  • trunk/Views/JVStyleView.h

    r3259 r3333  
    8383- (void) jumpToMessage:(JVChatMessage *) message; 
    8484- (void) scrollToBottom; 
     85- (BOOL) scrolledNearBottom; 
    8586 
    8687- (NSTextView *) nextTextView; 
  • trunk/Views/JVStyleView.m

    r3332 r3333  
    1616#pragma mark - 
    1717 
    18 @interface WebView (WebViewPrivate) // WebKit 1.3/2.0 pending public API 
    19 - (void) setDrawsBackground:(BOOL) draws; 
    20 - (BOOL) drawsBackground; 
     18@interface WebView (WebViewLeopard) 
     19- (void) setDrawsBackground:(BOOL) draws; // supported in 10.3.9/Tiger 
     20- (BOOL) drawsBackground; // supported in 10.3.9/Tiger 
    2121- (WebFrame *) selectedFrame; 
     22@end 
     23 
     24@interface WebView (WebViewPrivate) 
    2225- (WebFrame *) _frameForCurrentSelection; 
    2326@end 
    2427 
    25 @interface DOMHTMLElement (DOMHTMLElementPrivate
     28@interface DOMHTMLElement (DOMHTMLElementLeopard
    2629- (int) offsetTop; 
     30- (int) offsetHeight; 
    2731- (int) scrollHeight; 
    2832@end 
     
    4246- (void) _prependMessages:(NSString *) messages; 
    4347- (void) _styleError; 
    44 - (NSString *) _baseHTML; 
    4548- (NSString *) _contentHTMLWithBody:(NSString *) html; 
     49- (NSURL *) _baseURL; 
    4650- (unsigned long) _visibleMessageCount; 
    4751- (long) _locationOfMessage:(JVChatMessage *) message; 
     
    307311 
    308312                unsigned int location = 0; 
    309                 if( [elt respondsToSelector:@selector( scrollTop )] ) 
     313                if( [elt respondsToSelector:@selector( offsetTop )] ) 
    310314                        location = [elt offsetTop]; 
    311315                else location = [[elt valueForKey:@"offsetTop"] longValue]; 
     
    475479 
    476480                WebFrame *contentFrame = [[self mainFrame] findFrameNamed:@"content"]; 
    477                 [contentFrame loadHTMLString:[self _contentHTMLWithBody:@""] baseURL:nil]; 
    478         } else if( _mainFrameReady) { 
     481                [contentFrame loadHTMLString:[self _contentHTMLWithBody:@""] baseURL:[self _baseURL]]; 
     482        } else if( _mainFrameReady ) { 
    479483                if( [[[[[frame dataSource] response] URL] absoluteString] isEqualToString:@"about:blank"] ) { 
    480484                        // this was a false content frame load, try again 
    481                         [frame loadHTMLString:[self _contentHTMLWithBody:@""] baseURL:nil]; 
     485                        [frame loadHTMLString:[self _contentHTMLWithBody:@""] baseURL:[self _baseURL]]; 
    482486                        return; 
    483487                } 
     
    579583        else [_body setValue:[_body valueForKey:@"scrollHeight"] forKey:@"scrollTop"]; 
    580584} 
     585 
     586- (BOOL) scrolledNearBottom { 
     587        WebFrame *contentFrame = [[self mainFrame] findFrameNamed:@"content"]; 
     588        DOMHTMLElement *contentFrameElement = [contentFrame frameElement]; 
     589        unsigned int frameHeight = 0; 
     590        if( [contentFrameElement respondsToSelector:@selector( offsetHeight )] ) 
     591                frameHeight = [contentFrameElement offsetHeight]; 
     592        else frameHeight = [[contentFrameElement valueForKey:@"offsetHeight"] unsignedIntValue]; 
     593 
     594        unsigned int scrollHeight = 0; 
     595        if( [_body respondsToSelector:@selector( scrollHeight )] ) 
     596                scrollHeight = [_body scrollHeight]; 
     597        else scrollHeight = [[_body valueForKey:@"scrollHeight"] unsignedIntValue]; 
     598 
     599        unsigned int scrollTop = [[_body valueForKey:@"scrollTop"] unsignedIntValue]; 
     600 
     601        // check if we are near the bottom 10 pixels of the chat area 
     602        return ( ( frameHeight + scrollTop ) >= ( scrollHeight - 15 ) ); 
     603} 
    581604@end 
    582605 
     
    617640        _contentFrameReady = NO; 
    618641        if( _rememberScrollPosition ) { 
    619                 if( [_body respondsToSelector:@selector( scrollTop )] ) 
    620                         _lastScrollPosition = [_body offsetTop]; 
    621                 else _lastScrollPosition = [[_body valueForKey:@"scrollTop"] longValue]; 
     642                _lastScrollPosition = [[_body valueForKey:@"scrollTop"] longValue]; 
    622643        } else _lastScrollPosition = 0; 
    623644 
     
    626647        if( _mainFrameReady ) { 
    627648                WebFrame *contentFrame = [[self mainFrame] findFrameNamed:@"content"]; 
    628                 [contentFrame loadHTMLString:[self _contentHTMLWithBody:@""] baseURL:nil]; 
    629         } else [[self mainFrame] loadHTMLString:[self _baseHTML] baseURL:nil]; 
     649                [contentFrame loadHTMLString:[self _contentHTMLWithBody:@""] baseURL:[self _baseURL]]; 
     650        } else { 
     651                NSString *path = [[NSBundle mainBundle] pathForResource:@"base" ofType:@"html"]; 
     652                NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:5.]; 
     653                [[self mainFrame] loadRequest:request]; 
     654        } 
    630655} 
    631656 
     
    701726 
    702727        // check if we are near the bottom of the chat area, and if we should scroll down later 
    703         BOOL scrollNeeded = ( ! [(NSScrollView *)[scroller superview] hasVerticalScroller] || [scroller floatValue] >= 0.990 )
     728        BOOL scrollNeeded = [self scrolledNearBottom]
    704729 
    705730        // check how much we need to shift the scrollbar marks 
     
    741766 
    742767        if( ! scrollNeeded && shiftAmount > 0 ) { 
    743                 unsigned long scrollTop = 0; 
    744                 if( [_body respondsToSelector:@selector( scrollTop )] ) 
    745                         scrollTop = [_body offsetTop]; 
    746                 else scrollTop = [[_body valueForKey:@"scrollTop"] longValue]; 
     768                unsigned long scrollTop = [[_body valueForKey:@"scrollTop"] longValue]; 
    747769                [_body setValue:[NSNumber numberWithUnsignedLong:( scrollTop - shiftAmount )] forKey:@"scrollTop"]; 
    748770        } 
     
    760782 
    761783        // check if we are near the bottom of the chat area, and if we should scroll down later 
    762         JVMarkedScroller *scroller = [self verticalMarkedScroller]; 
    763         BOOL scrollNeeded = ( ! scroller || [scroller floatValue] >= 0.985 ); 
     784        BOOL scrollNeeded = [self scrolledNearBottom]; 
    764785 
    765786        // parses the message so we can get the DOM tree 
     
    813834#pragma mark - 
    814835 
    815 - (NSString *) _baseHTML { 
    816         NSURL *resources = [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]; 
    817  
    818         NSString *shell = nil; 
    819         if( floor( NSAppKitVersionNumber ) <= NSAppKitVersionNumber10_3 ) // test for 10.3 
    820                 shell = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"base" ofType:@"html"]]; 
    821         else shell = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"base" ofType:@"html"] encoding:NSUTF8StringEncoding error:NULL]; 
    822  
    823         return [NSString stringWithFormat:shell, @"", [resources absoluteString]]; 
    824 } 
    825  
    826836- (NSString *) _contentHTMLWithBody:(NSString *) html { 
    827         NSURL *resources = [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]; 
    828837        NSString *variantStyleSheetLocation = [[[self style] variantStyleSheetLocationWithName:[self styleVariant]] absoluteString]; 
    829838        if( ! variantStyleSheetLocation ) variantStyleSheetLocation = @""; 
     
    834843        else shell = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"template" ofType:@"html"] encoding:NSUTF8StringEncoding error:NULL]; 
    835844 
    836         return [NSString stringWithFormat:shell, @"", @"", [resources absoluteString], [[[self emoticons] styleSheetLocation] absoluteString], [[[self style] mainStyleSheetLocation] absoluteString], variantStyleSheetLocation, [[[self style] baseLocation] absoluteString], [[self style] contentsOfBodyTemplateWithName:[self bodyTemplate]]]; 
     845        return [NSString stringWithFormat:shell, @"", @"", [[[self emoticons] styleSheetLocation] absoluteString], [[[self style] mainStyleSheetLocation] absoluteString], variantStyleSheetLocation, [[[self style] baseLocation] absoluteString], [[self style] contentsOfBodyTemplateWithName:[self bodyTemplate]]]; 
     846
     847 
     848- (NSURL *) _baseURL { 
     849        return [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"template" ofType:@"html"]]; 
    837850} 
    838851