⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 281668 in webkit


Ignore:
Timestamp:
Aug 26, 2021, 4:02:17 PM (5 years ago)
Author:
Wenson Hsieh
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):

Location:
trunk/Source/WebKit
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r281661 r281668  
     12021-08-26  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add type-safe transaction identifiers for EditorState and FocusedElementInformation
     4        https://bugs.webkit.org/show_bug.cgi?id=229571
     5
     6        Reviewed by Tim Horton.
     7
     8        Make `transactionID` a monotonic object identifier instead of a generic `TransactionID`, and replace
     9        `FocusedElementIdentifier` (which is currently type-defined to `uint64_t`) with its own monotonic object
     10        identifier type.
     11
     12        In a future patch, I plan to implement a mechanism to synchronize `EditorState` and `FocusedElementInformation`
     13        updates, which would require one or both of these objects to hold both types of transactional identifiers; in
     14        order to do this, we need to ensure that these two identifiers are distinct types, so that they can't be easily
     15        mixed up.
     16
     17        * Shared/EditorState.cpp:
     18        (WebKit::EditorState::encode const):
     19        (WebKit::EditorState::decode):
     20        * Shared/EditorState.h:
     21        * Shared/FocusedElementInformation.cpp:
     22        (WebKit::FocusedElementInformation::encode const):
     23        (WebKit::FocusedElementInformation::decode):
     24        * Shared/FocusedElementInformation.h:
     25        * Shared/IdentifierTypes.h:
     26        * UIProcess/WebPageProxy.cpp:
     27        (WebKit::WebPageProxy::updateEditorState):
     28        * UIProcess/ios/WKContentViewInteraction.mm:
     29        (-[WKContentView updateCurrentFocusedElementInformation:]):
     30        * WebProcess/WebPage/WebPage.cpp:
     31        (WebKit::WebPage::editorState const):
     32        (WebKit::WebPage::elementDidFocus):
     33        * WebProcess/WebPage/WebPage.h:
     34
     35        Additionally rename `m_currentFocusedElementIdentifier` to `m_lastFocusedElementInformationIdentifier`, for
     36        consistency with `m_lastEditorStateIdentifier`.
     37
     38        * WebProcess/WebPage/ios/WebPageIOS.mm:
     39        (WebKit::WebPage::focusedElementInformation):
     40
    1412021-08-26  Cameron McCormack  <heycam@apple.com>
    242
  • trunk/Source/WebKit/Shared/EditorState.cpp

    r280019 r281668  
    3535void EditorState::encode(IPC::Encoder& encoder) const
    3636{
    37     encoder << transactionID;
     37    encoder << identifier;
    3838    encoder << originIdentifierForPasteboard;
    3939    encoder << shouldIgnoreSelectionChanges;
     
    5454bool EditorState::decode(IPC::Decoder& decoder, EditorState& result)
    5555{
    56     if (!decoder.decode(result.transactionID))
     56    if (!decoder.decode(result.identifier))
    5757        return false;
    5858
  • trunk/Source/WebKit/Shared/EditorState.h

    r280019 r281668  
    2727
    2828#include "ArgumentCoders.h"
    29 #include "TransactionID.h"
     29#include "IdentifierTypes.h"
    3030#include <WebCore/Color.h>
    3131#include <WebCore/FontAttributes.h>
     
    7171
    7272struct EditorState {
    73     TransactionID transactionID;
     73    EditorStateIdentifier identifier;
    7474    String originIdentifierForPasteboard;
    7575    bool shouldIgnoreSelectionChanges { false };
  • trunk/Source/WebKit/Shared/FocusedElementInformation.cpp

    r278253 r281668  
    9999    encoder << label;
    100100    encoder << ariaLabel;
    101     encoder << focusedElementIdentifier;
     101    encoder << identifier;
    102102    encoder << containerScrollingNodeID;
    103103#if ENABLE(DATALIST_ELEMENT)
     
    224224        return false;
    225225
    226     if (!decoder.decode(result.focusedElementIdentifier))
     226    if (!decoder.decode(result.identifier))
    227227        return false;
    228228
  • trunk/Source/WebKit/Shared/FocusedElementInformation.h

    r278253 r281668  
    2727
    2828#include "ArgumentCoders.h"
     29#include "IdentifierTypes.h"
    2930#include <WebCore/AutocapitalizeTypes.h>
    3031#include <WebCore/Autofill.h>
     
    8889};
    8990
    90 using FocusedElementIdentifier = uint64_t;
    91 
    9291struct FocusedElementInformation {
    9392    WebCore::IntRect interactionRect;
     
    141140    bool isFocusingWithValidationMessage { false };
    142141
    143     FocusedElementIdentifier focusedElementIdentifier { 0 };
     142    FocusedElementInformationIdentifier identifier;
    144143    WebCore::ScrollingNodeID containerScrollingNodeID { 0 };
    145144
  • trunk/Source/WebKit/Shared/IdentifierTypes.h

    r281606 r281668  
    2626#pragma once
    2727
     28#include "MonotonicObjectIdentifier.h"
    2829#include <wtf/ObjectIdentifier.h>
    2930
     
    4243using TextCheckerRequestID = ObjectIdentifier<TextCheckerRequestType>;
    4344
     45enum EditorStateIdentifierType { };
     46using EditorStateIdentifier = MonotonicObjectIdentifier<EditorStateIdentifierType>;
     47
     48enum FocusedElementInformationIdentifierType { };
     49using FocusedElementInformationIdentifier = MonotonicObjectIdentifier<FocusedElementInformationIdentifierType>;
     50
    4451} // namespace WebKit
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r281606 r281668  
    74607460bool WebPageProxy::updateEditorState(const EditorState& newEditorState)
    74617461{
    7462     if (newEditorState.transactionID < m_editorState.transactionID)
     7462    if (newEditorState.identifier < m_editorState.identifier)
    74637463        return false;
    74647464
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r281646 r281668  
    66856685{
    66866686    WeakObjCPtr<WKContentView> weakSelf { self };
    6687     auto identifierBeforeUpdate = _focusedElementInformation.focusedElementIdentifier;
     6687    auto identifierBeforeUpdate = _focusedElementInformation.identifier;
    66886688    _page->requestFocusedElementInformation([callback = WTFMove(callback), identifierBeforeUpdate, weakSelf] (auto& info) {
    6689         if (!weakSelf || !info || info->focusedElementIdentifier != identifierBeforeUpdate) {
     6689        if (!weakSelf || !info || info->identifier != identifierBeforeUpdate) {
    66906690            // If the focused element may have changed in the meantime, don't overwrite focused element information.
    66916691            callback(false);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r281606 r281668  
    12261226    auto& editor = frame->editor();
    12271227
    1228     result.transactionID = m_lastEditorStateTransactionID.increment();
     1228    result.identifier = m_lastEditorStateIdentifier.increment();
    12291229    result.selectionIsNone = selection.isNone();
    12301230    result.selectionIsRange = selection.isRange();
     
    60326032#endif
    60336033
    6034         ++m_currentFocusedElementIdentifier;
    60356034        auto information = focusedElementInformation();
    60366035        if (!information)
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r281606 r281668  
    22442244    OptionSet<WebKit::WebEvent::Modifier> m_pendingSyntheticClickModifiers;
    22452245    WebCore::PointerID m_pendingSyntheticClickPointerId { 0 };
    2246     FocusedElementIdentifier m_currentFocusedElementIdentifier { 0 };
     2246    FocusedElementInformationIdentifier m_lastFocusedElementInformationIdentifier;
    22472247    std::optional<DynamicViewportSizeUpdateID> m_pendingDynamicViewportSizeUpdateID;
    22482248    double m_lastTransactionPageScaleFactor { 0 };
     
    22832283    enum class EditorStateIsContentEditable { No, Yes, Unset };
    22842284    mutable EditorStateIsContentEditable m_lastEditorStateWasContentEditable { EditorStateIsContentEditable::Unset };
    2285     mutable TransactionID m_lastEditorStateTransactionID;
     2285    mutable EditorStateIdentifier m_lastEditorStateIdentifier;
    22862286
    22872287#if PLATFORM(GTK) || PLATFORM(WPE)
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r281450 r281668  
    32273227        information.hasPreviousNode = true;
    32283228    }
    3229     information.focusedElementIdentifier = m_currentFocusedElementIdentifier;
     3229    information.identifier = m_lastFocusedElementInformationIdentifier.increment();
    32303230
    32313231    if (is<LabelableElement>(*focusedElement)) {
Note: See TracChangeset for help on using the changeset viewer.