haikuwebkit/Source/WebCore/page/UndoManager.h

63 lines
2.1 KiB
C
Raw Permalink Normal View History

Introduce IDL files for runtime-enabled UndoManager and UndoItem JavaScript API https://bugs.webkit.org/show_bug.cgi?id=193109 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. Source/WebCore: Adds new IDL files and stubs for UndoManager and UndoItem. This is an experimental DOM API that (in the near future) is intended only for use in internal WebKit text editing clients. This API allows the page to participate in the processes of undoing and redoing by defining custom undo and redo handlers, to be executed when undo or redo is triggered. Tests: editing/undo-manager/undo-manager-interfaces.html editing/undo-manager/undo-manager-keeps-wrapper-alive.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * UnifiedSources-input.xcfilelist: * WebCore.xcodeproj/project.pbxproj: Add new source files. * bindings/js/WebCoreBuiltinNames.h: Add "UndoManager" and "UndoItem" names. * dom/Document.cpp: (WebCore::m_undoManager): Have the document own a UndoManager. * dom/Document.h: (WebCore::Document::undoManager const): * dom/Document.idl: * page/RuntimeEnabledFeatures.h: (WebCore::RuntimeEnabledFeatures::setUndoManagerAPIEnabled): (WebCore::RuntimeEnabledFeatures::undoManagerAPIEnabled const): Guard the new bindings behind a runtime-enabled feature flag. * page/UndoItem.h: Added. (WebCore::UndoItem::create): (WebCore::UndoItem::label const): (WebCore::UndoItem::undoHandler const): (WebCore::UndoItem::redoHandler const): (WebCore::UndoItem::UndoItem): * page/UndoItem.idl: Added. * page/UndoManager.cpp: Added. (WebCore::UndoManager::addItem): * page/UndoManager.h: Added. (WebCore::UndoManager::create): (WebCore::UndoManager::document): (WebCore::UndoManager::UndoManager): * page/UndoManager.idl: Added. * page/mac/WheelEventDeltaFilterMac.h: Necessary (albeit unrelated) build fix to appease unified sources. Source/WebKit: Add a new SPI configuration flag to enable the UndoManager API. This is off by default. * Shared/WebPreferences.yaml: * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _initializeWithConfiguration:]): * UIProcess/API/Cocoa/WKWebViewConfiguration.mm: (-[WKWebViewConfiguration init]): (-[WKWebViewConfiguration copyWithZone:]): (-[WKWebViewConfiguration _setUndoManagerAPIEnabled:]): (-[WKWebViewConfiguration _undoManagerAPIEnabled]): * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: Tools: Introduce and respect a test option to enable the UndoManager API. * WebKitTestRunner/TestController.cpp: (WTR::updateTestOptionsFromTestHeader): * WebKitTestRunner/TestOptions.h: (WTR::TestOptions::hasSameInitializationOptions const): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::TestController::platformCreateWebView): LayoutTests: Add UndoManager tests to exercise new bindings, and verify that the JS wrapper for Document's UndoManager survives garbage collection. * TestExpectations: * editing/undo-manager/undo-manager-interfaces-expected.txt: Added. * editing/undo-manager/undo-manager-interfaces.html: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive-expected.txt: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive.html: Added. * platform/ios-wk2/TestExpectations: * platform/mac-wk2/TestExpectations: Canonical link: https://commits.webkit.org/207849@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239864 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-11 18:28:06 +00:00
/*
* 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.
*/
#pragma once
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): Canonical link: https://commits.webkit.org/208316@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240476 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-25 17:23:06 +00:00
#include "ExceptionOr.h"
Introduce IDL files for runtime-enabled UndoManager and UndoItem JavaScript API https://bugs.webkit.org/show_bug.cgi?id=193109 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. Source/WebCore: Adds new IDL files and stubs for UndoManager and UndoItem. This is an experimental DOM API that (in the near future) is intended only for use in internal WebKit text editing clients. This API allows the page to participate in the processes of undoing and redoing by defining custom undo and redo handlers, to be executed when undo or redo is triggered. Tests: editing/undo-manager/undo-manager-interfaces.html editing/undo-manager/undo-manager-keeps-wrapper-alive.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * UnifiedSources-input.xcfilelist: * WebCore.xcodeproj/project.pbxproj: Add new source files. * bindings/js/WebCoreBuiltinNames.h: Add "UndoManager" and "UndoItem" names. * dom/Document.cpp: (WebCore::m_undoManager): Have the document own a UndoManager. * dom/Document.h: (WebCore::Document::undoManager const): * dom/Document.idl: * page/RuntimeEnabledFeatures.h: (WebCore::RuntimeEnabledFeatures::setUndoManagerAPIEnabled): (WebCore::RuntimeEnabledFeatures::undoManagerAPIEnabled const): Guard the new bindings behind a runtime-enabled feature flag. * page/UndoItem.h: Added. (WebCore::UndoItem::create): (WebCore::UndoItem::label const): (WebCore::UndoItem::undoHandler const): (WebCore::UndoItem::redoHandler const): (WebCore::UndoItem::UndoItem): * page/UndoItem.idl: Added. * page/UndoManager.cpp: Added. (WebCore::UndoManager::addItem): * page/UndoManager.h: Added. (WebCore::UndoManager::create): (WebCore::UndoManager::document): (WebCore::UndoManager::UndoManager): * page/UndoManager.idl: Added. * page/mac/WheelEventDeltaFilterMac.h: Necessary (albeit unrelated) build fix to appease unified sources. Source/WebKit: Add a new SPI configuration flag to enable the UndoManager API. This is off by default. * Shared/WebPreferences.yaml: * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _initializeWithConfiguration:]): * UIProcess/API/Cocoa/WKWebViewConfiguration.mm: (-[WKWebViewConfiguration init]): (-[WKWebViewConfiguration copyWithZone:]): (-[WKWebViewConfiguration _setUndoManagerAPIEnabled:]): (-[WKWebViewConfiguration _undoManagerAPIEnabled]): * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: Tools: Introduce and respect a test option to enable the UndoManager API. * WebKitTestRunner/TestController.cpp: (WTR::updateTestOptionsFromTestHeader): * WebKitTestRunner/TestOptions.h: (WTR::TestOptions::hasSameInitializationOptions const): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::TestController::platformCreateWebView): LayoutTests: Add UndoManager tests to exercise new bindings, and verify that the JS wrapper for Document's UndoManager survives garbage collection. * TestExpectations: * editing/undo-manager/undo-manager-interfaces-expected.txt: Added. * editing/undo-manager/undo-manager-interfaces.html: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive-expected.txt: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive.html: Added. * platform/ios-wk2/TestExpectations: * platform/mac-wk2/TestExpectations: Canonical link: https://commits.webkit.org/207849@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239864 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-11 18:28:06 +00:00
#include <wtf/IsoMalloc.h>
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
Add some bindings-related bookkeeping to UndoManager and UndoItem https://bugs.webkit.org/show_bug.cgi?id=193111 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. This patch is work in progress towards supporting `UndoManager.addItem()`. Here, we add helper methods to UndoItem and UndoManager which later patches will exercise, as well as introduce some custom bindings to properly handle the case where UndoItems are given anonymous JavaScript functions (see below for more details). No new tests, because there is no script-observable change in behavior yet. When `addItems()` is hooked up, I will write a test to verify that the undo and redo JavaScript functions survive garbage collection. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * bindings/js/JSUndoItemCustom.cpp: (WebCore::JSUndoItem::visitAdditionalChildren): Have each JSUndoItem visit its undo and redo callback functions to ensure that the JavaScript wrapper objects for these functions are not garbage collected underneath the item. (WebCore::JSUndoItemOwner::isReachableFromOpaqueRoots): Consider the undo item wrapper reachable from opaque roots if it is associated with its UndoManager's Document. This ensures that if script isn't holding on to a reference to the wrapper (for instance, by calling `UndoManager.addItem(new UndoItem({ ... }))`), we still protect the corresponding JSUndoItem as long as the UndoManager's Document is alive. In the case where the undo item is not associated with a document, either (1) script is keeping a reference to it, in which case it will be trivially reachable, or (2) script won't be able to observe the destruction of the wrapper anyways (e.g. calling `new UndoItem({ ... })` by itself). * dom/Document.cpp: (WebCore::Document::prepareForDestruction): Invalidate all undo items when the document is about to go away. * page/UndoItem.cpp: (WebCore::UndoItem::setUndoManager): (WebCore::UndoItem::invalidate): (WebCore::UndoItem::isValid const): Add a few helpers, to be used in a future patch. We consider an UndoItem valid if it has been added to an UndoManager, and is thus associated with a document. (WebCore::UndoItem::document const): * page/UndoItem.h: * page/UndoItem.idl: * page/UndoManager.cpp: (WebCore::UndoManager::UndoManager): (WebCore::UndoManager::addItem): Have an UndoManager keep its UndoItems alive. These UndoItems remain in this set until either the document will be destroyed, or the corresponding undo action is no longer needed because the platform undo stack has changed (this latter behavior is yet to be implemented). (WebCore::UndoManager::removeItem): (WebCore::UndoManager::removeAllItems): * page/UndoManager.h: (WebCore::UndoManager::UndoManager): Deleted. * page/scrolling/ScrollingTreeScrollingNode.cpp: Unified build fix. Canonical link: https://commits.webkit.org/208215@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240315 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-23 02:06:53 +00:00
#include <wtf/RefPtr.h>
#include <wtf/WeakPtr.h>
Introduce IDL files for runtime-enabled UndoManager and UndoItem JavaScript API https://bugs.webkit.org/show_bug.cgi?id=193109 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. Source/WebCore: Adds new IDL files and stubs for UndoManager and UndoItem. This is an experimental DOM API that (in the near future) is intended only for use in internal WebKit text editing clients. This API allows the page to participate in the processes of undoing and redoing by defining custom undo and redo handlers, to be executed when undo or redo is triggered. Tests: editing/undo-manager/undo-manager-interfaces.html editing/undo-manager/undo-manager-keeps-wrapper-alive.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * UnifiedSources-input.xcfilelist: * WebCore.xcodeproj/project.pbxproj: Add new source files. * bindings/js/WebCoreBuiltinNames.h: Add "UndoManager" and "UndoItem" names. * dom/Document.cpp: (WebCore::m_undoManager): Have the document own a UndoManager. * dom/Document.h: (WebCore::Document::undoManager const): * dom/Document.idl: * page/RuntimeEnabledFeatures.h: (WebCore::RuntimeEnabledFeatures::setUndoManagerAPIEnabled): (WebCore::RuntimeEnabledFeatures::undoManagerAPIEnabled const): Guard the new bindings behind a runtime-enabled feature flag. * page/UndoItem.h: Added. (WebCore::UndoItem::create): (WebCore::UndoItem::label const): (WebCore::UndoItem::undoHandler const): (WebCore::UndoItem::redoHandler const): (WebCore::UndoItem::UndoItem): * page/UndoItem.idl: Added. * page/UndoManager.cpp: Added. (WebCore::UndoManager::addItem): * page/UndoManager.h: Added. (WebCore::UndoManager::create): (WebCore::UndoManager::document): (WebCore::UndoManager::UndoManager): * page/UndoManager.idl: Added. * page/mac/WheelEventDeltaFilterMac.h: Necessary (albeit unrelated) build fix to appease unified sources. Source/WebKit: Add a new SPI configuration flag to enable the UndoManager API. This is off by default. * Shared/WebPreferences.yaml: * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _initializeWithConfiguration:]): * UIProcess/API/Cocoa/WKWebViewConfiguration.mm: (-[WKWebViewConfiguration init]): (-[WKWebViewConfiguration copyWithZone:]): (-[WKWebViewConfiguration _setUndoManagerAPIEnabled:]): (-[WKWebViewConfiguration _undoManagerAPIEnabled]): * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: Tools: Introduce and respect a test option to enable the UndoManager API. * WebKitTestRunner/TestController.cpp: (WTR::updateTestOptionsFromTestHeader): * WebKitTestRunner/TestOptions.h: (WTR::TestOptions::hasSameInitializationOptions const): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::TestController::platformCreateWebView): LayoutTests: Add UndoManager tests to exercise new bindings, and verify that the JS wrapper for Document's UndoManager survives garbage collection. * TestExpectations: * editing/undo-manager/undo-manager-interfaces-expected.txt: Added. * editing/undo-manager/undo-manager-interfaces.html: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive-expected.txt: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive.html: Added. * platform/ios-wk2/TestExpectations: * platform/mac-wk2/TestExpectations: Canonical link: https://commits.webkit.org/207849@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239864 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-11 18:28:06 +00:00
namespace WebCore {
class Document;
class UndoItem;
Add some bindings-related bookkeeping to UndoManager and UndoItem https://bugs.webkit.org/show_bug.cgi?id=193111 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. This patch is work in progress towards supporting `UndoManager.addItem()`. Here, we add helper methods to UndoItem and UndoManager which later patches will exercise, as well as introduce some custom bindings to properly handle the case where UndoItems are given anonymous JavaScript functions (see below for more details). No new tests, because there is no script-observable change in behavior yet. When `addItems()` is hooked up, I will write a test to verify that the undo and redo JavaScript functions survive garbage collection. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * bindings/js/JSUndoItemCustom.cpp: (WebCore::JSUndoItem::visitAdditionalChildren): Have each JSUndoItem visit its undo and redo callback functions to ensure that the JavaScript wrapper objects for these functions are not garbage collected underneath the item. (WebCore::JSUndoItemOwner::isReachableFromOpaqueRoots): Consider the undo item wrapper reachable from opaque roots if it is associated with its UndoManager's Document. This ensures that if script isn't holding on to a reference to the wrapper (for instance, by calling `UndoManager.addItem(new UndoItem({ ... }))`), we still protect the corresponding JSUndoItem as long as the UndoManager's Document is alive. In the case where the undo item is not associated with a document, either (1) script is keeping a reference to it, in which case it will be trivially reachable, or (2) script won't be able to observe the destruction of the wrapper anyways (e.g. calling `new UndoItem({ ... })` by itself). * dom/Document.cpp: (WebCore::Document::prepareForDestruction): Invalidate all undo items when the document is about to go away. * page/UndoItem.cpp: (WebCore::UndoItem::setUndoManager): (WebCore::UndoItem::invalidate): (WebCore::UndoItem::isValid const): Add a few helpers, to be used in a future patch. We consider an UndoItem valid if it has been added to an UndoManager, and is thus associated with a document. (WebCore::UndoItem::document const): * page/UndoItem.h: * page/UndoItem.idl: * page/UndoManager.cpp: (WebCore::UndoManager::UndoManager): (WebCore::UndoManager::addItem): Have an UndoManager keep its UndoItems alive. These UndoItems remain in this set until either the document will be destroyed, or the corresponding undo action is no longer needed because the platform undo stack has changed (this latter behavior is yet to be implemented). (WebCore::UndoManager::removeItem): (WebCore::UndoManager::removeAllItems): * page/UndoManager.h: (WebCore::UndoManager::UndoManager): Deleted. * page/scrolling/ScrollingTreeScrollingNode.cpp: Unified build fix. Canonical link: https://commits.webkit.org/208215@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240315 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-23 02:06:53 +00:00
class UndoManager : public RefCounted<UndoManager>, public CanMakeWeakPtr<UndoManager> {
Introduce IDL files for runtime-enabled UndoManager and UndoItem JavaScript API https://bugs.webkit.org/show_bug.cgi?id=193109 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. Source/WebCore: Adds new IDL files and stubs for UndoManager and UndoItem. This is an experimental DOM API that (in the near future) is intended only for use in internal WebKit text editing clients. This API allows the page to participate in the processes of undoing and redoing by defining custom undo and redo handlers, to be executed when undo or redo is triggered. Tests: editing/undo-manager/undo-manager-interfaces.html editing/undo-manager/undo-manager-keeps-wrapper-alive.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * UnifiedSources-input.xcfilelist: * WebCore.xcodeproj/project.pbxproj: Add new source files. * bindings/js/WebCoreBuiltinNames.h: Add "UndoManager" and "UndoItem" names. * dom/Document.cpp: (WebCore::m_undoManager): Have the document own a UndoManager. * dom/Document.h: (WebCore::Document::undoManager const): * dom/Document.idl: * page/RuntimeEnabledFeatures.h: (WebCore::RuntimeEnabledFeatures::setUndoManagerAPIEnabled): (WebCore::RuntimeEnabledFeatures::undoManagerAPIEnabled const): Guard the new bindings behind a runtime-enabled feature flag. * page/UndoItem.h: Added. (WebCore::UndoItem::create): (WebCore::UndoItem::label const): (WebCore::UndoItem::undoHandler const): (WebCore::UndoItem::redoHandler const): (WebCore::UndoItem::UndoItem): * page/UndoItem.idl: Added. * page/UndoManager.cpp: Added. (WebCore::UndoManager::addItem): * page/UndoManager.h: Added. (WebCore::UndoManager::create): (WebCore::UndoManager::document): (WebCore::UndoManager::UndoManager): * page/UndoManager.idl: Added. * page/mac/WheelEventDeltaFilterMac.h: Necessary (albeit unrelated) build fix to appease unified sources. Source/WebKit: Add a new SPI configuration flag to enable the UndoManager API. This is off by default. * Shared/WebPreferences.yaml: * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _initializeWithConfiguration:]): * UIProcess/API/Cocoa/WKWebViewConfiguration.mm: (-[WKWebViewConfiguration init]): (-[WKWebViewConfiguration copyWithZone:]): (-[WKWebViewConfiguration _setUndoManagerAPIEnabled:]): (-[WKWebViewConfiguration _undoManagerAPIEnabled]): * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: Tools: Introduce and respect a test option to enable the UndoManager API. * WebKitTestRunner/TestController.cpp: (WTR::updateTestOptionsFromTestHeader): * WebKitTestRunner/TestOptions.h: (WTR::TestOptions::hasSameInitializationOptions const): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::TestController::platformCreateWebView): LayoutTests: Add UndoManager tests to exercise new bindings, and verify that the JS wrapper for Document's UndoManager survives garbage collection. * TestExpectations: * editing/undo-manager/undo-manager-interfaces-expected.txt: Added. * editing/undo-manager/undo-manager-interfaces.html: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive-expected.txt: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive.html: Added. * platform/ios-wk2/TestExpectations: * platform/mac-wk2/TestExpectations: Canonical link: https://commits.webkit.org/207849@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239864 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-11 18:28:06 +00:00
WTF_MAKE_ISO_ALLOCATED(UndoManager);
public:
static Ref<UndoManager> create(Document& document)
{
return adoptRef(*new UndoManager(document));
}
Add some bindings-related bookkeeping to UndoManager and UndoItem https://bugs.webkit.org/show_bug.cgi?id=193111 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. This patch is work in progress towards supporting `UndoManager.addItem()`. Here, we add helper methods to UndoItem and UndoManager which later patches will exercise, as well as introduce some custom bindings to properly handle the case where UndoItems are given anonymous JavaScript functions (see below for more details). No new tests, because there is no script-observable change in behavior yet. When `addItems()` is hooked up, I will write a test to verify that the undo and redo JavaScript functions survive garbage collection. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * bindings/js/JSUndoItemCustom.cpp: (WebCore::JSUndoItem::visitAdditionalChildren): Have each JSUndoItem visit its undo and redo callback functions to ensure that the JavaScript wrapper objects for these functions are not garbage collected underneath the item. (WebCore::JSUndoItemOwner::isReachableFromOpaqueRoots): Consider the undo item wrapper reachable from opaque roots if it is associated with its UndoManager's Document. This ensures that if script isn't holding on to a reference to the wrapper (for instance, by calling `UndoManager.addItem(new UndoItem({ ... }))`), we still protect the corresponding JSUndoItem as long as the UndoManager's Document is alive. In the case where the undo item is not associated with a document, either (1) script is keeping a reference to it, in which case it will be trivially reachable, or (2) script won't be able to observe the destruction of the wrapper anyways (e.g. calling `new UndoItem({ ... })` by itself). * dom/Document.cpp: (WebCore::Document::prepareForDestruction): Invalidate all undo items when the document is about to go away. * page/UndoItem.cpp: (WebCore::UndoItem::setUndoManager): (WebCore::UndoItem::invalidate): (WebCore::UndoItem::isValid const): Add a few helpers, to be used in a future patch. We consider an UndoItem valid if it has been added to an UndoManager, and is thus associated with a document. (WebCore::UndoItem::document const): * page/UndoItem.h: * page/UndoItem.idl: * page/UndoManager.cpp: (WebCore::UndoManager::UndoManager): (WebCore::UndoManager::addItem): Have an UndoManager keep its UndoItems alive. These UndoItems remain in this set until either the document will be destroyed, or the corresponding undo action is no longer needed because the platform undo stack has changed (this latter behavior is yet to be implemented). (WebCore::UndoManager::removeItem): (WebCore::UndoManager::removeAllItems): * page/UndoManager.h: (WebCore::UndoManager::UndoManager): Deleted. * page/scrolling/ScrollingTreeScrollingNode.cpp: Unified build fix. Canonical link: https://commits.webkit.org/208215@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240315 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-23 02:06:53 +00:00
~UndoManager();
void removeItem(UndoItem&);
void removeAllItems();
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): Canonical link: https://commits.webkit.org/208316@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240476 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-25 17:23:06 +00:00
ExceptionOr<void> addItem(Ref<UndoItem>&&);
Introduce IDL files for runtime-enabled UndoManager and UndoItem JavaScript API https://bugs.webkit.org/show_bug.cgi?id=193109 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. Source/WebCore: Adds new IDL files and stubs for UndoManager and UndoItem. This is an experimental DOM API that (in the near future) is intended only for use in internal WebKit text editing clients. This API allows the page to participate in the processes of undoing and redoing by defining custom undo and redo handlers, to be executed when undo or redo is triggered. Tests: editing/undo-manager/undo-manager-interfaces.html editing/undo-manager/undo-manager-keeps-wrapper-alive.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * UnifiedSources-input.xcfilelist: * WebCore.xcodeproj/project.pbxproj: Add new source files. * bindings/js/WebCoreBuiltinNames.h: Add "UndoManager" and "UndoItem" names. * dom/Document.cpp: (WebCore::m_undoManager): Have the document own a UndoManager. * dom/Document.h: (WebCore::Document::undoManager const): * dom/Document.idl: * page/RuntimeEnabledFeatures.h: (WebCore::RuntimeEnabledFeatures::setUndoManagerAPIEnabled): (WebCore::RuntimeEnabledFeatures::undoManagerAPIEnabled const): Guard the new bindings behind a runtime-enabled feature flag. * page/UndoItem.h: Added. (WebCore::UndoItem::create): (WebCore::UndoItem::label const): (WebCore::UndoItem::undoHandler const): (WebCore::UndoItem::redoHandler const): (WebCore::UndoItem::UndoItem): * page/UndoItem.idl: Added. * page/UndoManager.cpp: Added. (WebCore::UndoManager::addItem): * page/UndoManager.h: Added. (WebCore::UndoManager::create): (WebCore::UndoManager::document): (WebCore::UndoManager::UndoManager): * page/UndoManager.idl: Added. * page/mac/WheelEventDeltaFilterMac.h: Necessary (albeit unrelated) build fix to appease unified sources. Source/WebKit: Add a new SPI configuration flag to enable the UndoManager API. This is off by default. * Shared/WebPreferences.yaml: * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _initializeWithConfiguration:]): * UIProcess/API/Cocoa/WKWebViewConfiguration.mm: (-[WKWebViewConfiguration init]): (-[WKWebViewConfiguration copyWithZone:]): (-[WKWebViewConfiguration _setUndoManagerAPIEnabled:]): (-[WKWebViewConfiguration _undoManagerAPIEnabled]): * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: Tools: Introduce and respect a test option to enable the UndoManager API. * WebKitTestRunner/TestController.cpp: (WTR::updateTestOptionsFromTestHeader): * WebKitTestRunner/TestOptions.h: (WTR::TestOptions::hasSameInitializationOptions const): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::TestController::platformCreateWebView): LayoutTests: Add UndoManager tests to exercise new bindings, and verify that the JS wrapper for Document's UndoManager survives garbage collection. * TestExpectations: * editing/undo-manager/undo-manager-interfaces-expected.txt: Added. * editing/undo-manager/undo-manager-interfaces.html: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive-expected.txt: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive.html: Added. * platform/ios-wk2/TestExpectations: * platform/mac-wk2/TestExpectations: Canonical link: https://commits.webkit.org/207849@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239864 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-11 18:28:06 +00:00
Document& document() { return m_document; }
private:
Add some bindings-related bookkeeping to UndoManager and UndoItem https://bugs.webkit.org/show_bug.cgi?id=193111 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. This patch is work in progress towards supporting `UndoManager.addItem()`. Here, we add helper methods to UndoItem and UndoManager which later patches will exercise, as well as introduce some custom bindings to properly handle the case where UndoItems are given anonymous JavaScript functions (see below for more details). No new tests, because there is no script-observable change in behavior yet. When `addItems()` is hooked up, I will write a test to verify that the undo and redo JavaScript functions survive garbage collection. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * bindings/js/JSUndoItemCustom.cpp: (WebCore::JSUndoItem::visitAdditionalChildren): Have each JSUndoItem visit its undo and redo callback functions to ensure that the JavaScript wrapper objects for these functions are not garbage collected underneath the item. (WebCore::JSUndoItemOwner::isReachableFromOpaqueRoots): Consider the undo item wrapper reachable from opaque roots if it is associated with its UndoManager's Document. This ensures that if script isn't holding on to a reference to the wrapper (for instance, by calling `UndoManager.addItem(new UndoItem({ ... }))`), we still protect the corresponding JSUndoItem as long as the UndoManager's Document is alive. In the case where the undo item is not associated with a document, either (1) script is keeping a reference to it, in which case it will be trivially reachable, or (2) script won't be able to observe the destruction of the wrapper anyways (e.g. calling `new UndoItem({ ... })` by itself). * dom/Document.cpp: (WebCore::Document::prepareForDestruction): Invalidate all undo items when the document is about to go away. * page/UndoItem.cpp: (WebCore::UndoItem::setUndoManager): (WebCore::UndoItem::invalidate): (WebCore::UndoItem::isValid const): Add a few helpers, to be used in a future patch. We consider an UndoItem valid if it has been added to an UndoManager, and is thus associated with a document. (WebCore::UndoItem::document const): * page/UndoItem.h: * page/UndoItem.idl: * page/UndoManager.cpp: (WebCore::UndoManager::UndoManager): (WebCore::UndoManager::addItem): Have an UndoManager keep its UndoItems alive. These UndoItems remain in this set until either the document will be destroyed, or the corresponding undo action is no longer needed because the platform undo stack has changed (this latter behavior is yet to be implemented). (WebCore::UndoManager::removeItem): (WebCore::UndoManager::removeAllItems): * page/UndoManager.h: (WebCore::UndoManager::UndoManager): Deleted. * page/scrolling/ScrollingTreeScrollingNode.cpp: Unified build fix. Canonical link: https://commits.webkit.org/208215@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240315 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-23 02:06:53 +00:00
UndoManager(Document&);
Introduce IDL files for runtime-enabled UndoManager and UndoItem JavaScript API https://bugs.webkit.org/show_bug.cgi?id=193109 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. Source/WebCore: Adds new IDL files and stubs for UndoManager and UndoItem. This is an experimental DOM API that (in the near future) is intended only for use in internal WebKit text editing clients. This API allows the page to participate in the processes of undoing and redoing by defining custom undo and redo handlers, to be executed when undo or redo is triggered. Tests: editing/undo-manager/undo-manager-interfaces.html editing/undo-manager/undo-manager-keeps-wrapper-alive.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * UnifiedSources-input.xcfilelist: * WebCore.xcodeproj/project.pbxproj: Add new source files. * bindings/js/WebCoreBuiltinNames.h: Add "UndoManager" and "UndoItem" names. * dom/Document.cpp: (WebCore::m_undoManager): Have the document own a UndoManager. * dom/Document.h: (WebCore::Document::undoManager const): * dom/Document.idl: * page/RuntimeEnabledFeatures.h: (WebCore::RuntimeEnabledFeatures::setUndoManagerAPIEnabled): (WebCore::RuntimeEnabledFeatures::undoManagerAPIEnabled const): Guard the new bindings behind a runtime-enabled feature flag. * page/UndoItem.h: Added. (WebCore::UndoItem::create): (WebCore::UndoItem::label const): (WebCore::UndoItem::undoHandler const): (WebCore::UndoItem::redoHandler const): (WebCore::UndoItem::UndoItem): * page/UndoItem.idl: Added. * page/UndoManager.cpp: Added. (WebCore::UndoManager::addItem): * page/UndoManager.h: Added. (WebCore::UndoManager::create): (WebCore::UndoManager::document): (WebCore::UndoManager::UndoManager): * page/UndoManager.idl: Added. * page/mac/WheelEventDeltaFilterMac.h: Necessary (albeit unrelated) build fix to appease unified sources. Source/WebKit: Add a new SPI configuration flag to enable the UndoManager API. This is off by default. * Shared/WebPreferences.yaml: * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _initializeWithConfiguration:]): * UIProcess/API/Cocoa/WKWebViewConfiguration.mm: (-[WKWebViewConfiguration init]): (-[WKWebViewConfiguration copyWithZone:]): (-[WKWebViewConfiguration _setUndoManagerAPIEnabled:]): (-[WKWebViewConfiguration _undoManagerAPIEnabled]): * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: Tools: Introduce and respect a test option to enable the UndoManager API. * WebKitTestRunner/TestController.cpp: (WTR::updateTestOptionsFromTestHeader): * WebKitTestRunner/TestOptions.h: (WTR::TestOptions::hasSameInitializationOptions const): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::TestController::platformCreateWebView): LayoutTests: Add UndoManager tests to exercise new bindings, and verify that the JS wrapper for Document's UndoManager survives garbage collection. * TestExpectations: * editing/undo-manager/undo-manager-interfaces-expected.txt: Added. * editing/undo-manager/undo-manager-interfaces.html: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive-expected.txt: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive.html: Added. * platform/ios-wk2/TestExpectations: * platform/mac-wk2/TestExpectations: Canonical link: https://commits.webkit.org/207849@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239864 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-11 18:28:06 +00:00
Document& m_document;
Add some bindings-related bookkeeping to UndoManager and UndoItem https://bugs.webkit.org/show_bug.cgi?id=193111 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. This patch is work in progress towards supporting `UndoManager.addItem()`. Here, we add helper methods to UndoItem and UndoManager which later patches will exercise, as well as introduce some custom bindings to properly handle the case where UndoItems are given anonymous JavaScript functions (see below for more details). No new tests, because there is no script-observable change in behavior yet. When `addItems()` is hooked up, I will write a test to verify that the undo and redo JavaScript functions survive garbage collection. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * bindings/js/JSUndoItemCustom.cpp: (WebCore::JSUndoItem::visitAdditionalChildren): Have each JSUndoItem visit its undo and redo callback functions to ensure that the JavaScript wrapper objects for these functions are not garbage collected underneath the item. (WebCore::JSUndoItemOwner::isReachableFromOpaqueRoots): Consider the undo item wrapper reachable from opaque roots if it is associated with its UndoManager's Document. This ensures that if script isn't holding on to a reference to the wrapper (for instance, by calling `UndoManager.addItem(new UndoItem({ ... }))`), we still protect the corresponding JSUndoItem as long as the UndoManager's Document is alive. In the case where the undo item is not associated with a document, either (1) script is keeping a reference to it, in which case it will be trivially reachable, or (2) script won't be able to observe the destruction of the wrapper anyways (e.g. calling `new UndoItem({ ... })` by itself). * dom/Document.cpp: (WebCore::Document::prepareForDestruction): Invalidate all undo items when the document is about to go away. * page/UndoItem.cpp: (WebCore::UndoItem::setUndoManager): (WebCore::UndoItem::invalidate): (WebCore::UndoItem::isValid const): Add a few helpers, to be used in a future patch. We consider an UndoItem valid if it has been added to an UndoManager, and is thus associated with a document. (WebCore::UndoItem::document const): * page/UndoItem.h: * page/UndoItem.idl: * page/UndoManager.cpp: (WebCore::UndoManager::UndoManager): (WebCore::UndoManager::addItem): Have an UndoManager keep its UndoItems alive. These UndoItems remain in this set until either the document will be destroyed, or the corresponding undo action is no longer needed because the platform undo stack has changed (this latter behavior is yet to be implemented). (WebCore::UndoManager::removeItem): (WebCore::UndoManager::removeAllItems): * page/UndoManager.h: (WebCore::UndoManager::UndoManager): Deleted. * page/scrolling/ScrollingTreeScrollingNode.cpp: Unified build fix. Canonical link: https://commits.webkit.org/208215@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240315 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-23 02:06:53 +00:00
HashSet<RefPtr<UndoItem>> m_items;
Introduce IDL files for runtime-enabled UndoManager and UndoItem JavaScript API https://bugs.webkit.org/show_bug.cgi?id=193109 <rdar://problem/44807048> Reviewed by Ryosuke Niwa. Source/WebCore: Adds new IDL files and stubs for UndoManager and UndoItem. This is an experimental DOM API that (in the near future) is intended only for use in internal WebKit text editing clients. This API allows the page to participate in the processes of undoing and redoing by defining custom undo and redo handlers, to be executed when undo or redo is triggered. Tests: editing/undo-manager/undo-manager-interfaces.html editing/undo-manager/undo-manager-keeps-wrapper-alive.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * UnifiedSources-input.xcfilelist: * WebCore.xcodeproj/project.pbxproj: Add new source files. * bindings/js/WebCoreBuiltinNames.h: Add "UndoManager" and "UndoItem" names. * dom/Document.cpp: (WebCore::m_undoManager): Have the document own a UndoManager. * dom/Document.h: (WebCore::Document::undoManager const): * dom/Document.idl: * page/RuntimeEnabledFeatures.h: (WebCore::RuntimeEnabledFeatures::setUndoManagerAPIEnabled): (WebCore::RuntimeEnabledFeatures::undoManagerAPIEnabled const): Guard the new bindings behind a runtime-enabled feature flag. * page/UndoItem.h: Added. (WebCore::UndoItem::create): (WebCore::UndoItem::label const): (WebCore::UndoItem::undoHandler const): (WebCore::UndoItem::redoHandler const): (WebCore::UndoItem::UndoItem): * page/UndoItem.idl: Added. * page/UndoManager.cpp: Added. (WebCore::UndoManager::addItem): * page/UndoManager.h: Added. (WebCore::UndoManager::create): (WebCore::UndoManager::document): (WebCore::UndoManager::UndoManager): * page/UndoManager.idl: Added. * page/mac/WheelEventDeltaFilterMac.h: Necessary (albeit unrelated) build fix to appease unified sources. Source/WebKit: Add a new SPI configuration flag to enable the UndoManager API. This is off by default. * Shared/WebPreferences.yaml: * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _initializeWithConfiguration:]): * UIProcess/API/Cocoa/WKWebViewConfiguration.mm: (-[WKWebViewConfiguration init]): (-[WKWebViewConfiguration copyWithZone:]): (-[WKWebViewConfiguration _setUndoManagerAPIEnabled:]): (-[WKWebViewConfiguration _undoManagerAPIEnabled]): * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: Tools: Introduce and respect a test option to enable the UndoManager API. * WebKitTestRunner/TestController.cpp: (WTR::updateTestOptionsFromTestHeader): * WebKitTestRunner/TestOptions.h: (WTR::TestOptions::hasSameInitializationOptions const): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::TestController::platformCreateWebView): LayoutTests: Add UndoManager tests to exercise new bindings, and verify that the JS wrapper for Document's UndoManager survives garbage collection. * TestExpectations: * editing/undo-manager/undo-manager-interfaces-expected.txt: Added. * editing/undo-manager/undo-manager-interfaces.html: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive-expected.txt: Added. * editing/undo-manager/undo-manager-keeps-wrapper-alive.html: Added. * platform/ios-wk2/TestExpectations: * platform/mac-wk2/TestExpectations: Canonical link: https://commits.webkit.org/207849@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239864 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-11 18:28:06 +00:00
};
} // namespace WebCore