Changeset 2160
- Timestamp:
- 12/28/04 10:42:43 (4 years ago)
- Files:
-
- trunk/JVChatTranscript.m (modified) (4 diffs)
- trunk/JVDirectChat.m (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/JVChatTranscript.m
r2131 r2160 676 676 677 677 // Allows some simple code to work when not built with WebKit/Safari 1.3 678 #ifndef _WEB_SCRIPT_OBJECT_H_678 #ifndef WebKitVersion146 679 679 #define WebMenuItemTagGoBack 9 680 680 #define WebMenuItemTagGoForward 10 … … 810 810 - (void) webView:(WebView *) sender didFinishLoadForFrame:(WebFrame *) frame { 811 811 // Test for WebKit/Safari 1.3 812 #ifdef _WEB_SCRIPT_OBJECT_H_812 #ifdef WebKitVersion146 813 813 if( [display respondsToSelector:@selector( setDrawsBackground: )] ) { 814 814 DOMCSSStyleDeclaration *style = [sender computedStyleForElement:[(DOMHTMLDocument *)[[sender mainFrame] DOMDocument] body] pseudoElement:nil]; … … 954 954 955 955 - (void) _prependMessages:(NSString *) messages { 956 #ifdef WebKitVersion146 956 957 if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 957 #ifdef _WEB_SCRIPT_OBJECT_H_958 958 NSMutableString *result = [messages mutableCopy]; 959 959 [result replaceOccurrencesOfString:@" " withString:@" " options:NSLiteralSearch range:NSMakeRange( 0, [result length] )]; … … 979 979 // scroll down if we need to 980 980 if( [scrollNeeded boolValue] ) [body setValue:[body valueForKey:@"offsetHeight"] forKey:@"scrollTop"]; 981 } else 981 982 #endif 982 } else {983 { // old JavaScript method 983 984 NSMutableString *result = [messages mutableCopy]; 984 985 [result escapeCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\\\"'"]]; trunk/JVDirectChat.m
r2158 r2160 101 101 - (void) addEventMessageToLogAndDisplay:(NSString *) message withName:(NSString *) name andAttributes:(NSDictionary *) attributes entityEncodeAttributes:(BOOL) encode; 102 102 - (void) addMessageToLogAndDisplay:(NSData *) message fromUser:(NSString *) user asAction:(BOOL) action; 103 - (int) visibleMessageCount; 103 104 - (int) locationOfMessage:(unsigned int) identifier; 104 105 - (int) locationOfElementByIndex:(unsigned int) index; … … 1548 1549 1549 1550 - (int) locationOfMessage:(unsigned int) identifier { 1551 #ifdef WebKitVersion146 1550 1552 if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 1551 1553 DOMElement *element = [[[display mainFrame] DOMDocument] getElementById:[NSString stringWithFormat:@"%d", identifier]]; 1552 1554 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]; 1556 1559 } 1557 1560 1558 1561 - (int) locationOfElementByIndex:(unsigned int) index { 1562 #ifdef WebKitVersion146 1559 1563 if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 1560 1564 DOMHTMLElement *body = [(DOMHTMLDocument *)[[display mainFrame] DOMDocument] body]; 1561 1565 if( index < [[body children] length] ) return [[[[body children] item:index] valueForKey:@"offsetTop"] intValue]; 1562 1566 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]; 1566 1581 } 1567 1582 1568 1583 - (void) scrollToBottom { 1584 #ifdef WebKitVersion146 1569 1585 if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 1570 1586 DOMHTMLElement *body = [(DOMHTMLDocument *)[[display mainFrame] DOMDocument] body]; 1571 1587 [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();"]; 1575 1592 } 1576 1593 1577 1594 - (void) appendMessage:(NSString *) html subsequent:(BOOL) subsequent { 1578 unsigned int messageCount = 0;1595 unsigned int messageCount = [self visibleMessageCount]; 1579 1596 unsigned int scrollbackLimit = [[NSUserDefaults standardUserDefaults] integerForKey:@"JVChatScrollbackLimit"]; 1580 1597 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 method1585 messageCount = [[display stringByEvaluatingJavaScriptFromString:@"scrollBackMessageCount();"] intValue];1586 }1587 1598 1588 1599 if( ! subsequent && ( messageCount + 1 ) > scrollbackLimit ) { … … 1592 1603 } 1593 1604 1605 #ifdef WebKitVersion146 1594 1606 if( [[display mainFrame] respondsToSelector:@selector( DOMDocument )] ) { 1595 1607 DOMHTMLElement *element = (DOMHTMLElement *)[[[display mainFrame] DOMDocument] createElement:@"span"]; … … 1633 1645 // scroll down if we need to 1634 1646 if( [scrollNeeded boolValue] ) [self scrollToBottom]; 1635 } else { // old JavaScript method 1647 } else 1648 #endif 1649 { // old JavaScript method 1636 1650 NSMutableString *transformedMessage = [html mutableCopy]; 1637 1651 [transformedMessage escapeCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\\\"'"]]; … … 1879 1893 [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]]; 1880 1894 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 )]; 1891 1897 1892 1898 NSScroller *scroller = [[[[[display mainFrame] frameView] documentView] enclosingScrollView] verticalScroller]; … … 1895 1901 [self addEventMessageToDisplay:NSLocalizedString( @"You have returned from away.", "self away status removed message" ) withName:@"awayRemoved" andAttributes:nil]; 1896 1902 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 )]; 1907 1905 1908 1906 NSScroller *scroller = [[[[[display mainFrame] frameView] documentView] enclosingScrollView] verticalScroller];
