Changeset 65265 in webkit
- Timestamp:
- Aug 12, 2010 2:06:42 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r65261 r65265 1 2010-08-11 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Kent Tamura. 4 5 merge MarkupAccumulator and MarkupAccumulatorWrapper 6 https://bugs.webkit.org/show_bug.cgi?id=43834 7 8 Removed MarkupAccumulator and added serializeNodesWithNamespaces to use MarkupAccumulatorWrapper 9 in both versions of createMarkup. Accumulation of nodes done manually in serializeNodes is 10 now done by MarkupAccumulatorWrapper as done in the original MarkupAccumulator. 11 12 No new tests added since this is a cleanup. 13 14 * editing/markup.cpp: 15 (WebCore::MarkupAccumulatorWrapper::MarkupAccumulatorWrapper): Takes vector of nodes and set it to m_nodes. 16 (WebCore::MarkupAccumulatorWrapper::insertOpenTag): Adds node to m_nodes. 17 (WebCore::MarkupAccumulatorWrapper::wrapWithNode): Adds node to m_nodes. 18 (WebCore::serializeNodes): Adding node to nodes is moved into MarkupAccumulatorWrapper. 19 (WebCore::createMarkup): Instantiates MarkupAccumulatorWrapper. 20 (WebCore::serializeNodesWithNamespaces): Renamed from MarkupAccumulator::appendMarkup. 21 1 22 2010-08-12 Dirk Schulze <krit@webkit.org> 2 23 -
trunk/WebCore/editing/markup.cpp
r65021 r65265 592 592 } 593 593 594 class MarkupAccumulator {595 public:596 MarkupAccumulator(Node* nodeToSkip, Vector<Node*>* nodes)597 : m_nodeToSkip(nodeToSkip)598 , m_nodes(nodes)599 {600 }601 602 void appendMarkup(Node* startNode, EChildrenOnly, EAbsoluteURLs, const HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces = 0);603 604 String takeResult() { return String::adopt(m_result); }605 606 private:607 Vector<UChar> m_result;608 Node* m_nodeToSkip;609 Vector<Node*>* m_nodes;610 };611 612 // FIXME: Would be nice to do this in a non-recursive way.613 void MarkupAccumulator::appendMarkup(Node* startNode, EChildrenOnly childrenOnly, EAbsoluteURLs absoluteURLs, const HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces)614 {615 if (startNode == m_nodeToSkip)616 return;617 618 HashMap<AtomicStringImpl*, AtomicStringImpl*> namespaceHash;619 if (namespaces)620 namespaceHash = *namespaces;621 622 // start tag623 if (!childrenOnly) {624 if (m_nodes)625 m_nodes->append(startNode);626 appendStartMarkup(m_result, startNode, 0, DoNotAnnotateForInterchange, absoluteURLs, false, &namespaceHash);627 }628 629 // children630 if (!(startNode->document()->isHTMLDocument() && doesHTMLForbidEndTag(startNode))) {631 for (Node* current = startNode->firstChild(); current; current = current->nextSibling())632 appendMarkup(current, IncludeNode, absoluteURLs, &namespaceHash);633 }634 635 // end tag636 if (!childrenOnly)637 appendEndMarkup(m_result, startNode);638 }639 640 594 static void completeURLs(Node* node, const String& baseURL) 641 595 { … … 738 692 class MarkupAccumulatorWrapper { 739 693 public: 740 MarkupAccumulatorWrapper() 694 MarkupAccumulatorWrapper(Vector<Node*>* nodes) 695 : m_nodes(nodes) 741 696 { 742 697 } … … 747 702 } 748 703 749 void insertOpenTag(const Node* node, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs, bool convertBlocksToInlines = false, RangeFullySelectsNode rangeFullySelectsNode = DoesFullySelectNode)704 void insertOpenTag(const Node* node, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs, bool convertBlocksToInlines = false, HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces = 0, RangeFullySelectsNode rangeFullySelectsNode = DoesFullySelectNode) 750 705 { 751 706 Vector<UChar> result; 752 appendStartMarkup(result, node, range, annotate, absoluteURLs, convertBlocksToInlines, 0, rangeFullySelectsNode);707 appendStartMarkup(result, node, range, annotate, absoluteURLs, convertBlocksToInlines, namespaces, rangeFullySelectsNode); 753 708 postMarkups.append(String::adopt(result)); 709 if (m_nodes) 710 m_nodes->append(const_cast<Node*>(node)); 754 711 } 755 712 … … 761 718 } 762 719 763 void wrapWithNode(const Node* node, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs, bool convertBlocksToInlines = false, RangeFullySelectsNode rangeFullySelectsNode = DoesFullySelectNode)720 void wrapWithNode(const Node* node, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs, bool convertBlocksToInlines = false, HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces = 0, RangeFullySelectsNode rangeFullySelectsNode = DoesFullySelectNode) 764 721 { 765 722 Vector<UChar> result; 766 appendStartMarkup(result, node, range, annotate, absoluteURLs, convertBlocksToInlines, 0, rangeFullySelectsNode);723 appendStartMarkup(result, node, range, annotate, absoluteURLs, convertBlocksToInlines, namespaces, rangeFullySelectsNode); 767 724 preMarkups.append(String::adopt(result)); 768 725 insertEndTag(node); 726 if (m_nodes) 727 m_nodes->append(const_cast<Node*>(node)); 769 728 } 770 729 … … 815 774 816 775 private: 776 Vector<Node*>* m_nodes; 817 777 Vector<String> preMarkups; 818 778 Vector<String> postMarkups; 819 779 }; 820 780 821 static Node* serializeNodes(MarkupAccumulatorWrapper& accumulator, Node* startNode, Node* pastEnd, Vector<Node*>* nodes,const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs)781 static Node* serializeNodes(MarkupAccumulatorWrapper& accumulator, Node* startNode, Node* pastEnd, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs) 822 782 { 823 783 Vector<Node*> ancestorsToClose; … … 848 808 // Add the node to the markup if we're not skipping the descendants 849 809 accumulator.insertOpenTag(n, range, annotate, absoluteURLs); 850 if (nodes)851 nodes->append(n);852 810 853 811 // If node has no children, close the tag now. … … 886 844 ASSERT(startNode->isDescendantOf(parent)); 887 845 accumulator.wrapWithNode(parent, range, annotate, absoluteURLs); 888 if (nodes)889 nodes->append(parent);890 846 lastClosed = parent; 891 847 } … … 933 889 document->updateLayoutIgnorePendingStylesheets(); 934 890 935 MarkupAccumulatorWrapper accumulator ;891 MarkupAccumulatorWrapper accumulator(nodes); 936 892 Node* pastEnd = updatedRange->pastLastNode(); 937 893 … … 956 912 } 957 913 958 Node* lastClosed = serializeNodes(accumulator, startNode, pastEnd, nodes,range, annotate, absoluteURLs);914 Node* lastClosed = serializeNodes(accumulator, startNode, pastEnd, range, annotate, absoluteURLs); 959 915 960 916 // Include ancestors that aren't completely inside the range but are required to retain … … 1031 987 // Since this node and all the other ancestors are not in the selection we want to set RangeFullySelectsNode to DoesNotFullySelectNode 1032 988 // so that styles that affect the exterior of the node are not included. 1033 accumulator.wrapWithNode(ancestor, updatedRange.get(), annotate, absoluteURLs, convertBlocksToInlines, DoesNotFullySelectNode);989 accumulator.wrapWithNode(ancestor, updatedRange.get(), annotate, absoluteURLs, convertBlocksToInlines, 0, DoesNotFullySelectNode); 1034 990 } 1035 991 if (nodes) … … 1096 1052 } 1097 1053 1054 static void serializeNodesWithNamespaces(MarkupAccumulatorWrapper& accumulator, const Node* node, Node* nodeToSkip, EChildrenOnly childrenOnly, EAbsoluteURLs absoluteURLs, const HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces) 1055 { 1056 if (node == nodeToSkip) 1057 return; 1058 1059 HashMap<AtomicStringImpl*, AtomicStringImpl*> namespaceHash; 1060 if (namespaces) 1061 namespaceHash = *namespaces; 1062 1063 if (!childrenOnly) 1064 accumulator.insertOpenTag(node, 0, DoNotAnnotateForInterchange, absoluteURLs, false, &namespaceHash); 1065 1066 if (!(node->document()->isHTMLDocument() && doesHTMLForbidEndTag(node))) { 1067 for (Node* current = node->firstChild(); current; current = current->nextSibling()) 1068 serializeNodesWithNamespaces(accumulator, current, nodeToSkip, IncludeNode, absoluteURLs, &namespaceHash); 1069 } 1070 1071 if (!childrenOnly) 1072 accumulator.insertEndTag(node); 1073 } 1074 1098 1075 String createMarkup(const Node* node, EChildrenOnly childrenOnly, Vector<Node*>* nodes, EAbsoluteURLs absoluteURLs) 1099 1076 { … … 1108 1085 } 1109 1086 1110 MarkupAccumulator accumulator(deleteButtonContainerElement,nodes);1111 accumulator.appendMarkup(const_cast<Node*>(node), childrenOnly, absoluteURLs);1112 return accumulator.takeResult ();1087 MarkupAccumulatorWrapper accumulator(nodes); 1088 serializeNodesWithNamespaces(accumulator, node, deleteButtonContainerElement, childrenOnly, absoluteURLs, 0); 1089 return accumulator.takeResults(); 1113 1090 } 1114 1091
Note: See TracChangeset
for help on using the changeset viewer.