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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 if (fragment) { | 665 if (fragment) { |
666 result = fragment; | 666 result = fragment; |
667 result->appendChild(c.release(), exceptionState); | 667 result->appendChild(c.release(), exceptionState); |
668 } else | 668 } else |
669 result = c.release(); | 669 result = c.release(); |
670 } | 670 } |
671 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) | 671 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) |
672 toCharacterData(container)->deleteData(startOffset, endOffset - star
tOffset, exceptionState); | 672 toCharacterData(container)->deleteData(startOffset, endOffset - star
tOffset, exceptionState); |
673 break; | 673 break; |
674 case Node::ELEMENT_NODE: | 674 case Node::ELEMENT_NODE: |
675 case Node::ATTRIBUTE_NODE: | |
676 case Node::DOCUMENT_NODE: | 675 case Node::DOCUMENT_NODE: |
677 case Node::DOCUMENT_FRAGMENT_NODE: | 676 case Node::DOCUMENT_FRAGMENT_NODE: |
678 // FIXME: Should we assert that some nodes never appear here? | 677 // FIXME: Should we assert that some nodes never appear here? |
679 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { | 678 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { |
680 if (fragment) | 679 if (fragment) |
681 result = fragment; | 680 result = fragment; |
682 else | 681 else |
683 result = container->cloneNode(false); | 682 result = container->cloneNode(false); |
684 } | 683 } |
685 | 684 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 | 834 |
836 for (Node* n = m_start.container(); n; n = n->parentNode()) { | 835 for (Node* n = m_start.container(); n; n = n->parentNode()) { |
837 if (n == newNode) { | 836 if (n == newNode) { |
838 exceptionState.throwDOMException(HierarchyRequestError, "The node to
be inserted contains the insertion point; it may not be inserted into itself.")
; | 837 exceptionState.throwDOMException(HierarchyRequestError, "The node to
be inserted contains the insertion point; it may not be inserted into itself.")
; |
839 return; | 838 return; |
840 } | 839 } |
841 } | 840 } |
842 | 841 |
843 // InvalidNodeTypeError: Raised if newNode is an Attr, Entity, Notation, Sha
dowRoot or Document node. | 842 // InvalidNodeTypeError: Raised if newNode is an Attr, Entity, Notation, Sha
dowRoot or Document node. |
844 switch (newNodeType) { | 843 switch (newNodeType) { |
845 case Node::ATTRIBUTE_NODE: | |
846 case Node::DOCUMENT_NODE: | 844 case Node::DOCUMENT_NODE: |
847 exceptionState.throwDOMException(InvalidNodeTypeError, "The node to be i
nserted is a '" + newNode->nodeName() + "' node, which may not be inserted here.
"); | 845 exceptionState.throwDOMException(InvalidNodeTypeError, "The node to be i
nserted is a '" + newNode->nodeName() + "' node, which may not be inserted here.
"); |
848 return; | 846 return; |
849 default: | 847 default: |
850 if (newNode->isShadowRoot()) { | 848 if (newNode->isShadowRoot()) { |
851 exceptionState.throwDOMException(InvalidNodeTypeError, "The node to
be inserted is a shadow root, which may not be inserted here."); | 849 exceptionState.throwDOMException(InvalidNodeTypeError, "The node to
be inserted is a shadow root, which may not be inserted here."); |
852 return; | 850 return; |
853 } | 851 } |
854 break; | 852 break; |
855 } | 853 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 // This is now a no-op as per the DOM specification. | 933 // This is now a no-op as per the DOM specification. |
936 } | 934 } |
937 | 935 |
938 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionState& exceptionStat
e) const | 936 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionState& exceptionStat
e) const |
939 { | 937 { |
940 switch (n->nodeType()) { | 938 switch (n->nodeType()) { |
941 case Node::TEXT_NODE: | 939 case Node::TEXT_NODE: |
942 if (static_cast<unsigned>(offset) > toCharacterData(n)->length()) | 940 if (static_cast<unsigned>(offset) > toCharacterData(n)->length()) |
943 exceptionState.throwDOMException(IndexSizeError, "The offset " +
String::number(offset) + " is larger than or equal to the node's length (" + St
ring::number(toCharacterData(n)->length()) + ")."); | 941 exceptionState.throwDOMException(IndexSizeError, "The offset " +
String::number(offset) + " is larger than or equal to the node's length (" + St
ring::number(toCharacterData(n)->length()) + ")."); |
944 return 0; | 942 return 0; |
945 case Node::ATTRIBUTE_NODE: | |
946 case Node::DOCUMENT_FRAGMENT_NODE: | 943 case Node::DOCUMENT_FRAGMENT_NODE: |
947 case Node::DOCUMENT_NODE: | 944 case Node::DOCUMENT_NODE: |
948 case Node::ELEMENT_NODE: { | 945 case Node::ELEMENT_NODE: { |
949 if (!offset) | 946 if (!offset) |
950 return 0; | 947 return 0; |
951 Node* childBefore = NodeTraversal::childAt(*n, offset - 1); | 948 Node* childBefore = NodeTraversal::childAt(*n, offset - 1); |
952 if (!childBefore) | 949 if (!childBefore) |
953 exceptionState.throwDOMException(IndexSizeError, "There is no ch
ild at offset " + String::number(offset) + "."); | 950 exceptionState.throwDOMException(IndexSizeError, "There is no ch
ild at offset " + String::number(offset) + "."); |
954 return childBefore; | 951 return childBefore; |
955 } | 952 } |
(...skipping 12 matching lines...) Expand all Loading... |
968 // InvalidNodeTypeError: Raised if the root container of refNode is not an | 965 // InvalidNodeTypeError: Raised if the root container of refNode is not an |
969 // Attr, Document, DocumentFragment or ShadowRoot node, or part of a SVG sha
dow DOM tree, | 966 // Attr, Document, DocumentFragment or ShadowRoot node, or part of a SVG sha
dow DOM tree, |
970 // or if refNode is a Document, DocumentFragment, ShadowRoot, Attr, Entity,
or Notation node. | 967 // or if refNode is a Document, DocumentFragment, ShadowRoot, Attr, Entity,
or Notation node. |
971 | 968 |
972 if (!n->parentNode()) { | 969 if (!n->parentNode()) { |
973 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h
as no parent."); | 970 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h
as no parent."); |
974 return; | 971 return; |
975 } | 972 } |
976 | 973 |
977 switch (n->nodeType()) { | 974 switch (n->nodeType()) { |
978 case Node::ATTRIBUTE_NODE: | |
979 case Node::DOCUMENT_FRAGMENT_NODE: | 975 case Node::DOCUMENT_FRAGMENT_NODE: |
980 case Node::DOCUMENT_NODE: | 976 case Node::DOCUMENT_NODE: |
981 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro
vided is of type '" + n->nodeName() + "'."); | 977 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro
vided is of type '" + n->nodeName() + "'."); |
982 return; | 978 return; |
983 case Node::ELEMENT_NODE: | 979 case Node::ELEMENT_NODE: |
984 case Node::TEXT_NODE: | 980 case Node::TEXT_NODE: |
985 break; | 981 break; |
986 } | 982 } |
987 | 983 |
988 Node* root = n; | 984 Node* root = n; |
989 while (ContainerNode* parent = root->parentNode()) | 985 while (ContainerNode* parent = root->parentNode()) |
990 root = parent; | 986 root = parent; |
991 | 987 |
992 switch (root->nodeType()) { | 988 switch (root->nodeType()) { |
993 case Node::ATTRIBUTE_NODE: | |
994 case Node::DOCUMENT_NODE: | 989 case Node::DOCUMENT_NODE: |
995 case Node::DOCUMENT_FRAGMENT_NODE: | 990 case Node::DOCUMENT_FRAGMENT_NODE: |
996 case Node::ELEMENT_NODE: | 991 case Node::ELEMENT_NODE: |
997 break; | 992 break; |
998 case Node::TEXT_NODE: | 993 case Node::TEXT_NODE: |
999 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro
vided is of type '" + n->nodeName() + "'."); | 994 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro
vided is of type '" + n->nodeName() + "'."); |
1000 return; | 995 return; |
1001 } | 996 } |
1002 } | 997 } |
1003 | 998 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 return; | 1040 return; |
1046 } | 1041 } |
1047 | 1042 |
1048 // InvalidNodeTypeError: Raised if an ancestor of refNode is an Entity, Nota
tion or | 1043 // InvalidNodeTypeError: Raised if an ancestor of refNode is an Entity, Nota
tion or |
1049 // DocumentType node or if refNode is a Document, DocumentFragment, ShadowRo
ot, Attr, Entity, or Notation | 1044 // DocumentType node or if refNode is a Document, DocumentFragment, ShadowRo
ot, Attr, Entity, or Notation |
1050 // node. | 1045 // node. |
1051 switch (refNode->nodeType()) { | 1046 switch (refNode->nodeType()) { |
1052 case Node::ELEMENT_NODE: | 1047 case Node::ELEMENT_NODE: |
1053 case Node::TEXT_NODE: | 1048 case Node::TEXT_NODE: |
1054 break; | 1049 break; |
1055 case Node::ATTRIBUTE_NODE: | |
1056 case Node::DOCUMENT_FRAGMENT_NODE: | 1050 case Node::DOCUMENT_FRAGMENT_NODE: |
1057 case Node::DOCUMENT_NODE: | 1051 case Node::DOCUMENT_NODE: |
1058 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro
vided is of type '" + refNode->nodeName() + "'."); | 1052 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro
vided is of type '" + refNode->nodeName() + "'."); |
1059 return; | 1053 return; |
1060 } | 1054 } |
1061 | 1055 |
1062 if (m_ownerDocument != refNode->document()) | 1056 if (m_ownerDocument != refNode->document()) |
1063 setDocument(refNode->document()); | 1057 setDocument(refNode->document()); |
1064 | 1058 |
1065 setStartBefore(refNode); | 1059 setStartBefore(refNode); |
(...skipping 30 matching lines...) Expand all Loading... |
1096 if (endNonTextContainer->nodeType() == Node::TEXT_NODE) | 1090 if (endNonTextContainer->nodeType() == Node::TEXT_NODE) |
1097 endNonTextContainer = endNonTextContainer->parentNode(); | 1091 endNonTextContainer = endNonTextContainer->parentNode(); |
1098 if (startNonTextContainer != endNonTextContainer) { | 1092 if (startNonTextContainer != endNonTextContainer) { |
1099 exceptionState.throwDOMException(InvalidStateError, "The Range has parti
ally selected a non-Text node."); | 1093 exceptionState.throwDOMException(InvalidStateError, "The Range has parti
ally selected a non-Text node."); |
1100 return; | 1094 return; |
1101 } | 1095 } |
1102 | 1096 |
1103 // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType, No
tation, | 1097 // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType, No
tation, |
1104 // Document, or DocumentFragment node. | 1098 // Document, or DocumentFragment node. |
1105 switch (newParent->nodeType()) { | 1099 switch (newParent->nodeType()) { |
1106 case Node::ATTRIBUTE_NODE: | |
1107 case Node::DOCUMENT_FRAGMENT_NODE: | 1100 case Node::DOCUMENT_FRAGMENT_NODE: |
1108 case Node::DOCUMENT_NODE: | 1101 case Node::DOCUMENT_NODE: |
1109 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro
vided is of type '" + newParent->nodeName() + "'."); | 1102 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro
vided is of type '" + newParent->nodeName() + "'."); |
1110 return; | 1103 return; |
1111 case Node::ELEMENT_NODE: | 1104 case Node::ELEMENT_NODE: |
1112 case Node::TEXT_NODE: | 1105 case Node::TEXT_NODE: |
1113 break; | 1106 break; |
1114 } | 1107 } |
1115 | 1108 |
1116 // Raise a HierarchyRequestError if m_start.container() doesn't accept child
ren like newParent. | 1109 // Raise a HierarchyRequestError if m_start.container() doesn't accept child
ren like newParent. |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 | 1542 |
1550 void showTree(const blink::Range* range) | 1543 void showTree(const blink::Range* range) |
1551 { | 1544 { |
1552 if (range && range->boundaryPointsValid()) { | 1545 if (range && range->boundaryPointsValid()) { |
1553 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1546 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
1554 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1547 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
1555 } | 1548 } |
1556 } | 1549 } |
1557 | 1550 |
1558 #endif | 1551 #endif |
OLD | NEW |