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

Unified Diff: Source/core/layout/PendingSelection.cpp

Issue 1189963003: Templatize PendingSelection class (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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: Source/core/layout/PendingSelection.cpp
diff --git a/Source/core/layout/PendingSelection.cpp b/Source/core/layout/PendingSelection.cpp
index 4b6db8e251d7d83e1c27bf19b22fa495726aa6c7..84f945064dc3ed8d69cefe5ae1ed5ef292621d13 100644
--- a/Source/core/layout/PendingSelection.cpp
+++ b/Source/core/layout/PendingSelection.cpp
@@ -50,31 +50,42 @@ void PendingSelection::clear()
m_shouldShowBlockCursor = false;
}
-bool PendingSelection::isInDocument(const Document& document) const
+template <typename Strategy>
+bool PendingSelection::isInDocumentAlgorithm(const Document& document) const
{
- Position start = m_selection.start();
+ using PositionType = typename Strategy::PositionType;
+
+ PositionType start = Strategy::selectionStart(m_selection);
if (start.isNotNull() && (!start.inDocument() || start.document() != document))
return false;
- Position end = m_selection.end();
+ PositionType end = Strategy::selectionEnd(m_selection);
if (end.isNotNull() && (!end.inDocument() || end.document() != document))
return false;
- Position extent = m_selection.extent();
+ PositionType extent = Strategy::selectionExtent(m_selection);
if (extent.isNotNull() && (!extent.inDocument() || extent.document() != document))
return false;
return true;
}
-VisibleSelection PendingSelection::calcVisibleSelection() const
+bool PendingSelection::isInDocument(const Document& document) const
+{
+ return isInDocumentAlgorithm<VisibleSelection::InDOMTree>(document);
+}
+
+template <typename Strategy>
+VisibleSelection PendingSelection::calcVisibleSelectionAlgorithm() const
{
- Position start = m_selection.start();
- Position end = m_selection.end();
+ using PositionType = typename Strategy::PositionType;
+
+ PositionType start = Strategy::selectionStart(m_selection);
+ PositionType end = Strategy::selectionEnd(m_selection);
SelectionType selectionType = VisibleSelection::selectionType(start, end);
EAffinity affinity = m_selection.affinity();
bool paintBlockCursor = m_shouldShowBlockCursor && selectionType == SelectionType::CaretSelection && !isLogicalEndOfLine(VisiblePosition(end, affinity));
VisibleSelection selection;
- if (enclosingTextFormControl(start)) {
- Position endPosition = paintBlockCursor ? m_selection.extent().next() : end;
+ if (enclosingTextFormControl(start.containerNode())) {
+ PositionType endPosition = paintBlockCursor ? Strategy::selectionExtent(m_selection).next() : end;
selection.setWithoutValidation(start, endPosition);
return selection;
}
@@ -89,6 +100,11 @@ VisibleSelection PendingSelection::calcVisibleSelection() const
return VisibleSelection(visibleStart, visibleEnd);
}
+VisibleSelection PendingSelection::calcVisibleSelection() const
+{
+ return calcVisibleSelectionAlgorithm<VisibleSelection::InDOMTree>();
+}
+
DEFINE_TRACE(PendingSelection)
{
visitor->trace(m_selection);
« Source/core/editing/VisibleSelection.h ('K') | « Source/core/layout/PendingSelection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698