OLD | NEW |
| (Empty) |
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 "sky/engine/public/web/WebRange.h" | |
32 | |
33 #include "sky/engine/bindings/exception_state.h" | |
34 #include "sky/engine/bindings/exception_state_placeholder.h" | |
35 #include "sky/engine/core/dom/Document.h" | |
36 #include "sky/engine/core/dom/Element.h" | |
37 #include "sky/engine/core/dom/Range.h" | |
38 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | |
39 #include "sky/engine/core/editing/FrameSelection.h" | |
40 #include "sky/engine/core/editing/PlainTextRange.h" | |
41 #include "sky/engine/core/frame/FrameView.h" | |
42 #include "sky/engine/core/frame/LocalFrame.h" | |
43 #include "sky/engine/public/platform/WebString.h" | |
44 #include "sky/engine/public/web/WebExceptionCode.h" | |
45 #include "sky/engine/public/web/WebNode.h" | |
46 #include "sky/engine/web/WebLocalFrameImpl.h" | |
47 #include "sky/engine/wtf/PassRefPtr.h" | |
48 | |
49 namespace blink { | |
50 | |
51 void WebRange::reset() | |
52 { | |
53 m_private.reset(); | |
54 } | |
55 | |
56 void WebRange::assign(const WebRange& other) | |
57 { | |
58 m_private = other.m_private; | |
59 } | |
60 | |
61 int WebRange::startOffset() const | |
62 { | |
63 return m_private->startOffset(); | |
64 } | |
65 | |
66 int WebRange::endOffset() const | |
67 { | |
68 return m_private->endOffset(); | |
69 } | |
70 | |
71 WebNode WebRange::startContainer(WebExceptionCode& exceptionCode) const | |
72 { | |
73 // FIXME: Create a wrapper class that just sets the internal int. | |
74 RefPtr<Node> node(m_private->startContainer()); | |
75 exceptionCode = 0; | |
76 return node.release(); | |
77 } | |
78 | |
79 WebNode WebRange::endContainer(WebExceptionCode& exceptionCode) const | |
80 { | |
81 // FIXME: Create a wrapper class that just sets the internal int. | |
82 RefPtr<Node> node(m_private->endContainer()); | |
83 exceptionCode = 0; | |
84 return node.release(); | |
85 } | |
86 | |
87 WebString WebRange::toPlainText() const | |
88 { | |
89 return m_private->text(); | |
90 } | |
91 | |
92 WebRange WebRange::expandedToParagraph() const | |
93 { | |
94 WebRange copy(*this); | |
95 copy.m_private->expand("block", IGNORE_EXCEPTION); | |
96 return copy; | |
97 } | |
98 | |
99 // static | |
100 WebRange WebRange::fromDocumentRange(WebLocalFrame* frame, int start, int length
) | |
101 { | |
102 LocalFrame* webFrame = toWebLocalFrameImpl(frame)->frame(); | |
103 ContainerNode* selectionRoot = webFrame->selection().rootEditableElement(); | |
104 ContainerNode* scope = selectionRoot ? selectionRoot : webFrame->document(); | |
105 return PlainTextRange(start, start + length).createRange(*scope); | |
106 } | |
107 | |
108 WebRange::WebRange(const PassRefPtr<Range>& range) | |
109 : m_private(range) | |
110 { | |
111 } | |
112 | |
113 WebRange::operator PassRefPtr<Range>() const | |
114 { | |
115 return m_private.get(); | |
116 } | |
117 | |
118 } // namespace blink | |
OLD | NEW |