Diff
Modified: trunk/Source/WTF/ChangeLog (287018 => 287019)
--- trunk/Source/WTF/ChangeLog 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WTF/ChangeLog 2021-12-14 10:29:29 UTC (rev 287019)
@@ -1,3 +1,14 @@
+2021-12-14 Darin Adler <da...@apple.com>
+
+ 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.
+
+ * 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.
+
2021-12-13 Saam Barati <sbar...@apple.com>
Roll back r286345, r286387, r286471, r286667, r286849
Modified: trunk/Source/WTF/wtf/NeverDestroyed.h (287018 => 287019)
--- trunk/Source/WTF/wtf/NeverDestroyed.h 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WTF/wtf/NeverDestroyed.h 2021-12-14 10:29:29 UTC (rev 287019)
@@ -179,6 +179,9 @@
typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type m_storage;
};
+template<typename T> NeverDestroyed(T) -> NeverDestroyed<T>;
+
+// FIXME: Remove this function, relying instead on the deduction guide for NeverDestroyed above.
template<typename T, typename AccessTraits> inline NeverDestroyed<T, AccessTraits> makeNeverDestroyed(T&& argument)
{
return std::forward<T>(argument);
Modified: trunk/Source/WebCore/ChangeLog (287018 => 287019)
--- trunk/Source/WebCore/ChangeLog 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WebCore/ChangeLog 2021-12-14 10:29:29 UTC (rev 287019)
@@ -1,3 +1,56 @@
+2021-12-14 Darin Adler <da...@apple.com>
+
+ 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.
+
+ * 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.
+
2021-12-14 Antti Koivisto <an...@apple.com>
[CSS Cascade Layers] revert-layer should revert style attribute to regular author style
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (287018 => 287019)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2021-12-14 10:29:29 UTC (rev 287019)
@@ -487,7 +487,7 @@
}
}
-sub EventHandlerAttributeEventName
+sub EventHandlerAttributeShortEventName
{
my $attribute = shift;
my $eventType = $attribute->extendedAttributes->{ImplementedAs} || $attribute->name;
@@ -495,9 +495,15 @@
# Remove the "on" prefix.
$eventType = substr($eventType, 2);
- return "eventNames().${eventType}Event";
+ return "${eventType}Event";
}
+sub EventHandlerAttributeEventName
+{
+ my $attribute = shift;
+ return "eventNames()." . EventHandlerAttributeShortEventName($attribute);
+}
+
sub GetParentClassName
{
my $interface = shift;
@@ -3027,7 +3033,7 @@
if ($interface->extendedAttributes->{CustomPushEventHandlerScope}) {
push(@headerContent, " JSC::JSScope* pushEventHandlerScope(JSC::JSGlobalObject*, JSC::JSScope*) const;\n\n");
}
-
+
# Constructor object getter
unless ($interface->extendedAttributes->{LegacyNoInterfaceObject}) {
push(@headerContent, " static JSC::JSValue getConstructor(JSC::VM&, const JSC::JSGlobalObject*);\n");
@@ -3034,6 +3040,13 @@
push(@headerContent, " static JSC::JSValue getLegacyFactoryFunction(JSC::VM&, JSC::JSGlobalObject*);\n") if $interface->extendedAttributes->{LegacyFactoryFunction};
}
+ if ($interface->extendedAttributes->{GenerateForEachEventHandlerContentAttribute}) {
+ push(@headerContent, " static void forEachEventHandlerContentAttribute(const Function<void(const AtomString& attributeName, const AtomString& eventName)>&);\n\n");
+ }
+ if ($interface->extendedAttributes->{GenerateForEachWindowEventHandlerContentAttribute}) {
+ push(@headerContent, " static void forEachWindowEventHandlerContentAttribute(const Function<void(const AtomString& attributeName, const AtomString& eventName)>&);\n\n");
+ }
+
my $numCustomOperations = 0;
my $numCustomAttributes = 0;
@@ -4944,6 +4957,13 @@
push(@implContent, "}\n\n");
}
+ if ($interface->extendedAttributes->{GenerateForEachEventHandlerContentAttribute}) {
+ GenerateForEachEventHandlerContentAttribute(\@implContent, $interface, $className, "forEachEventHandlerContentAttribute");
+ }
+ if ($interface->extendedAttributes->{GenerateForEachWindowEventHandlerContentAttribute}) {
+ GenerateForEachEventHandlerContentAttribute(\@implContent, $interface, $className, "forEachWindowEventHandlerContentAttribute", "WindowEventHandler");
+ }
+
if ($indexedGetterOperation) {
$implIncludes{"<wtf/URL.h>"} = 1 if $indexedGetterOperation->type->name eq "DOMString";
if ($interfaceName =~ /^HTML\w*Collection$/ or $interfaceName eq "RadioNodeList") {
@@ -5184,6 +5204,27 @@
push(@$outputArray, "#endif\n") if $conditionalString;
}
+sub GenerateForEachEventHandlerContentAttribute
+{
+ my ($outputArray, $interface, $className, $functionName, $eventHandlerExtendedAttributeName) = @_;
+ AddToImplIncludes("HTMLNames.h");
+ push(@$outputArray, "void ${className}::${functionName}(const Function<void(const AtomString& attributeName, const AtomString& eventName)>& function)\n");
+ push(@$outputArray, "{\n");
+ push(@$outputArray, " static constexpr std::pair<LazyNeverDestroyed<const QualifiedName>*, const AtomString EventNames::*> table[] = {\n");
+ foreach my $attribute (@{$interface->attributes}) {
+ if ($attribute->type->name eq "EventHandler" && (!defined $eventHandlerExtendedAttributeName || $attribute->extendedAttributes->{$eventHandlerExtendedAttributeName})) {
+ my $attributeName = $attribute->name;
+ my $eventName = EventHandlerAttributeShortEventName($attribute);
+ push(@$outputArray, " { &HTMLNames::${attributeName}Attr, &EventNames::${eventName} },\n");
+ }
+ }
+ push(@$outputArray, " };\n");
+ push(@$outputArray, " auto& eventNames = WebCore::eventNames();\n");
+ push(@$outputArray, " for (auto& names : table)\n");
+ push(@$outputArray, " function(names.first->get().localName(), eventNames.*names.second);\n");
+ push(@$outputArray, "}\n\n");
+}
+
sub GenerateAttributeGetterBodyDefinition
{
my ($outputArray, $interface, $className, $attribute, $attributeGetterBodyName, $conditional) = @_;
Modified: trunk/Source/WebCore/bindings/scripts/IDLAttributes.json (287018 => 287019)
--- trunk/Source/WebCore/bindings/scripts/IDLAttributes.json 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WebCore/bindings/scripts/IDLAttributes.json 2021-12-14 10:29:29 UTC (rev 287019)
@@ -227,14 +227,22 @@
"url": "https://webidl.spec.whatwg.org/#Exposed"
}
},
- "GenerateIsReachable": {
+ "GenerateAddOpaqueRoot": {
"contextsAllowed": ["interface"],
- "values": ["", "Impl", "ImplWebGLRenderingContext", "ImplCanvasBase", "ImplDocument", "ImplElementRoot", "ImplOwnerNodeRoot", "ImplScriptExecutionContext", "ReachableFromDOMWindow", "ReachableFromNavigator"]
+ "values": ["*"]
},
- "GenerateAddOpaqueRoot": {
+ "GenerateForEachEventHandlerContentAttribute": {
"contextsAllowed": ["interface"],
"values": ["*"]
},
+ "GenerateForEachWindowEventHandlerContentAttribute": {
+ "contextsAllowed": ["interface"],
+ "values": ["*"]
+ },
+ "GenerateIsReachable": {
+ "contextsAllowed": ["interface"],
+ "values": ["", "Impl", "ImplWebGLRenderingContext", "ImplCanvasBase", "ImplDocument", "ImplElementRoot", "ImplOwnerNodeRoot", "ImplScriptExecutionContext", "ReachableFromDOMWindow", "ReachableFromNavigator"]
+ },
"Global": {
"contextsAllowed": ["interface"],
"values": ["*"],
Modified: trunk/Source/WebCore/html/HTMLAttributeNames.in (287018 => 287019)
--- trunk/Source/WebCore/html/HTMLAttributeNames.in 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WebCore/html/HTMLAttributeNames.in 2021-12-14 10:29:29 UTC (rev 287019)
@@ -4,8 +4,8 @@
attrsNullNamespace
abbr
+accept
accept_charset
-accept
accesskey
action
align
@@ -71,7 +71,9 @@
attributiondestination
attributionsourceid
attributionsourcenonce
+autocapitalize
autocomplete
+autocorrect
autofocus
autopictureinpicture
autoplay
@@ -84,14 +86,14 @@
border
bordercolor
capture
+cellborder
cellpadding
cellspacing
+challenge
char
-challenge
charoff
charset
checked
-cellborder
cite
class
classid
@@ -125,7 +127,6 @@
download
draggable
dropzone
-webkitdropzone
enctype
end
enterkeyhint
@@ -178,10 +179,9 @@
loading
longdesc
loop
-low
-playcount
loopend
loopstart
+low
lowsrc
manifest
marginheight
@@ -188,12 +188,12 @@
marginwidth
max
maxlength
-minlength
mayscript
media
mediagroup
method
min
+minlength
multiple
muted
name
@@ -207,10 +207,10 @@
object
onabort
onafterprint
+onanimationcancel
+onanimationend
+onanimationiteration
onanimationstart
-onanimationiteration
-onanimationend
-onanimationcancel
onautocomplete
onautocompleteerror
onbeforecopy
@@ -229,6 +229,7 @@
onclose
oncontextmenu
oncopy
+oncuechange
oncut
ondblclick
ondevicechange
@@ -247,6 +248,10 @@
onfocusin
onfocusout
onformdata
+ongesturechange
+ongestureend
+ongesturestart
+ongotpointercapture
onhashchange
oninput
oninvalid
@@ -253,10 +258,6 @@
onkeydown
onkeypress
onkeyup
-ongesturestart
-ongesturechange
-ongestureend
-ongotpointercapture
onlanguagechange
onload
onloadeddata
@@ -272,8 +273,8 @@
onmouseover
onmouseup
onmousewheel
+onoffline
ononline
-onoffline
onorientationchange
onpagehide
onpageshow
@@ -281,17 +282,18 @@
onpause
onplay
onplaying
+onpointercancel
onpointerdown
+onpointerenter
+onpointerleave
onpointermove
+onpointerout
+onpointerover
onpointerup
-onpointercancel
-onpointerover
-onpointerout
-onpointerenter
-onpointerleave
onpopstate
onprogress
onratechange
+onrejectionhandled
onreset
onresize
onscroll
@@ -300,32 +302,33 @@
onseeked
onseeking
onselect
+onselectionchange
onselectstart
-onselectionchange
onslotchange
-onwheel
onstalled
onstorage
+onsubmit
onsuspend
-onsubmit
ontimeupdate
ontoggle
+ontouchcancel
+ontouchend
ontouchforcechange
+ontouchmove
ontouchstart
-ontouchmove
-ontouchend
-ontouchcancel
ontransitioncancel
ontransitionend
ontransitionrun
ontransitionstart
+onunhandledrejection
onunload
onvolumechange
onwaiting
+onwebkitanimationend
+onwebkitanimationiteration
onwebkitanimationstart
-onwebkitanimationiteration
-onwebkitanimationend
onwebkitbeginfullscreen
+onwebkitcurrentplaybacktargetiswirelesschanged
onwebkitendfullscreen
onwebkitfullscreenchange
onwebkitfullscreenerror
@@ -337,19 +340,23 @@
onwebkitmouseforceup
onwebkitmouseforcewillbegin
onwebkitneedkey
+onwebkitplaybacktargetavailabilitychanged
+onwebkitpresentationmodechanged
onwebkitsourceclose
onwebkitsourceended
onwebkitsourceopen
onwebkittransitionend
+onwheel
open
optimum
part
pattern
+ping
placeholder
+playcount
playsinline
pluginspage
pluginurl
-ping
poster
precision
preload
@@ -385,13 +392,11 @@
sortable
sortdirection
span
-x-webkit-speech
-x-webkit-grammar
spellcheck
src
-srcset
srcdoc
srclang
+srcset
standby
start
step
@@ -416,27 +421,22 @@
version
vlink
vspace
+webkit-playsinline
webkitallowfullscreen
+webkitattachmentbloburl
webkitattachmentid
webkitattachmentpath
-webkitattachmentbloburl
webkitdirectory
+webkitdropzone
width
wrap
-
-autocorrect
-autocapitalize
-onwebkitcurrentplaybacktargetiswirelesschanged
-onwebkitplaybacktargetavailabilitychanged
-onwebkitpresentationmodechanged
-x-webkit-imagemenu
-webkit-playsinline
-x-webkit-airplay
-x-webkit-wirelessvideoplaybackdisabled
-x-itunes-inherit-uri-query-component
-
x-apple-data-detectors
+x-apple-data-detectors-result
x-apple-data-detectors-type
-x-apple-data-detectors-result
-
x-apple-pdf-annotation
+x-itunes-inherit-uri-query-component
+x-webkit-airplay
+x-webkit-grammar
+x-webkit-imagemenu
+x-webkit-speech
+x-webkit-wirelessvideoplaybackdisabled
Modified: trunk/Source/WebCore/html/HTMLBodyElement.cpp (287018 => 287019)
--- trunk/Source/WebCore/html/HTMLBodyElement.cpp 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WebCore/html/HTMLBodyElement.cpp 2021-12-14 10:29:29 UTC (rev 287019)
@@ -3,7 +3,7 @@
* (C) 1999 Antti Koivisto (koivi...@kde.org)
* (C) 2000 Simon Hausmann (hausm...@kde.org)
* (C) 2001 Dirk Mueller (muel...@kde.org)
- * Copyright (C) 2004-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2021 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -35,6 +35,7 @@
#include "HTMLIFrameElement.h"
#include "HTMLNames.h"
#include "HTMLParserIdioms.h"
+#include "JSHTMLBodyElement.h"
#include "StyleProperties.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/NeverDestroyed.h>
@@ -96,46 +97,19 @@
HTMLElement::collectPresentationalHintsForAttribute(name, value, style);
}
-HTMLElement::EventHandlerNameMap HTMLBodyElement::createWindowEventHandlerNameMap()
-{
- static const QualifiedName* const table[] = {
- &onafterprintAttr.get(),
- &onbeforeprintAttr.get(),
- &onbeforeunloadAttr.get(),
- &onblurAttr.get(),
- &onerrorAttr.get(),
- &onfocusAttr.get(),
- &onfocusinAttr.get(),
- &onfocusoutAttr.get(),
- &onhashchangeAttr.get(),
- &onlanguagechangeAttr.get(),
- &onloadAttr.get(),
- &onmessageAttr.get(),
- &onofflineAttr.get(),
- &ononlineAttr.get(),
- &onorientationchangeAttr.get(),
- &onpagehideAttr.get(),
- &onpageshowAttr.get(),
- &onpopstateAttr.get(),
- &onresizeAttr.get(),
- &onscrollAttr.get(),
- &onstorageAttr.get(),
- &onunloadAttr.get(),
- &onwebkitmouseforcechangedAttr.get(),
- &onwebkitmouseforcedownAttr.get(),
- &onwebkitmouseforceupAttr.get(),
- &onwebkitmouseforcewillbeginAttr.get(),
- };
-
- EventHandlerNameMap map;
- populateEventHandlerNameMap(map, table);
- return map;
-}
-
const AtomString& HTMLBodyElement::eventNameForWindowEventHandlerAttribute(const QualifiedName& attributeName)
{
- static NeverDestroyed<EventHandlerNameMap> map = createWindowEventHandlerNameMap();
- return eventNameForEventHandlerAttribute(attributeName, map.get());
+ static NeverDestroyed map = [] {
+ EventHandlerNameMap map;
+ JSHTMLBodyElement::forEachWindowEventHandlerContentAttribute([&] (const AtomString& attributeName, const AtomString& eventName) {
+ // 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.
+ if (attributeName == onrejectionhandledAttr.get().localName() || attributeName == onunhandledrejectionAttr.get().localName())
+ return;
+ map.add(attributeName.impl(), eventName);
+ });
+ return map;
+ }();
+ return eventNameForEventHandlerAttribute(attributeName, map);
}
void HTMLBodyElement::parseAttribute(const QualifiedName& name, const AtomString& value)
Modified: trunk/Source/WebCore/html/HTMLBodyElement.h (287018 => 287019)
--- trunk/Source/WebCore/html/HTMLBodyElement.h 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WebCore/html/HTMLBodyElement.h 2021-12-14 10:29:29 UTC (rev 287019)
@@ -51,8 +51,6 @@
bool supportsFocus() const final;
void addSubresourceAttributeURLs(ListHashSet<URL>&) const final;
-
- static EventHandlerNameMap createWindowEventHandlerNameMap();
};
} //namespace
Modified: trunk/Source/WebCore/html/HTMLBodyElement.idl (287018 => 287019)
--- trunk/Source/WebCore/html/HTMLBodyElement.idl 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WebCore/html/HTMLBodyElement.idl 2021-12-14 10:29:29 UTC (rev 287019)
@@ -19,7 +19,8 @@
*/
[
- Exposed=Window
+ Exposed=Window,
+ GenerateForEachWindowEventHandlerContentAttribute,
] interface HTMLBodyElement : HTMLElement {
[CEReactions=NotNeeded, Reflect] attribute [LegacyNullToEmptyString] DOMString aLink;
[CEReactions=NotNeeded, Reflect] attribute DOMString background;
Modified: trunk/Source/WebCore/html/HTMLElement.cpp (287018 => 287019)
--- trunk/Source/WebCore/html/HTMLElement.cpp 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WebCore/html/HTMLElement.cpp 2021-12-14 10:29:29 UTC (rev 287019)
@@ -1,7 +1,7 @@
/*
* Copyright (C) 1999 Lars Knoll (kn...@kde.org)
* (C) 1999 Antti Koivisto (koivi...@kde.org)
- * Copyright (C) 2004-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2021 Apple Inc. All rights reserved.
* Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
* Copyright (C) 2011 Motorola Mobility. All rights reserved.
*
@@ -61,6 +61,7 @@
#include "HTMLTextAreaElement.h"
#include "HTMLTextFormControlElement.h"
#include "ImageOverlay.h"
+#include "JSHTMLElement.h"
#include "MediaControlsHost.h"
#include "NodeTraversal.h"
#include "RenderElement.h"
@@ -240,167 +241,6 @@
StyledElement::collectPresentationalHintsForAttribute(name, value, style);
}
-HTMLElement::EventHandlerNameMap HTMLElement::createEventHandlerNameMap()
-{
- EventHandlerNameMap map;
-
- static const QualifiedName* const table[] = {
- &onabortAttr.get(),
- &onanimationendAttr.get(),
- &onanimationiterationAttr.get(),
- &onanimationstartAttr.get(),
- &onanimationcancelAttr.get(),
- &onautocompleteAttr.get(),
- &onautocompleteerrorAttr.get(),
- &onbeforecopyAttr.get(),
- &onbeforecutAttr.get(),
- &onbeforeinputAttr.get(),
- &onbeforeloadAttr.get(),
- &onbeforepasteAttr.get(),
- &onblurAttr.get(),
- &oncancelAttr.get(),
- &oncanplayAttr.get(),
- &oncanplaythroughAttr.get(),
- &onchangeAttr.get(),
- &onclickAttr.get(),
- &oncloseAttr.get(),
- &oncontextmenuAttr.get(),
- &oncopyAttr.get(),
- &oncutAttr.get(),
- &ondblclickAttr.get(),
- &ondragAttr.get(),
- &ondragendAttr.get(),
- &ondragenterAttr.get(),
- &ondragleaveAttr.get(),
- &ondragoverAttr.get(),
- &ondragstartAttr.get(),
- &ondropAttr.get(),
- &ondurationchangeAttr.get(),
- &onemptiedAttr.get(),
- &onendedAttr.get(),
- &onerrorAttr.get(),
- &onfocusAttr.get(),
- &onfocusinAttr.get(),
- &onfocusoutAttr.get(),
- &onformdataAttr.get(),
- &ongesturechangeAttr.get(),
- &ongestureendAttr.get(),
- &ongesturestartAttr.get(),
- &ongotpointercaptureAttr.get(),
- &oninputAttr.get(),
- &oninvalidAttr.get(),
- &onkeydownAttr.get(),
- &onkeypressAttr.get(),
- &onkeyupAttr.get(),
- &onloadAttr.get(),
- &onloadeddataAttr.get(),
- &onloadedmetadataAttr.get(),
- &onloadstartAttr.get(),
- &onlostpointercaptureAttr.get(),
- &onmousedownAttr.get(),
- &onmouseenterAttr.get(),
- &onmouseleaveAttr.get(),
- &onmousemoveAttr.get(),
- &onmouseoutAttr.get(),
- &onmouseoverAttr.get(),
- &onmouseupAttr.get(),
- &onmousewheelAttr.get(),
- &onpasteAttr.get(),
- &onpauseAttr.get(),
- &onplayAttr.get(),
- &onplayingAttr.get(),
- &onpointerdownAttr.get(),
- &onpointermoveAttr.get(),
- &onpointerupAttr.get(),
- &onpointercancelAttr.get(),
- &onpointeroverAttr.get(),
- &onpointeroutAttr.get(),
- &onpointerenterAttr.get(),
- &onpointerleaveAttr.get(),
- &onprogressAttr.get(),
- &onratechangeAttr.get(),
- &onresetAttr.get(),
- &onresizeAttr.get(),
- &onscrollAttr.get(),
- &onsearchAttr.get(),
- &onsecuritypolicyviolationAttr.get(),
- &onseekedAttr.get(),
- &onseekingAttr.get(),
- &onselectAttr.get(),
- &onselectionchangeAttr.get(),
- &onselectstartAttr.get(),
- &onslotchangeAttr.get(),
- &onstalledAttr.get(),
- &onsubmitAttr.get(),
- &onsuspendAttr.get(),
- &ontimeupdateAttr.get(),
- &ontoggleAttr.get(),
- &ontouchcancelAttr.get(),
- &ontouchendAttr.get(),
- &ontouchforcechangeAttr.get(),
- &ontouchmoveAttr.get(),
- &ontouchstartAttr.get(),
- &ontransitioncancelAttr.get(),
- &ontransitionendAttr.get(),
- &ontransitionrunAttr.get(),
- &ontransitionstartAttr.get(),
- &onvolumechangeAttr.get(),
- &onwaitingAttr.get(),
- &onwebkitbeginfullscreenAttr.get(),
- &onwebkitcurrentplaybacktargetiswirelesschangedAttr.get(),
- &onwebkitendfullscreenAttr.get(),
- &onwebkitfullscreenchangeAttr.get(),
- &onwebkitfullscreenerrorAttr.get(),
- &onwebkitkeyaddedAttr.get(),
- &onwebkitkeyerrorAttr.get(),
- &onwebkitkeymessageAttr.get(),
- &onwebkitmouseforcechangedAttr.get(),
- &onwebkitmouseforcedownAttr.get(),
- &onwebkitmouseforcewillbeginAttr.get(),
- &onwebkitmouseforceupAttr.get(),
- &onwebkitneedkeyAttr.get(),
- &onwebkitplaybacktargetavailabilitychangedAttr.get(),
- &onwebkitpresentationmodechangedAttr.get(),
- &onwheelAttr.get(),
- };
-
- populateEventHandlerNameMap(map, table);
-
- struct UnusualMapping {
- const QualifiedName& attributeName;
- const AtomString& eventName;
- };
-
- const UnusualMapping unusualPairsTable[] = {
- { onwebkitanimationendAttr, eventNames().webkitAnimationEndEvent },
- { onwebkitanimationiterationAttr, eventNames().webkitAnimationIterationEvent },
- { onwebkitanimationstartAttr, eventNames().webkitAnimationStartEvent },
- { onwebkittransitionendAttr, eventNames().webkitTransitionEndEvent },
- };
-
- for (auto& entry : unusualPairsTable)
- map.add(entry.attributeName.localName().impl(), entry.eventName);
-
- return map;
-}
-
-void HTMLElement::populateEventHandlerNameMap(EventHandlerNameMap& map, const QualifiedName* const table[], size_t tableSize)
-{
- for (size_t i = 0; i < tableSize; ++i) {
- auto* entry = table[i];
-
- // FIXME: Would be nice to check these against the actual event names in eventNames().
- // Not obvious how to do that simply, though.
- auto& attributeName = entry->localName();
-
- // Remove the "on" prefix. Requires some memory allocation and computing a hash, but by not
- // using pointers from eventNames(), the passed-in table can be initialized at compile time.
- AtomString eventName = attributeName.string().substring(2);
-
- map.add(attributeName.impl(), WTFMove(eventName));
- }
-}
-
const AtomString& HTMLElement::eventNameForEventHandlerAttribute(const QualifiedName& attributeName, const EventHandlerNameMap& map)
{
ASSERT(!attributeName.localName().isNull());
@@ -420,8 +260,43 @@
const AtomString& HTMLElement::eventNameForEventHandlerAttribute(const QualifiedName& attributeName)
{
- static NeverDestroyed<EventHandlerNameMap> map = createEventHandlerNameMap();
- return eventNameForEventHandlerAttribute(attributeName, map.get());
+ static NeverDestroyed map = [] {
+ EventHandlerNameMap map;
+ JSHTMLElement::forEachEventHandlerContentAttribute([&] (const AtomString& attributeName, const AtomString& eventName) {
+ // FIXME: Remove this special case. This has an [EventHandler] line in the IDL but was not historically in this map.
+ if (attributeName == oncuechangeAttr.get().localName())
+ return;
+ map.add(attributeName.impl(), eventName);
+ });
+ // FIXME: Remove these special cases. These are not in IDL with [EventHandler] but were historically in this map.
+ static constexpr const LazyNeverDestroyed<const QualifiedName>* table[] = {
+ &onautocompleteAttr,
+ &onautocompleteerrorAttr,
+ &onbeforeloadAttr,
+ &onfocusinAttr,
+ &onfocusoutAttr,
+ &ongesturechangeAttr,
+ &ongestureendAttr,
+ &ongesturestartAttr,
+ &onwebkitbeginfullscreenAttr,
+ &onwebkitcurrentplaybacktargetiswirelesschangedAttr,
+ &onwebkitendfullscreenAttr,
+ &onwebkitfullscreenchangeAttr,
+ &onwebkitfullscreenerrorAttr,
+ &onwebkitkeyaddedAttr,
+ &onwebkitkeyerrorAttr,
+ &onwebkitkeymessageAttr,
+ &onwebkitneedkeyAttr,
+ &onwebkitplaybacktargetavailabilitychangedAttr,
+ &onwebkitpresentationmodechangedAttr,
+ };
+ for (auto& entry : table) {
+ auto* name = entry->get().localName().impl();
+ map.add(name, AtomString { name, 2, String::MaxLength });
+ }
+ return map;
+ }();
+ return eventNameForEventHandlerAttribute(attributeName, map);
}
Node::Editability HTMLElement::editabilityFromContentEditableAttr(const Node& node)
Modified: trunk/Source/WebCore/html/HTMLElement.h (287018 => 287019)
--- trunk/Source/WebCore/html/HTMLElement.h 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WebCore/html/HTMLElement.h 2021-12-14 10:29:29 UTC (rev 287019)
@@ -161,8 +161,7 @@
void childrenChanged(const ChildChange&) override;
void calculateAndAdjustDirectionality();
- typedef HashMap<AtomStringImpl*, AtomString> EventHandlerNameMap;
- template<size_t tableSize> static void populateEventHandlerNameMap(EventHandlerNameMap&, const QualifiedName* const (&table)[tableSize]);
+ using EventHandlerNameMap = HashMap<AtomStringImpl*, AtomString>;
static const AtomString& eventNameForEventHandlerAttribute(const QualifiedName& attributeName, const EventHandlerNameMap&);
private:
@@ -175,9 +174,6 @@
void adjustDirectionalityIfNeededAfterChildrenChanged(Element* beforeChange, ChildChange::Type);
TextDirection directionality(Node** strongDirectionalityTextNode= 0) const;
- static void populateEventHandlerNameMap(EventHandlerNameMap&, const QualifiedName* const table[], size_t tableSize);
- static EventHandlerNameMap createEventHandlerNameMap();
-
enum class AllowPercentage : bool { No, Yes };
enum class UseCSSPXAsUnitType : bool { No, Yes };
enum class IsMultiLength : bool { No, Yes };
@@ -190,11 +186,6 @@
ASSERT(tagName.localName().impl());
}
-template<size_t tableSize> inline void HTMLElement::populateEventHandlerNameMap(EventHandlerNameMap& map, const QualifiedName* const (&table)[tableSize])
-{
- populateEventHandlerNameMap(map, table, tableSize);
-}
-
inline bool Node::hasTagName(const HTMLQualifiedName& name) const
{
return is<HTMLElement>(*this) && downcast<HTMLElement>(*this).hasTagName(name);
Modified: trunk/Source/WebCore/html/HTMLElement.idl (287018 => 287019)
--- trunk/Source/WebCore/html/HTMLElement.idl 2021-12-14 10:13:54 UTC (rev 287018)
+++ trunk/Source/WebCore/html/HTMLElement.idl 2021-12-14 10:29:29 UTC (rev 287019)
@@ -21,8 +21,9 @@
[
CustomPushEventHandlerScope,
ExportMacro=WEBCORE_EXPORT,
+ Exposed=Window,
+ GenerateForEachEventHandlerContentAttribute,
JSGenerateToNativeObject,
- Exposed=Window
] interface HTMLElement : Element {
[Custom] constructor();