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 | 296 bool Range::isNodeFullyContained(Node& node, ExceptionState& exceptionState) con st |
297 { | 297 { |
298 // http://developer.mozilla.org/en/docs/DOM:range.compareNode | 298 ContainerNode* parentNode = node.parentNode(); |
299 // This method returns 0, 1, 2, or 3 based on if the node is before, after, | 299 int nodeIndex = node.nodeIndex(); |
philipj_slow
2015/07/01 08:22:01
Move this down to after the parentNode check, just
deepak.s
2015/07/07 05:41:32
Done.
| |
300 // before and after(surrounds), or inside the range, respectively | |
301 | 300 |
302 if (!refNode) { | 301 if (!parentNode) { |
303 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers! | 302 exceptionState.throwDOMException(NotFoundError, "The node provided has n o parent."); |
philipj_slow
2015/07/01 08:22:01
This exception is ignored on both call sites, so j
deepak.s
2015/07/07 05:41:32
Done.
| |
304 exceptionState.throwTypeError("The node provided is null."); | 303 return false; |
305 return NODE_BEFORE; | |
306 } | 304 } |
307 | 305 |
308 if (!refNode->inActiveDocument()) { | 306 if (comparePoint(parentNode, nodeIndex, exceptionState) == 0 // starts in th e middle of this range, or on the boundary points |
philipj_slow
2015/07/01 08:22:01
To actually handle these exceptions, you'll have t
deepak.s
2015/07/07 05:41:32
Removed exception handling and passed IGNORE_EXCEP
philipj_slow
2015/07/07 08:27:29
There are exception cases in Range::comparePoint t
deepak.s
2015/07/08 04:57:02
Updated method by using isPointInRange.
| |
309 // Firefox doesn't throw an exception for this case; it returns 0. | 307 && comparePoint(parentNode, nodeIndex + 1, exceptionState) == 0) // ends in the middle of this range, or on the boundary points |
310 return NODE_BEFORE; | 308 return true; |
311 } | |
312 | 309 |
313 if (refNode->document() != m_ownerDocument) { | 310 return false; |
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 } | 311 } |
338 | 312 |
339 short Range::compareBoundaryPoints(unsigned how, const Range* sourceRange, Excep tionState& exceptionState) const | 313 short Range::compareBoundaryPoints(unsigned how, const Range* sourceRange, Excep tionState& exceptionState) const |
340 { | 314 { |
341 if (!(how == START_TO_START || how == START_TO_END || how == END_TO_END || h ow == END_TO_START)) { | 315 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'."); | 316 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; | 317 return 0; |
344 } | 318 } |
345 | 319 |
346 Node* thisCont = commonAncestorContainer(); | 320 Node* thisCont = commonAncestorContainer(); |
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1725 { | 1699 { |
1726 if (range && range->boundaryPointsValid()) { | 1700 if (range && range->boundaryPointsValid()) { |
1727 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); | 1701 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); |
1728 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); | 1702 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); |
1729 } else { | 1703 } else { |
1730 fprintf(stderr, "Cannot show tree if range is null, or if boundary point s are invalid.\n"); | 1704 fprintf(stderr, "Cannot show tree if range is null, or if boundary point s are invalid.\n"); |
1731 } | 1705 } |
1732 } | 1706 } |
1733 | 1707 |
1734 #endif | 1708 #endif |
OLD | NEW |