Add an editing command for creating and inserting child lists
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Nov 2018 03:14:37 +0000 (03:14 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Nov 2018 03:14:37 +0000 (03:14 +0000)
commit9924ed1df97b7833dfba5ba81a8e35ec832508cd
tree62d62f22a4cc61e2a196615052058867bdce0c7b
parent7a603f07e5b50a44402aeed2a8b83c3e1ce18623
Add an editing command for creating and inserting child lists
https://bugs.webkit.org/show_bug.cgi?id=191335
<rdar://problem/45814050>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Currently, insertOrderedList and insertUnorderedList only toggle or change list state (i.e. if the selection is
in an ordered or unordered list, reinserting the same list type removes the current list, and inserting a
different list type changes the enclosing list).

However, for certain internal clients (e.g. Mail), if the start of the selection is enclosed by a list item, we
instead create a new list item and insert it after the enclosing list item, and then create a new list within
that list item. Currently, this logic is implemented in Mail for legacy-WebKit-based Mail compose. This patch
brings this logic into WebKit in the form of a new editing command.

Tests: editing/execCommand/insert-nested-lists-in-table.html
       editing/execCommand/insert-nested-lists-with-pre.html
       editing/execCommand/insert-nested-lists.html

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* editing/Editor.cpp:
(WebCore::Editor::insertOrderedList):
(WebCore::Editor::insertUnorderedList):
* editing/EditorCommand.cpp:
(WebCore::executeInsertOrderedList):
(WebCore::executeInsertUnorderedList):
(WebCore::executeInsertNestedUnorderedList):
(WebCore::executeInsertNestedOrderedList):
(WebCore::createCommandMap):
* editing/IndentOutdentCommand.cpp:
(WebCore::IndentOutdentCommand::outdentParagraph):
* editing/InsertListCommand.cpp:
(WebCore::InsertListCommand::doApply):
(WebCore::InsertListCommand::editingAction const):
* editing/InsertListCommand.h:

Change a couple of `enum`s into `enum class`es.

* editing/InsertNestedListCommand.cpp: Added.
(WebCore::InsertNestedListCommand::insertUnorderedList):
(WebCore::InsertNestedListCommand::insertOrderedList):
(WebCore::InsertNestedListCommand::doApply):
* editing/InsertNestedListCommand.h: Added.

Add a new edit command to insert a new list (as a child of any containing list). If the start of the selection
is in a list item, we create a new list item, move the selection into the list item, and increment its list
level; otherwise, simply fall back to inserting a list.

* editing/ModifySelectionListLevel.cpp:
(WebCore::IncreaseSelectionListLevelCommand::doApply):
(WebCore::IncreaseSelectionListLevelCommand::increaseSelectionListLevel):
(WebCore::IncreaseSelectionListLevelCommand::increaseSelectionListLevelOrdered):
(WebCore::IncreaseSelectionListLevelCommand::increaseSelectionListLevelUnordered):
* editing/ModifySelectionListLevel.h:

Expose this constructor, allowing other edit commands to change selection list level as a composite edit
command. Also, change an `enum` into an `enum class`.

(WebCore::IncreaseSelectionListLevelCommand::create):

LayoutTests:

Add a new layout tests that exercise the "InsertNested(Un)orderedList" editing commands in several scenarios
including undo, redo, executing the edit command with a ranged selection, outdenting to decrease list level,
inserting lists in and around tables and table cells, and inserting lists in and around pre elements.

* editing/execCommand/insert-nested-lists-expected.txt: Added.
* editing/execCommand/insert-nested-lists-in-table-expected.txt: Added.
* editing/execCommand/insert-nested-lists-in-table.html: Added.
* editing/execCommand/insert-nested-lists-with-pre-expected.txt: Added.
* editing/execCommand/insert-nested-lists-with-pre.html: Added.
* editing/execCommand/insert-nested-lists.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237976 268f45cc-cd09-0410-ab3c-d52691b4dbfc
19 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/execCommand/insert-nested-lists-expected.txt [new file with mode: 0644]
LayoutTests/editing/execCommand/insert-nested-lists-in-table-expected.txt [new file with mode: 0644]
LayoutTests/editing/execCommand/insert-nested-lists-in-table.html [new file with mode: 0644]
LayoutTests/editing/execCommand/insert-nested-lists-with-pre-expected.txt [new file with mode: 0644]
LayoutTests/editing/execCommand/insert-nested-lists-with-pre.html [new file with mode: 0644]
LayoutTests/editing/execCommand/insert-nested-lists.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/EditorCommand.cpp
Source/WebCore/editing/IndentOutdentCommand.cpp
Source/WebCore/editing/InsertListCommand.cpp
Source/WebCore/editing/InsertListCommand.h
Source/WebCore/editing/InsertNestedListCommand.cpp [new file with mode: 0644]
Source/WebCore/editing/InsertNestedListCommand.h [new file with mode: 0644]
Source/WebCore/editing/ModifySelectionListLevel.cpp
Source/WebCore/editing/ModifySelectionListLevel.h