Title: [281668] trunk/Source/WebKit
Revision
281668
Author
wenson_hs...@apple.com
Date
2021-08-26 16:02:17 -0700 (Thu, 26 Aug 2021)

Log Message

Add type-safe transaction identifiers for EditorState and FocusedElementInformation
https://bugs.webkit.org/show_bug.cgi?id=229571

Reviewed by Tim Horton.

Make `transactionID` a monotonic object identifier instead of a generic `TransactionID`, and replace
`FocusedElementIdentifier` (which is currently type-defined to `uint64_t`) with its own monotonic object
identifier type.

In a future patch, I plan to implement a mechanism to synchronize `EditorState` and `FocusedElementInformation`
updates, which would require one or both of these objects to hold both types of transactional identifiers; in
order to do this, we need to ensure that these two identifiers are distinct types, so that they can't be easily
mixed up.

* Shared/EditorState.cpp:
(WebKit::EditorState::encode const):
(WebKit::EditorState::decode):
* Shared/EditorState.h:
* Shared/FocusedElementInformation.cpp:
(WebKit::FocusedElementInformation::encode const):
(WebKit::FocusedElementInformation::decode):
* Shared/FocusedElementInformation.h:
* Shared/IdentifierTypes.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::updateEditorState):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView updateCurrentFocusedElementInformation:]):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):
(WebKit::WebPage::elementDidFocus):
* WebProcess/WebPage/WebPage.h:

Additionally rename `m_currentFocusedElementIdentifier` to `m_lastFocusedElementInformationIdentifier`, for
consistency with `m_lastEditorStateIdentifier`.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::focusedElementInformation):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (281667 => 281668)


--- trunk/Source/WebKit/ChangeLog	2021-08-26 22:50:10 UTC (rev 281667)
+++ trunk/Source/WebKit/ChangeLog	2021-08-26 23:02:17 UTC (rev 281668)
@@ -1,3 +1,43 @@
+2021-08-26  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Add type-safe transaction identifiers for EditorState and FocusedElementInformation
+        https://bugs.webkit.org/show_bug.cgi?id=229571
+
+        Reviewed by Tim Horton.
+
+        Make `transactionID` a monotonic object identifier instead of a generic `TransactionID`, and replace
+        `FocusedElementIdentifier` (which is currently type-defined to `uint64_t`) with its own monotonic object
+        identifier type.
+
+        In a future patch, I plan to implement a mechanism to synchronize `EditorState` and `FocusedElementInformation`
+        updates, which would require one or both of these objects to hold both types of transactional identifiers; in
+        order to do this, we need to ensure that these two identifiers are distinct types, so that they can't be easily
+        mixed up.
+
+        * Shared/EditorState.cpp:
+        (WebKit::EditorState::encode const):
+        (WebKit::EditorState::decode):
+        * Shared/EditorState.h:
+        * Shared/FocusedElementInformation.cpp:
+        (WebKit::FocusedElementInformation::encode const):
+        (WebKit::FocusedElementInformation::decode):
+        * Shared/FocusedElementInformation.h:
+        * Shared/IdentifierTypes.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::updateEditorState):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView updateCurrentFocusedElementInformation:]):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::editorState const):
+        (WebKit::WebPage::elementDidFocus):
+        * WebProcess/WebPage/WebPage.h:
+
+        Additionally rename `m_currentFocusedElementIdentifier` to `m_lastFocusedElementInformationIdentifier`, for
+        consistency with `m_lastEditorStateIdentifier`.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::focusedElementInformation):
+
 2021-08-26  Cameron McCormack  <hey...@apple.com>
 
         Manually release SharedBitmap if CGBitmapContextCreateWithData fails and doesn't do it

Modified: trunk/Source/WebKit/Shared/EditorState.cpp (281667 => 281668)


--- trunk/Source/WebKit/Shared/EditorState.cpp	2021-08-26 22:50:10 UTC (rev 281667)
+++ trunk/Source/WebKit/Shared/EditorState.cpp	2021-08-26 23:02:17 UTC (rev 281668)
@@ -34,7 +34,7 @@
 
 void EditorState::encode(IPC::Encoder& encoder) const
 {
-    encoder << transactionID;
+    encoder << identifier;
     encoder << originIdentifierForPasteboard;
     encoder << shouldIgnoreSelectionChanges;
     encoder << selectionIsNone;
@@ -53,7 +53,7 @@
 
 bool EditorState::decode(IPC::Decoder& decoder, EditorState& result)
 {
-    if (!decoder.decode(result.transactionID))
+    if (!decoder.decode(result.identifier))
         return false;
 
     if (!decoder.decode(result.originIdentifierForPasteboard))

Modified: trunk/Source/WebKit/Shared/EditorState.h (281667 => 281668)


--- trunk/Source/WebKit/Shared/EditorState.h	2021-08-26 22:50:10 UTC (rev 281667)
+++ trunk/Source/WebKit/Shared/EditorState.h	2021-08-26 23:02:17 UTC (rev 281668)
@@ -26,7 +26,7 @@
 #pragma once
 
 #include "ArgumentCoders.h"
-#include "TransactionID.h"
+#include "IdentifierTypes.h"
 #include <WebCore/Color.h>
 #include <WebCore/FontAttributes.h>
 #include <WebCore/IntRect.h>
@@ -70,7 +70,7 @@
 };
 
 struct EditorState {
-    TransactionID transactionID;
+    EditorStateIdentifier identifier;
     String originIdentifierForPasteboard;
     bool shouldIgnoreSelectionChanges { false };
     bool selectionIsNone { true }; // This will be false when there is a caret selection.

Modified: trunk/Source/WebKit/Shared/FocusedElementInformation.cpp (281667 => 281668)


--- trunk/Source/WebKit/Shared/FocusedElementInformation.cpp	2021-08-26 22:50:10 UTC (rev 281667)
+++ trunk/Source/WebKit/Shared/FocusedElementInformation.cpp	2021-08-26 23:02:17 UTC (rev 281668)
@@ -98,7 +98,7 @@
     encoder << placeholder;
     encoder << label;
     encoder << ariaLabel;
-    encoder << focusedElementIdentifier;
+    encoder << identifier;
     encoder << containerScrollingNodeID;
 #if ENABLE(DATALIST_ELEMENT)
     encoder << hasSuggestions;
@@ -223,7 +223,7 @@
     if (!decoder.decode(result.ariaLabel))
         return false;
 
-    if (!decoder.decode(result.focusedElementIdentifier))
+    if (!decoder.decode(result.identifier))
         return false;
 
     if (!decoder.decode(result.containerScrollingNodeID))

Modified: trunk/Source/WebKit/Shared/FocusedElementInformation.h (281667 => 281668)


--- trunk/Source/WebKit/Shared/FocusedElementInformation.h	2021-08-26 22:50:10 UTC (rev 281667)
+++ trunk/Source/WebKit/Shared/FocusedElementInformation.h	2021-08-26 23:02:17 UTC (rev 281668)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "ArgumentCoders.h"
+#include "IdentifierTypes.h"
 #include <WebCore/AutocapitalizeTypes.h>
 #include <WebCore/Autofill.h>
 #include <WebCore/Color.h>
@@ -87,8 +88,6 @@
     static std::optional<OptionItem> decode(IPC::Decoder&);
 };
 
-using FocusedElementIdentifier = uint64_t;
-
 struct FocusedElementInformation {
     WebCore::IntRect interactionRect;
     WebCore::ElementContext elementContext;
@@ -140,7 +139,7 @@
     bool shouldUseLegacySelectPopoverDismissalBehaviorInDataActivation { false };
     bool isFocusingWithValidationMessage { false };
 
-    FocusedElementIdentifier focusedElementIdentifier { 0 };
+    FocusedElementInformationIdentifier identifier;
     WebCore::ScrollingNodeID containerScrollingNodeID { 0 };
 
     void encode(IPC::Encoder&) const;

Modified: trunk/Source/WebKit/Shared/IdentifierTypes.h (281667 => 281668)


--- trunk/Source/WebKit/Shared/IdentifierTypes.h	2021-08-26 22:50:10 UTC (rev 281667)
+++ trunk/Source/WebKit/Shared/IdentifierTypes.h	2021-08-26 23:02:17 UTC (rev 281668)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "MonotonicObjectIdentifier.h"
 #include <wtf/ObjectIdentifier.h>
 
 namespace WebKit {
@@ -41,4 +42,10 @@
 enum TextCheckerRequestType { };
 using TextCheckerRequestID = ObjectIdentifier<TextCheckerRequestType>;
 
+enum EditorStateIdentifierType { };
+using EditorStateIdentifier = MonotonicObjectIdentifier<EditorStateIdentifierType>;
+
+enum FocusedElementInformationIdentifierType { };
+using FocusedElementInformationIdentifier = MonotonicObjectIdentifier<FocusedElementInformationIdentifierType>;
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (281667 => 281668)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-08-26 22:50:10 UTC (rev 281667)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-08-26 23:02:17 UTC (rev 281668)
@@ -7459,7 +7459,7 @@
 
 bool WebPageProxy::updateEditorState(const EditorState& newEditorState)
 {
-    if (newEditorState.transactionID < m_editorState.transactionID)
+    if (newEditorState.identifier < m_editorState.identifier)
         return false;
 
     auto oldEditorState = std::exchange(m_editorState, newEditorState);

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (281667 => 281668)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2021-08-26 22:50:10 UTC (rev 281667)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2021-08-26 23:02:17 UTC (rev 281668)
@@ -6684,9 +6684,9 @@
 - (void)updateCurrentFocusedElementInformation:(Function<void(bool didUpdate)>&&)callback
 {
     WeakObjCPtr<WKContentView> weakSelf { self };
-    auto identifierBeforeUpdate = _focusedElementInformation.focusedElementIdentifier;
+    auto identifierBeforeUpdate = _focusedElementInformation.identifier;
     _page->requestFocusedElementInformation([callback = WTFMove(callback), identifierBeforeUpdate, weakSelf] (auto& info) {
-        if (!weakSelf || !info || info->focusedElementIdentifier != identifierBeforeUpdate) {
+        if (!weakSelf || !info || info->identifier != identifierBeforeUpdate) {
             // If the focused element may have changed in the meantime, don't overwrite focused element information.
             callback(false);
             return;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (281667 => 281668)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-08-26 22:50:10 UTC (rev 281667)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-08-26 23:02:17 UTC (rev 281668)
@@ -1225,7 +1225,7 @@
     const VisibleSelection& selection = frame->selection().selection();
     auto& editor = frame->editor();
 
-    result.transactionID = m_lastEditorStateTransactionID.increment();
+    result.identifier = m_lastEditorStateIdentifier.increment();
     result.selectionIsNone = selection.isNone();
     result.selectionIsRange = selection.isRange();
     result.isContentEditable = selection.isContentEditable();
@@ -6031,7 +6031,6 @@
             element.document().fullscreenManager().cancelFullscreen();
 #endif
 
-        ++m_currentFocusedElementIdentifier;
         auto information = focusedElementInformation();
         if (!information)
             return;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (281667 => 281668)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-08-26 22:50:10 UTC (rev 281667)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-08-26 23:02:17 UTC (rev 281668)
@@ -2243,7 +2243,7 @@
     WebCore::FloatRect m_previousExposedContentRect;
     OptionSet<WebKit::WebEvent::Modifier> m_pendingSyntheticClickModifiers;
     WebCore::PointerID m_pendingSyntheticClickPointerId { 0 };
-    FocusedElementIdentifier m_currentFocusedElementIdentifier { 0 };
+    FocusedElementInformationIdentifier m_lastFocusedElementInformationIdentifier;
     std::optional<DynamicViewportSizeUpdateID> m_pendingDynamicViewportSizeUpdateID;
     double m_lastTransactionPageScaleFactor { 0 };
     TransactionID m_lastTransactionIDWithScaleChange;
@@ -2282,7 +2282,7 @@
 
     enum class EditorStateIsContentEditable { No, Yes, Unset };
     mutable EditorStateIsContentEditable m_lastEditorStateWasContentEditable { EditorStateIsContentEditable::Unset };
-    mutable TransactionID m_lastEditorStateTransactionID;
+    mutable EditorStateIdentifier m_lastEditorStateIdentifier;
 
 #if PLATFORM(GTK) || PLATFORM(WPE)
     std::optional<InputMethodState> m_inputMethodState;

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (281667 => 281668)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2021-08-26 22:50:10 UTC (rev 281667)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2021-08-26 23:02:17 UTC (rev 281668)
@@ -3226,7 +3226,7 @@
         information.previousNodeRect = rootViewBounds(*previousElement);
         information.hasPreviousNode = true;
     }
-    information.focusedElementIdentifier = m_currentFocusedElementIdentifier;
+    information.identifier = m_lastFocusedElementInformationIdentifier.increment();
 
     if (is<LabelableElement>(*focusedElement)) {
         if (auto labels = downcast<LabelableElement>(*focusedElement).labels()) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to