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

Changeset 287019 in webkit


Ignore:
Timestamp:
Dec 14, 2021, 2:29:29 AM (5 years ago)
Author:
Darin Adler
Message:

Automatically generate event handler content attribute maps so they are easier to maintain
https://bugs.webkit.org/show_bug.cgi?id=234254

Reviewed by Alexey Shvayka.

Source/WebCore:

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateHeader): Declare forEachEventHandlerContentAttribute
and forEachWindowEventHandlerContentAttribute as needed.
(GenerateImplementation): Call GenerateForEachEventHandlerContentAttribute
as needed.
(GenerateForEachEventHandlerContentAttribute): Define
forEachEventHandlerContentAttribute or forEachWindowEventHandlerContentAttribute.

  • bindings/scripts/IDLAttributes.json: Added

GenerateForEachEventHandlerContentAttribute and
GenerateForEachWindowEventHandlerContentAttribute. Even though each
is used in only one class, it's still better to not hard-code the class names.

  • html/HTMLAttributeNames.in: Added oncuechange, onrejectionhandled, and

onunhandledrejection even though we are not yet implementing any of them in
this behavior-preserving patch. They need to be present so the automatically
generated code compiles. But added explicit exceptions as mentioned below to
make sure no changes are implemented in this patch, and will take those exceptions
out later in a patch intended to produce a progression, likely with new test cases.
Re-sorted alphabetically, rather an arbitrary semi-sorted order.

  • html/HTMLBodyElement.cpp:

(WebCore::HTMLBodyElement::createWindowEventHandlerNameMap): Deleted.
(WebCore::HTMLBodyElement::eventNameForWindowEventHandlerAttribute): Use
JSHTMLBodyElement::forEachWindowEventHandlerContentAttribute to create the map.
Use a lambda instead of a separate function and take advantage of the
deduction guide for NeverDestroyed. Added exceptions for onrejectionhandled
and onunhandledrejection, which are both in the IDL file but were not handled
here, along with a FIXME suggesting we remove the exceptions.

  • html/HTMLElement.h: Removed createWindowEventHandlerNameMap.
  • html/HTMLBodyElement.idl: Added GenerateForEachWindowEventHandlerContentAttribute.
  • html/HTMLElement.cpp:

(WebCore::HTMLElement::createEventHandlerNameMap): Deleted.
(WebCore::HTMLElement::populateEventHandlerNameMap): Deleted.
(WebCore::HTMLElement::eventNameForEventHandlerAttribute): Use
JSHTMLElement::forEachEventHandlerContentAttribute to create the map.
Use a lambda instead of a separate function and take advantage of the
deduction guide for NeverDestroyed. Added exception for oncuechange,
which is in the IDL file but was not handled here, and for 19 other attributes,
which are not in the IDL file but were handled here, along with two FIXMEs
suggesting we remove the exceptions.

  • html/HTMLElement.h: Removed populateEventHandlerNameMap and

createEventHandlerNameMap.

  • html/HTMLElement.idl: Added GenerateForEachEventHandlerContentAttribute.

Source/WTF:

  • wtf/NeverDestroyed.h: Add a deduction guide for NeverDestroyed.

In the future we can use this instead of makeNeverDestroyed or writing
out the entire template class type including template arguments.

Location:
trunk/Source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r286994 r287019  
     12021-12-14  Darin Adler  <darin@apple.com>
     2
     3        Automatically generate event handler content attribute maps so they are easier to maintain
     4        https://bugs.webkit.org/show_bug.cgi?id=234254
     5
     6        Reviewed by Alexey Shvayka.
     7
     8        * wtf/NeverDestroyed.h: Add a deduction guide for NeverDestroyed.
     9        In the future we can use this instead of makeNeverDestroyed or writing
     10        out the entire template class type including template arguments.
     11
    1122021-12-13  Saam Barati  <sbarati@apple.com>
    213
  • trunk/Source/WTF/wtf/NeverDestroyed.h

    r274241 r287019  
    180180};
    181181
     182template<typename T> NeverDestroyed(T) -> NeverDestroyed<T>;
     183
     184// FIXME: Remove this function, relying instead on the deduction guide for NeverDestroyed above.
    182185template<typename T, typename AccessTraits> inline NeverDestroyed<T, AccessTraits> makeNeverDestroyed(T&& argument)
    183186{
  • trunk/Source/WebCore/ChangeLog

    r287018 r287019  
     12021-12-14  Darin Adler  <darin@apple.com>
     2
     3        Automatically generate event handler content attribute maps so they are easier to maintain
     4        https://bugs.webkit.org/show_bug.cgi?id=234254
     5
     6        Reviewed by Alexey Shvayka.
     7
     8        * bindings/scripts/CodeGeneratorJS.pm:
     9        (GenerateHeader): Declare forEachEventHandlerContentAttribute
     10        and forEachWindowEventHandlerContentAttribute as needed.
     11        (GenerateImplementation): Call GenerateForEachEventHandlerContentAttribute
     12        as needed.
     13        (GenerateForEachEventHandlerContentAttribute): Define
     14        forEachEventHandlerContentAttribute or forEachWindowEventHandlerContentAttribute.
     15
     16        * bindings/scripts/IDLAttributes.json: Added
     17        GenerateForEachEventHandlerContentAttribute and
     18        GenerateForEachWindowEventHandlerContentAttribute. Even though each
     19        is used in only one class, it's still better to not hard-code the class names.
     20
     21        * html/HTMLAttributeNames.in: Added oncuechange, onrejectionhandled, and
     22        onunhandledrejection even though we are not yet implementing any of them in
     23        this behavior-preserving patch. They need to be present so the automatically
     24        generated code compiles. But added explicit exceptions as mentioned below to
     25        make sure no changes are implemented in this patch, and will take those exceptions
     26        out later in a patch intended to produce a progression, likely with new test cases.
     27        Re-sorted alphabetically, rather an arbitrary semi-sorted order.
     28
     29        * html/HTMLBodyElement.cpp:
     30        (WebCore::HTMLBodyElement::createWindowEventHandlerNameMap): Deleted.
     31        (WebCore::HTMLBodyElement::eventNameForWindowEventHandlerAttribute): Use
     32        JSHTMLBodyElement::forEachWindowEventHandlerContentAttribute to create the map.
     33        Use a lambda instead of a separate function and take advantage of the
     34        deduction guide for NeverDestroyed. Added exceptions for onrejectionhandled
     35        and onunhandledrejection, which are both in the IDL file but were not handled
     36        here, along with a FIXME suggesting we remove the exceptions.
     37        * html/HTMLElement.h: Removed createWindowEventHandlerNameMap.
     38        * html/HTMLBodyElement.idl: Added GenerateForEachWindowEventHandlerContentAttribute.
     39
     40        * html/HTMLElement.cpp:
     41        (WebCore::HTMLElement::createEventHandlerNameMap): Deleted.
     42        (WebCore::HTMLElement::populateEventHandlerNameMap): Deleted.
     43        (WebCore::HTMLElement::eventNameForEventHandlerAttribute): Use
     44        JSHTMLElement::forEachEventHandlerContentAttribute to create the map.
     45        Use a lambda instead of a separate function and take advantage of the
     46        deduction guide for NeverDestroyed. Added exception for oncuechange,
     47        which is in the IDL file but was not handled here, and for 19 other attributes,
     48        which are not in the IDL file but were handled here, along with two FIXMEs
     49        suggesting we remove the exceptions.
     50        * html/HTMLElement.h: Removed populateEventHandlerNameMap and
     51        createEventHandlerNameMap.
     52        * html/HTMLElement.idl: Added GenerateForEachEventHandlerContentAttribute.
     53
    1542021-12-14  Antti Koivisto  <antti@apple.com>
    255
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r286895 r287019  
    488488}
    489489
    490 sub EventHandlerAttributeEventName
     490sub EventHandlerAttributeShortEventName
    491491{
    492492    my $attribute = shift;
     
    496496    $eventType = substr($eventType, 2);
    497497
    498     return "eventNames().${eventType}Event";
     498    return "${eventType}Event";
     499}
     500
     501sub EventHandlerAttributeEventName
     502{
     503    my $attribute = shift;
     504    return "eventNames()." . EventHandlerAttributeShortEventName($attribute);
    499505}
    500506
     
    30283034        push(@headerContent, "    JSC::JSScope* pushEventHandlerScope(JSC::JSGlobalObject*, JSC::JSScope*) const;\n\n");
    30293035    }
    3030    
     3036
    30313037    # Constructor object getter
    30323038    unless ($interface->extendedAttributes->{LegacyNoInterfaceObject}) {
    30333039        push(@headerContent, "    static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);\n");
    30343040        push(@headerContent, "    static JSC::JSValue getLegacyFactoryFunction(JSC::VM&, JSC::JSGlobalObject*);\n") if $interface->extendedAttributes->{LegacyFactoryFunction};
     3041    }
     3042
     3043    if ($interface->extendedAttributes->{GenerateForEachEventHandlerContentAttribute}) {
     3044        push(@headerContent, "    static void forEachEventHandlerContentAttribute(const Function<void(const AtomString& attributeName, const AtomString& eventName)>&);\n\n");
     3045    }
     3046    if ($interface->extendedAttributes->{GenerateForEachWindowEventHandlerContentAttribute}) {
     3047        push(@headerContent, "    static void forEachWindowEventHandlerContentAttribute(const Function<void(const AtomString& attributeName, const AtomString& eventName)>&);\n\n");
    30353048    }
    30363049
     
    49434956        push(@implContent, "    Base::analyzeHeap(cell, analyzer);\n");
    49444957        push(@implContent, "}\n\n");
     4958    }
     4959
     4960    if ($interface->extendedAttributes->{GenerateForEachEventHandlerContentAttribute}) {
     4961        GenerateForEachEventHandlerContentAttribute(\@implContent, $interface, $className, "forEachEventHandlerContentAttribute");
     4962    }
     4963    if ($interface->extendedAttributes->{GenerateForEachWindowEventHandlerContentAttribute}) {
     4964        GenerateForEachEventHandlerContentAttribute(\@implContent, $interface, $className, "forEachWindowEventHandlerContentAttribute", "WindowEventHandler");
    49454965    }
    49464966
     
    51855205}
    51865206
     5207sub GenerateForEachEventHandlerContentAttribute
     5208{
     5209    my ($outputArray, $interface, $className, $functionName, $eventHandlerExtendedAttributeName) = @_;
     5210    AddToImplIncludes("HTMLNames.h");
     5211    push(@$outputArray, "void ${className}::${functionName}(const Function<void(const AtomString& attributeName, const AtomString& eventName)>& function)\n");
     5212    push(@$outputArray, "{\n");
     5213    push(@$outputArray, "    static constexpr std::pair<LazyNeverDestroyed<const QualifiedName>*, const AtomString EventNames::*> table[] = {\n");
     5214    foreach my $attribute (@{$interface->attributes}) {
     5215        if ($attribute->type->name eq "EventHandler" && (!defined $eventHandlerExtendedAttributeName || $attribute->extendedAttributes->{$eventHandlerExtendedAttributeName})) {
     5216            my $attributeName = $attribute->name;
     5217            my $eventName = EventHandlerAttributeShortEventName($attribute);
     5218            push(@$outputArray, "        { &HTMLNames::${attributeName}Attr, &EventNames::${eventName} },\n");
     5219        }
     5220    }
     5221    push(@$outputArray, "    };\n");
     5222    push(@$outputArray, "    auto& eventNames = WebCore::eventNames();\n");
     5223    push(@$outputArray, "    for (auto& names : table)\n");
     5224    push(@$outputArray, "        function(names.first->get().localName(), eventNames.*names.second);\n");
     5225    push(@$outputArray, "}\n\n");
     5226}
     5227
    51875228sub GenerateAttributeGetterBodyDefinition
    51885229{
  • trunk/Source/WebCore/bindings/scripts/IDLAttributes.json

    r286916 r287019  
    228228            }
    229229        },
     230        "GenerateAddOpaqueRoot": {
     231            "contextsAllowed": ["interface"],
     232            "values": ["*"]
     233        },
     234        "GenerateForEachEventHandlerContentAttribute": {
     235            "contextsAllowed": ["interface"],
     236            "values": ["*"]
     237        },
     238        "GenerateForEachWindowEventHandlerContentAttribute": {
     239            "contextsAllowed": ["interface"],
     240            "values": ["*"]
     241        },
    230242        "GenerateIsReachable": {
    231243            "contextsAllowed": ["interface"],
    232244            "values": ["", "Impl", "ImplWebGLRenderingContext", "ImplCanvasBase", "ImplDocument", "ImplElementRoot", "ImplOwnerNodeRoot", "ImplScriptExecutionContext", "ReachableFromDOMWindow", "ReachableFromNavigator"]
    233         },
    234         "GenerateAddOpaqueRoot": {
    235             "contextsAllowed": ["interface"],
    236             "values": ["*"]
    237245        },
    238246        "Global": {
  • trunk/Source/WebCore/html/HTMLAttributeNames.in

    r286461 r287019  
    55
    66abbr
     7accept
    78accept_charset
    8 accept
    99accesskey
    1010action
     
    7272attributionsourceid
    7373attributionsourcenonce
     74autocapitalize
    7475autocomplete
     76autocorrect
    7577autofocus
    7678autopictureinpicture
     
    8587bordercolor
    8688capture
     89cellborder
    8790cellpadding
    8891cellspacing
     92challenge
    8993char
    90 challenge
    9194charoff
    9295charset
    9396checked
    94 cellborder
    9597cite
    9698class
     
    126128draggable
    127129dropzone
    128 webkitdropzone
    129130enctype
    130131end
     
    179180longdesc
    180181loop
    181 low
    182 playcount
    183182loopend
    184183loopstart
     184low
    185185lowsrc
    186186manifest
     
    189189max
    190190maxlength
    191 minlength
    192191mayscript
    193192media
     
    195194method
    196195min
     196minlength
    197197multiple
    198198muted
     
    208208onabort
    209209onafterprint
     210onanimationcancel
     211onanimationend
     212onanimationiteration
    210213onanimationstart
    211 onanimationiteration
    212 onanimationend
    213 onanimationcancel
    214214onautocomplete
    215215onautocompleteerror
     
    230230oncontextmenu
    231231oncopy
     232oncuechange
    232233oncut
    233234ondblclick
     
    248249onfocusout
    249250onformdata
     251ongesturechange
     252ongestureend
     253ongesturestart
     254ongotpointercapture
    250255onhashchange
    251256oninput
     
    254259onkeypress
    255260onkeyup
    256 ongesturestart
    257 ongesturechange
    258 ongestureend
    259 ongotpointercapture
    260261onlanguagechange
    261262onload
     
    273274onmouseup
    274275onmousewheel
     276onoffline
    275277ononline
    276 onoffline
    277278onorientationchange
    278279onpagehide
     
    282283onplay
    283284onplaying
     285onpointercancel
    284286onpointerdown
    285 onpointermove
    286 onpointerup
    287 onpointercancel
    288 onpointerover
    289 onpointerout
    290287onpointerenter
    291288onpointerleave
     289onpointermove
     290onpointerout
     291onpointerover
     292onpointerup
    292293onpopstate
    293294onprogress
    294295onratechange
     296onrejectionhandled
    295297onreset
    296298onresize
     
    301303onseeking
    302304onselect
     305onselectionchange
    303306onselectstart
    304 onselectionchange
    305307onslotchange
    306 onwheel
    307308onstalled
    308309onstorage
     310onsubmit
    309311onsuspend
    310 onsubmit
    311312ontimeupdate
    312313ontoggle
     314ontouchcancel
     315ontouchend
    313316ontouchforcechange
     317ontouchmove
    314318ontouchstart
    315 ontouchmove
    316 ontouchend
    317 ontouchcancel
    318319ontransitioncancel
    319320ontransitionend
    320321ontransitionrun
    321322ontransitionstart
     323onunhandledrejection
    322324onunload
    323325onvolumechange
    324326onwaiting
     327onwebkitanimationend
     328onwebkitanimationiteration
    325329onwebkitanimationstart
    326 onwebkitanimationiteration
    327 onwebkitanimationend
    328330onwebkitbeginfullscreen
     331onwebkitcurrentplaybacktargetiswirelesschanged
    329332onwebkitendfullscreen
    330333onwebkitfullscreenchange
     
    338341onwebkitmouseforcewillbegin
    339342onwebkitneedkey
     343onwebkitplaybacktargetavailabilitychanged
     344onwebkitpresentationmodechanged
    340345onwebkitsourceclose
    341346onwebkitsourceended
    342347onwebkitsourceopen
    343348onwebkittransitionend
     349onwheel
    344350open
    345351optimum
    346352part
    347353pattern
     354ping
    348355placeholder
     356playcount
    349357playsinline
    350358pluginspage
    351359pluginurl
    352 ping
    353360poster
    354361precision
     
    386393sortdirection
    387394span
    388 x-webkit-speech
    389 x-webkit-grammar
    390395spellcheck
    391396src
    392 srcset
    393397srcdoc
    394398srclang
     399srcset
    395400standby
    396401start
     
    417422vlink
    418423vspace
     424webkit-playsinline
    419425webkitallowfullscreen
     426webkitattachmentbloburl
    420427webkitattachmentid
    421428webkitattachmentpath
    422 webkitattachmentbloburl
    423429webkitdirectory
     430webkitdropzone
    424431width
    425432wrap
    426 
    427 autocorrect
    428 autocapitalize
    429 onwebkitcurrentplaybacktargetiswirelesschanged
    430 onwebkitplaybacktargetavailabilitychanged
    431 onwebkitpresentationmodechanged
     433x-apple-data-detectors
     434x-apple-data-detectors-result
     435x-apple-data-detectors-type
     436x-apple-pdf-annotation
     437x-itunes-inherit-uri-query-component
     438x-webkit-airplay
     439x-webkit-grammar
    432440x-webkit-imagemenu
    433 webkit-playsinline
    434 x-webkit-airplay
     441x-webkit-speech
    435442x-webkit-wirelessvideoplaybackdisabled
    436 x-itunes-inherit-uri-query-component
    437 
    438 x-apple-data-detectors
    439 x-apple-data-detectors-type
    440 x-apple-data-detectors-result
    441 
    442 x-apple-pdf-annotation
  • trunk/Source/WebCore/html/HTMLBodyElement.cpp

    r286223 r287019  
    44 *           (C) 2000 Simon Hausmann (hausmann@kde.org)
    55 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    6  * Copyright (C) 2004-2019 Apple Inc. All rights reserved.
     6 * Copyright (C) 2004-2021 Apple Inc. All rights reserved.
    77 *
    88 * This library is free software; you can redistribute it and/or
     
    3636#include "HTMLNames.h"
    3737#include "HTMLParserIdioms.h"
     38#include "JSHTMLBodyElement.h"
    3839#include "StyleProperties.h"
    3940#include <wtf/IsoMallocInlines.h>
     
    9798}
    9899
    99 HTMLElement::EventHandlerNameMap HTMLBodyElement::createWindowEventHandlerNameMap()
    100 {
    101     static const QualifiedName* const table[] = {
    102         &onafterprintAttr.get(),
    103         &onbeforeprintAttr.get(),
    104         &onbeforeunloadAttr.get(),
    105         &onblurAttr.get(),
    106         &onerrorAttr.get(),
    107         &onfocusAttr.get(),
    108         &onfocusinAttr.get(),
    109         &onfocusoutAttr.get(),
    110         &onhashchangeAttr.get(),
    111         &onlanguagechangeAttr.get(),
    112         &onloadAttr.get(),
    113         &onmessageAttr.get(),
    114         &onofflineAttr.get(),
    115         &ononlineAttr.get(),
    116         &onorientationchangeAttr.get(),
    117         &onpagehideAttr.get(),
    118         &onpageshowAttr.get(),
    119         &onpopstateAttr.get(),
    120         &onresizeAttr.get(),
    121         &onscrollAttr.get(),
    122         &onstorageAttr.get(),
    123         &onunloadAttr.get(),
    124         &onwebkitmouseforcechangedAttr.get(),
    125         &onwebkitmouseforcedownAttr.get(),
    126         &onwebkitmouseforceupAttr.get(),
    127         &onwebkitmouseforcewillbeginAttr.get(),
    128     };
    129 
    130     EventHandlerNameMap map;
    131     populateEventHandlerNameMap(map, table);
    132     return map;
    133 }
    134 
    135100const AtomString& HTMLBodyElement::eventNameForWindowEventHandlerAttribute(const QualifiedName& attributeName)
    136101{
    137     static NeverDestroyed<EventHandlerNameMap> map = createWindowEventHandlerNameMap();
    138     return eventNameForEventHandlerAttribute(attributeName, map.get());
     102    static NeverDestroyed map = [] {
     103        EventHandlerNameMap map;
     104        JSHTMLBodyElement::forEachWindowEventHandlerContentAttribute([&] (const AtomString& attributeName, const AtomString& eventName) {
     105            // FIXME: Remove these special cases. These have has an [WindowEventHandler] line in the IDL but were not in this map before, so this preserves behavior.
     106            if (attributeName == onrejectionhandledAttr.get().localName() || attributeName == onunhandledrejectionAttr.get().localName())
     107                return;
     108            map.add(attributeName.impl(), eventName);
     109        });
     110        return map;
     111    }();
     112    return eventNameForEventHandlerAttribute(attributeName, map);
    139113}
    140114
  • trunk/Source/WebCore/html/HTMLBodyElement.h

    r278277 r287019  
    5252
    5353    void addSubresourceAttributeURLs(ListHashSet<URL>&) const final;
    54 
    55     static EventHandlerNameMap createWindowEventHandlerNameMap();
    5654};
    5755
  • trunk/Source/WebCore/html/HTMLBodyElement.idl

    r267935 r287019  
    2020
    2121[
    22     Exposed=Window
     22    Exposed=Window,
     23    GenerateForEachWindowEventHandlerContentAttribute,
    2324] interface HTMLBodyElement : HTMLElement {
    2425    [CEReactions=NotNeeded, Reflect] attribute [LegacyNullToEmptyString] DOMString aLink;
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r286898 r287019  
    22 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    4  * Copyright (C) 2004-2020 Apple Inc. All rights reserved.
     4 * Copyright (C) 2004-2021 Apple Inc. All rights reserved.
    55 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
    66 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
     
    6262#include "HTMLTextFormControlElement.h"
    6363#include "ImageOverlay.h"
     64#include "JSHTMLElement.h"
    6465#include "MediaControlsHost.h"
    6566#include "NodeTraversal.h"
     
    241242}
    242243
    243 HTMLElement::EventHandlerNameMap HTMLElement::createEventHandlerNameMap()
    244 {
    245     EventHandlerNameMap map;
    246 
    247     static const QualifiedName* const table[] = {
    248         &onabortAttr.get(),
    249         &onanimationendAttr.get(),
    250         &onanimationiterationAttr.get(),
    251         &onanimationstartAttr.get(),
    252         &onanimationcancelAttr.get(),
    253         &onautocompleteAttr.get(),
    254         &onautocompleteerrorAttr.get(),
    255         &onbeforecopyAttr.get(),
    256         &onbeforecutAttr.get(),
    257         &onbeforeinputAttr.get(),
    258         &onbeforeloadAttr.get(),
    259         &onbeforepasteAttr.get(),
    260         &onblurAttr.get(),
    261         &oncancelAttr.get(),
    262         &oncanplayAttr.get(),
    263         &oncanplaythroughAttr.get(),
    264         &onchangeAttr.get(),
    265         &onclickAttr.get(),
    266         &oncloseAttr.get(),
    267         &oncontextmenuAttr.get(),
    268         &oncopyAttr.get(),
    269         &oncutAttr.get(),
    270         &ondblclickAttr.get(),
    271         &ondragAttr.get(),
    272         &ondragendAttr.get(),
    273         &ondragenterAttr.get(),
    274         &ondragleaveAttr.get(),
    275         &ondragoverAttr.get(),
    276         &ondragstartAttr.get(),
    277         &ondropAttr.get(),
    278         &ondurationchangeAttr.get(),
    279         &onemptiedAttr.get(),
    280         &onendedAttr.get(),
    281         &onerrorAttr.get(),
    282         &onfocusAttr.get(),
    283         &onfocusinAttr.get(),
    284         &onfocusoutAttr.get(),
    285         &onformdataAttr.get(),
    286         &ongesturechangeAttr.get(),
    287         &ongestureendAttr.get(),
    288         &ongesturestartAttr.get(),
    289         &ongotpointercaptureAttr.get(),
    290         &oninputAttr.get(),
    291         &oninvalidAttr.get(),
    292         &onkeydownAttr.get(),
    293         &onkeypressAttr.get(),
    294         &onkeyupAttr.get(),
    295         &onloadAttr.get(),
    296         &onloadeddataAttr.get(),
    297         &onloadedmetadataAttr.get(),
    298         &onloadstartAttr.get(),
    299         &onlostpointercaptureAttr.get(),
    300         &onmousedownAttr.get(),
    301         &onmouseenterAttr.get(),
    302         &onmouseleaveAttr.get(),
    303         &onmousemoveAttr.get(),
    304         &onmouseoutAttr.get(),
    305         &onmouseoverAttr.get(),
    306         &onmouseupAttr.get(),
    307         &onmousewheelAttr.get(),
    308         &onpasteAttr.get(),
    309         &onpauseAttr.get(),
    310         &onplayAttr.get(),
    311         &onplayingAttr.get(),
    312         &onpointerdownAttr.get(),
    313         &onpointermoveAttr.get(),
    314         &onpointerupAttr.get(),
    315         &onpointercancelAttr.get(),
    316         &onpointeroverAttr.get(),
    317         &onpointeroutAttr.get(),
    318         &onpointerenterAttr.get(),
    319         &onpointerleaveAttr.get(),
    320         &onprogressAttr.get(),
    321         &onratechangeAttr.get(),
    322         &onresetAttr.get(),
    323         &onresizeAttr.get(),
    324         &onscrollAttr.get(),
    325         &onsearchAttr.get(),
    326         &onsecuritypolicyviolationAttr.get(),
    327         &onseekedAttr.get(),
    328         &onseekingAttr.get(),
    329         &onselectAttr.get(),
    330         &onselectionchangeAttr.get(),
    331         &onselectstartAttr.get(),
    332         &onslotchangeAttr.get(),
    333         &onstalledAttr.get(),
    334         &onsubmitAttr.get(),
    335         &onsuspendAttr.get(),
    336         &ontimeupdateAttr.get(),
    337         &ontoggleAttr.get(),
    338         &ontouchcancelAttr.get(),
    339         &ontouchendAttr.get(),
    340         &ontouchforcechangeAttr.get(),
    341         &ontouchmoveAttr.get(),
    342         &ontouchstartAttr.get(),
    343         &ontransitioncancelAttr.get(),
    344         &ontransitionendAttr.get(),
    345         &ontransitionrunAttr.get(),
    346         &ontransitionstartAttr.get(),
    347         &onvolumechangeAttr.get(),
    348         &onwaitingAttr.get(),
    349         &onwebkitbeginfullscreenAttr.get(),
    350         &onwebkitcurrentplaybacktargetiswirelesschangedAttr.get(),
    351         &onwebkitendfullscreenAttr.get(),
    352         &onwebkitfullscreenchangeAttr.get(),
    353         &onwebkitfullscreenerrorAttr.get(),
    354         &onwebkitkeyaddedAttr.get(),
    355         &onwebkitkeyerrorAttr.get(),
    356         &onwebkitkeymessageAttr.get(),
    357         &onwebkitmouseforcechangedAttr.get(),
    358         &onwebkitmouseforcedownAttr.get(),
    359         &onwebkitmouseforcewillbeginAttr.get(),
    360         &onwebkitmouseforceupAttr.get(),
    361         &onwebkitneedkeyAttr.get(),
    362         &onwebkitplaybacktargetavailabilitychangedAttr.get(),
    363         &onwebkitpresentationmodechangedAttr.get(),
    364         &onwheelAttr.get(),
    365     };
    366 
    367     populateEventHandlerNameMap(map, table);
    368 
    369     struct UnusualMapping {
    370         const QualifiedName& attributeName;
    371         const AtomString& eventName;
    372     };
    373 
    374     const UnusualMapping unusualPairsTable[] = {
    375         { onwebkitanimationendAttr, eventNames().webkitAnimationEndEvent },
    376         { onwebkitanimationiterationAttr, eventNames().webkitAnimationIterationEvent },
    377         { onwebkitanimationstartAttr, eventNames().webkitAnimationStartEvent },
    378         { onwebkittransitionendAttr, eventNames().webkitTransitionEndEvent },
    379     };
    380 
    381     for (auto& entry : unusualPairsTable)
    382         map.add(entry.attributeName.localName().impl(), entry.eventName);
    383 
    384     return map;
    385 }
    386 
    387 void HTMLElement::populateEventHandlerNameMap(EventHandlerNameMap& map, const QualifiedName* const table[], size_t tableSize)
    388 {
    389     for (size_t i = 0; i < tableSize; ++i) {
    390         auto* entry = table[i];
    391 
    392         // FIXME: Would be nice to check these against the actual event names in eventNames().
    393         // Not obvious how to do that simply, though.
    394         auto& attributeName = entry->localName();
    395 
    396         // Remove the "on" prefix. Requires some memory allocation and computing a hash, but by not
    397         // using pointers from eventNames(), the passed-in table can be initialized at compile time.
    398         AtomString eventName = attributeName.string().substring(2);
    399 
    400         map.add(attributeName.impl(), WTFMove(eventName));
    401     }
    402 }
    403 
    404244const AtomString& HTMLElement::eventNameForEventHandlerAttribute(const QualifiedName& attributeName, const EventHandlerNameMap& map)
    405245{
     
    421261const AtomString& HTMLElement::eventNameForEventHandlerAttribute(const QualifiedName& attributeName)
    422262{
    423     static NeverDestroyed<EventHandlerNameMap> map = createEventHandlerNameMap();
    424     return eventNameForEventHandlerAttribute(attributeName, map.get());
     263    static NeverDestroyed map = [] {
     264        EventHandlerNameMap map;
     265        JSHTMLElement::forEachEventHandlerContentAttribute([&] (const AtomString& attributeName, const AtomString& eventName) {
     266            // FIXME: Remove this special case. This has an [EventHandler] line in the IDL but was not historically in this map.
     267            if (attributeName == oncuechangeAttr.get().localName())
     268                return;
     269            map.add(attributeName.impl(), eventName);
     270        });
     271        // FIXME: Remove these special cases. These are not in IDL with [EventHandler] but were historically in this map.
     272        static constexpr const LazyNeverDestroyed<const QualifiedName>* table[] = {
     273            &onautocompleteAttr,
     274            &onautocompleteerrorAttr,
     275            &onbeforeloadAttr,
     276            &onfocusinAttr,
     277            &onfocusoutAttr,
     278            &ongesturechangeAttr,
     279            &ongestureendAttr,
     280            &ongesturestartAttr,
     281            &onwebkitbeginfullscreenAttr,
     282            &onwebkitcurrentplaybacktargetiswirelesschangedAttr,
     283            &onwebkitendfullscreenAttr,
     284            &onwebkitfullscreenchangeAttr,
     285            &onwebkitfullscreenerrorAttr,
     286            &onwebkitkeyaddedAttr,
     287            &onwebkitkeyerrorAttr,
     288            &onwebkitkeymessageAttr,
     289            &onwebkitneedkeyAttr,
     290            &onwebkitplaybacktargetavailabilitychangedAttr,
     291            &onwebkitpresentationmodechangedAttr,
     292        };
     293        for (auto& entry : table) {
     294            auto* name = entry->get().localName().impl();
     295            map.add(name, AtomString { name, 2, String::MaxLength });
     296        }
     297        return map;
     298    }();
     299    return eventNameForEventHandlerAttribute(attributeName, map);
    425300}
    426301
  • trunk/Source/WebCore/html/HTMLElement.h

    r285655 r287019  
    162162    void calculateAndAdjustDirectionality();
    163163
    164     typedef HashMap<AtomStringImpl*, AtomString> EventHandlerNameMap;
    165     template<size_t tableSize> static void populateEventHandlerNameMap(EventHandlerNameMap&, const QualifiedName* const (&table)[tableSize]);
     164    using EventHandlerNameMap = HashMap<AtomStringImpl*, AtomString>;
    166165    static const AtomString& eventNameForEventHandlerAttribute(const QualifiedName& attributeName, const EventHandlerNameMap&);
    167166
     
    175174    void adjustDirectionalityIfNeededAfterChildrenChanged(Element* beforeChange, ChildChange::Type);
    176175    TextDirection directionality(Node** strongDirectionalityTextNode= 0) const;
    177 
    178     static void populateEventHandlerNameMap(EventHandlerNameMap&, const QualifiedName* const table[], size_t tableSize);
    179     static EventHandlerNameMap createEventHandlerNameMap();
    180176
    181177    enum class AllowPercentage : bool { No, Yes };
     
    191187}
    192188
    193 template<size_t tableSize> inline void HTMLElement::populateEventHandlerNameMap(EventHandlerNameMap& map, const QualifiedName* const (&table)[tableSize])
    194 {
    195     populateEventHandlerNameMap(map, table, tableSize);
    196 }
    197 
    198189inline bool Node::hasTagName(const HTMLQualifiedName& name) const
    199190{
  • trunk/Source/WebCore/html/HTMLElement.idl

    r283463 r287019  
    2222    CustomPushEventHandlerScope,
    2323    ExportMacro=WEBCORE_EXPORT,
     24    Exposed=Window,
     25    GenerateForEachEventHandlerContentAttribute,
    2426    JSGenerateToNativeObject,
    25     Exposed=Window
    2627] interface HTMLElement : Element {
    2728    [Custom] constructor();
Note: See TracChangeset for help on using the changeset viewer.