Title: [240328] trunk/Source/WebCore
Revision
240328
Author
wenson_hs...@apple.com
Date
2019-01-22 22:10:45 -0800 (Tue, 22 Jan 2019)

Log Message

Introduce CustomUndoStep.h and CustomUndoStep.cpp
https://bugs.webkit.org/show_bug.cgi?id=193704
<rdar://problem/44807048>

Reviewed by Ryosuke Niwa.

This patch is more work in progress towards supporting `UndoManager.addItem()`. Here, we introduce a helper
class, CustomUndoStep, that holds a weak reference to a script-defined UndoItem. See below for more details.

No change in behavior.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* editing/CustomUndoStep.cpp:
(WebCore::CustomUndoStep::CustomUndoStep):

Subclass UndoStep.

(WebCore::CustomUndoStep::unapply):
(WebCore::CustomUndoStep::reapply):

If possible, invoke the UndoItem's undo and redo handlers.

(WebCore::CustomUndoStep::isValid const):
* editing/CustomUndoStep.h:
* editing/EditingStyle.cpp:
* editing/InsertEditableImageCommand.cpp:
(WebCore::InsertEditableImageCommand::doApply):

Unified build fixes.

* page/UndoItem.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (240327 => 240328)


--- trunk/Source/WebCore/ChangeLog	2019-01-23 05:55:08 UTC (rev 240327)
+++ trunk/Source/WebCore/ChangeLog	2019-01-23 06:10:45 UTC (rev 240328)
@@ -1,3 +1,38 @@
+2019-01-22  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Introduce CustomUndoStep.h and CustomUndoStep.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=193704
+        <rdar://problem/44807048>
+
+        Reviewed by Ryosuke Niwa.
+
+        This patch is more work in progress towards supporting `UndoManager.addItem()`. Here, we introduce a helper
+        class, CustomUndoStep, that holds a weak reference to a script-defined UndoItem. See below for more details.
+
+        No change in behavior.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * editing/CustomUndoStep.cpp:
+        (WebCore::CustomUndoStep::CustomUndoStep):
+
+        Subclass UndoStep.
+
+        (WebCore::CustomUndoStep::unapply):
+        (WebCore::CustomUndoStep::reapply):
+
+        If possible, invoke the UndoItem's undo and redo handlers.
+
+        (WebCore::CustomUndoStep::isValid const):
+        * editing/CustomUndoStep.h:
+        * editing/EditingStyle.cpp:
+        * editing/InsertEditableImageCommand.cpp:
+        (WebCore::InsertEditableImageCommand::doApply):
+
+        Unified build fixes.
+
+        * page/UndoItem.h:
+
 2019-01-22  Simon Fraser  <simon.fra...@apple.com>
 
         Adding a child to a ScrollingStateNode needs to trigger a tree state commit

Modified: trunk/Source/WebCore/Sources.txt (240327 => 240328)


--- trunk/Source/WebCore/Sources.txt	2019-01-23 05:55:08 UTC (rev 240327)
+++ trunk/Source/WebCore/Sources.txt	2019-01-23 06:10:45 UTC (rev 240328)
@@ -952,6 +952,7 @@
 editing/ChangeListTypeCommand.cpp
 editing/CompositeEditCommand.cpp
 editing/CreateLinkCommand.cpp
+editing/CustomUndoStep.cpp
 editing/DeleteFromTextNodeCommand.cpp
 editing/DeleteSelectionCommand.cpp
 editing/DictationAlternative.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (240327 => 240328)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-01-23 05:55:08 UTC (rev 240327)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-01-23 06:10:45 UTC (rev 240328)
@@ -15131,6 +15131,8 @@
 		F4D9817E2195FBF6008230FC /* ChangeListTypeCommand.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ChangeListTypeCommand.cpp; sourceTree = "<group>"; };
 		F4E1965A21F2395000285078 /* JSUndoItemCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSUndoItemCustom.cpp; sourceTree = "<group>"; };
 		F4E1965F21F26E4E00285078 /* UndoItem.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = UndoItem.cpp; sourceTree = "<group>"; };
+		F4E1966121F27D3C00285078 /* CustomUndoStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomUndoStep.h; sourceTree = "<group>"; };
+		F4E1966221F27D3D00285078 /* CustomUndoStep.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomUndoStep.cpp; sourceTree = "<group>"; };
 		F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontAttributeChanges.h; sourceTree = "<group>"; };
 		F4E57EDF213F434A004EA98E /* WebCoreNSFontManagerExtras.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCoreNSFontManagerExtras.h; sourceTree = "<group>"; };
 		F4E57EE0213F434A004EA98E /* WebCoreNSFontManagerExtras.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSFontManagerExtras.mm; sourceTree = "<group>"; };
@@ -21107,6 +21109,8 @@
 				2DD5A7261EBEE47D009BA597 /* CompositionUnderline.h */,
 				D0B0556709C6700100307E43 /* CreateLinkCommand.cpp */,
 				D0B0556609C6700100307E43 /* CreateLinkCommand.h */,
+				F4E1966221F27D3D00285078 /* CustomUndoStep.cpp */,
+				F4E1966121F27D3C00285078 /* CustomUndoStep.h */,
 				93309D8F099E64910056E581 /* DeleteFromTextNodeCommand.cpp */,
 				93309D90099E64910056E581 /* DeleteFromTextNodeCommand.h */,
 				93309D91099E64910056E581 /* DeleteSelectionCommand.cpp */,

Copied: trunk/Source/WebCore/editing/CustomUndoStep.cpp (from rev 240327, trunk/Source/WebCore/page/UndoItem.h) (0 => 240328)


--- trunk/Source/WebCore/editing/CustomUndoStep.cpp	                        (rev 0)
+++ trunk/Source/WebCore/editing/CustomUndoStep.cpp	2019-01-23 06:10:45 UTC (rev 240328)
@@ -0,0 +1,68 @@
+/*
+ * 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 "CustomUndoStep.h"
+
+#include "Document.h"
+#include "UndoItem.h"
+#include "UndoManager.h"
+#include "VoidCallback.h"
+
+namespace WebCore {
+
+CustomUndoStep::CustomUndoStep(UndoItem& item)
+    : m_undoItem(makeWeakPtr(item))
+{
+}
+
+void CustomUndoStep::unapply()
+{
+    if (!isValid())
+        return;
+
+    // FIXME: It's currently unclear how input events should be dispatched when unapplying or reapplying custom
+    // edit commands. Should the page be allowed to specify a target in the DOM for undo and redo?
+    Ref<UndoItem> protectedUndoItem(*m_undoItem);
+    protectedUndoItem->document()->updateLayoutIgnorePendingStylesheets();
+    protectedUndoItem->undoHandler().handleEvent();
+}
+
+void CustomUndoStep::reapply()
+{
+    if (!isValid())
+        return;
+
+    Ref<UndoItem> protectedUndoItem(*m_undoItem);
+    protectedUndoItem->document()->updateLayoutIgnorePendingStylesheets();
+    protectedUndoItem->redoHandler().handleEvent();
+}
+
+bool CustomUndoStep::isValid() const
+{
+    return m_undoItem && m_undoItem->isValid();
+}
+
+} // namespace WebCore

Copied: trunk/Source/WebCore/editing/CustomUndoStep.h (from rev 240327, trunk/Source/WebCore/page/UndoItem.h) (0 => 240328)


--- trunk/Source/WebCore/editing/CustomUndoStep.h	                        (rev 0)
+++ trunk/Source/WebCore/editing/CustomUndoStep.h	2019-01-23 06:10:45 UTC (rev 240328)
@@ -0,0 +1,56 @@
+/*
+ * 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
+
+#include "UndoStep.h"
+#include <wtf/Ref.h>
+#include <wtf/WeakPtr.h>
+
+namespace WebCore {
+
+class Document;
+class UndoItem;
+
+class CustomUndoStep final : public UndoStep {
+public:
+    static Ref<CustomUndoStep> create(UndoItem& item)
+    {
+        return adoptRef(*new CustomUndoStep(item));
+    }
+
+private:
+    CustomUndoStep(UndoItem&);
+
+    void unapply() final;
+    void reapply() final;
+    EditAction editingAction() const final { return EditAction::Unspecified; }
+
+    bool isValid() const;
+
+    WeakPtr<UndoItem> m_undoItem;
+};
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (240327 => 240328)


--- trunk/Source/WebCore/editing/EditingStyle.cpp	2019-01-23 05:55:08 UTC (rev 240327)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp	2019-01-23 06:10:45 UTC (rev 240328)
@@ -45,6 +45,7 @@
 #include "Node.h"
 #include "NodeTraversal.h"
 #include "QualifiedName.h"
+#include "RenderElement.h"
 #include "RenderStyle.h"
 #include "StyleFontSizeFunctions.h"
 #include "StyleProperties.h"

Modified: trunk/Source/WebCore/editing/InsertEditableImageCommand.cpp (240327 => 240328)


--- trunk/Source/WebCore/editing/InsertEditableImageCommand.cpp	2019-01-23 05:55:08 UTC (rev 240327)
+++ trunk/Source/WebCore/editing/InsertEditableImageCommand.cpp	2019-01-23 06:10:45 UTC (rev 240328)
@@ -49,10 +49,10 @@
         return;
 
     m_imageElement = HTMLImageElement::create(document());
-    m_imageElement->setAttributeWithoutSynchronization(x_apple_editable_imageAttr, emptyAtom());
-    m_imageElement->setAttributeWithoutSynchronization(widthAttr, AtomicString("100%", AtomicString::ConstructFromLiteral));
-    m_imageElement->setAttributeWithoutSynchronization(heightAttr, AtomicString("300px", AtomicString::ConstructFromLiteral));
-    m_imageElement->setAttributeWithoutSynchronization(styleAttr, AtomicString("display: block", AtomicString::ConstructFromLiteral));
+    m_imageElement->setAttributeWithoutSynchronization(HTMLNames::x_apple_editable_imageAttr, emptyAtom());
+    m_imageElement->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString("100%", AtomicString::ConstructFromLiteral));
+    m_imageElement->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString("300px", AtomicString::ConstructFromLiteral));
+    m_imageElement->setAttributeWithoutSynchronization(HTMLNames::styleAttr, AtomicString("display: block", AtomicString::ConstructFromLiteral));
 
     insertNodeAt(*m_imageElement, endingSelection().start());
     setEndingSelection(visiblePositionAfterNode(*m_imageElement));

Modified: trunk/Source/WebCore/page/UndoItem.h (240327 => 240328)


--- trunk/Source/WebCore/page/UndoItem.h	2019-01-23 05:55:08 UTC (rev 240327)
+++ trunk/Source/WebCore/page/UndoItem.h	2019-01-23 06:10:45 UTC (rev 240328)
@@ -36,7 +36,7 @@
 class Document;
 class UndoManager;
 
-class UndoItem : public RefCounted<UndoItem> {
+class UndoItem : public RefCounted<UndoItem>, public CanMakeWeakPtr<UndoItem> {
     WTF_MAKE_ISO_ALLOCATED(UndoItem);
 public:
     struct Init {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to