Commit bf2bf97e authored by Anupam Snigdha's avatar Anupam Snigdha Committed by Commit Bot

Add enclosing block restriction while inserting unordered list in table

This patch adds a restriction in |HighestEnclosingNodeOfType| to
not cross the enclosing block. This is useful so we can get the
"outer" block node without crossing block boundaries as that
function only breaks when the loop hits the editable boundary or the
parent element has an inline style(as we pass |IsInline| to it). This
is useful in cases like <div contenteditable><i><table><tr>
<td>Please |put cursor here</td></tr></table></i></div> where | is
the selection position. When execCommand("insertUnorderedList") is
called the markup ends up as shown below:
<div contenteditable><i><table><tr><td><ul><li>
|Please put cursor here</li></ul></td></tr></table></i></div>.

Test: run_web_tests web_tests/editing/deleting/listify-paragraph-inside-table-cell.html

Bug: 1016530

Change-Id: I51f19b35e69fcf57f2c583e6a521e6460e7cb305
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2433025Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Anupam Snigdha <snianu@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#811103}
parent d0602298
...@@ -702,8 +702,17 @@ void InsertListCommand::MoveParagraphOverPositionIntoEmptyListItem( ...@@ -702,8 +702,17 @@ void InsertListCommand::MoveParagraphOverPositionIntoEmptyListItem(
const VisiblePosition& end = const VisiblePosition& end =
EndOfParagraph(valid_pos, kCanSkipOverEditingBoundary); EndOfParagraph(valid_pos, kCanSkipOverEditingBoundary);
ABORT_EDITING_COMMAND_IF(end.IsNull()); ABORT_EDITING_COMMAND_IF(end.IsNull());
// Get the constraining ancestor so it doesn't cross the enclosing block.
// This is useful to restrict the |HighestEnclosingNodeOfType| function to the
// enclosing block node so we can get the "outer" block node without crossing
// block boundaries as that function only breaks when the loop hits the
// editable boundary or the parent element has an inline style(as we pass
// |IsInline| to it).
Node* const constraining_ancestor =
EnclosingBlock(start.DeepEquivalent().AnchorNode());
Node* const outer_block = HighestEnclosingNodeOfType( Node* const outer_block = HighestEnclosingNodeOfType(
start.DeepEquivalent(), &IsInline, kCannotCrossEditingBoundary, nullptr); start.DeepEquivalent(), &IsInline, kCannotCrossEditingBoundary,
constraining_ancestor);
MoveParagraphWithClones( MoveParagraphWithClones(
start, end, list_item_element, start, end, list_item_element,
outer_block ? outer_block : start.DeepEquivalent().AnchorNode(), outer_block ? outer_block : start.DeepEquivalent().AnchorNode(),
......
<!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>',
'<i><table><tr><td>Please |put cursor here</td>',
'</tr></table></i>',
'</div>',
],
'insertUnorderedList',
[
'<div contenteditable>',
'<i><table><tbody><tr><td><ul><li>|Please put cursor here</li></ul></td>',
'</tr></tbody></table></i>',
'</div>',
],
'Create a list with enclosing italics element');
selection_test(
[
'<div contenteditable>',
'<b><table><tr><td>Please |put cursor here</td>',
'</tr></table></b>',
'</div>',
],
'insertUnorderedList',
[
'<div contenteditable>',
'<b><table><tbody><tr><td><ul><li>|Please put cursor here</li></ul></td>',
'</tr></tbody></table></b>',
'</div>',
],
'Create a list with enclosing bold element');
selection_test(
[
'<div contenteditable>',
'<u><table><tr><td>Please |put cursor here</td>',
'</tr></table></u>',
'</div>',
],
'insertUnorderedList',
[
'<div contenteditable>',
'<u><table><tbody><tr><td><ul><li>|Please put cursor here</li></ul></td>',
'</tr></tbody></table></u>',
'</div>',
],
'Create a list with enclosing underline element');
selection_test(
[
'<div contenteditable>',
'<i><b><table><tr><td>Please |put cursor here</td>',
'</tr></table></b></i>',
'</div>',
],
'insertUnorderedList',
[
'<div contenteditable>',
'<i><b><table><tbody><tr><td><ul><li>|Please put cursor here</li></ul></td>',
'</tr></tbody></table></b></i>',
'</div>',
],
'Create a list with multiple enclosing presentational element');
</script>
\ No newline at end of file
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