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/core/v8/ExceptionState.h"
35 #include "bindings/core/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/WebString.h"
45 #include "public/web/WebExceptionCode.h"
46 #include "public/web/WebNode.h"
47 #include "web/WebLocalFrameImpl.h"
48 #include "wtf/PassRefPtr.h"
52 void WebRange::reset()
57 void WebRange::assign(const WebRange& other)
59 m_private = other.m_private;
62 int WebRange::startOffset() const
64 return m_private->startOffset();
67 int WebRange::endOffset() const
69 return m_private->endOffset();
72 WebNode WebRange::startContainer(WebExceptionCode& exceptionCode) const
74 // FIXME: Create a wrapper class that just sets the internal int.
75 RefPtrWillBeRawPtr<Node> node(m_private->startContainer());
77 return node.release();
80 WebNode WebRange::endContainer(WebExceptionCode& exceptionCode) const
82 // FIXME: Create a wrapper class that just sets the internal int.
83 RefPtrWillBeRawPtr<Node> node(m_private->endContainer());
85 return node.release();
88 WebString WebRange::toHTMLText() const
90 return m_private->toHTML();
93 WebString WebRange::toPlainText() const
95 return m_private->text();
98 WebRange WebRange::expandedToParagraph() const
100 WebRange copy(*this);
101 copy.m_private->expand("block", IGNORE_EXCEPTION);
106 WebRange WebRange::fromDocumentRange(WebLocalFrame* frame, int start, int length)
108 LocalFrame* webFrame = toWebLocalFrameImpl(frame)->frame();
109 Element* selectionRoot = webFrame->selection().rootEditableElement();
110 ContainerNode* scope = selectionRoot ? selectionRoot : webFrame->document()->documentElement();
111 return PlainTextRange(start, start + length).createRange(*scope);
114 WebRange::WebRange(const PassRefPtrWillBeRawPtr<Range>& range)
119 WebRange::operator PassRefPtrWillBeRawPtr<Range>() const
121 return m_private.get();