Need a way for JavaScript (or bundle) code to participate in undo
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Jan 2019 17:23:06 +0000 (17:23 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Jan 2019 17:23:06 +0000 (17:23 +0000)
commit58d24c9e91a209f0130f1a8ac746ea97b1045a04
treef402b8e8391f828f4114ce9b4b5cc7b3621832f8
parent084149c3c6be94beec19642da6e7a8876cb5a85f
Need a way for JavaScript (or bundle) code to participate in undo
https://bugs.webkit.org/show_bug.cgi?id=190009
<rdar://problem/44807048>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Finish hooking up `UndoManager::addItems()` to CustomUndoStep.

Tests: editing/undo-manager/undo-manager-add-item-exceptions.html
       editing/undo-manager/undo-manager-add-item.html
       editing/undo-manager/undo-manager-delete-stale-undo-items.html
       editing/undo-manager/undo-manager-item-labels.html
       editing/undo-manager/undo-manager-undo-redo-after-garbage-collection.html

* editing/CompositeEditCommand.h:
* editing/CustomUndoStep.cpp:
(WebCore::CustomUndoStep::didRemoveFromUndoManager):

Add a method to invalidate CustomUndoStep. This clears out the pointer to the undo item, and also invalidates
the UndoItem, removing it from its UndoManager.

* editing/CustomUndoStep.h:
* editing/Editor.cpp:
(WebCore::Editor::registerCustomUndoStep):

Add a helper method to register a CustomUndoStep as a platform undoable step.

* editing/Editor.h:
* editing/UndoStep.h:
* page/UndoItem.h:
(WebCore::UndoItem::undoManager const):
* page/UndoManager.cpp:
(WebCore::UndoManager::addItem):

Create a CustomUndoStep with the given UndoItem, and register it with the platform undo manager.

* page/UndoManager.h:
* page/UndoManager.idl:

Mark addItem() as capable of throwing exceptions.

Source/WebKit:

Invalidate undo steps when removing them from WebPage. Invalidation is a no-op for editing actions that come
from the UA, but for custom undo steps backed by an UndoItem, we clear out the custom undo step's pointer to its
UndoItem and additionally disconnect the UndoItem from its UndoManager.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::addWebUndoStep):
(WebKit::WebPage::removeWebEditCommand):
* WebProcess/WebPage/WebUndoStep.h:
(WebKit::WebUndoStep::invalidate):

Tools:

Add UIScriptController helpers to grab the platform undo and redo action labels. Currently only implemented for
Cocoa platforms in WebKit2. See other ChangeLogs for more detail.

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::lastUndoLabel const):
(WTR::UIScriptController::firstRedoLabel const):
(WTR::UIScriptController::platformUndoManager const):
* DumpRenderTree/mac/UIScriptControllerMac.mm:
(WTR::UIScriptController::lastUndoLabel const):
(WTR::UIScriptController::firstRedoLabel const):
(WTR::UIScriptController::platformUndoManager const):
* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::lastUndoLabel const):
(WTR::UIScriptController::firstRedoLabel const):
* TestRunnerShared/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/UIScriptControllerCocoa.mm:
(WTR::UIScriptController::lastUndoLabel const):
(WTR::UIScriptController::firstRedoLabel const):
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::platformUndoManager const):
* WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptController::platformUndoManager const):

LayoutTests:

Add a few new layout tests covering `UndoManager.addItem()`.

* editing/undo-manager/undo-manager-add-item-exceptions-expected.txt: Added.
* editing/undo-manager/undo-manager-add-item-exceptions.html: Added.

Add a test to verify that we throw exceptions when calling addItem() in a couple of circumstances.

* editing/undo-manager/undo-manager-add-item-expected.txt: Added.
* editing/undo-manager/undo-manager-add-item.html: Added.

Add a test that exercises the new API in both the top-level context and a child frame.

* editing/undo-manager/undo-manager-delete-stale-undo-items-expected.txt: Added.
* editing/undo-manager/undo-manager-delete-stale-undo-items.html: Added.

Add a test to verify that after adding undo items, undoing, and then performing other edit actions, garbage
collection will destroy JS wrappers for the previously added UndoItems, since these undo items' handlers can no
longer be invoked.

* editing/undo-manager/undo-manager-item-labels-expected.txt: Added.
* editing/undo-manager/undo-manager-item-labels.html: Added.

Add a test verifying that the undo and redo action labels are updated correctly when undoing and redoing.

* editing/undo-manager/undo-manager-undo-redo-after-garbage-collection-expected.txt: Added.
* editing/undo-manager/undo-manager-undo-redo-after-garbage-collection.html: Added.

Add a test to verify that triggering garbage collection after adding an undo item without keeping references to
the item (or its undo/redo handlers) doesn't break the API.

* resources/ui-helper.js:
(window.UIHelper.undoAndRedoLabels):

Add a helper method to grab the platform's current undo and redo action names.

(window.UIHelper):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240476 268f45cc-cd09-0410-ab3c-d52691b4dbfc
35 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/undo-manager/undo-manager-add-item-exceptions-expected.txt [new file with mode: 0644]
LayoutTests/editing/undo-manager/undo-manager-add-item-exceptions.html [new file with mode: 0644]
LayoutTests/editing/undo-manager/undo-manager-add-item-expected.txt [new file with mode: 0644]
LayoutTests/editing/undo-manager/undo-manager-add-item.html [new file with mode: 0644]
LayoutTests/editing/undo-manager/undo-manager-delete-stale-undo-items-expected.txt [new file with mode: 0644]
LayoutTests/editing/undo-manager/undo-manager-delete-stale-undo-items.html [new file with mode: 0644]
LayoutTests/editing/undo-manager/undo-manager-item-labels-expected.txt [new file with mode: 0644]
LayoutTests/editing/undo-manager/undo-manager-item-labels.html [new file with mode: 0644]
LayoutTests/editing/undo-manager/undo-manager-undo-redo-after-garbage-collection-expected.txt [new file with mode: 0644]
LayoutTests/editing/undo-manager/undo-manager-undo-redo-after-garbage-collection.html [new file with mode: 0644]
LayoutTests/resources/ui-helper.js
Source/WebCore/ChangeLog
Source/WebCore/editing/CompositeEditCommand.h
Source/WebCore/editing/CustomUndoStep.cpp
Source/WebCore/editing/CustomUndoStep.h
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/editing/UndoStep.h
Source/WebCore/page/UndoItem.h
Source/WebCore/page/UndoManager.cpp
Source/WebCore/page/UndoManager.h
Source/WebCore/page/UndoManager.idl
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebUndoStep.h
Tools/ChangeLog
Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm
Tools/DumpRenderTree/mac/UIScriptControllerMac.mm
Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
Tools/WebKitTestRunner/UIScriptControllerCocoa.mm
Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm
Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm