Changeset 69909 in webkit
- Timestamp:
- Oct 15, 2010 8:16:18 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r69907 r69909 1 2010-10-15 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Tony Chang. 4 5 serializeNodesWithNamespaces should be in MarkupAccumulator 6 https://bugs.webkit.org/show_bug.cgi?id=47749 7 8 Moved serializeNodesWithNamespaces to MarkupAccumulator, and renamed it to serializeNodes. 9 MarkupAccumulator::serializeNode now returns the resultant string instead of having a separate takeResults(). 10 Added several helper functions to MarkupAccumulator. 11 12 No new tests are added since this is a cleanup. 13 14 * editing/MarkupAccumulator.cpp: 15 (WebCore::MarkupAccumulator::serializeNodes): Wrapper for serializeNodes and concatenateMarkup. 16 (WebCore::MarkupAccumulator::serializeNodesWithNamespaces): Moved from markup.cpp 17 (WebCore::MarkupAccumulator::appendStartTag): Calls appendString instead of appending into m_succeedingMarkup directly. 18 (WebCore::MarkupAccumulator::appendEndTag): Ditto. 19 (WebCore::MarkupAccumulator::totalLength): Added; extracted from takeResults. 20 (WebCore::MarkupAccumulator::concatenateMarkup): Ditto. 21 * editing/MarkupAccumulator.h: 22 (WebCore::MarkupAccumulator::length): Added; calls totalLength. 23 * editing/markup.cpp: 24 (WebCore::StyledMarkupAccumulator::appendString): Added; calls MarkupAccumulator's appendString. 25 (WebCore::StyledMarkupAccumulator::wrapWithStyleNode): Calls appendString. 26 (WebCore::StyledMarkupAccumulator::takeResults): Calls length, totalLength, and concatenateMarkup. 27 (WebCore::StyledMarkupAccumulator::serializeNodes): Became a member function. 28 (WebCore::createMarkup): Uses MarkupAccumulator. 29 1 30 2010-10-15 Kinuko Yasuda <kinuko@google.com> 2 31 -
trunk/WebCore/editing/MarkupAccumulator.cpp
r69880 r69909 1 1 /* 2 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 11 12 * documentation and/or other materials provided with the distribution. 12 13 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 25 */ 25 26 … … 84 85 } 85 86 87 String MarkupAccumulator::serializeNodes(Node* node, Node* nodeToSkip, EChildrenOnly childrenOnly) 88 { 89 Vector<UChar> out; 90 serializeNodesWithNamespaces(node, nodeToSkip, childrenOnly, 0); 91 out.reserveInitialCapacity(length()); 92 concatenateMarkup(out); 93 return String::adopt(out); 94 } 95 96 void MarkupAccumulator::serializeNodesWithNamespaces(Node* node, Node* nodeToSkip, EChildrenOnly childrenOnly, const Namespaces* namespaces) 97 { 98 if (node == nodeToSkip) 99 return; 100 101 Namespaces namespaceHash; 102 if (namespaces) 103 namespaceHash = *namespaces; 104 105 if (!childrenOnly) 106 appendStartTag(node, &namespaceHash); 107 108 if (!(node->document()->isHTMLDocument() && elementCannotHaveEndTag(node))) { 109 for (Node* current = node->firstChild(); current; current = current->nextSibling()) 110 serializeNodesWithNamespaces(current, nodeToSkip, IncludeNode, &namespaceHash); 111 } 112 113 if (!childrenOnly) 114 appendEndTag(node); 115 } 116 86 117 void MarkupAccumulator::appendString(const String& string) 87 118 { … … 93 124 Vector<UChar> markup; 94 125 appendStartMarkup(markup, node, namespaces); 95 m_succeedingMarkup.append(String::adopt(markup));126 appendString(String::adopt(markup)); 96 127 if (m_nodes) 97 128 m_nodes->append(node); … … 102 133 Vector<UChar> markup; 103 134 appendEndMarkup(markup, node); 104 m_succeedingMarkup.append(String::adopt(markup)); 135 appendString(String::adopt(markup)); 136 } 137 138 size_t MarkupAccumulator::totalLength(const Vector<String>& strings) 139 { 140 size_t length = 0; 141 for (size_t i = 0; i < strings.size(); ++i) 142 length += strings[i].length(); 143 return length; 105 144 } 106 145 … … 108 147 // We're converting results of appendStartMarkup and appendEndMarkup from Vector<UChar> to String 109 148 // and then back to Vector<UChar> and again to String here. 110 String MarkupAccumulator::takeResults() 111 { 112 size_t length = 0; 113 114 size_t postCount = m_succeedingMarkup.size(); 115 for (size_t i = 0; i < postCount; ++i) 116 length += m_succeedingMarkup[i].length(); 117 118 Vector<UChar> result; 119 result.reserveInitialCapacity(length); 120 121 for (size_t i = 0; i < postCount; ++i) 122 append(result, m_succeedingMarkup[i]); 123 124 return String::adopt(result); 149 void MarkupAccumulator::concatenateMarkup(Vector<UChar>& out) 150 { 151 for (size_t i = 0; i < m_succeedingMarkup.size(); ++i) 152 append(out, m_succeedingMarkup[i]); 125 153 } 126 154 -
trunk/WebCore/editing/MarkupAccumulator.h
r69880 r69909 70 70 virtual ~MarkupAccumulator(); 71 71 72 String serializeNodes(Node* node, Node* nodeToSkip, EChildrenOnly childrenOnly); 73 74 protected: 72 75 void appendString(const String&); 73 76 void appendStartTag(Node*, Namespaces* = 0); 74 77 void appendEndTag(Node*); 75 virtual String takeResults();76 77 protected: 78 static size_t totalLength(const Vector<String>&); 79 size_t length() const { return totalLength(m_succeedingMarkup); } 80 void concatenateMarkup(Vector<UChar>& out); 78 81 void appendAttributeValue(Vector<UChar>& result, const String& attribute, bool documentIsHTML); 79 82 void appendQuotedURLAttributeValue(Vector<UChar>& result, const String& urlString); … … 100 103 Vector<Node*>* const m_nodes; 101 104 const Range* const m_range; 102 Vector<String> m_succeedingMarkup;103 105 104 106 private: 107 void serializeNodesWithNamespaces(Node*, Node* nodeToSkip, EChildrenOnly, const Namespaces*); 108 109 Vector<String> m_succeedingMarkup; 105 110 const bool m_shouldResolveURLs; 106 111 }; -
trunk/WebCore/editing/markup.cpp
r69880 r69909 140 140 { 141 141 } 142 143 Node* serializeNodes(Node* startNode, Node* pastEnd); 144 void appendString(const String& s) { return MarkupAccumulator::appendString(s); } 142 145 void wrapWithNode(Node*, bool convertBlocksToInlines = false, RangeFullySelectsNode = DoesFullySelectNode); 143 146 void wrapWithStyleNode(CSSStyleDeclaration*, Document*, bool isBlock = false); 144 147 String takeResults(); 145 148 146 pr otected:149 private: 147 150 virtual void appendText(Vector<UChar>& out, Text*); 148 151 String renderedText(const Node*, const Range*); … … 154 157 bool shouldAnnotate() { return m_shouldAnnotate == AnnotateForInterchange; } 155 158 156 private:157 159 Vector<String> m_reversedPrecedingMarkup; 158 160 const EAnnotateForInterchange m_shouldAnnotate; … … 187 189 openTag.append('>'); 188 190 m_reversedPrecedingMarkup.append(String::adopt(openTag)); 189 m_succeedingMarkup.append(isBlock ? divClose : styleSpanClose);191 appendString(isBlock ? divClose : styleSpanClose); 190 192 } 191 193 192 194 String StyledMarkupAccumulator::takeResults() 193 195 { 194 size_t length = 0;195 196 size_t preCount = m_reversedPrecedingMarkup.size();197 for (size_t i = 0; i < preCount; ++i)198 length += m_reversedPrecedingMarkup[i].length();199 200 size_t postCount = m_succeedingMarkup.size();201 for (size_t i = 0; i < postCount; ++i)202 length += m_succeedingMarkup[i].length();203 204 196 Vector<UChar> result; 205 result.reserveInitialCapacity( length);206 207 for (size_t i = preCount; i > 0; --i)197 result.reserveInitialCapacity(totalLength(m_reversedPrecedingMarkup) + length()); 198 199 for (size_t i = m_reversedPrecedingMarkup.size(); i > 0; --i) 208 200 append(result, m_reversedPrecedingMarkup[i - 1]); 209 201 210 for (size_t i = 0; i < postCount; ++i) 211 append(result, m_succeedingMarkup[i]); 202 concatenateMarkup(result); 212 203 213 204 return String::adopt(result); … … 343 334 } 344 335 345 static Node* serializeNodes(StyledMarkupAccumulator& accumulator,Node* startNode, Node* pastEnd)336 Node* StyledMarkupAccumulator::serializeNodes(Node* startNode, Node* pastEnd) 346 337 { 347 338 Vector<Node*> ancestorsToClose; … … 371 362 } else { 372 363 // Add the node to the markup if we're not skipping the descendants 373 a ccumulator.appendStartTag(n);364 appendStartTag(n); 374 365 375 366 // If node has no children, close the tag now. 376 367 if (!n->childNodeCount()) { 377 a ccumulator.appendEndTag(n);368 appendEndTag(n); 378 369 lastClosed = n; 379 370 } else { … … 392 383 break; 393 384 // Not at the end of the range, close ancestors up to sibling of next node. 394 a ccumulator.appendEndTag(ancestor);385 appendEndTag(ancestor); 395 386 lastClosed = ancestor; 396 387 ancestorsToClose.removeLast(); … … 407 398 // or b) ancestors that we never encountered during a pre-order traversal starting at startNode: 408 399 ASSERT(startNode->isDescendantOf(parent)); 409 accumulator.wrapWithNode(parent);400 wrapWithNode(parent); 410 401 lastClosed = parent; 411 402 } … … 631 622 Node* specialCommonAncestor = highestAncestorToWrapMarkup(updatedRange.get(), fullySelectedRoot, shouldAnnotate); 632 623 633 Node* lastClosed = serializeNodes(accumulator,startNode, pastEnd);624 Node* lastClosed = accumulator.serializeNodes(startNode, pastEnd); 634 625 635 626 if (specialCommonAncestor && lastClosed) { … … 727 718 } 728 719 729 static void serializeNodesWithNamespaces(MarkupAccumulator& accumulator, Node* node, Node* nodeToSkip, EChildrenOnly childrenOnly, const Namespaces* namespaces)730 {731 if (node == nodeToSkip)732 return;733 734 Namespaces namespaceHash;735 if (namespaces)736 namespaceHash = *namespaces;737 738 if (!childrenOnly)739 accumulator.appendStartTag(node, &namespaceHash);740 741 if (!(node->document()->isHTMLDocument() && elementCannotHaveEndTag(node))) {742 for (Node* current = node->firstChild(); current; current = current->nextSibling())743 serializeNodesWithNamespaces(accumulator, current, nodeToSkip, IncludeNode, &namespaceHash);744 }745 746 if (!childrenOnly)747 accumulator.appendEndTag(node);748 }749 750 720 String createMarkup(const Node* node, EChildrenOnly childrenOnly, Vector<Node*>* nodes, EAbsoluteURLs shouldResolveURLs) 751 721 { … … 761 731 762 732 MarkupAccumulator accumulator(nodes, shouldResolveURLs); 763 serializeNodesWithNamespaces(accumulator, const_cast<Node*>(node), deleteButtonContainerElement, childrenOnly, 0); 764 return accumulator.takeResults(); 733 return accumulator.serializeNodes(const_cast<Node*>(node), deleteButtonContainerElement, childrenOnly); 765 734 } 766 735
Note: See TracChangeset
for help on using the changeset viewer.