Commit a4e8fc5a authored by xiaochengh's avatar xiaochengh Committed by Commit bot

Use RelocatablePosition in CompositeEditCommand::MoveParagraphWithClones

Clusterfuzz found a sample where
CompositeEditCommand::MoveParagraphWithClones() moves |before_paragraph|
out of the DOM tree after moving the paragraph. This patch uses
RelocatablePosition to track |before_paragraph| and |after_paragraph| so
that the positions we track are always connected.

Note: CompositeEditCommand::MoveParagraphs() is already using
RelocatablePosition to track positions before and after the moved
paragraphs.

BUG=712510
TEST=ApplyBlockElementCommandTest.IndentHeadingIntoBlockquote

Review-Url: https://codereview.chromium.org/2850773003
Cr-Commit-Position: refs/heads/master@{#468278}
parent e15ff1b5
......@@ -78,4 +78,35 @@ TEST_F(ApplyBlockElementCommandTest, visibilityChangeDuringCommand) {
GetDocument().documentElement()->innerHTML());
}
// This is a regression test for https://crbug.com/712510
TEST_F(ApplyBlockElementCommandTest, IndentHeadingIntoBlockquote) {
SetBodyContent(
"<div contenteditable=\"true\">"
"<h6><button><table></table></button></h6>"
"<object></object>"
"</div>");
Element* button = GetDocument().QuerySelector("button");
Element* object = GetDocument().QuerySelector("object");
Selection().SetSelection(SelectionInDOMTree::Builder()
.Collapse(Position(button, 0))
.Extend(Position(object, 0))
.Build());
IndentOutdentCommand* command = IndentOutdentCommand::Create(
GetDocument(), IndentOutdentCommand::kIndent);
command->Apply();
// This only records the current behavior, which can be wrong.
EXPECT_EQ(
"<div contenteditable=\"true\">"
"<blockquote style=\"margin: 0 0 0 40px; border: none; padding: 0px;\">"
"<h6><button></button></h6>"
"<h6><button><table></table></button></h6>"
"</blockquote>"
"<h6><button></button></h6><br>"
"<object></object>"
"</div>",
GetDocument().body()->innerHTML());
}
} // namespace blink
......@@ -1266,9 +1266,10 @@ void CompositeEditCommand::MoveParagraphWithClones(
DCHECK(outer_node);
DCHECK(block_element);
VisiblePosition before_paragraph =
PreviousPositionOf(start_of_paragraph_to_move);
VisiblePosition after_paragraph = NextPositionOf(end_of_paragraph_to_move);
RelocatablePosition relocatable_before_paragraph(
PreviousPositionOf(start_of_paragraph_to_move).DeepEquivalent());
RelocatablePosition relocatable_after_paragraph(
NextPositionOf(end_of_paragraph_to_move).DeepEquivalent());
// We upstream() the end and downstream() the start so that we don't include
// collapsed whitespace in the move. When we paste a fragment, spaces after
......@@ -1311,14 +1312,10 @@ void CompositeEditCommand::MoveParagraphWithClones(
// would cause 'baz' to collapse onto the line with 'foobar' unless we insert
// a br. Must recononicalize these two VisiblePositions after the pruning
// above.
// TODO(yosin): We should abort when |beforeParagraph| is a orphan when
// we have a sample.
before_paragraph = CreateVisiblePosition(before_paragraph.DeepEquivalent());
if (after_paragraph.IsOrphan()) {
editing_state->Abort();
return;
}
after_paragraph = CreateVisiblePosition(after_paragraph.DeepEquivalent());
const VisiblePosition& before_paragraph =
CreateVisiblePosition(relocatable_before_paragraph.GetPosition());
const VisiblePosition& after_paragraph =
CreateVisiblePosition(relocatable_after_paragraph.GetPosition());
if (before_paragraph.IsNotNull() &&
!IsDisplayInsideTable(before_paragraph.DeepEquivalent().AnchorNode()) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment