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

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

Issue 2653523003: Make DOMSelection cache Range (Closed)
Patch Set: cache Range in SelectionEditor Created 3 years, 10 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/SelectionEditor.cpp
diff --git a/third_party/WebKit/Source/core/editing/SelectionEditor.cpp b/third_party/WebKit/Source/core/editing/SelectionEditor.cpp
index 8206ecf15d3debae364272601af153a1bff8911d..fe22733f5adf2ad77ccc2a5f9118d7cda460a038 100644
--- a/third_party/WebKit/Source/core/editing/SelectionEditor.cpp
+++ b/third_party/WebKit/Source/core/editing/SelectionEditor.cpp
@@ -25,6 +25,7 @@
#include "core/editing/SelectionEditor.h"
+#include "core/editing/DOMSelection.h"
yosin_UTC9 2017/02/09 06:52:06 nit: SelectionEditor should not depend to DOMSelec
yoichio 2017/02/09 09:31:19 Done.
#include "core/editing/EditingUtilities.h"
#include "core/editing/Editor.h"
#include "core/editing/SelectionAdjuster.h"
@@ -50,6 +51,7 @@ void SelectionEditor::clearVisibleSelection() {
void SelectionEditor::dispose() {
resetLogicalRange();
+ clearDocumentCachedRange();
clearVisibleSelection();
}
@@ -85,6 +87,8 @@ void SelectionEditor::setVisibleSelection(
FrameSelection::SetSelectionOptions options) {
DCHECK(newSelection.isValidFor(document())) << newSelection;
resetLogicalRange();
+ clearDocumentCachedRange();
+
m_selection = newSelection;
if (options & FrameSelection::DoNotAdjustInFlatTree) {
m_selectionInFlatTree.setWithoutValidation(
@@ -103,6 +107,8 @@ void SelectionEditor::setVisibleSelection(
DCHECK(newSelection.isValidFor(document())) << newSelection;
DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree));
resetLogicalRange();
+ clearDocumentCachedRange();
+
m_selectionInFlatTree = newSelection;
SelectionAdjuster::adjustSelectionInDOMTree(&m_selection,
m_selectionInFlatTree);
@@ -115,6 +121,8 @@ void SelectionEditor::setWithoutValidation(const Position& base,
DCHECK_EQ(base.document(), document());
if (extent.isNotNull())
DCHECK_EQ(extent.document(), document());
+ clearDocumentCachedRange();
+
m_selection.setWithoutValidation(base, extent);
m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base),
toPositionInFlatTree(extent));
@@ -164,12 +172,21 @@ void SelectionEditor::updateIfNeeded() {
m_selectionInFlatTree.updateIfNeeded();
}
+void SelectionEditor::clearDocumentCachedRange() {
+ if (!m_cachedRange)
+ return;
+
+ m_cachedRange->dispose();
+ m_cachedRange = nullptr;
+}
+
DEFINE_TRACE(SelectionEditor) {
visitor->trace(m_document);
visitor->trace(m_frame);
visitor->trace(m_selection);
visitor->trace(m_selectionInFlatTree);
visitor->trace(m_logicalRange);
+ visitor->trace(m_cachedRange);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698