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 | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
7 * rights reserved. | 7 * rights reserved. |
8 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 8 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
9 * | 9 * |
10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1312 | 1312 |
1313 RangeBoundaryPoint startBoundaryPoint(refNode); | 1313 RangeBoundaryPoint startBoundaryPoint(refNode); |
1314 startBoundaryPoint.setToStartOfNode(*refNode); | 1314 startBoundaryPoint.setToStartOfNode(*refNode); |
1315 start = startBoundaryPoint.toPosition(); | 1315 start = startBoundaryPoint.toPosition(); |
1316 RangeBoundaryPoint endBoundaryPoint(refNode); | 1316 RangeBoundaryPoint endBoundaryPoint(refNode); |
1317 endBoundaryPoint.setToEndOfNode(*refNode); | 1317 endBoundaryPoint.setToEndOfNode(*refNode); |
1318 end = endBoundaryPoint.toPosition(); | 1318 end = endBoundaryPoint.toPosition(); |
1319 return true; | 1319 return true; |
1320 } | 1320 } |
1321 | 1321 |
1322 // https://dom.spec.whatwg.org/#dom-range-surroundcontents | |
1322 void Range::surroundContents(Node* newParent, ExceptionState& exceptionState) { | 1323 void Range::surroundContents(Node* newParent, ExceptionState& exceptionState) { |
1323 if (!newParent) { | 1324 if (!newParent) { |
1324 // FIXME: Generated bindings code never calls with null, and neither should | 1325 // FIXME: Generated bindings code never calls with null, and neither should |
1325 // other callers! | 1326 // other callers! |
1326 exceptionState.throwTypeError("The node provided is null."); | 1327 exceptionState.throwTypeError("The node provided is null."); |
1327 return; | 1328 return; |
1328 } | 1329 } |
1329 | 1330 |
1330 // InvalidStateError: Raised if the Range partially selects a non-Text node. | 1331 // 1. If a non-Text node is partially contained in the context object, then |
1332 // throw an InvalidStateError. | |
1331 Node* startNonTextContainer = m_start.container(); | 1333 Node* startNonTextContainer = m_start.container(); |
1332 if (startNonTextContainer->getNodeType() == Node::kTextNode) | 1334 if (startNonTextContainer->getNodeType() == Node::kTextNode) |
1333 startNonTextContainer = startNonTextContainer->parentNode(); | 1335 startNonTextContainer = startNonTextContainer->parentNode(); |
1334 Node* endNonTextContainer = m_end.container(); | 1336 Node* endNonTextContainer = m_end.container(); |
1335 if (endNonTextContainer->getNodeType() == Node::kTextNode) | 1337 if (endNonTextContainer->getNodeType() == Node::kTextNode) |
1336 endNonTextContainer = endNonTextContainer->parentNode(); | 1338 endNonTextContainer = endNonTextContainer->parentNode(); |
1337 if (startNonTextContainer != endNonTextContainer) { | 1339 if (startNonTextContainer != endNonTextContainer) { |
1338 exceptionState.throwDOMException( | 1340 exceptionState.throwDOMException( |
1339 InvalidStateError, "The Range has partially selected a non-Text node."); | 1341 InvalidStateError, "The Range has partially selected a non-Text node."); |
1340 return; | 1342 return; |
1341 } | 1343 } |
1342 | 1344 |
1343 // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType, | 1345 // 2. If newParent is a Document, DocumentType, or DocumentFragment node, then |
1344 // Notation, | 1346 // throw an InvalidNodeTypeError. |
1345 // Document, or DocumentFragment node. | |
1346 switch (newParent->getNodeType()) { | 1347 switch (newParent->getNodeType()) { |
1347 case Node::kAttributeNode: | 1348 case Node::kAttributeNode: |
1348 case Node::kDocumentFragmentNode: | 1349 case Node::kDocumentFragmentNode: |
1349 case Node::kDocumentNode: | 1350 case Node::kDocumentNode: |
1350 case Node::kDocumentTypeNode: | 1351 case Node::kDocumentTypeNode: |
1351 exceptionState.throwDOMException( | 1352 exceptionState.throwDOMException( |
1352 InvalidNodeTypeError, | 1353 InvalidNodeTypeError, |
1353 "The node provided is of type '" + newParent->nodeName() + "'."); | 1354 "The node provided is of type '" + newParent->nodeName() + "'."); |
1354 return; | 1355 return; |
1355 case Node::kCdataSectionNode: | 1356 case Node::kCdataSectionNode: |
(...skipping 24 matching lines...) Expand all Loading... | |
1380 } | 1381 } |
1381 | 1382 |
1382 if (!parentOfNewParent->childTypeAllowed(newParent->getNodeType())) { | 1383 if (!parentOfNewParent->childTypeAllowed(newParent->getNodeType())) { |
1383 exceptionState.throwDOMException(HierarchyRequestError, | 1384 exceptionState.throwDOMException(HierarchyRequestError, |
1384 "The node provided is of type '" + | 1385 "The node provided is of type '" + |
1385 newParent->nodeName() + | 1386 newParent->nodeName() + |
1386 "', which may not be inserted here."); | 1387 "', which may not be inserted here."); |
1387 return; | 1388 return; |
1388 } | 1389 } |
1389 | 1390 |
1390 if (newParent->isShadowIncludingInclusiveAncestorOf(m_start.container())) { | 1391 // 4. If newParent has children, replace all with null within newParent. |
1391 exceptionState.throwDOMException(HierarchyRequestError, | |
1392 "The node provided contains the insertion " | |
1393 "point; it may not be inserted into " | |
1394 "itself."); | |
1395 return; | |
1396 } | |
1397 | |
1398 // FIXME: Do we need a check if the node would end up with a child node of a | |
tkent
2017/03/09 22:36:33
This FIXME comment was bogus. The check already ex
| |
1399 // type not allowed by the type of node? | |
1400 | |
1401 while (Node* n = newParent->firstChild()) { | 1392 while (Node* n = newParent->firstChild()) { |
1402 toContainerNode(newParent)->removeChild(n, exceptionState); | 1393 toContainerNode(newParent)->removeChild(n, exceptionState); |
1403 if (exceptionState.hadException()) | 1394 if (exceptionState.hadException()) |
1404 return; | 1395 return; |
1405 } | 1396 } |
1397 | |
1398 // 3. Let fragment be the result of extracting context object. | |
1406 DocumentFragment* fragment = extractContents(exceptionState); | 1399 DocumentFragment* fragment = extractContents(exceptionState); |
1407 if (exceptionState.hadException()) | 1400 if (exceptionState.hadException()) |
1408 return; | 1401 return; |
1402 | |
1403 // 5. If newParent has children, replace all with null within newParent. | |
1409 insertNode(newParent, exceptionState); | 1404 insertNode(newParent, exceptionState); |
1410 if (exceptionState.hadException()) | 1405 if (exceptionState.hadException()) |
1411 return; | 1406 return; |
1407 | |
1408 // 6. Append fragment to newParent. | |
1412 newParent->appendChild(fragment, exceptionState); | 1409 newParent->appendChild(fragment, exceptionState); |
1413 if (exceptionState.hadException()) | 1410 if (exceptionState.hadException()) |
1414 return; | 1411 return; |
1412 | |
1413 // 7. Select newParent within context object. | |
1415 selectNode(newParent, exceptionState); | 1414 selectNode(newParent, exceptionState); |
1416 } | 1415 } |
1417 | 1416 |
1418 void Range::setStartBefore(Node* refNode, ExceptionState& exceptionState) { | 1417 void Range::setStartBefore(Node* refNode, ExceptionState& exceptionState) { |
1419 checkNodeBA(refNode, exceptionState); | 1418 checkNodeBA(refNode, exceptionState); |
1420 if (exceptionState.hadException()) | 1419 if (exceptionState.hadException()) |
1421 return; | 1420 return; |
1422 | 1421 |
1423 setStart(refNode->parentNode(), refNode->nodeIndex(), exceptionState); | 1422 setStart(refNode->parentNode(), refNode->nodeIndex(), exceptionState); |
1424 } | 1423 } |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1827 .data() | 1826 .data() |
1828 << "start offset: " << range->startOffset() | 1827 << "start offset: " << range->startOffset() |
1829 << ", end offset: " << range->endOffset(); | 1828 << ", end offset: " << range->endOffset(); |
1830 } else { | 1829 } else { |
1831 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " | 1830 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " |
1832 "invalid."; | 1831 "invalid."; |
1833 } | 1832 } |
1834 } | 1833 } |
1835 | 1834 |
1836 #endif | 1835 #endif |
OLD | NEW |