Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Cocoa] Merge WebEditCommandProxy::nameForEditAction and undoNameForE…
…ditAction into a single function

https://bugs.webkit.org/show_bug.cgi?id=193129

Reviewed by Tim Horton.

Source/WebCore:

Adds a new helper function that returns the undo/redo name for a given EditAction. No change in behavior.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* editing/EditAction.cpp: Copied from Source/WebKit/UIProcess/WebEditCommandProxy.cpp.
(WebCore::nameForUndoRedo):
* editing/EditAction.h:
* editing/Editor.cpp:

Source/WebKit:

Remove WebEditCommandProxy::nameForEditAction and use WebCore::nameForUndoRedo instead.

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::registerEditCommand):
* UIProcess/WebEditCommandProxy.cpp:
(WebKit::WebEditCommandProxy::WebEditCommandProxy):
(WebKit::WebEditCommandProxy::~WebEditCommandProxy):
(WebKit::WebEditCommandProxy::nameForEditAction): Deleted.
* UIProcess/WebEditCommandProxy.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::addEditCommand):
(WebKit::WebPageProxy::removeEditCommand):
(WebKit::WebPageProxy::isValidEditCommand): Deleted.

Bit of drive-by refactoring: remove an unused function, and make addEditCommand and removeEditCommand take
references instead of pointers, since these are assumed to be nonnull.

* UIProcess/WebPageProxy.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::registerEditCommand):

Source/WebKitLegacy/mac:

Remove undoNameForEditAction and use WebCore::nameForUndoRedo instead.

* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::registerUndoOrRedoStep):
(undoNameForEditAction): Deleted.


Canonical link: https://commits.webkit.org/207655@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239627 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed Jan 4, 2019
1 parent d3b8e12 commit 648cc70
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 206 deletions.
16 changes: 16 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,19 @@
2019-01-04 Wenson Hsieh <wenson_hsieh@apple.com>

[Cocoa] Merge WebEditCommandProxy::nameForEditAction and undoNameForEditAction into a single function
https://bugs.webkit.org/show_bug.cgi?id=193129

Reviewed by Tim Horton.

Adds a new helper function that returns the undo/redo name for a given EditAction. No change in behavior.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* editing/EditAction.cpp: Copied from Source/WebKit/UIProcess/WebEditCommandProxy.cpp.
(WebCore::nameForUndoRedo):
* editing/EditAction.h:
* editing/Editor.cpp:

2019-01-03 Matt Rajca <mrajca@apple.com>

Make DidPlayMediaPreventedFromPlaying autoplay event more generic.
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Sources.txt
Expand Up @@ -913,6 +913,7 @@ editing/DeleteFromTextNodeCommand.cpp
editing/DeleteSelectionCommand.cpp
editing/DictationAlternative.cpp
editing/DictationCommand.cpp
editing/EditAction.cpp
editing/EditCommand.cpp
editing/Editing.cpp
editing/EditingStyle.cpp
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Expand Up @@ -14935,6 +14935,7 @@
F48D2AA32159740D00C6752B /* ColorCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorCocoa.h; sourceTree = "<group>"; };
F48D2AA42159740D00C6752B /* ColorCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ColorCocoa.mm; sourceTree = "<group>"; };
F49786871FF45FA500E060AB /* PasteboardItemInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PasteboardItemInfo.h; sourceTree = "<group>"; };
F49E98E421DEE6C1009AE55E /* EditAction.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = EditAction.cpp; sourceTree = "<group>"; };
F4D43D64218802E600ECECAC /* SerializedAttachmentData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SerializedAttachmentData.h; sourceTree = "<group>"; };
F4D9817D2195FBF6008230FC /* ChangeListTypeCommand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ChangeListTypeCommand.h; sourceTree = "<group>"; };
F4D9817E2195FBF6008230FC /* ChangeListTypeCommand.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ChangeListTypeCommand.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -20780,6 +20781,7 @@
CECADFC4153778FF00E37068 /* DictationCommand.cpp */,
CECADFC5153778FF00E37068 /* DictationCommand.h */,
2D5646AF1B8F8493003C4994 /* DictionaryPopupInfo.h */,
F49E98E421DEE6C1009AE55E /* EditAction.cpp */,
93309D93099E64910056E581 /* EditAction.h */,
93309D94099E64910056E581 /* EditCommand.cpp */,
93309D95099E64910056E581 /* EditCommand.h */,
Expand Down
147 changes: 147 additions & 0 deletions Source/WebCore/editing/EditAction.cpp
@@ -0,0 +1,147 @@
/*
* Copyright (C) 2019 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.
*/

#include "config.h"
#include "EditAction.h"

#include "LocalizedStrings.h"

namespace WebCore {

String nameForUndoRedo(EditAction editAction)
{
switch (editAction) {
case EditAction::Unspecified:
case EditAction::Insert:
case EditAction::InsertReplacement:
case EditAction::InsertFromDrop:
return { };
case EditAction::SetColor:
return WEB_UI_STRING_KEY("Set Color", "Set Color (Undo action name)", "Undo action name");
case EditAction::SetBackgroundColor:
return WEB_UI_STRING_KEY("Set Background Color", "Set Background Color (Undo action name)", "Undo action name");
case EditAction::TurnOffKerning:
return WEB_UI_STRING_KEY("Turn Off Kerning", "Turn Off Kerning (Undo action name)", "Undo action name");
case EditAction::TightenKerning:
return WEB_UI_STRING_KEY("Tighten Kerning", "Tighten Kerning (Undo action name)", "Undo action name");
case EditAction::LoosenKerning:
return WEB_UI_STRING_KEY("Loosen Kerning", "Loosen Kerning (Undo action name)", "Undo action name");
case EditAction::UseStandardKerning:
return WEB_UI_STRING_KEY("Use Standard Kerning", "Use Standard Kerning (Undo action name)", "Undo action name");
case EditAction::TurnOffLigatures:
return WEB_UI_STRING_KEY("Turn Off Ligatures", "Turn Off Ligatures (Undo action name)", "Undo action name");
case EditAction::UseStandardLigatures:
return WEB_UI_STRING_KEY("Use Standard Ligatures", "Use Standard Ligatures (Undo action name)", "Undo action name");
case EditAction::UseAllLigatures:
return WEB_UI_STRING_KEY("Use All Ligatures", "Use All Ligatures (Undo action name)", "Undo action name");
case EditAction::RaiseBaseline:
return WEB_UI_STRING_KEY("Raise Baseline", "Raise Baseline (Undo action name)", "Undo action name");
case EditAction::LowerBaseline:
return WEB_UI_STRING_KEY("Lower Baseline", "Lower Baseline (Undo action name)", "Undo action name");
case EditAction::SetTraditionalCharacterShape:
return WEB_UI_STRING_KEY("Set Traditional Character Shape", "Set Traditional Character Shape (Undo action name)", "Undo action name");
case EditAction::SetFont:
return WEB_UI_STRING_KEY("Set Font", "Set Font (Undo action name)", "Undo action name");
case EditAction::ChangeAttributes:
return WEB_UI_STRING_KEY("Change Attributes", "Change Attributes (Undo action name)", "Undo action name");
case EditAction::AlignLeft:
return WEB_UI_STRING_KEY("Align Left", "Align Left (Undo action name)", "Undo action name");
case EditAction::AlignRight:
return WEB_UI_STRING_KEY("Align Right", "Align Right (Undo action name)", "Undo action name");
case EditAction::Center:
return WEB_UI_STRING_KEY("Center", "Center (Undo action name)", "Undo action name");
case EditAction::Justify:
return WEB_UI_STRING_KEY("Justify", "Justify (Undo action name)", "Undo action name");
case EditAction::SetWritingDirection:
return WEB_UI_STRING_KEY("Set Writing Direction", "Set Writing Direction (Undo action name)", "Undo action name");
case EditAction::Subscript:
return WEB_UI_STRING_KEY("Subscript", "Subscript (Undo action name)", "Undo action name");
case EditAction::Superscript:
return WEB_UI_STRING_KEY("Superscript", "Superscript (Undo action name)", "Undo action name");
case EditAction::Underline:
return WEB_UI_STRING_KEY("Underline", "Underline (Undo action name)", "Undo action name");
case EditAction::Outline:
return WEB_UI_STRING_KEY("Outline", "Outline (Undo action name)", "Undo action name");
case EditAction::Unscript:
return WEB_UI_STRING_KEY("Unscript", "Unscript (Undo action name)", "Undo action name");
case EditAction::DeleteByDrag:
return WEB_UI_STRING_KEY("Drag", "Drag (Undo action name)", "Undo action name");
case EditAction::Cut:
return WEB_UI_STRING_KEY("Cut", "Cut (Undo action name)", "Undo action name");
case EditAction::Bold:
return WEB_UI_STRING_KEY("Bold", "Bold (Undo action name)", "Undo action name");
case EditAction::Italics:
return WEB_UI_STRING_KEY("Italics", "Italics (Undo action name)", "Undo action name");
case EditAction::Delete:
return WEB_UI_STRING_KEY("Delete", "Delete (Undo action name)", "Undo action name");
case EditAction::Dictation:
return WEB_UI_STRING_KEY("Dictation", "Dictation (Undo action name)", "Undo action name");
case EditAction::Paste:
return WEB_UI_STRING_KEY("Paste", "Paste (Undo action name)", "Undo action name");
case EditAction::PasteFont:
return WEB_UI_STRING_KEY("Paste Font", "Paste Font (Undo action name)", "Undo action name");
case EditAction::PasteRuler:
return WEB_UI_STRING_KEY("Paste Ruler", "Paste Ruler (Undo action name)", "Undo action name");
case EditAction::TypingDeleteSelection:
case EditAction::TypingDeleteBackward:
case EditAction::TypingDeleteForward:
case EditAction::TypingDeleteWordBackward:
case EditAction::TypingDeleteWordForward:
case EditAction::TypingDeleteLineBackward:
case EditAction::TypingDeleteLineForward:
case EditAction::TypingDeletePendingComposition:
case EditAction::TypingDeleteFinalComposition:
case EditAction::TypingInsertText:
case EditAction::TypingInsertLineBreak:
case EditAction::TypingInsertParagraph:
case EditAction::TypingInsertPendingComposition:
case EditAction::TypingInsertFinalComposition:
return WEB_UI_STRING_KEY("Typing", "Typing (Undo action name)", "Undo action name");
case EditAction::CreateLink:
return WEB_UI_STRING_KEY("Create Link", "Create Link (Undo action name)", "Undo action name");
case EditAction::Unlink:
return WEB_UI_STRING_KEY("Unlink", "Unlink (Undo action name)", "Undo action name");
case EditAction::InsertUnorderedList:
case EditAction::InsertOrderedList:
return WEB_UI_STRING_KEY("Insert List", "Insert List (Undo action name)", "Undo action name");
case EditAction::FormatBlock:
return WEB_UI_STRING_KEY("Formatting", "Format Block (Undo action name)", "Undo action name");
case EditAction::Indent:
return WEB_UI_STRING_KEY("Indent", "Indent (Undo action name)", "Undo action name");
case EditAction::Outdent:
return WEB_UI_STRING_KEY("Outdent", "Outdent (Undo action name)", "Undo action name");
// FIXME: We should give internal clients a way to override these undo names. For instance, Mail refers to ordered and unordered lists as "numbered" and "bulleted" lists, respectively,
// despite the fact that ordered and unordered lists are not necessarily displayed using bullets and numerals.
case EditAction::ConvertToOrderedList:
return WEB_UI_STRING_KEY("Convert to Ordered List", "Convert to Ordered List (Undo action name)", "Undo action name");
case EditAction::ConvertToUnorderedList:
return WEB_UI_STRING_KEY("Convert to Unordered List", "Convert to Unordered List (Undo action name)", "Undo action name");
case EditAction::InsertEditableImage:
return WEB_UI_STRING_KEY("Insert Drawing", "Insert Drawing (Undo action name)", "Undo action name");
}
return { };
}

} // namespace WebCore
6 changes: 6 additions & 0 deletions Source/WebCore/editing/EditAction.h
Expand Up @@ -25,6 +25,10 @@

#pragma once

namespace WTF {
class String;
}

namespace WebCore {

enum class EditAction : uint8_t {
Expand Down Expand Up @@ -91,4 +95,6 @@ enum class EditAction : uint8_t {
InsertEditableImage
};

WEBCORE_EXPORT WTF::String nameForUndoRedo(EditAction);

} // namespace WebCore
4 changes: 4 additions & 0 deletions Source/WebCore/editing/Editor.cpp
Expand Up @@ -32,6 +32,8 @@
#include "ApplyStyleCommand.h"
#include "CSSComputedStyleDeclaration.h"
#include "CSSPropertyNames.h"
#include "CSSValueList.h"
#include "CSSValuePool.h"
#include "CachedResourceLoader.h"
#include "ChangeListTypeCommand.h"
#include "ClipboardEvent.h"
Expand Down Expand Up @@ -63,8 +65,10 @@
#include "HTMLImageElement.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "HTMLOListElement.h"
#include "HTMLQuoteElement.h"
#include "HTMLSpanElement.h"
#include "HTMLUListElement.h"
#include "HitTestResult.h"
#include "IndentOutdentCommand.h"
#include "InputEvent.h"
Expand Down
28 changes: 28 additions & 0 deletions Source/WebKit/ChangeLog
@@ -1,3 +1,31 @@
2019-01-04 Wenson Hsieh <wenson_hsieh@apple.com>

[Cocoa] Merge WebEditCommandProxy::nameForEditAction and undoNameForEditAction into a single function
https://bugs.webkit.org/show_bug.cgi?id=193129

Reviewed by Tim Horton.

Remove WebEditCommandProxy::nameForEditAction and use WebCore::nameForUndoRedo instead.

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::registerEditCommand):
* UIProcess/WebEditCommandProxy.cpp:
(WebKit::WebEditCommandProxy::WebEditCommandProxy):
(WebKit::WebEditCommandProxy::~WebEditCommandProxy):
(WebKit::WebEditCommandProxy::nameForEditAction): Deleted.
* UIProcess/WebEditCommandProxy.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::addEditCommand):
(WebKit::WebPageProxy::removeEditCommand):
(WebKit::WebPageProxy::isValidEditCommand): Deleted.

Bit of drive-by refactoring: remove an unused function, and make addEditCommand and removeEditCommand take
references instead of pointers, since these are assumed to be nonnull.

* UIProcess/WebPageProxy.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::registerEditCommand):

2019-01-03 Matt Rajca <mrajca@apple.com>

Make DidPlayMediaPreventedFromPlaying autoplay event more generic.
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Expand Up @@ -2677,7 +2677,7 @@ static String commandNameForSelector(SEL selector)

void WebViewImpl::registerEditCommand(Ref<WebEditCommandProxy>&& command, UndoOrRedo undoOrRedo)
{
auto actionName = WebEditCommandProxy::nameForEditAction(command->editAction());
auto actionName = WebCore::nameForUndoRedo(command->editAction());
auto commandObjC = adoptNS([[WKEditCommand alloc] initWithWebEditCommandProxy:WTFMove(command)]);

NSUndoManager *undoManager = [m_view undoManager];
Expand Down

0 comments on commit 648cc70

Please sign in to comment.