1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
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
13 * distribution.
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.
17 *
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.
29 */
30
31 #include "config.h"
32 #include "WebRange.h"
33
34 #include "Range.h"
35 #include "WebString.h"
36 #include <wtf/PassRefPtr.h>
37
38 using namespace WebCore;
39
40 namespace WebKit {
41
42 class WebRangePrivate : public Range {
43 };
44
reset()45 void WebRange::reset()
46 {
47 assign(0);
48 }
49
assign(const WebRange & other)50 void WebRange::assign(const WebRange& other)
51 {
52 WebRangePrivate* p = const_cast<WebRangePrivate*>(other.m_private);
53 if (p)
54 p->ref();
55 assign(p);
56 }
57
startOffset() const58 int WebRange::startOffset() const
59 {
60 return m_private->startOffset();
61 }
62
endOffset() const63 int WebRange::endOffset() const
64 {
65 return m_private->endOffset();
66 }
67
startContainer(int & exceptionCode) const68 Node* WebRange::startContainer(int& exceptionCode) const
69 {
70 return m_private->startContainer(exceptionCode);
71 }
72
endContainer(int & exceptionCode) const73 Node* WebRange::endContainer(int& exceptionCode) const
74 {
75 return m_private->endContainer(exceptionCode);
76 }
77
toHTMLText() const78 WebString WebRange::toHTMLText() const
79 {
80 return m_private->toHTML();
81 }
82
toPlainText() const83 WebString WebRange::toPlainText() const
84 {
85 return m_private->text();
86 }
87
WebRange(const WTF::PassRefPtr<WebCore::Range> & range)88 WebRange::WebRange(const WTF::PassRefPtr<WebCore::Range>& range)
89 : m_private(static_cast<WebRangePrivate*>(range.releaseRef()))
90 {
91 }
92
operator =(const WTF::PassRefPtr<WebCore::Range> & range)93 WebRange& WebRange::operator=(const WTF::PassRefPtr<WebCore::Range>& range)
94 {
95 assign(static_cast<WebRangePrivate*>(range.releaseRef()));
96 return *this;
97 }
98
operator WTF::PassRefPtr<WebCore::Range>() const99 WebRange::operator WTF::PassRefPtr<WebCore::Range>() const
100 {
101 return PassRefPtr<Range>(const_cast<WebRangePrivate*>(m_private));
102 }
103
assign(WebRangePrivate * p)104 void WebRange::assign(WebRangePrivate* p)
105 {
106 // p is already ref'd for us by the caller
107 if (m_private)
108 m_private->deref();
109 m_private = p;
110 }
111
112 } // namespace WebKit
113