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 "FrameView.h"
39
#include "ShadowRoot.h"
40
#include "TextIterator.h"
41
#include "WebFrameImpl.h"
43
#include <public/WebFloatQuad.h>
44
#include <public/WebString.h>
45
#include <wtf/PassRefPtr.h>
47
using namespace WebCore;
51
class WebRangePrivate : public Range {
54
void WebRange::reset()
59
void WebRange::assign(const WebRange& other)
61
WebRangePrivate* p = const_cast<WebRangePrivate*>(other.m_private);
67
int WebRange::startOffset() const
69
return m_private->startOffset();
72
int WebRange::endOffset() const
74
return m_private->endOffset();
77
WebNode WebRange::startContainer(int& exceptionCode) const
79
return PassRefPtr<Node>(m_private->startContainer(exceptionCode));
82
WebNode WebRange::endContainer(int& exceptionCode) const
84
return PassRefPtr<Node>(m_private->endContainer(exceptionCode));
87
WebString WebRange::toHTMLText() const
89
return m_private->toHTML();
92
WebString WebRange::toPlainText() const
94
return m_private->text();
98
WebRange WebRange::fromDocumentRange(WebFrame* frame, int start, int length)
100
WebCore::Frame* webFrame = static_cast<WebFrameImpl*>(frame)->frame();
101
Element* selectionRoot = webFrame->selection()->rootEditableElement();
102
ContainerNode* scope = selectionRoot ? selectionRoot : webFrame->document()->documentElement();
103
return TextIterator::rangeFromLocationAndLength(scope, start, length);
106
WebVector<WebFloatQuad> WebRange::textQuads() const
109
return WebVector<WebFloatQuad>();
111
Frame* frame = m_private->ownerDocument() ? m_private->ownerDocument()->frame() : 0;
113
return WebVector<WebFloatQuad>();
115
Vector<FloatQuad> quads;
116
m_private->textQuads(quads);
117
for (unsigned i = 0; i < quads.size(); ++i) {
118
quads[i].setP1(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p1())));
119
quads[i].setP2(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p2())));
120
quads[i].setP3(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p3())));
121
quads[i].setP4(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p4())));
127
WebRange::WebRange(const WTF::PassRefPtr<WebCore::Range>& range)
128
: m_private(static_cast<WebRangePrivate*>(range.leakRef()))
132
WebRange& WebRange::operator=(const WTF::PassRefPtr<WebCore::Range>& range)
134
assign(static_cast<WebRangePrivate*>(range.leakRef()));
138
WebRange::operator WTF::PassRefPtr<WebCore::Range>() const
140
return PassRefPtr<Range>(const_cast<WebRangePrivate*>(m_private));
143
void WebRange::assign(WebRangePrivate* p)
145
// p is already ref'd for us by the caller
151
} // namespace WebKit