| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
| 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. |
| 4 * Copyright (C) 2011 Igalia S.L. | 4 * Copyright (C) 2011 Igalia S.L. |
| 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 positionBeforeNode(nodeAfterContext.get()).parentAnchoredEquivalent()); | 722 positionBeforeNode(nodeAfterContext.get()).parentAnchoredEquivalent()); |
| 723 | 723 |
| 724 Node* commonAncestor = range->commonAncestorContainer(ASSERT_NO_EXCEPTION); | 724 Node* commonAncestor = range->commonAncestorContainer(ASSERT_NO_EXCEPTION); |
| 725 Node* specialCommonAncestor = ancestorToRetainStructureAndAppearanceWithNoRe
nderer(commonAncestor); | 725 Node* specialCommonAncestor = ancestorToRetainStructureAndAppearanceWithNoRe
nderer(commonAncestor); |
| 726 | 726 |
| 727 // When there's a special common ancestor outside of the fragment, we must i
nclude it as well to | 727 // When there's a special common ancestor outside of the fragment, we must i
nclude it as well to |
| 728 // preserve the structure and appearance of the fragment. For example, if th
e fragment contains | 728 // preserve the structure and appearance of the fragment. For example, if th
e fragment contains |
| 729 // TD, we need to include the enclosing TABLE tag as well. | 729 // TD, we need to include the enclosing TABLE tag as well. |
| 730 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document); | 730 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document); |
| 731 if (specialCommonAncestor) | 731 if (specialCommonAncestor) |
| 732 fragment->appendChild(specialCommonAncestor, ASSERT_NO_EXCEPTION); | 732 fragment->appendChild(specialCommonAncestor, ASSERT_NO_EXCEPTION, Deprec
atedAttachNow); |
| 733 else | 733 else |
| 734 fragment->takeAllChildrenFrom(toContainerNode(commonAncestor)); | 734 fragment->takeAllChildrenFrom(toContainerNode(commonAncestor)); |
| 735 | 735 |
| 736 trimFragment(fragment.get(), nodeBeforeContext.get(), nodeAfterContext.get()
); | 736 trimFragment(fragment.get(), nodeBeforeContext.get(), nodeAfterContext.get()
); |
| 737 | 737 |
| 738 return fragment; | 738 return fragment; |
| 739 } | 739 } |
| 740 | 740 |
| 741 String createMarkup(const Node* node, EChildrenOnly childrenOnly, Vector<Node*>*
nodes, EAbsoluteURLs shouldResolveURLs, Vector<QualifiedName>* tagNamesToSkip) | 741 String createMarkup(const Node* node, EChildrenOnly childrenOnly, Vector<Node*>*
nodes, EAbsoluteURLs shouldResolveURLs, Vector<QualifiedName>* tagNamesToSkip) |
| 742 { | 742 { |
| 743 if (!node) | 743 if (!node) |
| 744 return ""; | 744 return ""; |
| 745 | 745 |
| 746 MarkupAccumulator accumulator(nodes, shouldResolveURLs); | 746 MarkupAccumulator accumulator(nodes, shouldResolveURLs); |
| 747 return accumulator.serializeNodes(const_cast<Node*>(node), childrenOnly, tag
NamesToSkip); | 747 return accumulator.serializeNodes(const_cast<Node*>(node), childrenOnly, tag
NamesToSkip); |
| 748 } | 748 } |
| 749 | 749 |
| 750 static void fillContainerFromString(ContainerNode* paragraph, const String& stri
ng) | 750 static void fillContainerFromString(ContainerNode* paragraph, const String& stri
ng) |
| 751 { | 751 { |
| 752 Document* document = paragraph->document(); | 752 Document* document = paragraph->document(); |
| 753 | 753 |
| 754 if (string.isEmpty()) { | 754 if (string.isEmpty()) { |
| 755 paragraph->appendChild(createBlockPlaceholderElement(document), ASSERT_N
O_EXCEPTION); | 755 paragraph->appendChild(createBlockPlaceholderElement(document), ASSERT_N
O_EXCEPTION, DeprecatedAttachNow); |
| 756 return; | 756 return; |
| 757 } | 757 } |
| 758 | 758 |
| 759 ASSERT(string.find('\n') == notFound); | 759 ASSERT(string.find('\n') == notFound); |
| 760 | 760 |
| 761 Vector<String> tabList; | 761 Vector<String> tabList; |
| 762 string.split('\t', true, tabList); | 762 string.split('\t', true, tabList); |
| 763 String tabText = emptyString(); | 763 String tabText = emptyString(); |
| 764 bool first = true; | 764 bool first = true; |
| 765 size_t numEntries = tabList.size(); | 765 size_t numEntries = tabList.size(); |
| 766 for (size_t i = 0; i < numEntries; ++i) { | 766 for (size_t i = 0; i < numEntries; ++i) { |
| 767 const String& s = tabList[i]; | 767 const String& s = tabList[i]; |
| 768 | 768 |
| 769 // append the non-tab textual part | 769 // append the non-tab textual part |
| 770 if (!s.isEmpty()) { | 770 if (!s.isEmpty()) { |
| 771 if (!tabText.isEmpty()) { | 771 if (!tabText.isEmpty()) { |
| 772 paragraph->appendChild(createTabSpanElement(document, tabText),
ASSERT_NO_EXCEPTION); | 772 paragraph->appendChild(createTabSpanElement(document, tabText),
ASSERT_NO_EXCEPTION, DeprecatedAttachNow); |
| 773 tabText = emptyString(); | 773 tabText = emptyString(); |
| 774 } | 774 } |
| 775 RefPtr<Node> textNode = document->createTextNode(stringWithRebalance
dWhitespace(s, first, i + 1 == numEntries)); | 775 RefPtr<Node> textNode = document->createTextNode(stringWithRebalance
dWhitespace(s, first, i + 1 == numEntries)); |
| 776 paragraph->appendChild(textNode.release(), ASSERT_NO_EXCEPTION); | 776 paragraph->appendChild(textNode.release(), ASSERT_NO_EXCEPTION, Depr
ecatedAttachNow); |
| 777 } | 777 } |
| 778 | 778 |
| 779 // there is a tab after every entry, except the last entry | 779 // there is a tab after every entry, except the last entry |
| 780 // (if the last character is a tab, the list gets an extra empty entry) | 780 // (if the last character is a tab, the list gets an extra empty entry) |
| 781 if (i + 1 != numEntries) | 781 if (i + 1 != numEntries) |
| 782 tabText.append('\t'); | 782 tabText.append('\t'); |
| 783 else if (!tabText.isEmpty()) | 783 else if (!tabText.isEmpty()) |
| 784 paragraph->appendChild(createTabSpanElement(document, tabText), ASSE
RT_NO_EXCEPTION); | 784 paragraph->appendChild(createTabSpanElement(document, tabText), ASSE
RT_NO_EXCEPTION, DeprecatedAttachNow); |
| 785 | 785 |
| 786 first = false; | 786 first = false; |
| 787 } | 787 } |
| 788 } | 788 } |
| 789 | 789 |
| 790 bool isPlainTextMarkup(Node *node) | 790 bool isPlainTextMarkup(Node *node) |
| 791 { | 791 { |
| 792 if (!node->isElementNode() || !node->hasTagName(divTag) || toElement(node)->
hasAttributes()) | 792 if (!node->isElementNode() || !node->hasTagName(divTag) || toElement(node)->
hasAttributes()) |
| 793 return false; | 793 return false; |
| 794 | 794 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 822 RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); | 822 RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); |
| 823 | 823 |
| 824 if (text.isEmpty()) | 824 if (text.isEmpty()) |
| 825 return fragment.release(); | 825 return fragment.release(); |
| 826 | 826 |
| 827 String string = text; | 827 String string = text; |
| 828 string.replace("\r\n", "\n"); | 828 string.replace("\r\n", "\n"); |
| 829 string.replace('\r', '\n'); | 829 string.replace('\r', '\n'); |
| 830 | 830 |
| 831 if (shouldPreserveNewline(*context)) { | 831 if (shouldPreserveNewline(*context)) { |
| 832 fragment->appendChild(document->createTextNode(string), ASSERT_NO_EXCEPT
ION); | 832 fragment->appendChild(document->createTextNode(string), ASSERT_NO_EXCEPT
ION, DeprecatedAttachNow); |
| 833 if (string.endsWith('\n')) { | 833 if (string.endsWith('\n')) { |
| 834 RefPtr<Element> element = createBreakElement(document); | 834 RefPtr<Element> element = createBreakElement(document); |
| 835 element->setAttribute(classAttr, AppleInterchangeNewline); | 835 element->setAttribute(classAttr, AppleInterchangeNewline); |
| 836 fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION); | 836 fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION, Deprec
atedAttachNow); |
| 837 } | 837 } |
| 838 return fragment.release(); | 838 return fragment.release(); |
| 839 } | 839 } |
| 840 | 840 |
| 841 // A string with no newlines gets added inline, rather than being put into a
paragraph. | 841 // A string with no newlines gets added inline, rather than being put into a
paragraph. |
| 842 if (string.find('\n') == notFound) { | 842 if (string.find('\n') == notFound) { |
| 843 fillContainerFromString(fragment.get(), string); | 843 fillContainerFromString(fragment.get(), string); |
| 844 return fragment.release(); | 844 return fragment.release(); |
| 845 } | 845 } |
| 846 | 846 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 868 } else if (useLineBreak) { | 868 } else if (useLineBreak) { |
| 869 element = createBreakElement(document); | 869 element = createBreakElement(document); |
| 870 fillContainerFromString(fragment.get(), s); | 870 fillContainerFromString(fragment.get(), s); |
| 871 } else { | 871 } else { |
| 872 if (useClonesOfEnclosingBlock) | 872 if (useClonesOfEnclosingBlock) |
| 873 element = block->cloneElementWithoutChildren(); | 873 element = block->cloneElementWithoutChildren(); |
| 874 else | 874 else |
| 875 element = createDefaultParagraphElement(document); | 875 element = createDefaultParagraphElement(document); |
| 876 fillContainerFromString(element.get(), s); | 876 fillContainerFromString(element.get(), s); |
| 877 } | 877 } |
| 878 fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION); | 878 fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION, Deprecated
AttachNow); |
| 879 } | 879 } |
| 880 return fragment.release(); | 880 return fragment.release(); |
| 881 } | 881 } |
| 882 | 882 |
| 883 PassRefPtr<DocumentFragment> createFragmentFromNodes(Document *document, const V
ector<Node*>& nodes) | 883 PassRefPtr<DocumentFragment> createFragmentFromNodes(Document *document, const V
ector<Node*>& nodes) |
| 884 { | 884 { |
| 885 if (!document) | 885 if (!document) |
| 886 return 0; | 886 return 0; |
| 887 | 887 |
| 888 RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); | 888 RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); |
| 889 | 889 |
| 890 size_t size = nodes.size(); | 890 size_t size = nodes.size(); |
| 891 for (size_t i = 0; i < size; ++i) { | 891 for (size_t i = 0; i < size; ++i) { |
| 892 RefPtr<Element> element = createDefaultParagraphElement(document); | 892 RefPtr<Element> element = createDefaultParagraphElement(document); |
| 893 element->appendChild(nodes[i], ASSERT_NO_EXCEPTION); | 893 element->appendChild(nodes[i], ASSERT_NO_EXCEPTION, DeprecatedAttachNow)
; |
| 894 fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION); | 894 fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION, Deprecated
AttachNow); |
| 895 } | 895 } |
| 896 | 896 |
| 897 return fragment.release(); | 897 return fragment.release(); |
| 898 } | 898 } |
| 899 | 899 |
| 900 String createFullMarkup(const Node* node) | 900 String createFullMarkup(const Node* node) |
| 901 { | 901 { |
| 902 if (!node) | 902 if (!node) |
| 903 return String(); | 903 return String(); |
| 904 | 904 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 | 992 |
| 993 return fragment.release(); | 993 return fragment.release(); |
| 994 } | 994 } |
| 995 | 995 |
| 996 static inline void removeElementPreservingChildren(PassRefPtr<DocumentFragment>
fragment, HTMLElement* element) | 996 static inline void removeElementPreservingChildren(PassRefPtr<DocumentFragment>
fragment, HTMLElement* element) |
| 997 { | 997 { |
| 998 RefPtr<Node> nextChild; | 998 RefPtr<Node> nextChild; |
| 999 for (RefPtr<Node> child = element->firstChild(); child; child = nextChild) { | 999 for (RefPtr<Node> child = element->firstChild(); child; child = nextChild) { |
| 1000 nextChild = child->nextSibling(); | 1000 nextChild = child->nextSibling(); |
| 1001 element->removeChild(child.get(), ASSERT_NO_EXCEPTION); | 1001 element->removeChild(child.get(), ASSERT_NO_EXCEPTION); |
| 1002 fragment->insertBefore(child, element, ASSERT_NO_EXCEPTION); | 1002 fragment->insertBefore(child, element, ASSERT_NO_EXCEPTION, DeprecatedAt
tachNow); |
| 1003 } | 1003 } |
| 1004 fragment->removeChild(element, ASSERT_NO_EXCEPTION); | 1004 fragment->removeChild(element, ASSERT_NO_EXCEPTION); |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 PassRefPtr<DocumentFragment> createContextualFragment(const String& markup, HTML
Element* element, ParserContentPolicy parserContentPolicy, ExceptionState& es) | 1007 PassRefPtr<DocumentFragment> createContextualFragment(const String& markup, HTML
Element* element, ParserContentPolicy parserContentPolicy, ExceptionState& es) |
| 1008 { | 1008 { |
| 1009 ASSERT(element); | 1009 ASSERT(element); |
| 1010 if (element->ieForbidsInsertHTML()) { | 1010 if (element->ieForbidsInsertHTML()) { |
| 1011 es.throwDOMException(NotSupportedError); | 1011 es.throwDOMException(NotSupportedError); |
| 1012 return 0; | 1012 return 0; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 if (containerNode->hasOneChild()) { | 1080 if (containerNode->hasOneChild()) { |
| 1081 containerNode->replaceChild(textNode.release(), containerNode->firstChil
d(), es, AttachLazily); | 1081 containerNode->replaceChild(textNode.release(), containerNode->firstChil
d(), es, AttachLazily); |
| 1082 return; | 1082 return; |
| 1083 } | 1083 } |
| 1084 | 1084 |
| 1085 containerNode->removeChildren(); | 1085 containerNode->removeChildren(); |
| 1086 containerNode->appendChild(textNode.release(), es, AttachLazily); | 1086 containerNode->appendChild(textNode.release(), es, AttachLazily); |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 } | 1089 } |
| OLD | NEW |