Changeset 2160

Show
Ignore:
Timestamp:
12/28/04 10:42:43 (4 years ago)
Author:
timothy
Message:

Added a new define "WebKitVersion146", so we can selectively compile with or without the new WebKit? stuff.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/JVChatTranscript.m

    r2131 r2160  
    676676 
    677677// Allows some simple code to work when not built with WebKit/Safari 1.3 
    678 #ifndef _WEB_SCRIPT_OBJECT_H_ 
     678#ifndef WebKitVersion146 
    679679#define WebMenuItemTagGoBack 9 
    680680#define WebMenuItemTagGoForward 10 
     
    810810- (void) webView:(WebView *) sender didFinishLoadForFrame:(WebFrame *) frame { 
    811811// Test for WebKit/Safari 1.3 
    812 #ifdef _WEB_SCRIPT_OBJECT_H_ 
     812#ifdef WebKitVersion146 
    813813        if( [display respondsToSelector:@selector( setDrawsBackground: )] ) { 
    814814                DOMCSSStyleDeclaration *style = [sender computedStyleForElement:[(DOMHTMLDocument *)[[sender mainFrame] DOMDocument] body] pseudoElement:nil]; 
     
    954954 
    955955- (void) _prependMessages:(NSString *) messages { 
     956#ifdef WebKitVersion146 
    956957        if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 
    957 #ifdef _WEB_SCRIPT_OBJECT_H_ 
    958958                NSMutableString *result = [messages mutableCopy]; 
    959959                [result replaceOccurrencesOfString:@"  " withString:@"  " options:NSLiteralSearch range:NSMakeRange( 0, [result length] )]; 
     
    979979                // scroll down if we need to 
    980980                if( [scrollNeeded boolValue] ) [body setValue:[body valueForKey:@"offsetHeight"] forKey:@"scrollTop"]; 
     981        } else 
    981982#endif 
    982         } else { 
     983        { // old JavaScript method 
    983984                NSMutableString *result = [messages mutableCopy]; 
    984985                [result escapeCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\\\"'"]]; 
  • trunk/JVDirectChat.m

    r2158 r2160  
    101101- (void) addEventMessageToLogAndDisplay:(NSString *) message withName:(NSString *) name andAttributes:(NSDictionary *) attributes entityEncodeAttributes:(BOOL) encode; 
    102102- (void) addMessageToLogAndDisplay:(NSData *) message fromUser:(NSString *) user asAction:(BOOL) action; 
     103- (int) visibleMessageCount; 
    103104- (int) locationOfMessage:(unsigned int) identifier; 
    104105- (int) locationOfElementByIndex:(unsigned int) index; 
     
    15481549 
    15491550- (int) locationOfMessage:(unsigned int) identifier { 
     1551#ifdef WebKitVersion146 
    15501552        if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 
    15511553                DOMElement *element = [[[display mainFrame] DOMDocument] getElementById:[NSString stringWithFormat:@"%d", identifier]]; 
    15521554                return [[element valueForKey:@"offsetTop"] intValue]; 
    1553         } else { // old JavaScript method 
    1554                 return [[display stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"locationOfMessage( \"%d\" );", identifier]] intValue]; 
    1555         } 
     1555        } else 
     1556#endif 
     1557        // old JavaScript method 
     1558        return [[display stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"locationOfMessage( \"%d\" );", identifier]] intValue]; 
    15561559} 
    15571560 
    15581561- (int) locationOfElementByIndex:(unsigned int) index { 
     1562#ifdef WebKitVersion146 
    15591563        if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 
    15601564                DOMHTMLElement *body = [(DOMHTMLDocument *)[[display mainFrame] DOMDocument] body]; 
    15611565                if( index < [[body children] length] ) return [[[[body children] item:index] valueForKey:@"offsetTop"] intValue]; 
    15621566                else return 0; 
    1563         } else { // old JavaScript method 
    1564                 return [[display stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"locationOfElementByIndex( %d );", index]] intValue]; 
    1565         } 
     1567        } else 
     1568#endif 
     1569        // old JavaScript method 
     1570        return [[display stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"locationOfElementByIndex( %d );", index]] intValue]; 
     1571
     1572 
     1573- (int) visibleMessageCount { 
     1574#ifdef WebKitVersion146 
     1575        if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 
     1576                return [[[(DOMHTMLDocument *)[[display mainFrame] DOMDocument] body] children] length]; 
     1577        } else 
     1578#endif 
     1579        // old JavaScript method 
     1580        return [[display stringByEvaluatingJavaScriptFromString:@"scrollBackMessageCount();"] intValue]; 
    15661581} 
    15671582 
    15681583- (void) scrollToBottom { 
     1584#ifdef WebKitVersion146 
    15691585        if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 
    15701586                DOMHTMLElement *body = [(DOMHTMLDocument *)[[display mainFrame] DOMDocument] body]; 
    15711587                [body setValue:[body valueForKey:@"offsetHeight"] forKey:@"scrollTop"]; 
    1572         } else { // old JavaScript method 
    1573                 [display stringByEvaluatingJavaScriptFromString:@"scrollToBottom();"]; 
    1574         } 
     1588        } else 
     1589#endif 
     1590        // old JavaScript method 
     1591        [display stringByEvaluatingJavaScriptFromString:@"scrollToBottom();"]; 
    15751592} 
    15761593 
    15771594- (void) appendMessage:(NSString *) html subsequent:(BOOL) subsequent { 
    1578         unsigned int messageCount = 0
     1595        unsigned int messageCount = [self visibleMessageCount]
    15791596        unsigned int scrollbackLimit = [[NSUserDefaults standardUserDefaults] integerForKey:@"JVChatScrollbackLimit"]; 
    15801597        NSScroller *scroller = [[[[[display mainFrame] frameView] documentView] enclosingScrollView] verticalScroller]; 
    1581  
    1582         if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 
    1583                 messageCount = [[[(DOMHTMLDocument *)[[display mainFrame] DOMDocument] body] children] length]; 
    1584         } else { // old JavaScript method 
    1585                 messageCount = [[display stringByEvaluatingJavaScriptFromString:@"scrollBackMessageCount();"] intValue]; 
    1586         } 
    15871598 
    15881599        if( ! subsequent && ( messageCount + 1 ) > scrollbackLimit ) { 
     
    15921603        } 
    15931604 
     1605#ifdef WebKitVersion146 
    15941606        if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 
    15951607                DOMHTMLElement *element = (DOMHTMLElement *)[[[display mainFrame] DOMDocument] createElement:@"span"]; 
     
    16331645                // scroll down if we need to 
    16341646                if( [scrollNeeded boolValue] ) [self scrollToBottom]; 
    1635         } else { // old JavaScript method 
     1647        } else 
     1648#endif   
     1649        { // old JavaScript method 
    16361650                NSMutableString *transformedMessage = [html mutableCopy]; 
    16371651                [transformedMessage escapeCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\\\"'"]]; 
     
    18791893                [self addEventMessageToDisplay:[NSString stringWithFormat:NSLocalizedString( @"You have set yourself away with \"%@\".", "self away status set message" ), msgString] withName:@"awaySet" andAttributes:[NSDictionary dictionaryWithObjectsAndKeys:messageString, @"away-message", nil]]; 
    18801894 
    1881                 unsigned int messageCount = 0; 
    1882                 unsigned long loc = 0; 
    1883  
    1884                 if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 
    1885                         messageCount = [[[(DOMHTMLDocument *)[[display mainFrame] DOMDocument] body] children] length]; 
    1886                         loc = [self locationOfElementByIndex:( messageCount - 1 )]; 
    1887                 } else { // old JavaScript method 
    1888                         messageCount = [[display stringByEvaluatingJavaScriptFromString:@"scrollBackMessageCount();"] intValue]; 
    1889                         loc = [[display stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"locationOfElementByIndex( %d );", ( messageCount - 1 )]] intValue]; 
    1890                 } 
     1895                unsigned int messageCount = [self visibleMessageCount]; 
     1896                unsigned long loc = [self locationOfElementByIndex:( messageCount - 1 )]; 
    18911897 
    18921898                NSScroller *scroller = [[[[[display mainFrame] frameView] documentView] enclosingScrollView] verticalScroller]; 
     
    18951901                [self addEventMessageToDisplay:NSLocalizedString( @"You have returned from away.", "self away status removed message" ) withName:@"awayRemoved" andAttributes:nil]; 
    18961902 
    1897                 unsigned int messageCount = 0; 
    1898                 unsigned long loc = 0; 
    1899  
    1900                 if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 
    1901                         messageCount = [[[(DOMHTMLDocument *)[[display mainFrame] DOMDocument] body] children] length]; 
    1902                         loc = [self locationOfElementByIndex:( messageCount - 1 )]; 
    1903                 } else { // old JavaScript method 
    1904                         messageCount = [[display stringByEvaluatingJavaScriptFromString:@"scrollBackMessageCount();"] intValue]; 
    1905                         loc = [[display stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"locationOfElementByIndex( %d );", ( messageCount - 1 )]] intValue]; 
    1906                 } 
     1903                unsigned int messageCount = [self visibleMessageCount]; 
     1904                unsigned long loc = [self locationOfElementByIndex:( messageCount - 1 )]; 
    19071905 
    19081906                NSScroller *scroller = [[[[[display mainFrame] frameView] documentView] enclosingScrollView] verticalScroller];