| 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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 } | 398 } |
| 399 | 399 |
| 400 bool Range::intersectsNode(Node* refNode, ExceptionState& exceptionState) | 400 bool Range::intersectsNode(Node* refNode, ExceptionState& exceptionState) |
| 401 { | 401 { |
| 402 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode | 402 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode |
| 403 // Returns a bool if the node intersects the range. | 403 // Returns a bool if the node intersects the range. |
| 404 if (!nodeValidForIntersects(refNode, m_ownerDocument.get(), exceptionState)) | 404 if (!nodeValidForIntersects(refNode, m_ownerDocument.get(), exceptionState)) |
| 405 return false; | 405 return false; |
| 406 | 406 |
| 407 ContainerNode* parentNode = refNode->parentNode(); | 407 ContainerNode* parentNode = refNode->parentNode(); |
| 408 if (!parentNode) |
| 409 return true; |
| 410 |
| 408 int nodeIndex = refNode->nodeIndex(); | 411 int nodeIndex = refNode->nodeIndex(); |
| 409 | 412 |
| 410 if (!parentNode) { | |
| 411 // if the node is the top document we should return NODE_BEFORE_AND_AFTE
R | |
| 412 // but we throw to match firefox behavior | |
| 413 exceptionState.throwDOMException(NotFoundError, "The node provided has n
o parent."); | |
| 414 return false; | |
| 415 } | |
| 416 | |
| 417 if (comparePoint(parentNode, nodeIndex, exceptionState) < 0 // starts before
start | 413 if (comparePoint(parentNode, nodeIndex, exceptionState) < 0 // starts before
start |
| 418 && comparePoint(parentNode, nodeIndex + 1, exceptionState) < 0) { // end
s before start | 414 && comparePoint(parentNode, nodeIndex + 1, exceptionState) < 0) { // end
s before start |
| 419 return false; | 415 return false; |
| 420 } | 416 } |
| 421 | 417 |
| 422 if (comparePoint(parentNode, nodeIndex, exceptionState) > 0 // starts after
end | 418 if (comparePoint(parentNode, nodeIndex, exceptionState) > 0 // starts after
end |
| 423 && comparePoint(parentNode, nodeIndex + 1, exceptionState) > 0) { // end
s after end | 419 && comparePoint(parentNode, nodeIndex + 1, exceptionState) > 0) { // end
s after end |
| 424 return false; | 420 return false; |
| 425 } | 421 } |
| 426 | 422 |
| 427 return true; // all other cases | 423 return true; // all other cases |
| 428 } | 424 } |
| 429 | 425 |
| 430 bool Range::intersectsNode(Node* refNode, const Position& start, const Position&
end, ExceptionState& exceptionState) | 426 bool Range::intersectsNode(Node* refNode, const Position& start, const Position&
end, ExceptionState& exceptionState) |
| 431 { | 427 { |
| 432 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode | 428 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode |
| 433 // Returns a bool if the node intersects the range. | 429 // Returns a bool if the node intersects the range. |
| 434 if (!nodeValidForIntersects(refNode, start.document(), exceptionState)) | 430 if (!nodeValidForIntersects(refNode, start.document(), exceptionState)) |
| 435 return false; | 431 return false; |
| 436 | 432 |
| 437 ContainerNode* parentNode = refNode->parentNode(); | 433 ContainerNode* parentNode = refNode->parentNode(); |
| 434 if (!parentNode) |
| 435 return true; |
| 436 |
| 438 int nodeIndex = refNode->nodeIndex(); | 437 int nodeIndex = refNode->nodeIndex(); |
| 439 | 438 |
| 440 if (!parentNode) { | |
| 441 // if the node is the top document we should return NODE_BEFORE_AND_AFTE
R | |
| 442 // but we throw to match firefox behavior | |
| 443 exceptionState.throwDOMException(NotFoundError, "The node provided has n
o parent."); | |
| 444 return false; | |
| 445 } | |
| 446 | |
| 447 Node* startContainerNode = start.computeContainerNode(); | 439 Node* startContainerNode = start.computeContainerNode(); |
| 448 int startOffset = start.computeOffsetInContainerNode(); | 440 int startOffset = start.computeOffsetInContainerNode(); |
| 449 | 441 |
| 450 if (compareBoundaryPoints(parentNode, nodeIndex, startContainerNode, startOf
fset, exceptionState) < 0 // starts before start | 442 if (compareBoundaryPoints(parentNode, nodeIndex, startContainerNode, startOf
fset, exceptionState) < 0 // starts before start |
| 451 && compareBoundaryPoints(parentNode, nodeIndex + 1, startContainerNode,
startOffset, exceptionState) < 0) { // ends before start | 443 && compareBoundaryPoints(parentNode, nodeIndex + 1, startContainerNode,
startOffset, exceptionState) < 0) { // ends before start |
| 452 ASSERT(!exceptionState.hadException()); | 444 ASSERT(!exceptionState.hadException()); |
| 453 return false; | 445 return false; |
| 454 } | 446 } |
| 455 | 447 |
| 456 Node* endContainerNode = end.computeContainerNode(); | 448 Node* endContainerNode = end.computeContainerNode(); |
| (...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 { | 1682 { |
| 1691 if (range && range->boundaryPointsValid()) { | 1683 if (range && range->boundaryPointsValid()) { |
| 1692 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1684 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
| 1693 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1685 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
| 1694 } else { | 1686 } else { |
| 1695 fprintf(stderr, "Cannot show tree if range is null, or if boundary point
s are invalid.\n"); | 1687 fprintf(stderr, "Cannot show tree if range is null, or if boundary point
s are invalid.\n"); |
| 1696 } | 1688 } |
| 1697 } | 1689 } |
| 1698 | 1690 |
| 1699 #endif | 1691 #endif |
| OLD | NEW |