| 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..e9f7d47fdc25c336d33ed472c5fd506aee2bb22a 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 (documentCachedRange())
|
| + return 1;
|
| return frame()->selection().isNone() ? 0 : 1;
|
| }
|
|
|
| @@ -286,6 +288,8 @@ void DOMSelection::setBaseAndExtent(Node* baseNode,
|
| if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
|
| return;
|
|
|
| + clearCachedRangeIfSelectionOfDocument();
|
| +
|
| // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
|
| // needs to be audited. See http://crbug.com/590369 for more details.
|
| // In the long term, we should change FrameSelection::setSelection to take a
|
| @@ -383,6 +387,7 @@ void DOMSelection::extend(Node* node,
|
| if (!isValidForPosition(node))
|
| return;
|
|
|
| + clearCachedRangeIfSelectionOfDocument();
|
| const Position& base = frame()->selection().base();
|
| if (base.isNull()) {
|
| // TODO(editing-dev): We should throw |InvalidStateError| if selection is
|
| @@ -413,6 +418,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 (Range* cachedRange = documentCachedRange())
|
| + return cachedRange;
|
| +
|
| + Range* range = createRangeFromSelectionEditor();
|
| + cacheRangeIfSelectionOfDocument(range);
|
| + return range;
|
| +}
|
| +
|
| +Range* DOMSelection::createRangeFromSelectionEditor() {
|
| Position anchor = anchorPosition(visibleSelection());
|
| if (!anchor.anchorNode()->isInShadowTree())
|
| return frame()->selection().firstRange();
|
| @@ -427,6 +441,28 @@ Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) {
|
| focusOffset());
|
| }
|
|
|
| +bool DOMSelection::isSelectionOfDocument() const {
|
| + return m_treeScope == m_treeScope->document();
|
| +}
|
| +
|
| +void DOMSelection::cacheRangeIfSelectionOfDocument(Range* range) {
|
| + if (!isSelectionOfDocument())
|
| + return;
|
| + frame()->selection().cacheRangeOfDocument(range);
|
| +}
|
| +
|
| +Range* DOMSelection::documentCachedRange() const {
|
| + if (!isSelectionOfDocument())
|
| + return nullptr;
|
| + return frame()->selection().documentCachedRange();
|
| +}
|
| +
|
| +void DOMSelection::clearCachedRangeIfSelectionOfDocument() {
|
| + if (!isSelectionOfDocument())
|
| + return;
|
| + frame()->selection().clearDocumentCachedRange();
|
| +}
|
| +
|
| void DOMSelection::removeAllRanges() {
|
| if (!isAvailable())
|
| return;
|
| @@ -463,6 +499,7 @@ void DOMSelection::addRange(Range* newRange) {
|
|
|
| if (selection.isNone()) {
|
| selection.setSelectedRange(EphemeralRange(newRange), VP_DEFAULT_AFFINITY);
|
| + cacheRangeIfSelectionOfDocument(newRange);
|
| return;
|
| }
|
|
|
| @@ -510,6 +547,7 @@ void DOMSelection::addRange(Range* newRange) {
|
| EphemeralRange(start->startPosition(), end->endPosition());
|
| TextAffinity affinity = selection.selection().affinity();
|
| selection.setSelectedRange(merged, affinity);
|
| + cacheRangeIfSelectionOfDocument(createRange(merged));
|
| }
|
|
|
| void DOMSelection::deleteFromDocument() {
|
|
|