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.
32 #include "public/web/WebRange.h"
34 #include "bindings/v8/ExceptionState.h"
35 #include "bindings/v8/ExceptionStatePlaceholder.h"
36 #include "core/dom/Document.h"
37 #include "core/dom/Element.h"
38 #include "core/dom/Range.h"
39 #include "core/dom/shadow/ShadowRoot.h"
40 #include "core/editing/FrameSelection.h"
41 #include "core/editing/PlainTextRange.h"
42 #include "core/frame/FrameView.h"
43 #include "core/frame/LocalFrame.h"
44 #include "public/platform/WebFloatQuad.h"
45 #include "public/platform/WebString.h"
46 #include "public/web/WebExceptionCode.h"
47 #include "public/web/WebNode.h"
48 #include "web/WebLocalFrameImpl.h"
49 #include "wtf/PassRefPtr.h"
51 using namespace WebCore;
55 void WebRange::reset()
60 void WebRange::assign(const WebRange& other)
62 m_private = other.m_private;
65 int WebRange::startOffset() const
67 return m_private->startOffset();
70 int WebRange::endOffset() const
72 return m_private->endOffset();
75 WebNode WebRange::startContainer(WebExceptionCode& exceptionCode) const
77 // FIXME: Create a wrapper class that just sets the internal int.
78 RefPtrWillBeRawPtr<Node> node(m_private->startContainer());
80 return node.release();
83 WebNode WebRange::endContainer(WebExceptionCode& exceptionCode) const
85 // FIXME: Create a wrapper class that just sets the internal int.
86 RefPtrWillBeRawPtr<Node> node(m_private->endContainer());
88 return node.release();
91 WebString WebRange::toHTMLText() const
93 return m_private->toHTML();
96 WebString WebRange::toPlainText() const
98 return m_private->text();
101 WebRange WebRange::expandedToParagraph() const
103 WebRange copy(*this);
104 copy.m_private->expand("block", IGNORE_EXCEPTION);
109 WebRange WebRange::fromDocumentRange(WebLocalFrame* frame, int start, int length)
111 WebCore::LocalFrame* webFrame = toWebLocalFrameImpl(frame)->frame();
112 Element* selectionRoot = webFrame->selection().rootEditableElement();
113 ContainerNode* scope = selectionRoot ? selectionRoot : webFrame->document()->documentElement();
114 return PlainTextRange(start, start + length).createRange(*scope);
117 WebVector<WebFloatQuad> WebRange::textQuads() const
120 return WebVector<WebFloatQuad>();
122 LocalFrame* frame = m_private->ownerDocument().frame();
124 return WebVector<WebFloatQuad>();
126 Vector<FloatQuad> quads;
127 m_private->textQuads(quads);
128 for (unsigned i = 0; i < quads.size(); ++i) {
129 quads[i].setP1(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p1())));
130 quads[i].setP2(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p2())));
131 quads[i].setP3(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p3())));
132 quads[i].setP4(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p4())));
138 WebRange::WebRange(const PassRefPtrWillBeRawPtr<WebCore::Range>& range)
143 WebRange::operator PassRefPtrWillBeRawPtr<WebCore::Range>() const
145 return m_private.get();