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 Apple Inc. All rights reserv
ed. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include <wtf/text/StringBuilder.h> | 51 #include <wtf/text/StringBuilder.h> |
52 | 52 |
53 namespace WebCore { | 53 namespace WebCore { |
54 | 54 |
55 using namespace std; | 55 using namespace std; |
56 | 56 |
57 #ifndef NDEBUG | 57 #ifndef NDEBUG |
58 static WTF::RefCountedLeakCounter rangeCounter("Range"); | 58 static WTF::RefCountedLeakCounter rangeCounter("Range"); |
59 #endif | 59 #endif |
60 | 60 |
| 61 typedef Vector<RefPtr<Node> > NodeVector; |
| 62 |
61 inline Range::Range(PassRefPtr<Document> ownerDocument) | 63 inline Range::Range(PassRefPtr<Document> ownerDocument) |
62 : m_ownerDocument(ownerDocument) | 64 : m_ownerDocument(ownerDocument) |
63 , m_start(m_ownerDocument) | 65 , m_start(m_ownerDocument) |
64 , m_end(m_ownerDocument) | 66 , m_end(m_ownerDocument) |
65 { | 67 { |
66 #ifndef NDEBUG | 68 #ifndef NDEBUG |
67 rangeCounter.increment(); | 69 rangeCounter.increment(); |
68 #endif | 70 #endif |
69 | 71 |
70 m_ownerDocument->attachRange(this); | 72 m_ownerDocument->attachRange(this); |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 case Node::XPATH_NAMESPACE_NODE: | 664 case Node::XPATH_NAMESPACE_NODE: |
663 case Node::SHADOW_ROOT_NODE: | 665 case Node::SHADOW_ROOT_NODE: |
664 return node->childNodeCount(); | 666 return node->childNodeCount(); |
665 } | 667 } |
666 ASSERT_NOT_REACHED(); | 668 ASSERT_NOT_REACHED(); |
667 return 0; | 669 return 0; |
668 } | 670 } |
669 | 671 |
670 PassRefPtr<DocumentFragment> Range::processContents(ActionType action, Exception
Code& ec) | 672 PassRefPtr<DocumentFragment> Range::processContents(ActionType action, Exception
Code& ec) |
671 { | 673 { |
672 typedef Vector<RefPtr<Node> > NodeVector; | |
673 | |
674 RefPtr<DocumentFragment> fragment; | 674 RefPtr<DocumentFragment> fragment; |
675 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) | 675 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) |
676 fragment = DocumentFragment::create(m_ownerDocument.get()); | 676 fragment = DocumentFragment::create(m_ownerDocument.get()); |
677 | 677 |
678 ec = 0; | 678 ec = 0; |
679 if (collapsed(ec)) | 679 if (collapsed(ec)) |
680 return fragment.release(); | 680 return fragment.release(); |
681 if (ec) | 681 if (ec) |
682 return 0; | 682 return 0; |
683 | 683 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 if (RefPtr<Node> clonedAncestor = ancestor->cloneNode(false)) { // M
ight have been removed already during mutation event. | 877 if (RefPtr<Node> clonedAncestor = ancestor->cloneNode(false)) { // M
ight have been removed already during mutation event. |
878 clonedAncestor->appendChild(clonedContainer, ec); | 878 clonedAncestor->appendChild(clonedContainer, ec); |
879 clonedContainer = clonedAncestor; | 879 clonedContainer = clonedAncestor; |
880 } | 880 } |
881 } | 881 } |
882 | 882 |
883 // Copy siblings of an ancestor of start/end containers | 883 // Copy siblings of an ancestor of start/end containers |
884 // FIXME: This assertion may fail if DOM is modified during mutation eve
nt | 884 // FIXME: This assertion may fail if DOM is modified during mutation eve
nt |
885 // FIXME: Share code with Range::processNodes | 885 // FIXME: Share code with Range::processNodes |
886 ASSERT(!firstChildInAncestorToProcess || firstChildInAncestorToProcess->
parentNode() == ancestor); | 886 ASSERT(!firstChildInAncestorToProcess || firstChildInAncestorToProcess->
parentNode() == ancestor); |
887 RefPtr<Node> next; | 887 |
888 for (Node* child = firstChildInAncestorToProcess.get(); child; child = n
ext.get()) { | 888 NodeVector nodes; |
889 next = direction == ProcessContentsForward ? child->nextSibling() :
child->previousSibling(); | 889 for (Node* child = firstChildInAncestorToProcess.get(); child; |
| 890 child = (direction == ProcessContentsForward) ? child->nextSibling()
: child->previousSibling()) |
| 891 nodes.append(child); |
| 892 |
| 893 for (NodeVector::const_iterator it = nodes.begin(); it != nodes.end(); i
t++) { |
| 894 Node* child = it->get(); |
890 switch (action) { | 895 switch (action) { |
891 case DELETE_CONTENTS: | 896 case DELETE_CONTENTS: |
892 ancestor->removeChild(child, ec); | 897 ancestor->removeChild(child, ec); |
893 break; | 898 break; |
894 case EXTRACT_CONTENTS: // will remove child from ancestor | 899 case EXTRACT_CONTENTS: // will remove child from ancestor |
895 if (direction == ProcessContentsForward) | 900 if (direction == ProcessContentsForward) |
896 clonedContainer->appendChild(child, ec); | 901 clonedContainer->appendChild(child, ec); |
897 else | 902 else |
898 clonedContainer->insertBefore(child, clonedContainer->firstC
hild(), ec); | 903 clonedContainer->insertBefore(child, clonedContainer->firstC
hild(), ec); |
899 break; | 904 break; |
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 | 2017 |
2013 void showTree(const WebCore::Range* range) | 2018 void showTree(const WebCore::Range* range) |
2014 { | 2019 { |
2015 if (range && range->boundaryPointsValid()) { | 2020 if (range && range->boundaryPointsValid()) { |
2016 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 2021 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
2017 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 2022 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
2018 } | 2023 } |
2019 } | 2024 } |
2020 | 2025 |
2021 #endif | 2026 #endif |
OLD | NEW |