Open Bug 1845422 Opened 10 months ago Updated 9 months ago

Reverse the order of the calls to IsEventAttributeName and GetEventNameForAttr, to simplify some code

Categories

(Core :: DOM: Events, task)

task

Tracking

()

ASSIGNED

People

(Reporter: mstange, Assigned: mstange)

Details

Attachments

(3 files)

In EventNameList.h, we list some events solely so that <div onblah="..."> passes the "attribute is event handler" check:

https://searchfox.org/mozilla-central/rev/3c7b40d1d74c26a82486f38b5828c3f3a43e05da/dom/events/EventNameList.h#529-542

#ifndef MESSAGE_TO_EVENT
// These are only here so that IsEventAttributeName() will return the right
// thing for these events.  We could probably remove them if we used
// Element::GetEventNameForAttr on the input to IsEventAttributeName before
// looking it up in the hashtable...
EVENT(webkitanimationend, eUnidentifiedEvent, EventNameType_All,
      eAnimationEventClass)
EVENT(webkitanimationiteration, eUnidentifiedEvent, EventNameType_All,
      eAnimationEventClass)
EVENT(webkitanimationstart, eUnidentifiedEvent, EventNameType_All,
      eAnimationEventClass)
EVENT(webkittransitionend, eUnidentifiedEvent, EventNameType_All,
      eTransitionEventClass)
#endif

https://searchfox.org/mozilla-central/rev/3c7b40d1d74c26a82486f38b5828c3f3a43e05da/dom/html/nsGenericHTMLElement.cpp#714-724

void nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
                                        const nsAttrValue* aValue,
                                        const nsAttrValue* aOldValue,
                                        nsIPrincipal* aMaybeScriptedPrincipal,
                                        bool aNotify) {
  if (aNamespaceID == kNameSpaceID_None) {
    if (IsEventAttributeName(aName) && aValue) {
      MOZ_ASSERT(aValue->Type() == nsAttrValue::eString,
                 "Expected string value for script body");
      SetEventHandler(GetEventNameForAttr(aName), aValue->GetStringValue());
    } else if (aNotify && aName == nsGkAtoms::spellcheck) {

This bug is for making the change suggested in the comment: First, check if the attribute name starts with "on". If it does, call GetEventNameForAttr to map it to an event name. Then, call IsEventAttributeName, which at that point it should be renamed to IsEventTypeAtom.

This pattern is used in a bunch of different places.

Assignee: nobody → mstange.moz
Status: NEW → ASSIGNED

Some event names differ from their corresponding event attribute names.
For example, on SVG elements, "onbegin" is the attribute name for the
event with the name "beginEvent", whose event type atom is nsGkAtoms::onbeginEvent.

In EventNameList.h, in the past we had to duplicate some items because
nsContentUtils::IsEventAttributeName wasn't differentiating between the two
properly.

This patch removes the duplicate items, renames nsContentUtils::IsEventAttributeName
to nsContentUtils::IsValidEventNameForElementType, and makes it so that
nsIContent::IsEventAttributeName (now Element::IsEventAttributeName) does
the appropriate translation.

Depends on D188495

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: