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

Unified Diff: third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp

Issue 2772203002: Move EditingUtilities::isNodeVisiblyContainedWithin() to CompositeEditCommand (Closed)
Patch Set: Created 3 years, 9 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/commands/CompositeEditCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
index 012a9693251f32f8d429ad6c62433ff70c5ff4e7..1f73b2ff4b369aa83f5c50b385b7f68acd2dfa26 100644
--- a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp
@@ -1960,6 +1960,37 @@ void CompositeEditCommand::setParent(CompositeEditCommand* parent) {
m_endingSelection = parent->m_endingSelection;
}
+// Determines whether a node is inside a range or visibly starts and ends at the
+// boundaries of the range. Call this function to determine whether a node is
+// visibly fit inside selectedRange
+bool CompositeEditCommand::isNodeVisiblyContainedWithin(
+ Node& node,
+ const Range& selectedRange) {
+ DCHECK(!needsLayoutTreeUpdate(node));
+ DocumentLifecycle::DisallowTransitionScope disallowTransition(
+ node.document().lifecycle());
+
+ if (selectedRange.isNodeFullyContained(node))
+ return true;
+
+ bool startIsVisuallySame =
+ visiblePositionBeforeNode(node).deepEquivalent() ==
+ createVisiblePosition(selectedRange.startPosition()).deepEquivalent();
+ if (startIsVisuallySame && comparePositions(Position::inParentAfterNode(node),
+ selectedRange.endPosition()) < 0)
+ return true;
+
+ bool endIsVisuallySame =
+ visiblePositionAfterNode(node).deepEquivalent() ==
+ createVisiblePosition(selectedRange.endPosition()).deepEquivalent();
+ if (endIsVisuallySame &&
+ comparePositions(selectedRange.startPosition(),
+ Position::inParentBeforeNode(node)) < 0)
+ return true;
+
+ return startIsVisuallySame && endIsVisuallySame;
+}
+
DEFINE_TRACE(CompositeEditCommand) {
visitor->trace(m_commands);
visitor->trace(m_startingSelection);

Powered by Google App Engine
This is Rietveld 408576698