Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/StaticRange.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/StaticRange.cpp b/third_party/WebKit/Source/core/dom/StaticRange.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c9b029345194b486b195ef6236ed69c8f38d73f3 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/dom/StaticRange.cpp |
| @@ -0,0 +1,64 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// https://discourse.wicg.io/t/proposal-staticrange-to-be-used-instead-of-range-for-new-apis/1472 |
| + |
| +#include "core/dom/StaticRange.h" |
| + |
| +#include "bindings/core/v8/ExceptionState.h" |
| +#include "bindings/core/v8/ScriptState.h" |
| +#include "core/dom/Range.h" |
| +#include "core/frame/LocalDOMWindow.h" |
| + |
| +namespace blink { |
| + |
| +StaticRange::StaticRange() |
| + : m_startContainer(nullptr) |
| + , m_startOffset(0) |
| + , m_endContainer(nullptr) |
| + , m_endOffset(0) |
| +{ |
| +} |
| + |
| +StaticRange::StaticRange(Node* startContainer, int startOffset, Node* endContainer, int endOffset) |
| + : m_startContainer(startContainer) |
| + , m_startOffset(startOffset) |
| + , m_endContainer(endContainer) |
| + , m_endOffset(endOffset) |
| +{ |
| +} |
| + |
| +void StaticRange::setStart(Node* container, int offset) |
| +{ |
| + m_startContainer = container; |
| + m_startOffset = offset; |
| +} |
| + |
| +void StaticRange::setEnd(Node* container, int offset) |
| +{ |
| + m_endContainer = container; |
| + m_endOffset = offset; |
| +} |
| + |
| +Range* StaticRange::toRange(ScriptState* scriptState, ExceptionState& exceptionState) const |
| +{ |
| + 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.
|
| +} |
| + |
| +Range* StaticRange::toRangeImpl(Document& document, ExceptionState& exceptionState) const |
| +{ |
| + Range* range = Range::create(document); |
| + // Do the offset checking. |
| + range->setStart(m_startContainer, m_startOffset, exceptionState); |
| + range->setEnd(m_endContainer, m_endOffset, exceptionState); |
| + return range; |
| +} |
| + |
| +DEFINE_TRACE(StaticRange) |
| +{ |
| + visitor->trace(m_startContainer); |
| + visitor->trace(m_endContainer); |
| +} |
| + |
| +} // namespace blink |