| Index: third_party/WebKit/Source/core/editing/DOMSelection.cpp
|
| diff --git a/third_party/WebKit/Source/core/editing/DOMSelection.cpp b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
|
| index 34c9a1c8e64719d26bfc41d5b133c9a5c5b780e6..ba1dd89a31a079f82a788ec5eca1be4636ba347b 100644
|
| --- a/third_party/WebKit/Source/core/editing/DOMSelection.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
|
| @@ -175,6 +175,8 @@ String DOMSelection::type() const {
|
| int DOMSelection::rangeCount() const {
|
| if (!isAvailable())
|
| return 0;
|
| + if (m_range)
|
| + return 1;
|
| return frame()->selection().isNone() ? 0 : 1;
|
| }
|
|
|
| @@ -383,6 +385,7 @@ void DOMSelection::extend(Node* node,
|
| if (!isValidForPosition(node))
|
| return;
|
|
|
| + markRangeDirty();
|
| const Position& base = frame()->selection().base();
|
| if (base.isNull()) {
|
| // TODO(editing-dev): We should throw |InvalidStateError| if selection is
|
| @@ -413,6 +416,15 @@ Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) {
|
| // If you're hitting this, you've added broken multi-range selection support
|
| DCHECK_EQ(rangeCount(), 1);
|
|
|
| + if (m_range)
|
| + return m_range;
|
| +
|
| + Range* range = createRangeFromSelectionEditor();
|
| + cacheRangeIfAttachedToRootDocument(range);
|
| + return range;
|
| +}
|
| +
|
| +Range* DOMSelection::createRangeFromSelectionEditor() {
|
| Position anchor = anchorPosition(visibleSelection());
|
| if (!anchor.anchorNode()->isInShadowTree())
|
| return frame()->selection().firstRange();
|
| @@ -427,7 +439,19 @@ Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) {
|
| focusOffset());
|
| }
|
|
|
| +void DOMSelection::markRangeDirty() {
|
| + m_range = nullptr;
|
| +}
|
| +
|
| +void DOMSelection::cacheRangeIfAttachedToRootDocument(Range* range) {
|
| + if (m_treeScope->parentTreeScope())
|
| + return;
|
| +
|
| + m_range = range;
|
| +}
|
| +
|
| void DOMSelection::removeAllRanges() {
|
| + m_range = nullptr;
|
| if (!isAvailable())
|
| return;
|
| frame()->selection().clear();
|
| @@ -463,6 +487,7 @@ void DOMSelection::addRange(Range* newRange) {
|
|
|
| if (selection.isNone()) {
|
| selection.setSelectedRange(EphemeralRange(newRange), VP_DEFAULT_AFFINITY);
|
| + cacheRangeIfAttachedToRootDocument(newRange);
|
| return;
|
| }
|
|
|
| @@ -510,6 +535,7 @@ void DOMSelection::addRange(Range* newRange) {
|
| EphemeralRange(start->startPosition(), end->endPosition());
|
| TextAffinity affinity = selection.selection().affinity();
|
| selection.setSelectedRange(merged, affinity);
|
| + cacheRangeIfAttachedToRootDocument(createRange(merged));
|
| }
|
|
|
| void DOMSelection::deleteFromDocument() {
|
| @@ -671,6 +697,7 @@ void DOMSelection::addConsoleError(const String& message) {
|
|
|
| DEFINE_TRACE(DOMSelection) {
|
| visitor->trace(m_treeScope);
|
| + visitor->trace(m_range);
|
| ContextClient::trace(visitor);
|
| }
|
|
|
|
|