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

Side by Side Diff: third_party/WebKit/Source/core/dom/StaticRange.cpp

Issue 2022863002: [InputEvent] Introduce |StaticRange| and use in |InputEvent::getRanges()| (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduce |StaticRange| and add tests Created 4 years, 6 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // https://discourse.wicg.io/t/proposal-staticrange-to-be-used-instead-of-range- for-new-apis/1472
6
7 #include "core/dom/StaticRange.h"
8
9 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/ScriptState.h"
11 #include "core/dom/Range.h"
12 #include "core/frame/LocalDOMWindow.h"
13
14 namespace blink {
15
16 StaticRange::StaticRange()
17 : m_startContainer(nullptr)
18 , m_startOffset(0)
19 , m_endContainer(nullptr)
20 , m_endOffset(0)
21 {
22 }
23
24 StaticRange::StaticRange(Node* startContainer, int startOffset, Node* endContain er, int endOffset)
25 : m_startContainer(startContainer)
26 , m_startOffset(startOffset)
27 , m_endContainer(endContainer)
28 , m_endOffset(endOffset)
29 {
30 }
31
32 void StaticRange::setStart(Node* container, int offset)
33 {
34 m_startContainer = container;
35 m_startOffset = offset;
36 }
37
38 void StaticRange::setEnd(Node* container, int offset)
39 {
40 m_endContainer = container;
41 m_endOffset = offset;
42 }
43
44 Range* StaticRange::toRange(ScriptState* scriptState, ExceptionState& exceptionS tate) const
45 {
46 return toRangeImpl(*scriptState->domWindow()->document(), exceptionState);
dtapuska 2016/06/02 15:26:29 Is this correct? does this work across iframes?
chongz 2016/06/06 19:43:43 Fixed by passing |Document| to constructor.
47 }
48
49 Range* StaticRange::toRangeImpl(Document& document, ExceptionState& exceptionSta te) const
50 {
51 Range* range = Range::create(document);
52 // Do the offset checking.
53 range->setStart(m_startContainer, m_startOffset, exceptionState);
54 range->setEnd(m_endContainer, m_endOffset, exceptionState);
55 return range;
56 }
57
58 DEFINE_TRACE(StaticRange)
59 {
60 visitor->trace(m_startContainer);
61 visitor->trace(m_endContainer);
62 }
63
64 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698