Changeset 8412 in webkit
- Timestamp:
- Jan 20, 2005 11:34:48 AM (19 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog-2005-08-23
r8411 r8412 1 2005-01-20 David Harrison <harrison@apple.com> 2 3 Reviewed by Darin. 4 5 PARTIAL fix for following bug. Create attributed string with fonts and links. Still need to add attachments. 6 <rdar://problem/3942606> AX: Support kAXAttributedStringForTextMarkerRangeParameterizedAttribute 7 8 * kwq/KWQAccObject.mm: 9 (-[KWQAccObject textUnderElement]): 10 Touched up previous checkin to match code review comments. 11 12 (-[KWQAccObject value]): 13 Use plainText for this one instead of obsolete attributedString. 14 15 (-[KWQAccObject accessibilityParameterizedAttributeNames]): 16 Advertise AXAttributedStringForTextMarkerRange. 17 18 (AXAttributeStringAddFont): 19 (AXAttributeStringAddElement): 20 (-[KWQAccObject linkUIElementForNode:]): 21 (-[KWQAccObject _addAttachmentForElement:URL:needsParagraph:usePlaceholder:]): 22 (-[KWQAccObject accessibilityAttributedStringForRange:]): 23 New routines to support AXAttributedStringForTextMarkerRange. 24 25 (-[KWQAccObject doAXAttributedStringForTextMarkerRange:]): 26 Use new routines instead of obsolete attributedString. 27 1 28 2005-01-20 David Harrison <harrison@apple.com> 2 29 -
trunk/WebCore/kwq/KWQAccObject.mm
r8411 r8412 35 35 #else 36 36 typedef AXTextMarkerRef (*TextMarkerFromTextMarkerRangeProc) (AXTextMarkerRangeRef theTextMarkerRange); 37 extern "C" AXUIElementRef NSAccessibilityCreateAXUIElementRef(id element); 37 38 #endif 38 39 … … 89 90 using khtml::RenderListMarker; 90 91 using khtml::RenderImage; 92 using khtml::RenderStyle; 91 93 using khtml::Selection; 94 using khtml::TextIterator; 92 95 using khtml::VisiblePosition; 93 96 … … 403 406 if (p) { 404 407 // catch stale KWQAccObject (see <rdar://problem/3960196>) 405 if (p->document().handle() ->docPtr()->document()!= d)408 if (p->document().handle() != d) 406 409 return nil; 407 410 408 411 Range r(p->document()); 409 412 if (m_renderer->isText()) { 410 411 412 413 414 415 416 417 418 413 r.setStartBefore(e); 414 r.setEndAfter(e); 415 return p->text(r).getNSString(); 416 } 417 if (e->firstChild()) { 418 r.setStartBefore(e->firstChild()); 419 r.setEndAfter(e->lastChild()); 420 return p->text(r).getNSString(); 421 } 419 422 } 420 423 } … … 439 442 return nil; 440 443 441 Position startPos = VisiblePosition(m_renderer->positionForCoordinates (0, 0, nil)).deepEquivalent(); 442 Position endPos = VisiblePosition(m_renderer->positionForCoordinates (LONG_MAX, LONG_MAX, nil)).deepEquivalent(); 443 NSAttributedString * attrString = docPart->attributedString(startPos.node(), startPos.offset(), endPos.node(), endPos.offset()); 444 return [attrString string]; 444 VisiblePosition startVisiblePosition = VisiblePosition(m_renderer->positionForCoordinates (0, 0, nil)); 445 VisiblePosition endVisiblePosition = VisiblePosition(m_renderer->positionForCoordinates (LONG_MAX, LONG_MAX, nil)); 446 QString qString = plainText(makeRange(startVisiblePosition, endVisiblePosition)); 447 448 // transform it to a CFString and return that 449 return (id)qString.getCFString(); 445 450 } 446 451 … … 920 925 kAXBoundsForTextMarkerRangeParameterizedAttribute, 921 926 // kAXStyleTextMarkerRangeForTextMarkerParameterizedAttribute, // NOTE: <rdar://problem/3942606> 922 // kAXAttributedStringForTextMarkerRangeParameterizedAttribute, // NOTE: <rdar://problem/3942647> 927 kAXAttributedStringForTextMarkerRangeParameterizedAttribute, 923 928 kAXTextMarkerRangeForUnorderedTextMarkersParameterizedAttribute, 924 929 kAXNextTextMarkerForTextMarkerParameterizedAttribute, … … 1075 1080 } 1076 1081 1082 static void AXAttributeStringAddFont(NSMutableAttributedString *attrStr, NSString *attribute, NSFont* font, NSRange range) 1083 { 1084 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: 1085 [font fontName] , NSAccessibilityFontNameKey, 1086 [font familyName] , NSAccessibilityFontFamilyKey, 1087 [font displayName] , NSAccessibilityVisibleNameKey, 1088 [NSNumber numberWithFloat:[font pointSize]] , NSAccessibilityFontSizeKey, 1089 nil]; 1090 1091 [attrStr addAttribute:attribute value:dict range:range]; 1092 } 1093 1094 static void AXAttributeStringAddElement(NSMutableAttributedString *attrStr, NSString *attribute, id element, NSRange range) 1095 { 1096 if (element != nil) { 1097 // make a serialiazable AX object 1098 AXUIElementRef axElement = NSAccessibilityCreateAXUIElementRef(element); 1099 if (axElement != NULL) { 1100 [attrStr addAttribute:attribute value:(id)axElement range:range]; 1101 CFRelease(axElement); 1102 } 1103 } 1104 } 1105 1106 - (KWQAccObject*)linkUIElementForNode: (Node)node 1107 { 1108 RenderObject *obj = node.handle()->renderer(); 1109 if (!obj) 1110 return nil; 1111 1112 KWQAccObject *axObj = obj->document()->getAccObjectCache()->accObject(obj); 1113 HTMLAnchorElementImpl* anchor = [axObj anchorElement]; 1114 if (!anchor || !anchor->renderer()) 1115 return nil; 1116 1117 return anchor->renderer()->document()->getAccObjectCache()->accObject(anchor->renderer()); 1118 } 1119 1120 #if 0 1121 -- model code from AppKits DOM attr string builder 1122 - (BOOL)_addAttachmentForElement:(DOMElement *)element URL:(NSURL *)url needsParagraph:(BOOL)needsParagraph usePlaceholder:(BOOL)flag { 1123 BOOL retval = NO; 1124 NSFileWrapper *fileWrapper = nil; 1125 static NSImage *missingImage = nil; 1126 1127 if (_flags.isIndexing) return NO; 1128 if ([url isFileURL]) { 1129 NSString *path = [[url path] stringByStandardizingPath]; 1130 if (path) fileWrapper = [[NSFileWrapper alloc] initWithPath:path]; 1131 } 1132 if (!fileWrapper) { 1133 WebResource *resource = [_dataSource subresourceForURL:url]; 1134 if (resource) { 1135 fileWrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:[resource data]] autorelease]; 1136 [fileWrapper setPreferredFilename:[url _web_suggestedFilenameWithMIMEType:[resource MIMEType]]]; 1137 } 1138 } 1139 if (!fileWrapper) fileWrapper = [_dataSource _fileWrapperForURL:url]; 1140 if (fileWrapper || flag) { 1141 unsigned textLength = [_attrStr length]; 1142 NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper]; 1143 NSTextAttachmentCell *cell; 1144 NSString *string = [[NSString alloc] initWithFormat:(needsParagraph ? @"%C\n" : @"%C"), NSAttachmentCharacter]; 1145 NSRange rangeToReplace = NSMakeRange(textLength, 0); 1146 NSDictionary *attrs; 1147 if (!fileWrapper) { 1148 if (!missingImage) { 1149 NSString *missingImagePath = [[self _webKitBundle] pathForResource:@"missing_image" ofType:@"tiff"]; 1150 if (missingImagePath) missingImage = [[NSImage allocWithZone:_NXAppZone()] initByReferencingFile:missingImagePath]; 1151 if (!missingImage) { 1152 missingImage = [[NSImage allocWithZone:_NXAppZone()] initByReferencingFile:[_NSKitBundle() pathForResource:@"NSMysteryDocument" ofType:@"tiff"]]; 1153 [missingImage setScalesWhenResized:YES]; 1154 [missingImage setSize:NSMakeSize(32.0, 32.0)]; 1155 } 1156 cell = [[NSTextAttachmentCell alloc] initImageCell:missingImage]; 1157 [attachment setAttachmentCell:cell]; 1158 [cell release]; 1159 } 1160 } 1161 [_attrStr replaceCharactersInRange:rangeToReplace withString:string]; 1162 rangeToReplace.length = [string length]; 1163 attrs = [self _attributesForElement:element]; 1164 if (!_flags.isTesting && rangeToReplace.length > 0) { 1165 [_attrStr setAttributes:attrs range:rangeToReplace]; 1166 rangeToReplace.length = 1; 1167 [_attrStr addAttribute:NSAttachmentAttributeName value:attachment range:rangeToReplace]; 1168 } 1169 [string release]; 1170 [attachment release]; 1171 _flags.isSoft = NO; 1172 retval = YES; 1173 } 1174 return retval; 1175 } 1176 #endif 1177 1178 - (NSAttributedString *) accessibilityAttributedStringForRange: (Range)range 1179 { 1180 NSRange attrStringRange = NSMakeRange(0, 0); 1181 TextIterator it(range); 1182 1183 NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init]; 1184 CFMutableStringRef textString = (CFMutableStringRef)[attrString mutableString]; 1185 1186 while (!it.atEnd()) { 1187 NSMutableDictionary *attrs = [[NSMutableDictionary alloc] initWithCapacity:4]; 1188 1189 if (it.length() != 0) { 1190 // append the text for this run 1191 CFStringAppendCharacters(textString, (const UniChar *)it.characters(), it.length()); 1192 1193 // prepare to add the attributes for this run 1194 attrStringRange.location += attrStringRange.length; 1195 attrStringRange.length = it.length(); 1196 Node node = it.range().startContainer(); 1197 ASSERT(node == it.range().endContainer()); 1198 RenderStyle *style = node.handle()->renderer()->style(); 1199 1200 // add the attributes 1201 AXAttributeStringAddFont(attrString, NSAccessibilityFontTextAttribute, style->font().getNSFont(), attrStringRange); 1202 AXAttributeStringAddElement(attrString, NSAccessibilityLinkTextAttribute, [self linkUIElementForNode:node], attrStringRange); 1203 } else { 1204 // handle replaced element, e.g attachments 1205 } 1206 1207 [attrs release]; 1208 it.advance(); 1209 } 1210 1211 return [attrString autorelease]; 1212 } 1213 1077 1214 - (id)doAXAttributedStringForTextMarkerRange: (AXTextMarkerRangeRef) textMarkerRange 1078 1215 { … … 1090 1227 return nil; 1091 1228 1092 // get the attributed string by asking the document part 1093 KWQKHTMLPart *docPart = KWQ([self topDocument]->part()); 1094 if (!docPart) 1095 return nil; 1096 1097 Position startPos = startVisiblePosition.deepEquivalent(); 1098 Position endPos = endVisiblePosition.deepEquivalent(); 1099 NSAttributedString * attrString = docPart->attributedString(startPos.node(), startPos.offset(), endPos.node(), endPos.offset()); 1100 return attrString; 1229 return [self accessibilityAttributedStringForRange: makeRange(startVisiblePosition, endVisiblePosition)]; 1101 1230 } 1102 1231
Note: See TracChangeset
for help on using the changeset viewer.