[webkit-changes] [WebKit/WebKit] 490b4f: Introduce enum classes to identify and categorize ...

Ryosuke Niwa noreply at github.com
Mon Jan 8 23:09:33 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 490b4fdda464141c8eedb0ec367dbf76c6077a77
      https://github.com/WebKit/WebKit/commit/490b4fdda464141c8eedb0ec367dbf76c6077a77
  Author: Ryosuke Niwa <rniwa at webkit.org>
  Date:   2024-01-08 (Mon, 08 Jan 2024)

  Changed paths:
    M Source/WebCore/dom/Document.cpp
    M Source/WebCore/dom/Document.h
    M Source/WebCore/dom/EventDispatcher.cpp
    M Source/WebCore/dom/EventListenerMap.h
    M Source/WebCore/dom/EventNames.json
    M Source/WebCore/dom/EventTarget.cpp
    M Source/WebCore/dom/EventTarget.h
    M Source/WebCore/dom/Node.cpp
    M Source/WebCore/dom/Node.h
    M Source/WebCore/dom/make-event-names.py
    M Source/WebCore/html/HTMLPlugInElement.cpp
    M Source/WebCore/html/HTMLPlugInElement.h
    M Source/WebCore/page/LocalDOMWindow.cpp
    M Source/WebCore/page/Quirks.cpp
    M Source/WebCore/page/Quirks.h
    M Source/WebKit/WebProcess/Plugins/PluginView.cpp

  Log Message:
  -----------
  Introduce enum classes to identify and categorize events
https://bugs.webkit.org/show_bug.cgi?id=267188

Reviewed by Yusuke Suzuki.

This PR introduces enum classes to uniquely identify and category builtin events.

EventType enum class has an unique value for each builtin event, and this allows various
functions to use a switch statement based on event types instead of having a sequence of
if-else statements.

EventCategory enum class bitfields identifies categories a given event belongs such as
TouchRelated and MouseMoveRelated. These categories are specified for each event in
EventNames.json by specifying "categories" array, which has been renamed from "types".

This PR replaces EventNames's is*EventType functions with checks for the corresponding
categories so that we would do a single HashMap lookup and a bitfield check instead of
a bunch of comparisons against AtomString's.

EventTypeInfo encompasses these two enum classes for a given event type as well as a flag
indicating whether a given event has default event handlers (C++ code which responds to
a given event dispatch), which is also specified in EventNames.json. In the future this
object can be extended to work like QualifiedName but for events.

Because event type names are AtomString, which is a thread specific object, a map of
event types to EventTypeInfo is stored in each thread's EventNames object using
MemoryCompactLookupOnlyRobinHoodHashMap.

In addition, this PR introduces the counters for each event type and plugin elements at
Document level so that EventDispatcher can circumvent EventPath construction and/or calls
to default event handlers.

* Source/WebCore/dom/Document.cpp:
(WebCore::Document::addListenerTypeIfNeeded):
(WebCore::Document::didAddEventListenersOfType): Added.
(WebCore::Document::didRemoveEventListenersOfType): Added.

* Source/WebCore/dom/Document.h:
(WebCore::Document::hasEventListnersOfType const): Added.
(WebCore::Document::hasConnectedPluginElements): Added.
(WebCore::Document::didConnectPluginElement): Added.
(WebCore::Document::didDisconnectPluginElement): Added.

* Source/WebCore/dom/EventDispatcher.cpp:
(WebCore::hasRelevantEventListener): Added.
(WebCore::resetAfterDispatchInShadowTree): Extracted from EventDispatcher::dispatchEvent.
(WebCore::EventDispatcher::dispatchEvent):

* Source/WebCore/dom/EventListenerMap.h:
(WebCore::EventListenerMap::enumerateEventListenerTypes): Added.

* Source/WebCore/dom/EventNames.json: Updated per the rename of "types" to "categories",
and the introduction of "defaultEventHandlers" flag, which indicates whether a given event
has default event handler behaviors or not.

* Source/WebCore/dom/EventTarget.cpp:
(WebCore::EventTarget::addEventListener):
(WebCore::EventTarget::removeEventListener):
(WebCore::EventTarget::legacyTypeForEvent): Renamed from legacyType and declared in the
header file so that EventDispatcher can use it.
(WebCore::EventTarget::fireEventListeners):

* Source/WebCore/dom/EventTarget.h:

* Source/WebCore/dom/Node.cpp:
(WebCore::Node::moveNodeToNewDocument):
(WebCore::isTouchRelatedEventType): Updated to use EventCategory bitfields.
(WebCore::tryAddEventListener): Notifies the document whenever an event listener is added.
(WebCore::tryRemoveEventListener): Ditto for removal.
(WebCore::Node::defaultEventHandler): Updated to use a switch statement and EventCategory
bitfields checks.
(WebCore::Node::willRespondToMouseMoveEvents const): Updated to use EventCategory checks.
(WebCore::Node::willRespondToTouchEvents const): Ditto.
(WebCore::Node::willRespondToMouseClickEventsWithEditability const): Ditto.

* Source/WebCore/dom/Node.h:

* Source/WebCore/dom/make-event-names.py:
(main): Now generates the code for EventType, EventCategory, and EventTypeInfo based on
the information newly available in EventNames.json.

* Source/WebCore/html/HTMLPlugInElement.cpp:
(WebCore::HTMLPlugInElement::insertedIntoAncestor): Added to notify the document when
a plugin element gets connected.
(WebCore::HTMLPlugInElement::removedFromAncestor): Ditto for disconnect.

* Source/WebCore/html/HTMLPlugInElement.h:

* Source/WebCore/page/LocalDOMWindow.cpp:
(WebCore::LocalDOMWindow::didSecureTransitionTo):
(WebCore::LocalDOMWindow::addEventListener): Updated to use a switch statement and
EventCategory bitfields checks. Also notify the document of a new event listener.
(WebCore::LocalDOMWindow::removeEventListener): Ditto for the removal.

* Source/WebCore/page/Quirks.cpp:
(WebCore::Quirks::shouldMakeEventListenerPassive): Now takes EventTypeInfo to do
EventCategory bitfields checks.

* Source/WebCore/page/Quirks.h:

* Source/WebKit/WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::handleEvent):

Canonical link: https://commits.webkit.org/272801@main




More information about the webkit-changes mailing list