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::isNodeFullySelected(Node& node) const |
297 { | 297 { |
298 // http://developer.mozilla.org/en/docs/DOM:range.compareNode | 298 return Range::compareBoundaryPoints(node.parentNode(), node.nodeIndex(), sta rtContainer(), startOffset(), IGNORE_EXCEPTION) >= 0 |
philipj_slow
2015/06/11 08:39:14
Now that this isn't static, could comparePoint() b
deepak.s
2015/06/25 10:52:36
Done.
| |
299 // This method returns 0, 1, 2, or 3 based on if the node is before, after, | 299 && Range::compareBoundaryPoints(node.parentNode(), node.nodeIndex() + 1, endContainer(), endOffset(), IGNORE_EXCEPTION) <= 0; |
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 } | 300 } |
338 | 301 |
339 short Range::compareBoundaryPoints(unsigned how, const Range* sourceRange, Excep tionState& exceptionState) const | 302 short Range::compareBoundaryPoints(unsigned how, const Range* sourceRange, Excep tionState& exceptionState) const |
340 { | 303 { |
341 if (!(how == START_TO_START || how == START_TO_END || how == END_TO_END || h ow == END_TO_START)) { | 304 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'."); | 305 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; | 306 return 0; |
344 } | 307 } |
345 | 308 |
346 Node* thisCont = commonAncestorContainer(); | 309 Node* thisCont = commonAncestorContainer(); |
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1722 { | 1685 { |
1723 if (range && range->boundaryPointsValid()) { | 1686 if (range && range->boundaryPointsValid()) { |
1724 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); | 1687 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); |
1725 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); | 1688 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); |
1726 } else { | 1689 } else { |
1727 fprintf(stderr, "Cannot show tree if range is null, or if boundary point s are invalid.\n"); | 1690 fprintf(stderr, "Cannot show tree if range is null, or if boundary point s are invalid.\n"); |
1728 } | 1691 } |
1729 } | 1692 } |
1730 | 1693 |
1731 #endif | 1694 #endif |
OLD | NEW |