Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: third_party/WebKit/Source/web/WebRange.cpp

Issue 2199523002: Convert WebRange to be a simple pair of numbers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moar cleanup. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "public/web/WebRange.h" 31 #include "public/web/WebRange.h"
32 32
33 #include "bindings/core/v8/ExceptionState.h"
34 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
35 #include "core/dom/Document.h" 33 #include "core/dom/Document.h"
36 #include "core/dom/Element.h"
37 #include "core/dom/Range.h" 34 #include "core/dom/Range.h"
38 #include "core/dom/shadow/ShadowRoot.h"
39 #include "core/editing/FrameSelection.h" 35 #include "core/editing/FrameSelection.h"
40 #include "core/editing/PlainTextRange.h" 36 #include "core/editing/PlainTextRange.h"
41 #include "core/frame/FrameView.h"
42 #include "core/frame/LocalFrame.h" 37 #include "core/frame/LocalFrame.h"
43 #include "public/platform/WebString.h"
44 #include "public/web/WebExceptionCode.h"
45 #include "public/web/WebNode.h"
46 #include "web/WebLocalFrameImpl.h"
47 #include "wtf/PassRefPtr.h"
48 38
49 namespace blink { 39 namespace blink {
50 40
51 void WebRange::reset() 41 WebRange::WebRange(int start, int length)
42 : m_start(start)
43 , m_end(start + length)
52 { 44 {
53 m_private.reset(); 45 DCHECK(start != 1 && length != 0) << "These values are reserved to indicate that the range is null";
ojan 2016/08/09 18:15:05 s/1/-1/ ?
dglazkov 2016/08/10 05:12:13 LOL. YES.
54 } 46 }
55 47
56 void WebRange::assign(const WebRange& other) 48 WebRange::WebRange(Range* range)
57 { 49 {
58 m_private = other.m_private; 50 if (!range)
51 return;
52
53 m_start = range->startOffset();
54 m_end = range->endOffset();
59 } 55 }
60 56
61 int WebRange::startOffset() const 57 Range* WebRange::createRange(LocalFrame* frame) const
62 { 58 {
63 return m_private->startOffset(); 59 Element* selectionRoot = frame->selection().rootEditableElement();
64 } 60 ContainerNode* scope = selectionRoot ? selectionRoot : frame->document()->do cumentElement();
65 61
66 int WebRange::endOffset() const 62 return blink::createRange(PlainTextRange(m_start, m_end).createRange(*scope) );
67 {
68 return m_private->endOffset();
69 }
70
71 WebString WebRange::toPlainText() const
72 {
73 return m_private->text();
74 }
75
76 // static
77 WebRange WebRange::fromDocumentRange(WebLocalFrame* frame, int start, int length )
78 {
79 LocalFrame* webFrame = toWebLocalFrameImpl(frame)->frame();
80 Element* selectionRoot = webFrame->selection().rootEditableElement();
81 ContainerNode* scope = selectionRoot ? selectionRoot : webFrame->document()- >documentElement();
82
83 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets n eeds to be audited.
84 // see http://crbug.com/590369 for more details.
85 scope->document().updateStyleAndLayoutIgnorePendingStylesheets();
86
87 return createRange(PlainTextRange(start, start + length).createRange(*scope) );
88 }
89
90 WebRange::WebRange(Range*range)
91 : m_private(range)
92 {
93 }
94
95 WebRange::operator Range*() const
96 {
97 return m_private.get();
98 } 63 }
99 64
100 } // namespace blink 65 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698