Commit 85e38294 authored by Anupam Snigdha's avatar Anupam Snigdha Committed by Commit Bot

Added enclosing block restriction while querying for "special ancestor" in

HighestAncestorToWrapMarkup

This patch adds a restriction in HighestAncestorToWrapMarkup to check for the
presentational elements in the ancestory of start and end position's common
ancestor till the enclosing block so it doesn't cross the block boundary.
This helps in creating the right markup during serialization when we have an
ill-formed HTML like <b><p></p></b> which should be serialized as
<p><b><b></p>.

Test: run_web_tests web_tests/editing/deleting/merge_paragraph_with_presentation_elements.html
BUG: 856413
Change-Id: I5fd03d837e61dea4c66a2ac376b612ac8711dea1
Reviewed-on: https://chromium-review.googlesource.com/c/1482117
Commit-Queue: Anupam Snigdha <snianu@microsoft.com>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635411}
parent a35325fe
......@@ -217,6 +217,13 @@ static HTMLElement* HighestAncestorToWrapMarkup(
Node* check_ancestor =
special_common_ancestor ? special_common_ancestor : common_ancestor;
if (check_ancestor->GetLayoutObject()) {
// We want to constrain the ancestor to the enclosing block.
// Ex: <b><p></p></b> is an ill-formed html and we don't want to return <b>
// as the ancestor because paragraph element is the enclosing block of the
// start and end positions provided to this API.
constraining_ancestor = constraining_ancestor
? constraining_ancestor
: EnclosingBlock(check_ancestor);
HTMLElement* new_special_common_ancestor =
ToHTMLElement(HighestEnclosingNodeOfType(
Position::FirstPositionInNode(*check_ancestor),
......
<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
selection_test(
[
'<div contenteditable>',
'<b><p>foo^</p><p>|bar</p></b></div>',
'</div>',
],
'delete',
[
'<div contenteditable>',
'<b><p>foo|',
'bar',
'</p></b>',
'</div>',
],
'Merge multiple paragraphs with enclosing bold element');
selection_test(
[
'<div contenteditable>',
'<i><p>foo^</p><p>|bar</p></i></div>',
'</div>',
],
'delete',
[
'<div contenteditable>',
'<i><p>foo|',
'bar',
'</p></i>',
'</div>',
],
'Merge multiple paragraphs with enclosing italics element');
selection_test(
[
'<div contenteditable>',
'<u><p>foo^</p><p>|bar</p></u></div>',
'</div>',
],
'delete',
[
'<div contenteditable>',
'<u><p>foo|',
'bar',
'</p></u>',
'</div>',
],
'Merge multiple paragraphs with enclosing underline element');
selection_test(
[
'<div contenteditable>',
'<b><i><p>foo^</p><p>|bar</p></i></b></div>',
'</div>',
],
'delete',
[
'<div contenteditable>',
'<b><i><p>foo|',
'bar',
'</p></i></b>',
'</div>',
],
'Merge multiple paragraphs with multiple enclosing presentational element');
</script>
\ No newline at end of file
......@@ -13,11 +13,11 @@
[
'<div contenteditable>',
'b|<b></b>',
'<b><div style="display: inline !important;">ar</div></b>',
'<span style="font-weight: bold;">ar</span>',
'<b><div>baz</div></b>',
'</div>',
].join('')),
'Merge multiple blocks with display:inline');
'Merge multiple blocks with bold format');
test(() => assert_selection(
[
......
......@@ -4,11 +4,11 @@ PASS confirmedMarkup is 'Hello'
PASS confirmedMarkup is '<b><i>Hello</i></b>'
PASS confirmedMarkup is '<b><i>Hello</i></b>'
PASS confirmedMarkup is 'Hello'
PASS confirmedMarkup is '<b><i>Hello</i></b>'
PASS confirmedMarkup is '<i style="font-weight: 700;">Hello</i>'
PASS confirmedMarkup is '<div style="text-align: center;"><b>Hello</b></div>'
PASS confirmedMarkup is '<div><b><i>hello</i></b></div><div><b><i>world</i></b></div>'
PASS confirmedMarkup is '<b><i><span style="font-weight: normal;"><b><i>hello1</i></b><b><i>&nbsp;hello2</i></b></span></i></b>'
FAIL confirmedMarkup should be <i style="margin: 10px;">hello</i></b></i>. Was <i style="margin: 10px;"><b><i style="margin: 10px;">hello</i></b></i>.
PASS confirmedMarkup is '<i style="margin: 10px;"><b><i style="margin: 10px;">hello</i></b></i>'
PASS confirmedMarkup is '<b><i>Hello&nbsp;world</i></b>'
PASS confirmedMarkup is '<b><i><span style="font-weight: normal;">plain text<b><i>bold italic text</i></b></span></i></b>'
PASS successfullyParsed is true
......
......@@ -38,13 +38,13 @@ testPaste("div", "Hello", "Hello");
testPaste("div", "<b><i>Hello</i></b>", "<b><i>Hello</i></b>");
testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>Hello</i></b></span></i></b></div>", "<b><i>Hello</i></b>");
testPaste("div", "<div><div><div>Hello</div></div></div>", "Hello");
testPaste("div", "<div><b><div><i>Hello</i></div></b></div>", "<b><i>Hello</i></b>");
testPaste("div", "<div><b><div><i>Hello</i></div></b></div>", "<i style=\"font-weight: 700;\">Hello</i>");
testPaste("div", "<div><div style=\"text-align: center;\"><b>Hello</b></div></div>", "<div style=\"text-align: center;\"><b>Hello</b></div>");
testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>hello</i></b></span></i></b></div><div><b><i><span style=\"font-weight: normal\"><b><i>world</i></b></span></i></b></div>",
"<div><b><i>hello</i></b></div><div><b><i>world</i></b></div>");
testPaste("div", "<div><b><i><span style=\"font-weight: normal;\"><b><i>hello1</i></b><b><i> hello2</i></b></span></i></b></div>", "<b><i><span style=\"font-weight: normal;\"><b><i>hello1</i></b><b><i>&nbsp;hello2</i></b></span></i></b>");
testPaste("div", "<i style=\"margin: 10px;\"><b><i style=\"margin: 10px;\">hello</i></b></i>",
"<i style=\"margin: 10px;\">hello</i></b></i>");
"<i style=\"margin: 10px;\"><b><i style=\"margin: 10px;\">hello</i></b></i>");
testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>Hello <!-- comment -->world</i></b></span></i></b></div>", "<b><i>Hello&nbsp;world</i></b>");
testPaste("div", "<div><b><i><span style=\"font-weight: normal\">plain text<b><i>bold italic text</i></b></span></i></b></div>", "<b><i><span style=\"font-weight: normal;\">plain text<b><i>bold italic text</i></b></span></i></b>");
......
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