diff --git a/dom/base/AncestorIterator.h b/dom/base/AncestorIterator.h index 2c8a9b6ed325..1dc7cc5824ae 100644 --- a/dom/base/AncestorIterator.h +++ b/dom/base/AncestorIterator.h @@ -50,6 +50,7 @@ namespace dom { nsINode* mCurrent; \ }; \ class name_ : public Inclusive##name_ { \ + public: \ using Super = Inclusive##name_; \ explicit name_(const nsINode& aNode) \ : Inclusive##name_(aNode.method_()) {} \ diff --git a/dom/base/FilteredNodeIterator.h b/dom/base/FilteredNodeIterator.h index 359a527de2f3..ce64fa65c81b 100644 --- a/dom/base/FilteredNodeIterator.h +++ b/dom/base/FilteredNodeIterator.h @@ -23,6 +23,11 @@ class FilteredNodeIterator : public Iter { EnsureValid(); } + static T* First(const nsINode& aNode) { + FilteredNodeIterator iter(aNode); + return *iter; + } + FilteredNodeIterator& begin() { return *this; } using Iter::end; diff --git a/dom/html/HTMLFormSubmission.cpp b/dom/html/HTMLFormSubmission.cpp index 7b6370deb099..0d723f6a7c78 100644 --- a/dom/html/HTMLFormSubmission.cpp +++ b/dom/html/HTMLFormSubmission.cpp @@ -30,6 +30,7 @@ #include "nsCExternalHandlerService.h" #include "nsContentUtils.h" +#include "mozilla/dom/AncestorIterator.h" #include "mozilla/dom/Directory.h" #include "mozilla/dom/File.h" #include "mozilla/StaticPrefs_dom.h" @@ -831,14 +832,8 @@ nsresult HTMLFormSubmission::GetFromForm(HTMLFormElement* aForm, } if (method == NS_FORM_METHOD_DIALOG) { - HTMLDialogElement* dialog = nullptr; - for (nsIContent* parent = aForm->GetParent(); parent; - parent = parent->GetParent()) { - dialog = HTMLDialogElement::FromNodeOrNull(parent); - if (dialog) { - break; - } - } + HTMLDialogElement* dialog = + AncestorsOfType::First(*aForm); // If there isn't one, or if it does not have an open attribute, do // nothing.