| 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 if (!m_start.container()) { | 297 if (!m_start.container()) { |
| 298 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu
te("isPointInRange", "Range", "The range has no container. Perhaps 'detatch()' h
as been invoked on this object?")); | 298 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu
te("isPointInRange", "Range", "The range has no container. Perhaps 'detatch()' h
as been invoked on this object?")); |
| 299 return false; | 299 return false; |
| 300 } | 300 } |
| 301 | 301 |
| 302 if (!refNode) { | 302 if (!refNode) { |
| 303 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); | 303 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); |
| 304 return false; | 304 return false; |
| 305 } | 305 } |
| 306 | 306 |
| 307 if (!refNode->attached() || &refNode->document() != m_ownerDocument) { | 307 if (!refNode->confusingAndOftenMisusedAttached() || &refNode->document() !=
m_ownerDocument) { |
| 308 return false; | 308 return false; |
| 309 } | 309 } |
| 310 | 310 |
| 311 checkNodeWOffset(refNode, offset, es); | 311 checkNodeWOffset(refNode, offset, es); |
| 312 if (es.hadException()) | 312 if (es.hadException()) |
| 313 return false; | 313 return false; |
| 314 | 314 |
| 315 return compareBoundaryPoints(refNode, offset, m_start.container(), m_start.o
ffset(), es) >= 0 && !es.hadException() | 315 return compareBoundaryPoints(refNode, offset, m_start.container(), m_start.o
ffset(), es) >= 0 && !es.hadException() |
| 316 && compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offse
t(), es) <= 0 && !es.hadException(); | 316 && compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offse
t(), es) <= 0 && !es.hadException(); |
| 317 } | 317 } |
| 318 | 318 |
| 319 short Range::comparePoint(Node* refNode, int offset, ExceptionState& es) const | 319 short Range::comparePoint(Node* refNode, int offset, ExceptionState& es) const |
| 320 { | 320 { |
| 321 // http://developer.mozilla.org/en/docs/DOM:range.comparePoint | 321 // http://developer.mozilla.org/en/docs/DOM:range.comparePoint |
| 322 // This method returns -1, 0 or 1 depending on if the point described by the | 322 // This method returns -1, 0 or 1 depending on if the point described by the |
| 323 // refNode node and an offset within the node is before, same as, or after t
he range respectively. | 323 // refNode node and an offset within the node is before, same as, or after t
he range respectively. |
| 324 | 324 |
| 325 if (!m_start.container()) { | 325 if (!m_start.container()) { |
| 326 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu
te("comparePoint", "Range", "The range has no container. Perhaps 'detatch()' has
been invoked on this object?")); | 326 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu
te("comparePoint", "Range", "The range has no container. Perhaps 'detatch()' has
been invoked on this object?")); |
| 327 return 0; | 327 return 0; |
| 328 } | 328 } |
| 329 | 329 |
| 330 if (!refNode) { | 330 if (!refNode) { |
| 331 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); | 331 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); |
| 332 return 0; | 332 return 0; |
| 333 } | 333 } |
| 334 | 334 |
| 335 if (!refNode->attached() || &refNode->document() != m_ownerDocument) { | 335 if (!refNode->confusingAndOftenMisusedAttached() || &refNode->document() !=
m_ownerDocument) { |
| 336 es.throwUninformativeAndGenericDOMException(WrongDocumentError); | 336 es.throwUninformativeAndGenericDOMException(WrongDocumentError); |
| 337 return 0; | 337 return 0; |
| 338 } | 338 } |
| 339 | 339 |
| 340 checkNodeWOffset(refNode, offset, es); | 340 checkNodeWOffset(refNode, offset, es); |
| 341 if (es.hadException()) | 341 if (es.hadException()) |
| 342 return 0; | 342 return 0; |
| 343 | 343 |
| 344 // compare to start, and point comes before | 344 // compare to start, and point comes before |
| 345 if (compareBoundaryPoints(refNode, offset, m_start.container(), m_start.offs
et(), es) < 0) | 345 if (compareBoundaryPoints(refNode, offset, m_start.container(), m_start.offs
et(), es) < 0) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 360 { | 360 { |
| 361 // http://developer.mozilla.org/en/docs/DOM:range.compareNode | 361 // http://developer.mozilla.org/en/docs/DOM:range.compareNode |
| 362 // This method returns 0, 1, 2, or 3 based on if the node is before, after, | 362 // This method returns 0, 1, 2, or 3 based on if the node is before, after, |
| 363 // before and after(surrounds), or inside the range, respectively | 363 // before and after(surrounds), or inside the range, respectively |
| 364 | 364 |
| 365 if (!refNode) { | 365 if (!refNode) { |
| 366 es.throwUninformativeAndGenericDOMException(NotFoundError); | 366 es.throwUninformativeAndGenericDOMException(NotFoundError); |
| 367 return NODE_BEFORE; | 367 return NODE_BEFORE; |
| 368 } | 368 } |
| 369 | 369 |
| 370 if (!m_start.container() && refNode->attached()) { | 370 if (!m_start.container() && refNode->confusingAndOftenMisusedAttached()) { |
| 371 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 371 es.throwUninformativeAndGenericDOMException(InvalidStateError); |
| 372 return NODE_BEFORE; | 372 return NODE_BEFORE; |
| 373 } | 373 } |
| 374 | 374 |
| 375 if (m_start.container() && !refNode->attached()) { | 375 if (m_start.container() && !refNode->confusingAndOftenMisusedAttached()) { |
| 376 // Firefox doesn't throw an exception for this case; it returns 0. | 376 // Firefox doesn't throw an exception for this case; it returns 0. |
| 377 return NODE_BEFORE; | 377 return NODE_BEFORE; |
| 378 } | 378 } |
| 379 | 379 |
| 380 if (&refNode->document() != m_ownerDocument) { | 380 if (&refNode->document() != m_ownerDocument) { |
| 381 // Firefox doesn't throw an exception for this case; it returns 0. | 381 // Firefox doesn't throw an exception for this case; it returns 0. |
| 382 return NODE_BEFORE; | 382 return NODE_BEFORE; |
| 383 } | 383 } |
| 384 | 384 |
| 385 ContainerNode* parentNode = refNode->parentNode(); | 385 ContainerNode* parentNode = refNode->parentNode(); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 // Throw exception if the range is already detached. | 574 // Throw exception if the range is already detached. |
| 575 if (!m_start.container()) { | 575 if (!m_start.container()) { |
| 576 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu
te("intersectsNode", "Range", "The range has no container. Perhaps 'detatch()' h
as been invoked on this object?")); | 576 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu
te("intersectsNode", "Range", "The range has no container. Perhaps 'detatch()' h
as been invoked on this object?")); |
| 577 return false; | 577 return false; |
| 578 } | 578 } |
| 579 if (!refNode) { | 579 if (!refNode) { |
| 580 es.throwUninformativeAndGenericDOMException(NotFoundError); | 580 es.throwUninformativeAndGenericDOMException(NotFoundError); |
| 581 return false; | 581 return false; |
| 582 } | 582 } |
| 583 | 583 |
| 584 if (!refNode->attached() || &refNode->document() != m_ownerDocument) { | 584 if (!refNode->confusingAndOftenMisusedAttached() || &refNode->document() !=
m_ownerDocument) { |
| 585 // Firefox doesn't throw an exception for these cases; it returns false. | 585 // Firefox doesn't throw an exception for these cases; it returns false. |
| 586 return false; | 586 return false; |
| 587 } | 587 } |
| 588 | 588 |
| 589 ContainerNode* parentNode = refNode->parentNode(); | 589 ContainerNode* parentNode = refNode->parentNode(); |
| 590 int nodeIndex = refNode->nodeIndex(); | 590 int nodeIndex = refNode->nodeIndex(); |
| 591 | 591 |
| 592 if (!parentNode) { | 592 if (!parentNode) { |
| 593 // if the node is the top document we should return NODE_BEFORE_AND_AFTE
R | 593 // if the node is the top document we should return NODE_BEFORE_AND_AFTE
R |
| 594 // but we throw to match firefox behavior | 594 // but we throw to match firefox behavior |
| (...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1901 | 1901 |
| 1902 void showTree(const WebCore::Range* range) | 1902 void showTree(const WebCore::Range* range) |
| 1903 { | 1903 { |
| 1904 if (range && range->boundaryPointsValid()) { | 1904 if (range && range->boundaryPointsValid()) { |
| 1905 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1905 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
| 1906 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1906 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
| 1907 } | 1907 } |
| 1908 } | 1908 } |
| 1909 | 1909 |
| 1910 #endif | 1910 #endif |
| OLD | NEW |