Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(754)

Side by Side Diff: Source/core/dom/Range.cpp

Issue 739433003: Remove CDATASection (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/dom/Text.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 PassRefPtrWillBeRawPtr<Node> Range::processContentsBetweenOffsets(ActionType act ion, PassRefPtrWillBeRawPtr<DocumentFragment> fragment, 700 PassRefPtrWillBeRawPtr<Node> Range::processContentsBetweenOffsets(ActionType act ion, PassRefPtrWillBeRawPtr<DocumentFragment> fragment,
701 Node* container, unsigned startOffset, unsigned endOffset, ExceptionState& e xceptionState) 701 Node* container, unsigned startOffset, unsigned endOffset, ExceptionState& e xceptionState)
702 { 702 {
703 ASSERT(container); 703 ASSERT(container);
704 ASSERT(startOffset <= endOffset); 704 ASSERT(startOffset <= endOffset);
705 705
706 // This switch statement must be consistent with that of Node::lengthOfConte nts. 706 // This switch statement must be consistent with that of Node::lengthOfConte nts.
707 RefPtrWillBeRawPtr<Node> result = nullptr; 707 RefPtrWillBeRawPtr<Node> result = nullptr;
708 switch (container->nodeType()) { 708 switch (container->nodeType()) {
709 case Node::TEXT_NODE: 709 case Node::TEXT_NODE:
710 case Node::CDATA_SECTION_NODE:
711 case Node::COMMENT_NODE: 710 case Node::COMMENT_NODE:
712 endOffset = std::min(endOffset, toCharacterData(container)->length()); 711 endOffset = std::min(endOffset, toCharacterData(container)->length());
713 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { 712 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) {
714 RefPtrWillBeRawPtr<CharacterData> c = static_pointer_cast<CharacterD ata>(container->cloneNode(true)); 713 RefPtrWillBeRawPtr<CharacterData> c = static_pointer_cast<CharacterD ata>(container->cloneNode(true));
715 deleteCharacterData(c, startOffset, endOffset, exceptionState); 714 deleteCharacterData(c, startOffset, endOffset, exceptionState);
716 if (fragment) { 715 if (fragment) {
717 result = fragment; 716 result = fragment;
718 result->appendChild(c.release(), exceptionState); 717 result->appendChild(c.release(), exceptionState);
719 } else 718 } else
720 result = c.release(); 719 result = c.release();
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 } 969 }
971 } 970 }
972 971
973 String Range::toString() const 972 String Range::toString() const
974 { 973 {
975 StringBuilder builder; 974 StringBuilder builder;
976 975
977 Node* pastLast = pastLastNode(); 976 Node* pastLast = pastLastNode();
978 for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(*n)) { 977 for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(*n)) {
979 Node::NodeType type = n->nodeType(); 978 Node::NodeType type = n->nodeType();
980 if (type == Node::TEXT_NODE || type == Node::CDATA_SECTION_NODE) { 979 if (type == Node::TEXT_NODE) {
981 String data = toCharacterData(n)->data(); 980 String data = toCharacterData(n)->data();
982 int length = data.length(); 981 int length = data.length();
983 int start = (n == m_start.container()) ? std::min(std::max(0, m_star t.offset()), length) : 0; 982 int start = (n == m_start.container()) ? std::min(std::max(0, m_star t.offset()), length) : 0;
984 int end = (n == m_end.container()) ? std::min(std::max(start, m_end. offset()), length) : length; 983 int end = (n == m_end.container()) ? std::min(std::max(start, m_end. offset()), length) : length;
985 builder.append(data, start, end - start); 984 builder.append(data, start, end - start);
986 } 985 }
987 } 986 }
988 987
989 return builder.toString(); 988 return builder.toString();
990 } 989 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 { 1042 {
1044 // This is now a no-op as per the DOM specification. 1043 // This is now a no-op as per the DOM specification.
1045 } 1044 }
1046 1045
1047 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionState& exceptionStat e) const 1046 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionState& exceptionStat e) const
1048 { 1047 {
1049 switch (n->nodeType()) { 1048 switch (n->nodeType()) {
1050 case Node::DOCUMENT_TYPE_NODE: 1049 case Node::DOCUMENT_TYPE_NODE:
1051 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + n->nodeName() + "'."); 1050 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + n->nodeName() + "'.");
1052 return nullptr; 1051 return nullptr;
1053 case Node::CDATA_SECTION_NODE:
1054 case Node::COMMENT_NODE: 1052 case Node::COMMENT_NODE:
1055 case Node::TEXT_NODE: 1053 case Node::TEXT_NODE:
1056 if (static_cast<unsigned>(offset) > toCharacterData(n)->length()) 1054 if (static_cast<unsigned>(offset) > toCharacterData(n)->length())
1057 exceptionState.throwDOMException(IndexSizeError, "The offset " + String::number(offset) + " is larger than or equal to the node's length (" + St ring::number(toCharacterData(n)->length()) + ")."); 1055 exceptionState.throwDOMException(IndexSizeError, "The offset " + String::number(offset) + " is larger than or equal to the node's length (" + St ring::number(toCharacterData(n)->length()) + ").");
1058 return nullptr; 1056 return nullptr;
1059 case Node::PROCESSING_INSTRUCTION_NODE: 1057 case Node::PROCESSING_INSTRUCTION_NODE:
1060 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data ().length()) 1058 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data ().length())
1061 exceptionState.throwDOMException(IndexSizeError, "The offset " + String::number(offset) + " is larger than or equal to than the node's length (" + String::number(toProcessingInstruction(n)->data().length()) + ")."); 1059 exceptionState.throwDOMException(IndexSizeError, "The offset " + String::number(offset) + " is larger than or equal to than the node's length (" + String::number(toProcessingInstruction(n)->data().length()) + ").");
1062 return nullptr; 1060 return nullptr;
1063 case Node::ATTRIBUTE_NODE: 1061 case Node::ATTRIBUTE_NODE:
(...skipping 27 matching lines...) Expand all
1091 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent."); 1089 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent.");
1092 return; 1090 return;
1093 } 1091 }
1094 1092
1095 switch (n->nodeType()) { 1093 switch (n->nodeType()) {
1096 case Node::ATTRIBUTE_NODE: 1094 case Node::ATTRIBUTE_NODE:
1097 case Node::DOCUMENT_FRAGMENT_NODE: 1095 case Node::DOCUMENT_FRAGMENT_NODE:
1098 case Node::DOCUMENT_NODE: 1096 case Node::DOCUMENT_NODE:
1099 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + n->nodeName() + "'."); 1097 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + n->nodeName() + "'.");
1100 return; 1098 return;
1101 case Node::CDATA_SECTION_NODE:
1102 case Node::COMMENT_NODE: 1099 case Node::COMMENT_NODE:
1103 case Node::DOCUMENT_TYPE_NODE: 1100 case Node::DOCUMENT_TYPE_NODE:
1104 case Node::ELEMENT_NODE: 1101 case Node::ELEMENT_NODE:
1105 case Node::PROCESSING_INSTRUCTION_NODE: 1102 case Node::PROCESSING_INSTRUCTION_NODE:
1106 case Node::TEXT_NODE: 1103 case Node::TEXT_NODE:
1107 break; 1104 break;
1108 } 1105 }
1109 1106
1110 Node* root = n; 1107 Node* root = n;
1111 while (ContainerNode* parent = root->parentNode()) 1108 while (ContainerNode* parent = root->parentNode())
1112 root = parent; 1109 root = parent;
1113 1110
1114 switch (root->nodeType()) { 1111 switch (root->nodeType()) {
1115 case Node::ATTRIBUTE_NODE: 1112 case Node::ATTRIBUTE_NODE:
1116 case Node::DOCUMENT_NODE: 1113 case Node::DOCUMENT_NODE:
1117 case Node::DOCUMENT_FRAGMENT_NODE: 1114 case Node::DOCUMENT_FRAGMENT_NODE:
1118 case Node::ELEMENT_NODE: 1115 case Node::ELEMENT_NODE:
1119 break; 1116 break;
1120 case Node::CDATA_SECTION_NODE:
1121 case Node::COMMENT_NODE: 1117 case Node::COMMENT_NODE:
1122 case Node::DOCUMENT_TYPE_NODE: 1118 case Node::DOCUMENT_TYPE_NODE:
1123 case Node::PROCESSING_INSTRUCTION_NODE: 1119 case Node::PROCESSING_INSTRUCTION_NODE:
1124 case Node::TEXT_NODE: 1120 case Node::TEXT_NODE:
1125 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + n->nodeName() + "'."); 1121 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + n->nodeName() + "'.");
1126 return; 1122 return;
1127 } 1123 }
1128 } 1124 }
1129 1125
1130 PassRefPtrWillBeRawPtr<Range> Range::cloneRange() const 1126 PassRefPtrWillBeRawPtr<Range> Range::cloneRange() const
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent."); 1166 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent.");
1171 return; 1167 return;
1172 } 1168 }
1173 1169
1174 // InvalidNodeTypeError: Raised if an ancestor of refNode is an Entity, Nota tion or 1170 // InvalidNodeTypeError: Raised if an ancestor of refNode is an Entity, Nota tion or
1175 // DocumentType node or if refNode is a Document, DocumentFragment, ShadowRo ot, Attr, Entity, or Notation 1171 // DocumentType node or if refNode is a Document, DocumentFragment, ShadowRo ot, Attr, Entity, or Notation
1176 // node. 1172 // node.
1177 for (ContainerNode* anc = refNode->parentNode(); anc; anc = anc->parentNode( )) { 1173 for (ContainerNode* anc = refNode->parentNode(); anc; anc = anc->parentNode( )) {
1178 switch (anc->nodeType()) { 1174 switch (anc->nodeType()) {
1179 case Node::ATTRIBUTE_NODE: 1175 case Node::ATTRIBUTE_NODE:
1180 case Node::CDATA_SECTION_NODE:
1181 case Node::COMMENT_NODE: 1176 case Node::COMMENT_NODE:
1182 case Node::DOCUMENT_FRAGMENT_NODE: 1177 case Node::DOCUMENT_FRAGMENT_NODE:
1183 case Node::DOCUMENT_NODE: 1178 case Node::DOCUMENT_NODE:
1184 case Node::ELEMENT_NODE: 1179 case Node::ELEMENT_NODE:
1185 case Node::PROCESSING_INSTRUCTION_NODE: 1180 case Node::PROCESSING_INSTRUCTION_NODE:
1186 case Node::TEXT_NODE: 1181 case Node::TEXT_NODE:
1187 break; 1182 break;
1188 case Node::DOCUMENT_TYPE_NODE: 1183 case Node::DOCUMENT_TYPE_NODE:
1189 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provided has an ancestor of type '" + anc->nodeName() + "'."); 1184 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provided has an ancestor of type '" + anc->nodeName() + "'.");
1190 return; 1185 return;
1191 } 1186 }
1192 } 1187 }
1193 1188
1194 switch (refNode->nodeType()) { 1189 switch (refNode->nodeType()) {
1195 case Node::CDATA_SECTION_NODE:
1196 case Node::COMMENT_NODE: 1190 case Node::COMMENT_NODE:
1197 case Node::DOCUMENT_TYPE_NODE: 1191 case Node::DOCUMENT_TYPE_NODE:
1198 case Node::ELEMENT_NODE: 1192 case Node::ELEMENT_NODE:
1199 case Node::PROCESSING_INSTRUCTION_NODE: 1193 case Node::PROCESSING_INSTRUCTION_NODE:
1200 case Node::TEXT_NODE: 1194 case Node::TEXT_NODE:
1201 break; 1195 break;
1202 case Node::ATTRIBUTE_NODE: 1196 case Node::ATTRIBUTE_NODE:
1203 case Node::DOCUMENT_FRAGMENT_NODE: 1197 case Node::DOCUMENT_FRAGMENT_NODE:
1204 case Node::DOCUMENT_NODE: 1198 case Node::DOCUMENT_NODE:
1205 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + refNode->nodeName() + "'."); 1199 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + refNode->nodeName() + "'.");
(...skipping 12 matching lines...) Expand all
1218 if (!refNode) { 1212 if (!refNode) {
1219 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll."); 1213 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll.");
1220 return; 1214 return;
1221 } 1215 }
1222 1216
1223 // InvalidNodeTypeError: Raised if refNode or an ancestor of refNode is an E ntity, Notation 1217 // InvalidNodeTypeError: Raised if refNode or an ancestor of refNode is an E ntity, Notation
1224 // or DocumentType node. 1218 // or DocumentType node.
1225 for (Node* n = refNode; n; n = n->parentNode()) { 1219 for (Node* n = refNode; n; n = n->parentNode()) {
1226 switch (n->nodeType()) { 1220 switch (n->nodeType()) {
1227 case Node::ATTRIBUTE_NODE: 1221 case Node::ATTRIBUTE_NODE:
1228 case Node::CDATA_SECTION_NODE:
1229 case Node::COMMENT_NODE: 1222 case Node::COMMENT_NODE:
1230 case Node::DOCUMENT_FRAGMENT_NODE: 1223 case Node::DOCUMENT_FRAGMENT_NODE:
1231 case Node::DOCUMENT_NODE: 1224 case Node::DOCUMENT_NODE:
1232 case Node::ELEMENT_NODE: 1225 case Node::ELEMENT_NODE:
1233 case Node::PROCESSING_INSTRUCTION_NODE: 1226 case Node::PROCESSING_INSTRUCTION_NODE:
1234 case Node::TEXT_NODE: 1227 case Node::TEXT_NODE:
1235 break; 1228 break;
1236 case Node::DOCUMENT_TYPE_NODE: 1229 case Node::DOCUMENT_TYPE_NODE:
1237 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + refNode->nodeName() + "'."); 1230 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + refNode->nodeName() + "'.");
1238 return; 1231 return;
1239 } 1232 }
1240 } 1233 }
1241 1234
1242 if (m_ownerDocument != refNode->document()) 1235 if (m_ownerDocument != refNode->document())
1243 setDocument(refNode->document()); 1236 setDocument(refNode->document());
1244 1237
1245 m_start.setToStartOfNode(*refNode); 1238 m_start.setToStartOfNode(*refNode);
1246 m_end.setToEndOfNode(*refNode); 1239 m_end.setToEndOfNode(*refNode);
1247 } 1240 }
1248 1241
1249 bool Range::selectNodeContents(Node* refNode, Position& start, Position& end) 1242 bool Range::selectNodeContents(Node* refNode, Position& start, Position& end)
1250 { 1243 {
1251 if (!refNode) { 1244 if (!refNode) {
1252 return false; 1245 return false;
1253 } 1246 }
1254 1247
1255 for (Node* n = refNode; n; n = n->parentNode()) { 1248 for (Node* n = refNode; n; n = n->parentNode()) {
1256 switch (n->nodeType()) { 1249 switch (n->nodeType()) {
1257 case Node::ATTRIBUTE_NODE: 1250 case Node::ATTRIBUTE_NODE:
1258 case Node::CDATA_SECTION_NODE:
1259 case Node::COMMENT_NODE: 1251 case Node::COMMENT_NODE:
1260 case Node::DOCUMENT_FRAGMENT_NODE: 1252 case Node::DOCUMENT_FRAGMENT_NODE:
1261 case Node::DOCUMENT_NODE: 1253 case Node::DOCUMENT_NODE:
1262 case Node::ELEMENT_NODE: 1254 case Node::ELEMENT_NODE:
1263 case Node::PROCESSING_INSTRUCTION_NODE: 1255 case Node::PROCESSING_INSTRUCTION_NODE:
1264 case Node::TEXT_NODE: 1256 case Node::TEXT_NODE:
1265 break; 1257 break;
1266 case Node::DOCUMENT_TYPE_NODE: 1258 case Node::DOCUMENT_TYPE_NODE:
1267 return false; 1259 return false;
1268 } 1260 }
(...skipping 30 matching lines...) Expand all
1299 1291
1300 // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType, No tation, 1292 // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType, No tation,
1301 // Document, or DocumentFragment node. 1293 // Document, or DocumentFragment node.
1302 switch (newParent->nodeType()) { 1294 switch (newParent->nodeType()) {
1303 case Node::ATTRIBUTE_NODE: 1295 case Node::ATTRIBUTE_NODE:
1304 case Node::DOCUMENT_FRAGMENT_NODE: 1296 case Node::DOCUMENT_FRAGMENT_NODE:
1305 case Node::DOCUMENT_NODE: 1297 case Node::DOCUMENT_NODE:
1306 case Node::DOCUMENT_TYPE_NODE: 1298 case Node::DOCUMENT_TYPE_NODE:
1307 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + newParent->nodeName() + "'."); 1299 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + newParent->nodeName() + "'.");
1308 return; 1300 return;
1309 case Node::CDATA_SECTION_NODE:
1310 case Node::COMMENT_NODE: 1301 case Node::COMMENT_NODE:
1311 case Node::ELEMENT_NODE: 1302 case Node::ELEMENT_NODE:
1312 case Node::PROCESSING_INSTRUCTION_NODE: 1303 case Node::PROCESSING_INSTRUCTION_NODE:
1313 case Node::TEXT_NODE: 1304 case Node::TEXT_NODE:
1314 break; 1305 break;
1315 } 1306 }
1316 1307
1317 // Raise a HierarchyRequestError if m_start.container() doesn't accept child ren like newParent. 1308 // Raise a HierarchyRequestError if m_start.container() doesn't accept child ren like newParent.
1318 Node* parentOfNewParent = m_start.container(); 1309 Node* parentOfNewParent = m_start.container();
1319 1310
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 1767
1777 void showTree(const blink::Range* range) 1768 void showTree(const blink::Range* range)
1778 { 1769 {
1779 if (range && range->boundaryPointsValid()) { 1770 if (range && range->boundaryPointsValid()) {
1780 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1771 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1781 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1772 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1782 } 1773 }
1783 } 1774 }
1784 1775
1785 #endif 1776 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/dom/Text.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698