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

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

Issue 2001083002: Explicit management of FrameSelection availability (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-06-06T17:09:04 Created 4 years, 6 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 0dc76f0fef3b9f52cab367db903ee52d1a675f81..e7025cf9d59ec9270904be7eed467078222a9773 100644
--- a/third_party/WebKit/Source/core/editing/SelectionEditor.cpp
+++ b/third_party/WebKit/Source/core/editing/SelectionEditor.cpp
@@ -36,15 +36,33 @@ SelectionEditor::SelectionEditor(FrameSelection& frameSelection)
: m_frameSelection(frameSelection)
, m_observingVisibleSelection(false)
{
+ clearVisibleSelection();
}
SelectionEditor::~SelectionEditor()
{
}
+void SelectionEditor::clearVisibleSelection()
+{
+ m_selection = VisibleSelection();
+ m_selectionInFlatTree = VisibleSelectionInFlatTree();
+ if (!shouldAlwaysUseDirectionalSelection())
+ return;
+ m_selection.setIsDirectional(true);
+ m_selectionInFlatTree.setIsDirectional(true);
+}
+
void SelectionEditor::dispose()
{
resetLogicalRange();
+ clearVisibleSelection();
+}
+
+const Document& SelectionEditor::document() const
+{
+ DCHECK(m_document);
+ return *m_document;
}
LocalFrame* SelectionEditor::frame() const
@@ -55,17 +73,28 @@ LocalFrame* SelectionEditor::frame() const
template <>
const VisibleSelection& SelectionEditor::visibleSelection<EditingStrategy>() const
{
+ DCHECK_EQ(frame()->document(), document());
+ DCHECK_EQ(frame(), document().frame());
+ if (m_selection.isNone())
+ return m_selection;
+ DCHECK_EQ(m_selection.base().document(), document());
return m_selection;
}
template <>
const VisibleSelectionInFlatTree& SelectionEditor::visibleSelection<EditingInFlatTreeStrategy>() const
{
+ DCHECK_EQ(frame()->document(), document());
+ DCHECK_EQ(frame(), document().frame());
+ if (m_selectionInFlatTree.isNone())
+ return m_selectionInFlatTree;
+ DCHECK_EQ(m_selectionInFlatTree.base().document(), document());
return m_selectionInFlatTree;
}
void SelectionEditor::setVisibleSelection(const VisibleSelection& newSelection, FrameSelection::SetSelectionOptions options)
{
+ DCHECK(newSelection.isValidFor(document())) << newSelection;
resetLogicalRange();
m_selection = newSelection;
if (options & FrameSelection::DoNotAdjustInFlatTree) {
@@ -78,25 +107,37 @@ void SelectionEditor::setVisibleSelection(const VisibleSelection& newSelection,
void SelectionEditor::setVisibleSelection(const VisibleSelectionInFlatTree& newSelection, FrameSelection::SetSelectionOptions options)
{
+ DCHECK(newSelection.isValidFor(document())) << newSelection;
DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree));
resetLogicalRange();
m_selectionInFlatTree = newSelection;
SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, m_selectionInFlatTree);
}
-void SelectionEditor::setIsDirectional(bool isDirectional)
-{
- m_selection.setIsDirectional(isDirectional);
- m_selectionInFlatTree.setIsDirectional(isDirectional);
-}
-
void SelectionEditor::setWithoutValidation(const Position& base, const Position& extent)
{
resetLogicalRange();
+ if (base.isNotNull())
+ DCHECK_EQ(base.document(), document());
+ if (extent.isNotNull())
+ DCHECK_EQ(extent.document(), document());
m_selection.setWithoutValidation(base, extent);
m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), toPositionInFlatTree(extent));
}
+void SelectionEditor::documentAttached(Document* document)
+{
+ DCHECK(!m_document);
tkent 2016/06/07 23:41:59 We should have DCHECK(document)
yosin_UTC9 2016/06/08 04:06:10 Done.
+ m_document = document;
+}
+
+void SelectionEditor::documentDetached(const Document& document)
+{
+ DCHECK_EQ(m_document, &document);
+ dispose();
+ m_document = nullptr;
+}
+
void SelectionEditor::resetLogicalRange()
{
// Non-collapsed ranges are not allowed to start at the end of a line that
@@ -109,6 +150,7 @@ void SelectionEditor::resetLogicalRange()
void SelectionEditor::setLogicalRange(Range* range)
{
+ DCHECK_EQ(range->ownerDocument(), document());
DCHECK(!m_logicalRange) << "A logical range should be one.";
m_logicalRange = range;
}
@@ -120,14 +162,22 @@ Range* SelectionEditor::firstRange() const
return firstRangeOf(m_selection);
}
+bool SelectionEditor::shouldAlwaysUseDirectionalSelection() const
+{
+ return frame()->editor().behavior().shouldConsiderSelectionAsDirectional();
+}
+
void SelectionEditor::updateIfNeeded()
{
+ DCHECK(m_selection.isValidFor(document())) << m_selection;
+ DCHECK(m_selectionInFlatTree.isValidFor(document())) << m_selection;
m_selection.updateIfNeeded();
m_selectionInFlatTree.updateIfNeeded();
}
DEFINE_TRACE(SelectionEditor)
{
+ visitor->trace(m_document);
visitor->trace(m_frameSelection);
visitor->trace(m_selection);
visitor->trace(m_selectionInFlatTree);

Powered by Google App Engine
This is Rietveld 408576698