Patch by Alexey Proskuryakov.
authorggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Oct 2005 22:15:08 +0000 (22:15 +0000)
committerggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Oct 2005 22:15:08 +0000 (22:15 +0000)
        Reviewed by Maciej.

        Fixes http://bugzilla.opendarwin.org/show_bug.cgi?id=5303
        TextInputController should support attributed strings

        * DumpRenderTree/TextInputController.m:
        (+[NSMutableAttributedString isSelectorExcludedFromWebScript:]):
        (+[NSMutableAttributedString webScriptNameForSelector:]):
        (-[NSMutableAttributedString getLength]):
        (-[NSMutableAttributedString attributeNamesAtIndex:]):
        (-[NSMutableAttributedString valueOfAttribute:atIndex:]):
        (-[NSMutableAttributedString addAttribute:value:]):
        (-[NSMutableAttributedString addAttribute:value:from:length:]):
        (-[NSMutableAttributedString addColorAttribute:red:green:blue:alpha:]):
        (-[NSMutableAttributedString addColorAttribute:red:green:blue:alpha:from:length:]):
        (-[NSMutableAttributedString addFontAttribute:fontName:size:]):
        (-[NSMutableAttributedString addFontAttribute:fontName:size:from:length:]):
        (+[TextInputController isSelectorExcludedFromWebScript:]):
        (+[TextInputController webScriptNameForSelector:]):
        (-[TextInputController insertText:]):
        (-[TextInputController attributedSubstringFrom:length:]):
        (-[TextInputController attributedStringWithString:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@10987 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/TextInputController.m

index 2efcd53e000b12320c288664a0c3921126d25253..3b312480805800ddbb4d50e5b9733b57915eba52 100644 (file)
@@ -1,3 +1,30 @@
+2005-10-27  Geoffrey Garen  <ggaren@apple.com>
+               
+               Patch by Alexey Proskuryakov.
+               
+        Reviewed by Maciej.
+        
+        Fixes http://bugzilla.opendarwin.org/show_bug.cgi?id=5303
+        TextInputController should support attributed strings
+
+        * DumpRenderTree/TextInputController.m:
+        (+[NSMutableAttributedString isSelectorExcludedFromWebScript:]):
+        (+[NSMutableAttributedString webScriptNameForSelector:]):
+        (-[NSMutableAttributedString getLength]):
+        (-[NSMutableAttributedString attributeNamesAtIndex:]):
+        (-[NSMutableAttributedString valueOfAttribute:atIndex:]):
+        (-[NSMutableAttributedString addAttribute:value:]):
+        (-[NSMutableAttributedString addAttribute:value:from:length:]):
+        (-[NSMutableAttributedString addColorAttribute:red:green:blue:alpha:]):
+        (-[NSMutableAttributedString addColorAttribute:red:green:blue:alpha:from:length:]):
+        (-[NSMutableAttributedString addFontAttribute:fontName:size:]):
+        (-[NSMutableAttributedString addFontAttribute:fontName:size:from:length:]):
+        (+[TextInputController isSelectorExcludedFromWebScript:]):
+        (+[TextInputController webScriptNameForSelector:]):
+        (-[TextInputController insertText:]):
+        (-[TextInputController attributedSubstringFrom:length:]):
+        (-[TextInputController attributedStringWithString:]):
+
 2005-10-11  Eric Seidel  <eseidel@apple.com>
 
         Reviewed by hyatt.
index 835b054442df534146995dbfb7e656a9a16264ed..6093e878571554422c13ed445781b98dd45b5733 100644 (file)
 #import <WebKit/WebFrameView.h>
 #import <WebKit/WebView.h>
 
-@implementation TextInputController
+@implementation NSMutableAttributedString (TextInputController)
+
++ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
+{
+    if (aSelector == @selector(string)
+            || aSelector == @selector(getLength)
+            || aSelector == @selector(attributeNamesAtIndex:)
+            || aSelector == @selector(valueOfAttribute:atIndex:)
+            || aSelector == @selector(addAttribute:value:)
+            || aSelector == @selector(addAttribute:value:from:length:)
+            || aSelector == @selector(addColorAttribute:red:green:blue:alpha:)
+            || aSelector == @selector(addColorAttribute:red:green:blue:alpha:from:length:)
+            || aSelector == @selector(addFontAttribute:fontName:size:)
+            || aSelector == @selector(addFontAttribute:fontName:size:from:length:))
+        return NO;
+    return YES;
+}
+
++ (NSString *)webScriptNameForSelector:(SEL)aSelector
+{
+    if (aSelector == @selector(getLength))
+        return @"length";
+    if (aSelector == @selector(attributeNamesAtIndex:))
+        return @"getAttributeNamesAtIndex";
+    if (aSelector == @selector(valueOfAttribute:atIndex:))
+        return @"getAttributeValueAtIndex";
+    if (aSelector == @selector(addAttribute:value:))
+        return @"addAttribute";
+    if (aSelector == @selector(addAttribute:value:from:length:))
+        return @"addAttributeForRange";
+    if (aSelector == @selector(addColorAttribute:red:green:blue:alpha:))
+        return @"addColorAttribute";
+    if (aSelector == @selector(addColorAttribute:red:green:blue:alpha:from:length:))
+        return @"addColorAttributeForRange";
+    if (aSelector == @selector(addFontAttribute:fontName:size:))
+        return @"addFontAttribute";
+    if (aSelector == @selector(addFontAttribute:fontName:size:from:length:))
+        return @"addFontAttributeForRange";
+
+    return nil;
+}
+
+- (int)getLength
+{
+    return (int)[self length];
+}
+
+- (NSArray *)attributeNamesAtIndex:(int)index
+{
+    NSDictionary *attributes = [self attributesAtIndex:(unsigned)index effectiveRange:nil];
+    return [attributes allKeys];
+}
+
+- (id)valueOfAttribute:(NSString *)attrName atIndex:(int)index
+{
+    return [self attribute:attrName atIndex:(unsigned)index effectiveRange:nil];
+}
+
+- (void)addAttribute:(NSString *)attrName value:(id)value
+{
+    [self addAttribute:attrName value:value range:NSMakeRange(0, [self length])];
+}
+
+- (void)addAttribute:(NSString *)attrName value:(id)value from:(int)from length:(int)length
+{
+    [self addAttribute:attrName value:value range:NSMakeRange((unsigned)from, (unsigned)length)];
+}
+
+- (void)addColorAttribute:(NSString *)attrName red:(float)red green:(float)green blue:(float)blue alpha:(float)alpha
+{
+    [self addAttribute:attrName value:[NSColor colorWithDeviceRed:red green:green blue:blue alpha:alpha] range:NSMakeRange(0, [self length])];
+}
+
+- (void)addColorAttribute:(NSString *)attrName red:(float)red green:(float)green blue:(float)blue alpha:(float)alpha from:(int)from length:(int)length
+{
+    [self addAttribute:attrName value:[NSColor colorWithDeviceRed:red green:green blue:blue alpha:alpha] range:NSMakeRange((unsigned)from, (unsigned)length)];
+}
 
-// FIXME: need to support attributed strings
+- (void)addFontAttribute:(NSString *)attrName fontName:(NSString *)fontName size:(float)fontSize
+{
+    [self addAttribute:attrName value:[NSFont fontWithName:fontName size:fontSize] range:NSMakeRange(0, [self length])];
+}
+
+- (void)addFontAttribute:(NSString *)attrName fontName:(NSString *)fontName size:(float)fontSize from:(int)from length:(int)length
+{
+    [self addAttribute:attrName value:[NSFont fontWithName:fontName size:fontSize] range:NSMakeRange((unsigned)from, (unsigned)length)];
+}
+
+@end
+
+@implementation TextInputController
 
 + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
 {
             || aSelector == @selector(hasMarkedText)
             || aSelector == @selector(conversationIdentifier)
             || aSelector == @selector(substringFrom:length:)
+            || aSelector == @selector(attributedSubstringFrom:length:)
             || aSelector == @selector(markedRange)
             || aSelector == @selector(selectedRange)
             || aSelector == @selector(firstRectForCharactersFrom:length:)
             || aSelector == @selector(characterIndexForPointX:Y:)
-            || aSelector == @selector(validAttributesForMarkedText))
+            || aSelector == @selector(validAttributesForMarkedText)
+            || aSelector == @selector(attributedStringWithString:))
         return NO;
     return YES;
 }
         return @"setMarkedText";
     else if (aSelector == @selector(substringFrom:length:))
         return @"substringFromRange";
+    else if (aSelector == @selector(attributedSubstringFrom:length:))
+        return @"attributedSubstringFromRange";
     else if (aSelector == @selector(firstRectForCharactersFrom:length:))
         return @"firstRectForCharacterRange";
     else if (aSelector == @selector(characterIndexForPointX:Y:))
         return @"characterIndexForPoint";
+    else if (aSelector == @selector(attributedStringWithString:))
+        return @"makeAttributedString"; // just a factory method, doesn't call into NSTextInput
 
     return nil;
 }
     return [view conformsToProtocol:@protocol(NSTextInput)] ? view : nil;
 }
 
-- (void)insertText:(NSString *)aString
+- (void)insertText:(id)aString
 {
     NSObject <NSTextInput> *textInput = [self textInput];
 
     return @"";
 }
 
+- (NSMutableAttributedString *)attributedSubstringFrom:(int)from length:(int)length
+{
+    NSObject <NSTextInput> *textInput = [self textInput];
+
+    NSMutableAttributedString *ret = [[[NSMutableAttributedString alloc] init] autorelease];
+
+    if (textInput)
+        [ret setAttributedString:[textInput attributedSubstringFromRange:NSMakeRange(from, length)]];
+    
+    return ret;
+}
+
 - (NSArray *)markedRange
 {
     NSObject <NSTextInput> *textInput = [self textInput];
     return nil;
 }
 
+- (NSMutableAttributedString *)attributedStringWithString:(NSString *)aString
+{
+    NSMutableAttributedString *ret = [[[NSMutableAttributedString alloc] init] autorelease];
+    [ret setAttributedString:[[[NSAttributedString alloc] initWithString:aString] autorelease]];
+    return ret;
+}
+
 @end