2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "TextIterator.h"
38 #include "WebFrameImpl.h"
40 #include "WebString.h"
41 #include <wtf/PassRefPtr.h>
43 using namespace WebCore;
47 class WebRangePrivate : public Range {
50 void WebRange::reset()
55 void WebRange::assign(const WebRange& other)
57 WebRangePrivate* p = const_cast<WebRangePrivate*>(other.m_private);
63 int WebRange::startOffset() const
65 return m_private->startOffset();
68 int WebRange::endOffset() const
70 return m_private->endOffset();
73 WebNode WebRange::startContainer(int& exceptionCode) const
75 return PassRefPtr<Node>(m_private->startContainer(exceptionCode));
78 WebNode WebRange::endContainer(int& exceptionCode) const
80 return PassRefPtr<Node>(m_private->endContainer(exceptionCode));
83 WebString WebRange::toHTMLText() const
85 return m_private->toHTML();
88 WebString WebRange::toPlainText() const
90 return m_private->text();
94 WebRange WebRange::fromDocumentRange(WebFrame* frame, int start, int length)
96 WebCore::Frame* webFrame = static_cast<WebFrameImpl*>(frame)->frame();
97 Element* selectionRoot = webFrame->selection()->rootEditableElement();
98 Element* scope = selectionRoot ? selectionRoot : webFrame->document()->documentElement();
99 return TextIterator::rangeFromLocationAndLength(scope, start, length);
102 WebRange::WebRange(const WTF::PassRefPtr<WebCore::Range>& range)
103 : m_private(static_cast<WebRangePrivate*>(range.leakRef()))
107 WebRange& WebRange::operator=(const WTF::PassRefPtr<WebCore::Range>& range)
109 assign(static_cast<WebRangePrivate*>(range.leakRef()));
113 WebRange::operator WTF::PassRefPtr<WebCore::Range>() const
115 return PassRefPtr<Range>(const_cast<WebRangePrivate*>(m_private));
118 void WebRange::assign(WebRangePrivate* p)
120 // p is already ref'd for us by the caller
126 } // namespace WebKit