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

Unified Diff: third_party/WebKit/Source/core/editing/DOMSelection.cpp

Issue 2653523003: Make DOMSelection cache Range (Closed)
Patch Set: Clear cached Range considering Shadow Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
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 4e5fc3c3eafdf43a05406ea05571836019927d53..4c65719d57f4c94354c29a20350e97dfa801808d 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;
}
@@ -413,6 +415,17 @@ 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* newRange = createRangeFromSelectionEditor();
+ if (!areRangesEqual(newRange, m_Range))
tkent 2017/01/25 07:59:12 m_Range is always nullptr. Is this code equivalent
yoichio 2017/01/27 08:33:04 Right.
+ m_Range = newRange;
+
+ return m_Range;
+}
+
+Range* DOMSelection::createRangeFromSelectionEditor() {
Position anchor = anchorPosition(visibleSelection());
if (!anchor.anchorNode()->isInShadowTree())
return frame()->selection().firstRange();
@@ -427,7 +440,12 @@ Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) {
focusOffset());
}
+void DOMSelection::markRangeDirty() {
+ m_Range = nullptr;
+}
+
void DOMSelection::removeAllRanges() {
+ m_Range = nullptr;
if (!isAvailable())
return;
frame()->selection().clear();
@@ -463,6 +481,7 @@ void DOMSelection::addRange(Range* newRange) {
if (selection.isNone()) {
selection.setSelectedRange(EphemeralRange(newRange), VP_DEFAULT_AFFINITY);
+ m_Range = newRange;
return;
}
@@ -510,6 +529,7 @@ void DOMSelection::addRange(Range* newRange) {
EphemeralRange(start->startPosition(), end->endPosition());
TextAffinity affinity = selection.selection().affinity();
selection.setSelectedRange(merged, affinity);
+ m_Range = createRange(merged);
}
void DOMSelection::deleteFromDocument() {
@@ -669,6 +689,7 @@ void DOMSelection::addConsoleError(const String& message) {
DEFINE_TRACE(DOMSelection) {
visitor->trace(m_treeScope);
+ visitor->trace(m_Range);
ContextClient::trace(visitor);
}

Powered by Google App Engine
This is Rietveld 408576698