| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) | 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) |
| 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) | 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) |
| 5 * (C) 2001 Peter Kelly (pmk@post.com) | 5 * (C) 2001 Peter Kelly (pmk@post.com) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
| 7 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 7 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 m_end = m_start; | 748 m_end = m_start; |
| 749 } | 749 } |
| 750 | 750 |
| 751 originalStart.clear(); | 751 originalStart.clear(); |
| 752 originalEnd.clear(); | 752 originalEnd.clear(); |
| 753 | 753 |
| 754 // Now add leftContents, stuff in between, and rightContents to the fragment | 754 // Now add leftContents, stuff in between, and rightContents to the fragment |
| 755 // (or just delete the stuff in between) | 755 // (or just delete the stuff in between) |
| 756 | 756 |
| 757 if ((action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) && leftContents
) | 757 if ((action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) && leftContents
) |
| 758 fragment->appendChild(leftContents, es); | 758 fragment->appendChild(leftContents, es, DeprecatedAttachNow); |
| 759 | 759 |
| 760 if (processStart) { | 760 if (processStart) { |
| 761 NodeVector nodes; | 761 NodeVector nodes; |
| 762 for (Node* n = processStart.get(); n && n != processEnd; n = n->nextSibl
ing()) | 762 for (Node* n = processStart.get(); n && n != processEnd; n = n->nextSibl
ing()) |
| 763 nodes.append(n); | 763 nodes.append(n); |
| 764 processNodes(action, nodes, commonRoot, fragment, es); | 764 processNodes(action, nodes, commonRoot, fragment, es); |
| 765 } | 765 } |
| 766 | 766 |
| 767 if ((action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) && rightContent
s) | 767 if ((action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) && rightContent
s) |
| 768 fragment->appendChild(rightContents, es); | 768 fragment->appendChild(rightContents, es, DeprecatedAttachNow); |
| 769 | 769 |
| 770 return fragment.release(); | 770 return fragment.release(); |
| 771 } | 771 } |
| 772 | 772 |
| 773 static inline void deleteCharacterData(PassRefPtr<CharacterData> data, unsigned
startOffset, unsigned endOffset, ExceptionState& es) | 773 static inline void deleteCharacterData(PassRefPtr<CharacterData> data, unsigned
startOffset, unsigned endOffset, ExceptionState& es) |
| 774 { | 774 { |
| 775 if (data->length() - endOffset) | 775 if (data->length() - endOffset) |
| 776 data->deleteData(endOffset, data->length() - endOffset, es); | 776 data->deleteData(endOffset, data->length() - endOffset, es); |
| 777 if (startOffset) | 777 if (startOffset) |
| 778 data->deleteData(0, startOffset, es); | 778 data->deleteData(0, startOffset, es); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 789 switch (container->nodeType()) { | 789 switch (container->nodeType()) { |
| 790 case Node::TEXT_NODE: | 790 case Node::TEXT_NODE: |
| 791 case Node::CDATA_SECTION_NODE: | 791 case Node::CDATA_SECTION_NODE: |
| 792 case Node::COMMENT_NODE: | 792 case Node::COMMENT_NODE: |
| 793 ASSERT(endOffset <= static_cast<CharacterData*>(container)->length()); | 793 ASSERT(endOffset <= static_cast<CharacterData*>(container)->length()); |
| 794 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { | 794 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { |
| 795 RefPtr<CharacterData> c = static_pointer_cast<CharacterData>(contain
er->cloneNode(true)); | 795 RefPtr<CharacterData> c = static_pointer_cast<CharacterData>(contain
er->cloneNode(true)); |
| 796 deleteCharacterData(c, startOffset, endOffset, es); | 796 deleteCharacterData(c, startOffset, endOffset, es); |
| 797 if (fragment) { | 797 if (fragment) { |
| 798 result = fragment; | 798 result = fragment; |
| 799 result->appendChild(c.release(), es); | 799 result->appendChild(c.release(), es, DeprecatedAttachNow); |
| 800 } else | 800 } else |
| 801 result = c.release(); | 801 result = c.release(); |
| 802 } | 802 } |
| 803 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) | 803 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) |
| 804 static_cast<CharacterData*>(container)->deleteData(startOffset, endO
ffset - startOffset, es); | 804 static_cast<CharacterData*>(container)->deleteData(startOffset, endO
ffset - startOffset, es); |
| 805 break; | 805 break; |
| 806 case Node::PROCESSING_INSTRUCTION_NODE: | 806 case Node::PROCESSING_INSTRUCTION_NODE: |
| 807 ASSERT(endOffset <= static_cast<ProcessingInstruction*>(container)->data
().length()); | 807 ASSERT(endOffset <= static_cast<ProcessingInstruction*>(container)->data
().length()); |
| 808 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { | 808 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { |
| 809 RefPtr<ProcessingInstruction> c = static_pointer_cast<ProcessingInst
ruction>(container->cloneNode(true)); | 809 RefPtr<ProcessingInstruction> c = static_pointer_cast<ProcessingInst
ruction>(container->cloneNode(true)); |
| 810 c->setData(c->data().substring(startOffset, endOffset - startOffset)
); | 810 c->setData(c->data().substring(startOffset, endOffset - startOffset)
); |
| 811 if (fragment) { | 811 if (fragment) { |
| 812 result = fragment; | 812 result = fragment; |
| 813 result->appendChild(c.release(), es); | 813 result->appendChild(c.release(), es, DeprecatedAttachNow); |
| 814 } else | 814 } else |
| 815 result = c.release(); | 815 result = c.release(); |
| 816 } | 816 } |
| 817 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) { | 817 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) { |
| 818 ProcessingInstruction* pi = static_cast<ProcessingInstruction*>(cont
ainer); | 818 ProcessingInstruction* pi = static_cast<ProcessingInstruction*>(cont
ainer); |
| 819 String data(pi->data()); | 819 String data(pi->data()); |
| 820 data.remove(startOffset, endOffset - startOffset); | 820 data.remove(startOffset, endOffset - startOffset); |
| 821 pi->setData(data); | 821 pi->setData(data); |
| 822 } | 822 } |
| 823 break; | 823 break; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 RefPtr<Node> clonedContainer = passedClonedContainer; | 875 RefPtr<Node> clonedContainer = passedClonedContainer; |
| 876 Vector<RefPtr<Node> > ancestors; | 876 Vector<RefPtr<Node> > ancestors; |
| 877 for (ContainerNode* n = container->parentNode(); n && n != commonRoot; n = n
->parentNode()) | 877 for (ContainerNode* n = container->parentNode(); n && n != commonRoot; n = n
->parentNode()) |
| 878 ancestors.append(n); | 878 ancestors.append(n); |
| 879 | 879 |
| 880 RefPtr<Node> firstChildInAncestorToProcess = direction == ProcessContentsFor
ward ? container->nextSibling() : container->previousSibling(); | 880 RefPtr<Node> firstChildInAncestorToProcess = direction == ProcessContentsFor
ward ? container->nextSibling() : container->previousSibling(); |
| 881 for (Vector<RefPtr<Node> >::const_iterator it = ancestors.begin(); it != anc
estors.end(); it++) { | 881 for (Vector<RefPtr<Node> >::const_iterator it = ancestors.begin(); it != anc
estors.end(); it++) { |
| 882 RefPtr<Node> ancestor = *it; | 882 RefPtr<Node> ancestor = *it; |
| 883 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { | 883 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { |
| 884 if (RefPtr<Node> clonedAncestor = ancestor->cloneNode(false)) { // M
ight have been removed already during mutation event. | 884 if (RefPtr<Node> clonedAncestor = ancestor->cloneNode(false)) { // M
ight have been removed already during mutation event. |
| 885 clonedAncestor->appendChild(clonedContainer, es); | 885 clonedAncestor->appendChild(clonedContainer, es, DeprecatedAttac
hNow); |
| 886 clonedContainer = clonedAncestor; | 886 clonedContainer = clonedAncestor; |
| 887 } | 887 } |
| 888 } | 888 } |
| 889 | 889 |
| 890 // Copy siblings of an ancestor of start/end containers | 890 // Copy siblings of an ancestor of start/end containers |
| 891 // FIXME: This assertion may fail if DOM is modified during mutation eve
nt | 891 // FIXME: This assertion may fail if DOM is modified during mutation eve
nt |
| 892 // FIXME: Share code with Range::processNodes | 892 // FIXME: Share code with Range::processNodes |
| 893 ASSERT(!firstChildInAncestorToProcess || firstChildInAncestorToProcess->
parentNode() == ancestor); | 893 ASSERT(!firstChildInAncestorToProcess || firstChildInAncestorToProcess->
parentNode() == ancestor); |
| 894 | 894 |
| 895 NodeVector nodes; | 895 NodeVector nodes; |
| 896 for (Node* child = firstChildInAncestorToProcess.get(); child; | 896 for (Node* child = firstChildInAncestorToProcess.get(); child; |
| 897 child = (direction == ProcessContentsForward) ? child->nextSibling()
: child->previousSibling()) | 897 child = (direction == ProcessContentsForward) ? child->nextSibling()
: child->previousSibling()) |
| 898 nodes.append(child); | 898 nodes.append(child); |
| 899 | 899 |
| 900 for (NodeVector::const_iterator it = nodes.begin(); it != nodes.end(); i
t++) { | 900 for (NodeVector::const_iterator it = nodes.begin(); it != nodes.end(); i
t++) { |
| 901 Node* child = it->get(); | 901 Node* child = it->get(); |
| 902 switch (action) { | 902 switch (action) { |
| 903 case DELETE_CONTENTS: | 903 case DELETE_CONTENTS: |
| 904 ancestor->removeChild(child, es); | 904 ancestor->removeChild(child, es); |
| 905 break; | 905 break; |
| 906 case EXTRACT_CONTENTS: // will remove child from ancestor | 906 case EXTRACT_CONTENTS: // will remove child from ancestor |
| 907 if (direction == ProcessContentsForward) | 907 if (direction == ProcessContentsForward) |
| 908 clonedContainer->appendChild(child, es); | 908 clonedContainer->appendChild(child, es, DeprecatedAttachNow)
; |
| 909 else | 909 else |
| 910 clonedContainer->insertBefore(child, clonedContainer->firstC
hild(), es); | 910 clonedContainer->insertBefore(child, clonedContainer->firstC
hild(), es, DeprecatedAttachNow); |
| 911 break; | 911 break; |
| 912 case CLONE_CONTENTS: | 912 case CLONE_CONTENTS: |
| 913 if (direction == ProcessContentsForward) | 913 if (direction == ProcessContentsForward) |
| 914 clonedContainer->appendChild(child->cloneNode(true), es); | 914 clonedContainer->appendChild(child->cloneNode(true), es, Dep
recatedAttachNow); |
| 915 else | 915 else |
| 916 clonedContainer->insertBefore(child->cloneNode(true), cloned
Container->firstChild(), es); | 916 clonedContainer->insertBefore(child->cloneNode(true), cloned
Container->firstChild(), es, DeprecatedAttachNow); |
| 917 break; | 917 break; |
| 918 } | 918 } |
| 919 } | 919 } |
| 920 firstChildInAncestorToProcess = direction == ProcessContentsForward ? an
cestor->nextSibling() : ancestor->previousSibling(); | 920 firstChildInAncestorToProcess = direction == ProcessContentsForward ? an
cestor->nextSibling() : ancestor->previousSibling(); |
| 921 } | 921 } |
| 922 | 922 |
| 923 return clonedContainer.release(); | 923 return clonedContainer.release(); |
| 924 } | 924 } |
| 925 | 925 |
| 926 PassRefPtr<DocumentFragment> Range::extractContents(ExceptionState& es) | 926 PassRefPtr<DocumentFragment> Range::extractContents(ExceptionState& es) |
| (...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1916 | 1916 |
| 1917 void showTree(const WebCore::Range* range) | 1917 void showTree(const WebCore::Range* range) |
| 1918 { | 1918 { |
| 1919 if (range && range->boundaryPointsValid()) { | 1919 if (range && range->boundaryPointsValid()) { |
| 1920 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1920 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
| 1921 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1921 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
| 1922 } | 1922 } |
| 1923 } | 1923 } |
| 1924 | 1924 |
| 1925 #endif | 1925 #endif |
| OLD | NEW |