haikuwebkit/Source/WebCore/editing/InsertNestedListCommand.h

67 lines
2.3 KiB
C
Raw Permalink Normal View History

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. Canonical link: https://commits.webkit.org/206198@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237976 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-11-08 03:14:37 +00:00
/*
* Copyright (C) 2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "CompositeEditCommand.h"
#include "EditAction.h"
namespace WebCore {
class InsertNestedListCommand final : public CompositeEditCommand {
public:
static void insertUnorderedList(Document&);
static void insertOrderedList(Document&);
private:
enum class Type : uint8_t { OrderedList, UnorderedList };
static Ref<InsertNestedListCommand> create(Document& document, Type type)
{
return adoptRef(*new InsertNestedListCommand(document, type));
}
InsertNestedListCommand(Document& document, Type type)
: CompositeEditCommand(document)
, m_type(type)
{
}
EditAction editingAction() const final
{
if (m_type == Type::OrderedList)
return EditAction::InsertOrderedList;
return EditAction::InsertUnorderedList;
}
bool preservesTypingStyle() const final { return true; }
void doApply() final;
Type m_type;
};
} // namespace WebCore