Bug 1808426 - Event handlers for form-associated img and custom elements occur within the form's context. r=edgar

Differential Revision: https://phabricator.services.mozilla.com/D166129
This commit is contained in:
Adam Vandolder 2023-01-06 18:17:05 +00:00
parent 9ccd32860d
commit 8101dd08cb
5 changed files with 19 additions and 6 deletions

View File

@ -49,6 +49,16 @@ void HTMLElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
nsGenericHTMLFormElement::GetEventTargetParent(aVisitor);
}
nsINode* HTMLElement::GetScopeChainParent() const {
if (IsFormAssociatedCustomElements()) {
auto* form = GetFormInternal();
if (form) {
return form;
}
}
return nsGenericHTMLFormElement::GetScopeChainParent();
}
nsresult HTMLElement::BindToTree(BindContext& aContext, nsINode& aParent) {
nsresult rv = nsGenericHTMLFormElement::BindToTree(aContext, aParent);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -25,6 +25,7 @@ class HTMLElement final : public nsGenericHTMLFormElement {
// nsINode
nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
nsINode* GetScopeChainParent() const override;
// nsIContent
nsresult BindToTree(BindContext&, nsINode& aParent) override;

View File

@ -502,6 +502,13 @@ void HTMLImageElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
nsGenericHTMLElement::GetEventTargetParent(aVisitor);
}
nsINode* HTMLImageElement::GetScopeChainParent() const {
if (mForm) {
return mForm;
}
return nsGenericHTMLElement::GetScopeChainParent();
}
bool HTMLImageElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
int32_t* aTabIndex) {
int32_t tabIndex = TabIndex();

View File

@ -69,6 +69,7 @@ class HTMLImageElement final : public nsGenericHTMLElement,
const override;
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
nsINode* GetScopeChainParent() const override;
bool IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
int32_t* aTabIndex) override;

View File

@ -1,6 +0,0 @@
[compile-event-handler-lexical-scopes-form-owner.html]
[<img> has a form owner]
expected: FAIL
[form-associated <x-foo> has a form owner]
expected: FAIL