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 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 } | 1201 } |
1202 | 1202 |
1203 void Range::surroundContents(PassRefPtrWillBeRawPtr<Node> passNewParent, Excepti
onState& exceptionState) | 1203 void Range::surroundContents(PassRefPtrWillBeRawPtr<Node> passNewParent, Excepti
onState& exceptionState) |
1204 { | 1204 { |
1205 RefPtrWillBeRawPtr<Node> newParent = passNewParent; | 1205 RefPtrWillBeRawPtr<Node> newParent = passNewParent; |
1206 if (!newParent) { | 1206 if (!newParent) { |
1207 exceptionState.throwDOMException(NotFoundError, "The node provided is nu
ll."); | 1207 exceptionState.throwDOMException(NotFoundError, "The node provided is nu
ll."); |
1208 return; | 1208 return; |
1209 } | 1209 } |
1210 | 1210 |
| 1211 // InvalidStateError: Raised if the Range partially selects a non-Text node. |
| 1212 Node* startNonTextContainer = m_start.container(); |
| 1213 if (startNonTextContainer->nodeType() == Node::TEXT_NODE) |
| 1214 startNonTextContainer = startNonTextContainer->parentNode(); |
| 1215 Node* endNonTextContainer = m_end.container(); |
| 1216 if (endNonTextContainer->nodeType() == Node::TEXT_NODE) |
| 1217 endNonTextContainer = endNonTextContainer->parentNode(); |
| 1218 if (startNonTextContainer != endNonTextContainer) { |
| 1219 exceptionState.throwDOMException(InvalidStateError, "The Range has parti
ally selected a non-Text node."); |
| 1220 return; |
| 1221 } |
| 1222 |
1211 // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType, No
tation, | 1223 // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType, No
tation, |
1212 // Document, or DocumentFragment node. | 1224 // Document, or DocumentFragment node. |
1213 switch (newParent->nodeType()) { | 1225 switch (newParent->nodeType()) { |
1214 case Node::ATTRIBUTE_NODE: | 1226 case Node::ATTRIBUTE_NODE: |
1215 case Node::DOCUMENT_FRAGMENT_NODE: | 1227 case Node::DOCUMENT_FRAGMENT_NODE: |
1216 case Node::DOCUMENT_NODE: | 1228 case Node::DOCUMENT_NODE: |
1217 case Node::DOCUMENT_TYPE_NODE: | 1229 case Node::DOCUMENT_TYPE_NODE: |
1218 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro
vided is of type '" + newParent->nodeName() + "'."); | 1230 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro
vided is of type '" + newParent->nodeName() + "'."); |
1219 return; | 1231 return; |
1220 case Node::CDATA_SECTION_NODE: | 1232 case Node::CDATA_SECTION_NODE: |
(...skipping 24 matching lines...) Expand all Loading... |
1245 } | 1257 } |
1246 | 1258 |
1247 if (newParent->contains(m_start.container())) { | 1259 if (newParent->contains(m_start.container())) { |
1248 exceptionState.throwDOMException(HierarchyRequestError, "The node provid
ed contains the insertion point; it may not be inserted into itself."); | 1260 exceptionState.throwDOMException(HierarchyRequestError, "The node provid
ed contains the insertion point; it may not be inserted into itself."); |
1249 return; | 1261 return; |
1250 } | 1262 } |
1251 | 1263 |
1252 // FIXME: Do we need a check if the node would end up with a child node of a
type not | 1264 // FIXME: Do we need a check if the node would end up with a child node of a
type not |
1253 // allowed by the type of node? | 1265 // allowed by the type of node? |
1254 | 1266 |
1255 // BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a non-Text
node. | |
1256 Node* startNonTextContainer = m_start.container(); | |
1257 if (startNonTextContainer->nodeType() == Node::TEXT_NODE) | |
1258 startNonTextContainer = startNonTextContainer->parentNode(); | |
1259 Node* endNonTextContainer = m_end.container(); | |
1260 if (endNonTextContainer->nodeType() == Node::TEXT_NODE) | |
1261 endNonTextContainer = endNonTextContainer->parentNode(); | |
1262 if (startNonTextContainer != endNonTextContainer) { | |
1263 exceptionState.throwDOMException(InvalidStateError, "The Range has parti
ally selected a non-Text node."); | |
1264 return; | |
1265 } | |
1266 | |
1267 while (Node* n = newParent->firstChild()) { | 1267 while (Node* n = newParent->firstChild()) { |
1268 toContainerNode(newParent)->removeChild(n, exceptionState); | 1268 toContainerNode(newParent)->removeChild(n, exceptionState); |
1269 if (exceptionState.hadException()) | 1269 if (exceptionState.hadException()) |
1270 return; | 1270 return; |
1271 } | 1271 } |
1272 RefPtrWillBeRawPtr<DocumentFragment> fragment = extractContents(exceptionSta
te); | 1272 RefPtrWillBeRawPtr<DocumentFragment> fragment = extractContents(exceptionSta
te); |
1273 if (exceptionState.hadException()) | 1273 if (exceptionState.hadException()) |
1274 return; | 1274 return; |
1275 insertNode(newParent, exceptionState); | 1275 insertNode(newParent, exceptionState); |
1276 if (exceptionState.hadException()) | 1276 if (exceptionState.hadException()) |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1702 | 1702 |
1703 void showTree(const blink::Range* range) | 1703 void showTree(const blink::Range* range) |
1704 { | 1704 { |
1705 if (range && range->boundaryPointsValid()) { | 1705 if (range && range->boundaryPointsValid()) { |
1706 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1706 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
1707 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1707 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
1708 } | 1708 } |
1709 } | 1709 } |
1710 | 1710 |
1711 #endif | 1711 #endif |
OLD | NEW |