Commit 7f32a883 authored by aliceli1's avatar aliceli1

Reviewed by Justin.

        - fixed <rdar://problem/4578115> support Range.isPointInRange
        - fixed <rdar://problem/4578123> support Range.comparePoint

        * dom/Range.cpp:
        (WebCore::Range::isPointInRange):
        added implementation
        (WebCore::Range::comparePoint):
        added implementation
        * dom/Range.h:
        added prototypes
        * dom/Range.idl:
        added bindings



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@14773 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 6e77b2fd
2006-06-08 Alice Liu <alice.liu@apple.com>
Reviewed by Justin.
- fixed <rdar://problem/4578115> support Range.isPointInRange
- fixed <rdar://problem/4578123> support Range.comparePoint
* dom/Range.cpp:
(WebCore::Range::isPointInRange):
added implementation
(WebCore::Range::comparePoint):
added implementation
* dom/Range.h:
added prototypes
* dom/Range.idl:
added bindings
2006-06-08 Darin Adler <darin@apple.com>
Reviewed by Justin.
......
......@@ -250,6 +250,85 @@ void Range::collapse( bool toStart, ExceptionCode& ec)
}
}
bool Range::isPointInRange(Node* refNode, int offset, ExceptionCode& ec)
{
if (!refNode) {
ec = NOT_FOUND_ERR;
return false;
}
if (m_detached && refNode->attached()) {
ec = INVALID_STATE_ERR;
return false;
}
if (!m_detached && !refNode->attached()) {
// firefox doesn't throw an exception for this case; it returns false
return false;
}
if (refNode->document() != m_ownerDocument) {
ec = WRONG_DOCUMENT_ERR;
return false;
}
checkNodeWOffset(refNode, offset, ec);
if (ec)
return false;
// point is not before the start and not after the end
if ((compareBoundaryPoints(refNode, offset, m_startContainer.get(), m_startOffset) != -1) &&
(compareBoundaryPoints(refNode, offset, m_endContainer.get(), m_endOffset) != 1))
return true;
else
return false;
}
short Range::comparePoint(Node* refNode, int offset, ExceptionCode& ec)
{
// http://developer.mozilla.org/en/docs/DOM:range.comparePoint
// This method returns 1, 0 or 1 depending on if the point described by the
// refNode node and an offset within the node is before, same as, or after the range respectively.
if (!refNode) {
ec = NOT_FOUND_ERR;
return 0;
}
if (m_detached && refNode->attached()) {
ec = INVALID_STATE_ERR;
return 0;
}
if (!m_detached && !refNode->attached()) {
// firefox doesn't throw an exception for this case; it returns 1
return -1;
}
if (refNode->document() != m_ownerDocument) {
ec = WRONG_DOCUMENT_ERR;
return 0;
}
checkNodeWOffset(refNode, offset, ec);
if (ec)
return 0;
// compare to start, and point comes before
if (compareBoundaryPoints(refNode, offset, m_startContainer.get(), m_startOffset) == -1)
return -1;
// compare to end, and point comes after
else if (compareBoundaryPoints(refNode, offset, m_endContainer.get(), m_endOffset) == 1)
return 1;
// point is in the middle of this range, or on the boundary points
else
return 0;
}
short Range::compareBoundaryPoints(CompareHow how, const Range *sourceRange, ExceptionCode& ec) const
{
if (m_detached) {
......
......@@ -64,6 +64,8 @@ public:
void setStart(Node* container, int offset, ExceptionCode&);
void setEnd(Node* container, int offset, ExceptionCode&);
void collapse(bool toStart, ExceptionCode&);
bool isPointInRange(Node* refNode, int offset, ExceptionCode& ec);
short comparePoint(Node* refNode, int offset, ExceptionCode& ec);
enum CompareHow { START_TO_START, START_TO_END, END_TO_END, END_TO_START };
short compareBoundaryPoints(CompareHow, const Range* sourceRange, ExceptionCode&) const;
static short compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB);
......
......@@ -66,6 +66,12 @@ module ranges {
short compareBoundaryPoints(in CompareHow how,
in Range sourceRange)
raises(dom::DOMException);
short comparePoint(in Node refNode,
in long offset)
raises(RangeException, dom::DOMException);
boolean isPointInRange(in Node refNode,
in long offset)
raises(RangeException, dom::DOMException);
void deleteContents()
raises(dom::DOMException);
DocumentFragment extractContents()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment