| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 231 } |
| 232 | 232 |
| 233 void Range::collapse(bool toStart) | 233 void Range::collapse(bool toStart) |
| 234 { | 234 { |
| 235 if (toStart) | 235 if (toStart) |
| 236 m_end = m_start; | 236 m_end = m_start; |
| 237 else | 237 else |
| 238 m_start = m_end; | 238 m_start = m_end; |
| 239 } | 239 } |
| 240 | 240 |
| 241 bool Range::isPointInRange(Node* refNode, int offset, ExceptionState& exceptionS
tate) | 241 bool Range::isNodeFullyContained(Node& node) const |
| 242 { |
| 243 ContainerNode* parentNode = node.parentNode(); |
| 244 int nodeIndex = node.nodeIndex(); |
| 245 return isPointInRange(parentNode, nodeIndex, IGNORE_EXCEPTION) // starts in
the middle of this range, or on the boundary points. |
| 246 && isPointInRange(parentNode, nodeIndex + 1, IGNORE_EXCEPTION); // ends
in the middle of this range, or on the boundary points. |
| 247 } |
| 248 |
| 249 bool Range::isPointInRange(Node* refNode, int offset, ExceptionState& exceptionS
tate) const |
| 242 { | 250 { |
| 243 if (!refNode) { | 251 if (!refNode) { |
| 244 // FIXME: Generated bindings code never calls with null, and neither sho
uld other callers! | 252 // FIXME: Generated bindings code never calls with null, and neither sho
uld other callers! |
| 245 exceptionState.throwTypeError("The node provided is null."); | 253 exceptionState.throwTypeError("The node provided is null."); |
| 246 return false; | 254 return false; |
| 247 } | 255 } |
| 248 | 256 |
| 249 if (!refNode->inActiveDocument() || refNode->document() != m_ownerDocument)
{ | 257 if (!refNode->inActiveDocument() || refNode->document() != m_ownerDocument)
{ |
| 250 return false; | 258 return false; |
| 251 } | 259 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 return 0; | 294 return 0; |
| 287 | 295 |
| 288 // compare to end, and point comes after | 296 // compare to end, and point comes after |
| 289 if (compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset()
, exceptionState) > 0 && !exceptionState.hadException()) | 297 if (compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset()
, exceptionState) > 0 && !exceptionState.hadException()) |
| 290 return 1; | 298 return 1; |
| 291 | 299 |
| 292 // point is in the middle of this range, or on the boundary points | 300 // point is in the middle of this range, or on the boundary points |
| 293 return 0; | 301 return 0; |
| 294 } | 302 } |
| 295 | 303 |
| 296 Range::CompareResults Range::compareNode(Node* refNode, ExceptionState& exceptio
nState) const | |
| 297 { | |
| 298 // http://developer.mozilla.org/en/docs/DOM:range.compareNode | |
| 299 // This method returns 0, 1, 2, or 3 based on if the node is before, after, | |
| 300 // before and after(surrounds), or inside the range, respectively | |
| 301 | |
| 302 if (!refNode) { | |
| 303 // FIXME: Generated bindings code never calls with null, and neither sho
uld other callers! | |
| 304 exceptionState.throwTypeError("The node provided is null."); | |
| 305 return NODE_BEFORE; | |
| 306 } | |
| 307 | |
| 308 if (!refNode->inActiveDocument()) { | |
| 309 // Firefox doesn't throw an exception for this case; it returns 0. | |
| 310 return NODE_BEFORE; | |
| 311 } | |
| 312 | |
| 313 if (refNode->document() != m_ownerDocument) { | |
| 314 // Firefox doesn't throw an exception for this case; it returns 0. | |
| 315 return NODE_BEFORE; | |
| 316 } | |
| 317 | |
| 318 ContainerNode* parentNode = refNode->parentNode(); | |
| 319 int nodeIndex = refNode->nodeIndex(); | |
| 320 | |
| 321 if (!parentNode) { | |
| 322 // if the node is the top document we should return NODE_BEFORE_AND_AFTE
R | |
| 323 // but we throw to match firefox behavior | |
| 324 exceptionState.throwDOMException(NotFoundError, "The provided node has n
o parent."); | |
| 325 return NODE_BEFORE; | |
| 326 } | |
| 327 | |
| 328 if (comparePoint(parentNode, nodeIndex, exceptionState) < 0) { // starts bef
ore | |
| 329 if (comparePoint(parentNode, nodeIndex + 1, exceptionState) > 0) // ends
after the range | |
| 330 return NODE_BEFORE_AND_AFTER; | |
| 331 return NODE_BEFORE; // ends before or in the range | |
| 332 } | |
| 333 // starts at or after the range start | |
| 334 if (comparePoint(parentNode, nodeIndex + 1, exceptionState) > 0) // ends aft
er the range | |
| 335 return NODE_AFTER; | |
| 336 return NODE_INSIDE; // ends inside the range | |
| 337 } | |
| 338 | |
| 339 short Range::compareBoundaryPoints(unsigned how, const Range* sourceRange, Excep
tionState& exceptionState) const | 304 short Range::compareBoundaryPoints(unsigned how, const Range* sourceRange, Excep
tionState& exceptionState) const |
| 340 { | 305 { |
| 341 if (!(how == START_TO_START || how == START_TO_END || how == END_TO_END || h
ow == END_TO_START)) { | 306 if (!(how == START_TO_START || how == START_TO_END || how == END_TO_END || h
ow == END_TO_START)) { |
| 342 exceptionState.throwDOMException(NotSupportedError, "The comparison meth
od provided must be one of 'START_TO_START', 'START_TO_END', 'END_TO_END', or 'E
ND_TO_START'."); | 307 exceptionState.throwDOMException(NotSupportedError, "The comparison meth
od provided must be one of 'START_TO_START', 'START_TO_END', 'END_TO_END', or 'E
ND_TO_START'."); |
| 343 return 0; | 308 return 0; |
| 344 } | 309 } |
| 345 | 310 |
| 346 Node* thisCont = commonAncestorContainer(); | 311 Node* thisCont = commonAncestorContainer(); |
| 347 Node* sourceCont = sourceRange->commonAncestorContainer(); | 312 Node* sourceCont = sourceRange->commonAncestorContainer(); |
| 348 if (thisCont->document() != sourceCont->document()) { | 313 if (thisCont->document() != sourceCont->document()) { |
| (...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1725 { | 1690 { |
| 1726 if (range && range->boundaryPointsValid()) { | 1691 if (range && range->boundaryPointsValid()) { |
| 1727 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1692 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
| 1728 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1693 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
| 1729 } else { | 1694 } else { |
| 1730 fprintf(stderr, "Cannot show tree if range is null, or if boundary point
s are invalid.\n"); | 1695 fprintf(stderr, "Cannot show tree if range is null, or if boundary point
s are invalid.\n"); |
| 1731 } | 1696 } |
| 1732 } | 1697 } |
| 1733 | 1698 |
| 1734 #endif | 1699 #endif |
| OLD | NEW |