WebUndoStep's monotonically increasing identifier should be a WebUndoStepID instead...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Jan 2019 15:34:34 +0000 (15:34 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Jan 2019 15:34:34 +0000 (15:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193100

Reviewed by Simon Fraser.

Add a type alias, WebUndoStepID, to represent the monotonically increasing undo step ID for each undoable
editing command, and use this type alias in lieu of `uint64_t`. No change in behavior.

* UIProcess/WebEditCommandProxy.cpp:
(WebKit::WebEditCommandProxy::WebEditCommandProxy):
* UIProcess/WebEditCommandProxy.h:
(WebKit::WebEditCommandProxy::create):
(WebKit::WebEditCommandProxy::commandID const):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::registerEditCommandForUndo):
* UIProcess/WebPageProxy.h:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::registerUndoStep):

Store the step ID in a temporary variable, since `webUndoStep` is now moved when calling `addWebUndoStep`.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::webUndoStep):
(WebKit::WebPage::addWebUndoStep):

Make this take a `Ref<WebUndoStep>&&` instead of a `WebUndoStep*`, and use move semantics to transfer the
given `Ref` to the table.

(WebKit::WebPage::removeWebEditCommand):
(WebKit::WebPage::unapplyEditCommand):
(WebKit::WebPage::reapplyEditCommand):

Use `auto*` in a couple of places.

(WebKit::WebPage::didRemoveEditCommand):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebUndoStep.cpp:
(WebKit::generateUndoStep):
* WebProcess/WebPage/WebUndoStep.h:
(WebKit::WebUndoStep::stepID const):
(WebKit::WebUndoStep::WebUndoStep):
* WebProcess/WebPage/WebUndoStepID.h: Copied from Source/WebKit/WebProcess/WebPage/WebUndoStep.cpp.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239589 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/WebEditCommandProxy.cpp
Source/WebKit/UIProcess/WebEditCommandProxy.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebUndoStep.cpp
Source/WebKit/WebProcess/WebPage/WebUndoStep.h
Source/WebKit/WebProcess/WebPage/WebUndoStepID.h [new file with mode: 0644]

index ff74565..a9590e8 100644 (file)
@@ -1,3 +1,49 @@
+2019-01-03  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        WebUndoStep's monotonically increasing identifier should be a WebUndoStepID instead of uint64_t
+        https://bugs.webkit.org/show_bug.cgi?id=193100
+
+        Reviewed by Simon Fraser.
+
+        Add a type alias, WebUndoStepID, to represent the monotonically increasing undo step ID for each undoable
+        editing command, and use this type alias in lieu of `uint64_t`. No change in behavior.
+
+        * UIProcess/WebEditCommandProxy.cpp:
+        (WebKit::WebEditCommandProxy::WebEditCommandProxy):
+        * UIProcess/WebEditCommandProxy.h:
+        (WebKit::WebEditCommandProxy::create):
+        (WebKit::WebEditCommandProxy::commandID const):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::registerEditCommandForUndo):
+        * UIProcess/WebPageProxy.h:
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::registerUndoStep):
+
+        Store the step ID in a temporary variable, since `webUndoStep` is now moved when calling `addWebUndoStep`.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::webUndoStep):
+        (WebKit::WebPage::addWebUndoStep):
+
+        Make this take a `Ref<WebUndoStep>&&` instead of a `WebUndoStep*`, and use move semantics to transfer the
+        given `Ref` to the table.
+
+        (WebKit::WebPage::removeWebEditCommand):
+        (WebKit::WebPage::unapplyEditCommand):
+        (WebKit::WebPage::reapplyEditCommand):
+
+        Use `auto*` in a couple of places.
+
+        (WebKit::WebPage::didRemoveEditCommand):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebUndoStep.cpp:
+        (WebKit::generateUndoStep):
+        * WebProcess/WebPage/WebUndoStep.h:
+        (WebKit::WebUndoStep::stepID const):
+        (WebKit::WebUndoStep::WebUndoStep):
+        * WebProcess/WebPage/WebUndoStepID.h: Copied from Source/WebKit/WebProcess/WebPage/WebUndoStep.cpp.
+
 2019-01-02  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Add support for using the current text selection as the find string on iOS
index a526477..f9ac146 100644 (file)
@@ -36,7 +36,7 @@
 namespace WebKit {
 using namespace WebCore;
 
-WebEditCommandProxy::WebEditCommandProxy(uint64_t commandID, WebCore::EditAction editAction, WebPageProxy* page)
+WebEditCommandProxy::WebEditCommandProxy(WebUndoStepID commandID, WebCore::EditAction editAction, WebPageProxy* page)
     : m_commandID(commandID)
     , m_editAction(editAction)
     , m_page(page)
index 070906f..b4e767f 100644 (file)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "APIObject.h"
+#include "WebUndoStepID.h"
 #include <WebCore/EditAction.h>
 #include <wtf/Forward.h>
 #include <wtf/RefCounted.h>
@@ -37,13 +38,13 @@ class WebPageProxy;
 
 class WebEditCommandProxy : public API::ObjectImpl<API::Object::Type::EditCommandProxy> {
 public:
-    static Ref<WebEditCommandProxy> create(uint64_t commandID, WebCore::EditAction editAction, WebPageProxy* page)
+    static Ref<WebEditCommandProxy> create(WebUndoStepID commandID, WebCore::EditAction editAction, WebPageProxy* page)
     {
         return adoptRef(*new WebEditCommandProxy(commandID, editAction, page));
     }
     ~WebEditCommandProxy();
 
-    uint64_t commandID() const { return m_commandID; }
+    WebUndoStepID commandID() const { return m_commandID; }
     WebCore::EditAction editAction() const { return m_editAction; }
 
     void invalidate() { m_page = 0; }
@@ -54,9 +55,9 @@ public:
     static String nameForEditAction(WebCore::EditAction);
 
 private:
-    WebEditCommandProxy(uint64_t commandID, WebCore::EditAction, WebPageProxy*);
+    WebEditCommandProxy(WebUndoStepID commandID, WebCore::EditAction, WebPageProxy*);
 
-    uint64_t m_commandID;
+    WebUndoStepID m_commandID;
     WebCore::EditAction m_editAction;
     WebPageProxy* m_page;
 };
index 9db7071..da7a94a 100644 (file)
@@ -5340,7 +5340,7 @@ void WebPageProxy::compositionWasCanceled()
 
 // Undo management
 
-void WebPageProxy::registerEditCommandForUndo(uint64_t commandID, uint32_t editAction)
+void WebPageProxy::registerEditCommandForUndo(WebUndoStepID commandID, uint32_t editAction)
 {
     registerEditCommand(WebEditCommandProxy::create(commandID, static_cast<EditAction>(editAction), this), UndoOrRedo::Undo);
 }
index 52834e6..18bf810 100644 (file)
@@ -65,6 +65,7 @@
 #include "WebPageProxyMessages.h"
 #include "WebPopupMenuProxy.h"
 #include "WebProcessLifetimeTracker.h"
+#include "WebUndoStepID.h"
 #include "WebsitePoliciesData.h"
 #include <WebCore/ActivityState.h>
 #include <WebCore/AutoplayEvent.h>
@@ -1615,7 +1616,7 @@ private:
     void backForwardClear();
 
     // Undo management
-    void registerEditCommandForUndo(uint64_t commandID, uint32_t editAction);
+    void registerEditCommandForUndo(WebUndoStepID commandID, uint32_t editAction);
     void registerInsertionUndoGrouping();
     void clearAllEditCommands();
     void canUndoRedo(UndoOrRedo, bool& result);
index 743d012..92dd695 100644 (file)
                F48D2A8421583A0200C6752B /* AppKitSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppKitSPI.h; sourceTree = "<group>"; };
                F496A42F1F58A272004C1757 /* DragDropInteractionState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DragDropInteractionState.h; path = ios/DragDropInteractionState.h; sourceTree = "<group>"; };
                F496A4301F58A272004C1757 /* DragDropInteractionState.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = DragDropInteractionState.mm; path = ios/DragDropInteractionState.mm; sourceTree = "<group>"; };
+               F4B378D021DDBBAB0095A378 /* WebUndoStepID.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebUndoStepID.h; sourceTree = "<group>"; };
                F4D5F519206087A00038BBA8 /* WKTextInputListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKTextInputListViewController.h; path = ios/forms/WKTextInputListViewController.h; sourceTree = "<group>"; };
                F4D5F51A206087A10038BBA8 /* WKTextInputListViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKTextInputListViewController.mm; path = ios/forms/WKTextInputListViewController.mm; sourceTree = "<group>"; };
                F4D5F51B206087A10038BBA8 /* WKQuickboardListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKQuickboardListViewController.h; path = ios/forms/WKQuickboardListViewController.h; sourceTree = "<group>"; };
                                2D5C9D0419C81D8F00B3C5C1 /* WebPageOverlay.h */,
                                BCA0EF7E12331E78007D3CFB /* WebUndoStep.cpp */,
                                BCA0EF7D12331E78007D3CFB /* WebUndoStep.h */,
+                               F4B378D021DDBBAB0095A378 /* WebUndoStepID.h */,
                                51D1242A1E6D41BC002B2820 /* WebURLSchemeHandlerProxy.cpp */,
                                51D1242B1E6D41BC002B2820 /* WebURLSchemeHandlerProxy.h */,
                                51D124211E6D349A002B2820 /* WebURLSchemeTaskProxy.cpp */,
index ab3367a..0094e35 100644 (file)
@@ -310,10 +310,11 @@ void WebEditorClient::registerUndoStep(UndoStep& step)
         return;
 
     auto webStep = WebUndoStep::create(step);
+    auto stepID = webStep->stepID();
     auto editAction = static_cast<uint32_t>(webStep->step().editingAction());
 
-    m_page->addWebUndoStep(webStep->stepID(), webStep.ptr());
-    m_page->send(Messages::WebPageProxy::RegisterEditCommandForUndo(webStep->stepID(), editAction), m_page->pageID(), IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
+    m_page->addWebUndoStep(stepID, WTFMove(webStep));
+    m_page->send(Messages::WebPageProxy::RegisterEditCommandForUndo(stepID, editAction), m_page->pageID(), IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
 }
 
 void WebEditorClient::registerRedoStep(UndoStep&)
index d161624..a97901d 100644 (file)
@@ -3765,17 +3765,17 @@ void WebPage::dragCancelled()
     
 #endif // ENABLE(DRAG_SUPPORT)
 
-WebUndoStep* WebPage::webUndoStep(uint64_t stepID)
+WebUndoStep* WebPage::webUndoStep(WebUndoStepID stepID)
 {
     return m_undoStepMap.get(stepID);
 }
 
-void WebPage::addWebUndoStep(uint64_t stepID, WebUndoStep* entry)
+void WebPage::addWebUndoStep(WebUndoStepID stepID, Ref<WebUndoStep>&& entry)
 {
-    m_undoStepMap.set(stepID, entry);
+    m_undoStepMap.set(stepID, WTFMove(entry));
 }
 
-void WebPage::removeWebEditCommand(uint64_t stepID)
+void WebPage::removeWebEditCommand(WebUndoStepID stepID)
 {
     m_undoStepMap.remove(stepID);
 }
@@ -3785,18 +3785,18 @@ bool WebPage::isAlwaysOnLoggingAllowed() const
     return corePage() && corePage()->isAlwaysOnLoggingAllowed();
 }
 
-void WebPage::unapplyEditCommand(uint64_t stepID)
+void WebPage::unapplyEditCommand(WebUndoStepID stepID)
 {
-    WebUndoStep* step = webUndoStep(stepID);
+    auto* step = webUndoStep(stepID);
     if (!step)
         return;
 
     step->step().unapply();
 }
 
-void WebPage::reapplyEditCommand(uint64_t stepID)
+void WebPage::reapplyEditCommand(WebUndoStepID stepID)
 {
-    WebUndoStep* step = webUndoStep(stepID);
+    auto* step = webUndoStep(stepID);
     if (!step)
         return;
 
@@ -3805,7 +3805,7 @@ void WebPage::reapplyEditCommand(uint64_t stepID)
     m_isInRedo = false;
 }
 
-void WebPage::didRemoveEditCommand(uint64_t commandID)
+void WebPage::didRemoveEditCommand(WebUndoStepID commandID)
 {
     removeWebEditCommand(commandID);
 }
index d8b8b30..0b42a61 100644 (file)
@@ -50,6 +50,7 @@
 #include "UserData.h"
 #include "WebBackForwardListProxy.h"
 #include "WebURLSchemeHandler.h"
+#include "WebUndoStepID.h"
 #include "WebUserContentController.h"
 #include "WebsitePoliciesData.h"
 #include <JavaScriptCore/InspectorFrontendChannel.h>
@@ -355,9 +356,9 @@ public:
 
     const String& overrideContentSecurityPolicy() const { return m_overrideContentSecurityPolicy; }
 
-    WebUndoStep* webUndoStep(uint64_t);
-    void addWebUndoStep(uint64_t, WebUndoStep*);
-    void removeWebEditCommand(uint64_t);
+    WebUndoStep* webUndoStep(WebUndoStepID);
+    void addWebUndoStep(WebUndoStepID, Ref<WebUndoStep>&&);
+    void removeWebEditCommand(WebUndoStepID);
     bool isInRedo() const { return m_isInRedo; }
 
     bool isAlwaysOnLoggingAllowed() const;
@@ -1324,9 +1325,9 @@ private:
 
     void setMainFrameIsScrollable(bool);
 
-    void unapplyEditCommand(uint64_t commandID);
-    void reapplyEditCommand(uint64_t commandID);
-    void didRemoveEditCommand(uint64_t commandID);
+    void unapplyEditCommand(WebUndoStepID commandID);
+    void reapplyEditCommand(WebUndoStepID commandID);
+    void didRemoveEditCommand(WebUndoStepID commandID);
 
     void findString(const String&, uint32_t findOptions, uint32_t maxMatchCount);
     void findStringMatches(const String&, uint32_t findOptions, uint32_t maxMatchCount);
@@ -1574,7 +1575,7 @@ private:
     RunLoop::Timer<WebPage> m_setCanStartMediaTimer;
     bool m_mayStartMediaWhenInWindow { false };
 
-    HashMap<uint64_t, RefPtr<WebUndoStep>> m_undoStepMap;
+    HashMap<WebUndoStepID, RefPtr<WebUndoStep>> m_undoStepMap;
 
 #if ENABLE(CONTEXT_MENUS)
     std::unique_ptr<API::InjectedBundle::PageContextMenuClient> m_contextMenuClient;
index 55ec550..1762c84 100644 (file)
@@ -28,9 +28,9 @@
 
 namespace WebKit {
 
-static uint64_t generateUndoStep()
+static WebUndoStepID generateUndoStep()
 {
-    static uint64_t uniqueEntryID = 1;
+    static WebUndoStepID uniqueEntryID = 1;
     return uniqueEntryID++;
 }
 
index 9b6fcf8..211fd99 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "WebUndoStepID.h"
 #include <WebCore/UndoStep.h>
 #include <wtf/Ref.h>
 
@@ -36,17 +37,17 @@ public:
     ~WebUndoStep();
 
     WebCore::UndoStep& step() const { return m_step.get(); }
-    uint64_t stepID() const { return m_stepID; }
+    WebUndoStepID stepID() const { return m_stepID; }
 
 private:
-    WebUndoStep(Ref<WebCore::UndoStep>&& step, uint64_t stepID)
+    WebUndoStep(Ref<WebCore::UndoStep>&& step, WebUndoStepID stepID)
         : m_step(WTFMove(step))
         , m_stepID(stepID)
     {
     }
 
     Ref<WebCore::UndoStep> m_step;
-    uint64_t m_stepID;
+    WebUndoStepID m_stepID;
 };
 
 } // namespace WebKit
diff --git a/Source/WebKit/WebProcess/WebPage/WebUndoStepID.h b/Source/WebKit/WebProcess/WebPage/WebUndoStepID.h
new file mode 100644 (file)
index 0000000..7fafc8f
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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
+
+using WebUndoStepID = uint64_t;