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

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

Issue 1642723002: Revert of Introduce SelectionAdjuster to adjust selections between DOM tree version and composed tree version (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisibleSelection.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/VisibleSelection.cpp
diff --git a/third_party/WebKit/Source/core/editing/VisibleSelection.cpp b/third_party/WebKit/Source/core/editing/VisibleSelection.cpp
index 113c340ccda4173bebe19761a72a09062f70d9f1..c61a043bad9605da78f450c00abfe3cf294885fb 100644
--- a/third_party/WebKit/Source/core/editing/VisibleSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleSelection.cpp
@@ -111,6 +111,30 @@
}
template <typename Strategy>
+VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(
+ const PositionTemplate<Strategy>& base,
+ const PositionTemplate<Strategy>& extent,
+ const PositionTemplate<Strategy>& start,
+ const PositionTemplate<Strategy>& end,
+ TextAffinity affinity,
+ bool isDirectional)
+ : m_base(base)
+ , m_extent(extent)
+ , m_start(start)
+ , m_end(end)
+ , m_affinity(affinity)
+ , m_changeObserver(nullptr) // Observer is associated with only one VisibleSelection, so this should not be copied.
+ , m_selectionType(computeSelectionType(start, end))
+ , m_baseIsFirst(base.isNull() || base.compareTo(extent) <= 0)
+ , m_isDirectional(isDirectional)
+{
+ ASSERT(base.isNull() == extent.isNull());
+ ASSERT(base.isNull() == start.isNull());
+ ASSERT(base.isNull() == end.isNull());
+ ASSERT(start.isNull() || start.compareTo(end) <= 0);
+}
+
+template <typename Strategy>
VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const VisibleSelectionTemplate<Strategy>& other)
: m_base(other.m_base)
, m_extent(other.m_extent)
@@ -139,6 +163,12 @@
m_baseIsFirst = other.m_baseIsFirst;
m_isDirectional = other.m_isDirectional;
return *this;
+}
+
+template <typename Strategy>
+VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::createWithoutValidation(const PositionTemplate<Strategy>& base, const PositionTemplate<Strategy>& extent, const PositionTemplate<Strategy>& start, const PositionTemplate<Strategy>& end, TextAffinity affinity, bool isDirectional)
+{
+ return VisibleSelectionTemplate<Strategy>(base, extent, start, end, affinity, isDirectional);
}
#if !ENABLE(OILPAN)
@@ -713,58 +743,46 @@
return Position();
}
-// TODO(yosin): We should move
-// |SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries()| to
-// "SelectionAdjuster.cpp"
-void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSelection* selection)
+static VisibleSelection computeSelectionToAvoidCrossingShadowBoundaries(const VisibleSelection& selection)
{
// Note: |m_selectionType| isn't computed yet.
- ASSERT(selection->base().isNotNull());
- ASSERT(selection->extent().isNotNull());
- ASSERT(selection->start().isNotNull());
- ASSERT(selection->end().isNotNull());
+ ASSERT(selection.base().isNotNull());
+ ASSERT(selection.extent().isNotNull());
+ ASSERT(selection.start().isNotNull());
+ ASSERT(selection.end().isNotNull());
// TODO(hajimehoshi): Checking treeScope is wrong when a node is
// distributed, but we leave it as it is for backward compatibility.
- if (selection->start().anchorNode()->treeScope() == selection->end().anchorNode()->treeScope())
- return;
-
- if (selection->isBaseFirst()) {
- const Position& newEnd = adjustPositionForEnd(selection->end(), selection->start().computeContainerNode());
- selection->m_extent = newEnd;
- selection->m_end = newEnd;
- return;
- }
-
- const Position& newStart = adjustPositionForStart(selection->start(), selection->end().computeContainerNode());
- selection->m_extent = newStart;
- selection->m_start = newStart;
-}
-
-// TODO(yosin): We should move
-// |SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries()| to
-// "SelectionAdjuster.cpp"
+ if (selection.start().anchorNode()->treeScope() == selection.end().anchorNode()->treeScope())
+ return selection;
+
+ if (selection.isBaseFirst()) {
+ const Position newEnd = adjustPositionForEnd(selection.end(), selection.start().computeContainerNode());
+ return VisibleSelection::createWithoutValidation(selection.base(), newEnd, selection.start(), newEnd, selection.affinity(), selection.isDirectional());
+ }
+
+ const Position newStart = adjustPositionForStart(selection.start(), selection.end().computeContainerNode());
+ return VisibleSelection::createWithoutValidation(selection.base(), newStart, newStart, selection.end(), selection.affinity(), selection.isDirectional());
+}
+
// This function is called twice. The first is called when |m_start| and |m_end|
// or |m_extent| are same, and the second when |m_start| and |m_end| are changed
// after downstream/upstream.
-void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSelectionInComposedTree* selection)
-{
- Node* const shadowHostStart = enclosingShadowHostForStart(selection->start());
- Node* const shadowHostEnd = enclosingShadowHostForEnd(selection->end());
+static VisibleSelectionInComposedTree computeSelectionToAvoidCrossingShadowBoundaries(const VisibleSelectionInComposedTree& selection)
+{
+ Node* shadowHostStart = enclosingShadowHostForStart(selection.start());
+ Node* shadowHostEnd = enclosingShadowHostForEnd(selection.end());
if (shadowHostStart == shadowHostEnd)
- return;
-
- if (selection->isBaseFirst()) {
- Node* const shadowHost = shadowHostStart ? shadowHostStart : shadowHostEnd;
- const PositionInComposedTree& newEnd = adjustPositionInComposedTreeForEnd(selection->end(), shadowHost);
- selection->m_extent = newEnd;
- selection->m_end = newEnd;
- return;
- }
- Node* const shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart;
- const PositionInComposedTree& newStart = adjustPositionInComposedTreeForStart(selection->start(), shadowHost);
- selection->m_extent = newStart;
- selection->m_start = newStart;
+ return selection;
+
+ if (selection.isBaseFirst()) {
+ Node* shadowHost = shadowHostStart ? shadowHostStart : shadowHostEnd;
+ const PositionInComposedTree newEnd = adjustPositionInComposedTreeForEnd(selection.end(), shadowHost);
+ return VisibleSelectionInComposedTree::createWithoutValidation(selection.base(), newEnd, selection.start(), newEnd, selection.affinity(), selection.isDirectional());
+ }
+ Node* shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart;
+ const PositionInComposedTree newStart = adjustPositionInComposedTreeForStart(selection.start(), shadowHost);
+ return VisibleSelectionInComposedTree::createWithoutValidation(selection.base(), newStart, newStart, selection.end(), selection.affinity(), selection.isDirectional());
}
template <typename Strategy>
@@ -772,7 +790,7 @@
{
if (m_base.isNull() || m_start.isNull() || m_base.isNull())
return;
- SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries(this);
+ *this = computeSelectionToAvoidCrossingShadowBoundaries(*this);
}
static Element* lowestEditableAncestor(Node* node)
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisibleSelection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698