diff options
Diffstat (limited to 'WebKit/mac/Misc/WebNSAttributedStringExtras.mm')
-rw-r--r-- | WebKit/mac/Misc/WebNSAttributedStringExtras.mm | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/WebKit/mac/Misc/WebNSAttributedStringExtras.mm b/WebKit/mac/Misc/WebNSAttributedStringExtras.mm index 5e50109..04d9075 100644 --- a/WebKit/mac/Misc/WebNSAttributedStringExtras.mm +++ b/WebKit/mac/Misc/WebNSAttributedStringExtras.mm @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -94,7 +94,7 @@ static NSFileWrapper *fileWrapperForElement(Element* e) const AtomicString& attr = e->getAttribute(srcAttr); if (!attr.isEmpty()) { - NSURL *URL = e->document()->completeURL(attr); + NSURL *URL = KURL(e->document()->completeURL(attr.deprecatedString())).getNSURL(); wrapper = [[kit(e->document()->frame()) _dataSource] _fileWrapperForURL:URL]; } if (!wrapper) { @@ -204,8 +204,8 @@ static NSFileWrapper *fileWrapperForElement(Element* e) pendingStyledSpace = nil; hasNewLine = false; } - String text; - String str = currentNode->nodeValue(); + DeprecatedString text; + DeprecatedString str = currentNode->nodeValue().deprecatedString(); int start = (currentNode == firstNode) ? startOffset : -1; int end = (currentNode == endNode) ? endOffset : -1; if (renderer->isText()) { @@ -217,17 +217,17 @@ static NSFileWrapper *fileWrapperForElement(Element* e) } int runStart = (start == -1) ? 0 : start; int runEnd = (end == -1) ? str.length() : end; - text += str.substring(runStart, runEnd-runStart); + text += str.mid(runStart, runEnd-runStart); [pendingStyledSpace release]; pendingStyledSpace = nil; - addedSpace = u_charDirection(str.characters()[runEnd - 1]) == U_WHITE_SPACE_NEUTRAL; + addedSpace = u_charDirection(str[runEnd - 1].unicode()) == U_WHITE_SPACE_NEUTRAL; } else { RenderText* textObj = static_cast<RenderText*>(renderer); if (!textObj->firstTextBox() && str.length() > 0 && !addedSpace) { // We have no runs, but we do have a length. This means we must be // whitespace that collapsed away at the end of a line. - text.append(' '); + text += ' '; addedSpace = true; } else { @@ -247,16 +247,16 @@ static NSFileWrapper *fileWrapperForElement(Element* e) ++linkStartLocation; [result appendAttributedString:pendingStyledSpace]; } else - text.append(' '); + text += ' '; } - String runText = str.substring(runStart, runEnd - runStart); + DeprecatedString runText = str.mid(runStart, runEnd - runStart); runText.replace('\n', ' '); text += runText; int nextRunStart = box->nextTextBox() ? box->nextTextBox()->m_start : str.length(); // collapsed space between runs or at the end needSpace = nextRunStart > runEnd; [pendingStyledSpace release]; pendingStyledSpace = nil; - addedSpace = u_charDirection(str.characters()[runEnd - 1]) == U_WHITE_SPACE_NEUTRAL; + addedSpace = u_charDirection(str[runEnd - 1].unicode()) == U_WHITE_SPACE_NEUTRAL; start = -1; } if (end != -1 && runEnd >= end) @@ -278,7 +278,7 @@ static NSFileWrapper *fileWrapperForElement(Element* e) if (text.length() > 0) { hasParagraphBreak = false; - NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:text attributes:attrs]; + NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:text.getNSString() attributes:attrs]; [result appendAttributedString: partialString]; [partialString release]; } @@ -292,7 +292,7 @@ static NSFileWrapper *fileWrapperForElement(Element* e) } } else { // This is our simple HTML -> ASCII transformation: - String text; + DeprecatedString text; if (currentNode->hasTagName(aTag)) { // Note the start of the <a> element. We will add the NSLinkAttributeName // attribute to the attributed string when navigating to the next sibling @@ -300,14 +300,14 @@ static NSFileWrapper *fileWrapperForElement(Element* e) linkStartLocation = [result length]; linkStartNode = static_cast<Element*>(currentNode); } else if (currentNode->hasTagName(brTag)) { - text.append('\n'); + text += "\n"; hasNewLine = true; } else if (currentNode->hasTagName(liTag)) { - String listText; + DeprecatedString listText; Element *itemParent = listParent(static_cast<Element*>(currentNode)); if (!hasNewLine) - listText.append('\n'); + listText += '\n'; hasNewLine = true; listItems.append(static_cast<Element*>(currentNode)); @@ -315,7 +315,7 @@ static NSFileWrapper *fileWrapperForElement(Element* e) info.end = 0; listItemLocations.append (info); - listText.append('\t'); + listText += '\t'; if (itemParent && renderer->isListItem()) { RenderListItem* listRenderer = static_cast<RenderListItem*>(renderer); @@ -323,15 +323,15 @@ static NSFileWrapper *fileWrapperForElement(Element* e) String marker = listRenderer->markerText(); if (!marker.isEmpty()) { - listText.append(marker); + listText += marker.deprecatedString(); // Use AppKit metrics, since this will be rendered by AppKit. NSString *markerNSString = marker; float markerWidth = [markerNSString sizeWithAttributes:[NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]].width; maxMarkerWidth = MAX(markerWidth, maxMarkerWidth); } - listText.append(' '); - listText.append('\t'); + listText += ' '; + listText += '\t'; NSMutableDictionary *attrs = [[NSMutableDictionary alloc] init]; [attrs setObject:font forKey:NSFontAttributeName]; @@ -340,14 +340,14 @@ static NSFileWrapper *fileWrapperForElement(Element* e) if (style && style->backgroundColor().isValid()) [attrs setObject:nsColor(style->backgroundColor()) forKey:NSBackgroundColorAttributeName]; - NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:listText attributes:attrs]; + NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:listText.getNSString() attributes:attrs]; [attrs release]; [result appendAttributedString: partialString]; [partialString release]; } } else if (currentNode->hasTagName(olTag) || currentNode->hasTagName(ulTag)) { if (!hasNewLine) - text.append('\n'); + text += "\n"; hasNewLine = true; } else if (currentNode->hasTagName(blockquoteTag) || currentNode->hasTagName(ddTag) @@ -360,7 +360,7 @@ static NSFileWrapper *fileWrapperForElement(Element* e) || currentNode->hasTagName(tdTag) || currentNode->hasTagName(thTag)) { if (!hasNewLine) - text.append('\n'); + text += '\n'; hasNewLine = true; } else if (currentNode->hasTagName(h1Tag) || currentNode->hasTagName(h2Tag) @@ -371,20 +371,21 @@ static NSFileWrapper *fileWrapperForElement(Element* e) || currentNode->hasTagName(pTag) || currentNode->hasTagName(trTag)) { if (!hasNewLine) - text.append('\n'); + text += '\n'; // In certain cases, emit a paragraph break. int bottomMargin = renderer->collapsedMarginBottom(); int fontSize = style->fontDescription().computedPixelSize(); if (bottomMargin * 2 >= fontSize) { if (!hasParagraphBreak) { - text.append('\n'); + text += '\n'; hasParagraphBreak = true; } } hasNewLine = true; - } else if (currentNode->hasTagName(imgTag)) { + } + else if (currentNode->hasTagName(imgTag)) { if (pendingStyledSpace != nil) { if (linkStartLocation == [result length]) ++linkStartLocation; @@ -399,18 +400,18 @@ static NSFileWrapper *fileWrapperForElement(Element* e) [attachment release]; } - NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:text]; + NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:text.getNSString()]; [result appendAttributedString: partialString]; [partialString release]; } } - Node* nextNode = currentNode->firstChild(); + Node *nextNode = currentNode->firstChild(); if (!nextNode) nextNode = currentNode->nextSibling(); while (!nextNode && currentNode->parentNode()) { - String text; + DeprecatedString text; currentNode = currentNode->parentNode(); if (currentNode == pastEndNode) break; @@ -421,14 +422,18 @@ static NSFileWrapper *fileWrapperForElement(Element* e) // for the range of the link. Note that we create the attributed string from the DOM, which // will have corrected any illegally nested <a> elements. if (linkStartNode && currentNode == linkStartNode) { - NSURL *URL = linkStartNode->document()->frame()->loader()->completeURL(parseURL(linkStartNode->getAttribute(hrefAttr))); + String href = parseURL(linkStartNode->getAttribute(hrefAttr)); + KURL kURL = linkStartNode->document()->frame()->loader()->completeURL(href.deprecatedString()); + + NSURL *URL = kURL.getNSURL(); NSRange tempRange = { linkStartLocation, [result length]-linkStartLocation }; // workaround for 4213314 [result addAttribute:NSLinkAttributeName value:URL range:tempRange]; linkStartNode = 0; } - } else if (currentNode->hasTagName(olTag) || currentNode->hasTagName(ulTag)) { + } + else if (currentNode->hasTagName(olTag) || currentNode->hasTagName(ulTag)) { if (!hasNewLine) - text.append('\n'); + text += '\n'; hasNewLine = true; } else if (currentNode->hasTagName(liTag)) { @@ -440,7 +445,7 @@ static NSFileWrapper *fileWrapperForElement(Element* e) } } if (!hasNewLine) - text.append('\n'); + text += '\n'; hasNewLine = true; } else if (currentNode->hasTagName(blockquoteTag) || currentNode->hasTagName(ddTag) || @@ -453,7 +458,7 @@ static NSFileWrapper *fileWrapperForElement(Element* e) currentNode->hasTagName(tdTag) || currentNode->hasTagName(thTag)) { if (!hasNewLine) - text.append('\n'); + text += '\n'; hasNewLine = true; } else if (currentNode->hasTagName(pTag) || currentNode->hasTagName(trTag) || @@ -464,13 +469,13 @@ static NSFileWrapper *fileWrapperForElement(Element* e) currentNode->hasTagName(h5Tag) || currentNode->hasTagName(h6Tag)) { if (!hasNewLine) - text.append('\n'); + text += '\n'; // An extra newline is needed at the start, not the end, of these types of tags, // so don't add another here. hasNewLine = true; } - NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:text]; + NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:text.getNSString()]; [result appendAttributedString:partialString]; [partialString release]; } |