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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 return 0; | 286 return 0; |
287 | 287 |
288 // compare to end, and point comes after | 288 // compare to end, and point comes after |
289 if (compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset()
, exceptionState) > 0 && !exceptionState.hadException()) | 289 if (compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset()
, exceptionState) > 0 && !exceptionState.hadException()) |
290 return 1; | 290 return 1; |
291 | 291 |
292 // point is in the middle of this range, or on the boundary points | 292 // point is in the middle of this range, or on the boundary points |
293 return 0; | 293 return 0; |
294 } | 294 } |
295 | 295 |
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 | 296 short Range::compareBoundaryPoints(unsigned how, const Range* sourceRange, Excep
tionState& exceptionState) const |
340 { | 297 { |
341 if (!(how == START_TO_START || how == START_TO_END || how == END_TO_END || h
ow == END_TO_START)) { | 298 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'."); | 299 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; | 300 return 0; |
344 } | 301 } |
345 | 302 |
346 Node* thisCont = commonAncestorContainer(); | 303 Node* thisCont = commonAncestorContainer(); |
347 Node* sourceCont = sourceRange->commonAncestorContainer(); | 304 Node* sourceCont = sourceRange->commonAncestorContainer(); |
348 if (thisCont->document() != sourceCont->document()) { | 305 if (thisCont->document() != sourceCont->document()) { |
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 { | 1679 { |
1723 if (range && range->boundaryPointsValid()) { | 1680 if (range && range->boundaryPointsValid()) { |
1724 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1681 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
1725 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1682 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
1726 } else { | 1683 } else { |
1727 fprintf(stderr, "Cannot show tree if range is null, or if boundary point
s are invalid.\n"); | 1684 fprintf(stderr, "Cannot show tree if range is null, or if boundary point
s are invalid.\n"); |
1728 } | 1685 } |
1729 } | 1686 } |
1730 | 1687 |
1731 #endif | 1688 #endif |
OLD | NEW |