Chromium Code Reviews| 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 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 728 case Node::DOCUMENT_TYPE_NODE: | 728 case Node::DOCUMENT_TYPE_NODE: |
| 729 case Node::DOCUMENT_FRAGMENT_NODE: | 729 case Node::DOCUMENT_FRAGMENT_NODE: |
| 730 // FIXME: Should we assert that some nodes never appear here? | 730 // FIXME: Should we assert that some nodes never appear here? |
| 731 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { | 731 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { |
| 732 if (fragment) | 732 if (fragment) |
| 733 result = fragment; | 733 result = fragment; |
| 734 else | 734 else |
| 735 result = container->cloneNode(false); | 735 result = container->cloneNode(false); |
| 736 } | 736 } |
| 737 | 737 |
| 738 Node* n = container->firstChild(); | 738 Node* n = toContainerNode(container)->firstChild(); |
|
esprehn
2014/06/02 19:03:37
This is not safe, a DOCUMENT_TYPE_NODE is not a Co
Inactive
2014/06/02 20:36:18
Good catch, thanks.
Inactive
2014/06/02 20:46:25
I kept this change out for now.
| |
| 739 Vector<RefPtr<Node> > nodes; | 739 Vector<RefPtr<Node> > nodes; |
| 740 for (unsigned i = startOffset; n && i; i--) | 740 for (unsigned i = startOffset; n && i; i--) |
| 741 n = n->nextSibling(); | 741 n = n->nextSibling(); |
| 742 for (unsigned i = startOffset; n && i < endOffset; i++, n = n->nextSibli ng()) | 742 for (unsigned i = startOffset; n && i < endOffset; i++, n = n->nextSibli ng()) |
| 743 nodes.append(n); | 743 nodes.append(n); |
| 744 | 744 |
| 745 processNodes(action, nodes, container, result, exceptionState); | 745 processNodes(action, nodes, container, result, exceptionState); |
| 746 break; | 746 break; |
| 747 } | 747 } |
| 748 | 748 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 if (startIsText) | 863 if (startIsText) |
| 864 checkAgainst = m_start.container()->parentNode(); | 864 checkAgainst = m_start.container()->parentNode(); |
| 865 else | 865 else |
| 866 checkAgainst = m_start.container(); | 866 checkAgainst = m_start.container(); |
| 867 | 867 |
| 868 Node::NodeType newNodeType = newNode->nodeType(); | 868 Node::NodeType newNodeType = newNode->nodeType(); |
| 869 int numNewChildren; | 869 int numNewChildren; |
| 870 if (newNodeType == Node::DOCUMENT_FRAGMENT_NODE && !newNode->isShadowRoot()) { | 870 if (newNodeType == Node::DOCUMENT_FRAGMENT_NODE && !newNode->isShadowRoot()) { |
| 871 // check each child node, not the DocumentFragment itself | 871 // check each child node, not the DocumentFragment itself |
| 872 numNewChildren = 0; | 872 numNewChildren = 0; |
| 873 for (Node* c = newNode->firstChild(); c; c = c->nextSibling()) { | 873 for (Node* c = toDocumentFragment(newNode)->firstChild(); c; c = c->next Sibling()) { |
| 874 if (!checkAgainst->childTypeAllowed(c->nodeType())) { | 874 if (!checkAgainst->childTypeAllowed(c->nodeType())) { |
| 875 exceptionState.throwDOMException(HierarchyRequestError, "The nod e to be inserted contains a '" + c->nodeName() + "' node, which may not be inser ted here."); | 875 exceptionState.throwDOMException(HierarchyRequestError, "The nod e to be inserted contains a '" + c->nodeName() + "' node, which may not be inser ted here."); |
| 876 return; | 876 return; |
| 877 } | 877 } |
| 878 ++numNewChildren; | 878 ++numNewChildren; |
| 879 } | 879 } |
| 880 } else { | 880 } else { |
| 881 numNewChildren = 1; | 881 numNewChildren = 1; |
| 882 if (!checkAgainst->childTypeAllowed(newNodeType)) { | 882 if (!checkAgainst->childTypeAllowed(newNodeType)) { |
| 883 exceptionState.throwDOMException(HierarchyRequestError, "The node to be inserted is a '" + newNode->nodeName() + "' node, which may not be inserted here."); | 883 exceptionState.throwDOMException(HierarchyRequestError, "The node to be inserted is a '" + newNode->nodeName() + "' node, which may not be inserted here."); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 916 return; | 916 return; |
| 917 | 917 |
| 918 container = m_start.container(); | 918 container = m_start.container(); |
| 919 container->parentNode()->insertBefore(newNode.release(), newText.get(), exceptionState); | 919 container->parentNode()->insertBefore(newNode.release(), newText.get(), exceptionState); |
| 920 if (exceptionState.hadException()) | 920 if (exceptionState.hadException()) |
| 921 return; | 921 return; |
| 922 | 922 |
| 923 if (collapsed) | 923 if (collapsed) |
| 924 m_end.setToBeforeChild(*newText); | 924 m_end.setToBeforeChild(*newText); |
| 925 } else { | 925 } else { |
| 926 RefPtr<Node> lastChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? newNode->lastChild() : newNode; | 926 RefPtr<Node> lastChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? toDocumentFragment(newNode)->lastChild() : newNode; |
| 927 if (lastChild && lastChild == m_start.childBefore()) { | 927 if (lastChild && lastChild == m_start.childBefore()) { |
| 928 // The insertion will do nothing, but we need to extend the range to include | 928 // The insertion will do nothing, but we need to extend the range to include |
| 929 // the inserted nodes. | 929 // the inserted nodes. |
| 930 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? n ewNode->firstChild() : newNode.get(); | 930 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? t oDocumentFragment(newNode)->firstChild() : newNode.get(); |
| 931 ASSERT(firstChild); | 931 ASSERT(firstChild); |
| 932 m_start.setToBeforeChild(*firstChild); | 932 m_start.setToBeforeChild(*firstChild); |
| 933 return; | 933 return; |
| 934 } | 934 } |
| 935 | 935 |
| 936 container = m_start.container(); | 936 container = m_start.container(); |
| 937 container->insertBefore(newNode.release(), container->traverseToChildAt( m_start.offset()), exceptionState); | 937 container->insertBefore(newNode.release(), container->traverseToChildAt( m_start.offset()), exceptionState); |
| 938 if (exceptionState.hadException()) | 938 if (exceptionState.hadException()) |
| 939 return; | 939 return; |
| 940 | 940 |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1688 | 1688 |
| 1689 void showTree(const WebCore::Range* range) | 1689 void showTree(const WebCore::Range* range) |
| 1690 { | 1690 { |
| 1691 if (range && range->boundaryPointsValid()) { | 1691 if (range && range->boundaryPointsValid()) { |
| 1692 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); | 1692 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); |
| 1693 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); | 1693 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); |
| 1694 } | 1694 } |
| 1695 } | 1695 } |
| 1696 | 1696 |
| 1697 #endif | 1697 #endif |
| OLD | NEW |