From c2b9a9e0057964d9ec96933cc02a11c60b234698 Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Wed, 5 Apr 2023 14:04:43 +0800 Subject: Issue #252 - Move getElementsByName from HTMLDocument to Document Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1415176 --- dom/base/nsDocument.cpp | 19 +++++++++++++++++++ dom/base/nsIDocument.h | 11 +++++++++++ 2 files changed, 30 insertions(+) (limited to 'dom/base') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 5667d1a0fc..20fbf72983 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -6690,6 +6690,25 @@ nsIDocument::SetDir(const nsAString& aDirection) } } +bool +nsIDocument::MatchNameAttribute(Element* aElement, int32_t aNamespaceID, + nsIAtom* aAtom, void* aData) +{ + NS_PRECONDITION(aElement, "Must have element to work with!"); + nsString* elementName = static_cast(aData); + return + aElement->GetNameSpaceID() == kNameSpaceID_XHTML && + aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, + *elementName, eCaseMatters); +} + +/* static */ +void* +nsIDocument::UseExistingNameString(nsINode* aRootNode, const nsString* aName) +{ + return const_cast(aName); +} + NS_IMETHODIMP nsDocument::GetInputEncoding(nsAString& aInputEncoding) { diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index d64827aa6d..6ae4eb4f55 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -2599,6 +2599,11 @@ public: virtual void SetTitle(const nsAString& aTitle, mozilla::ErrorResult& rv) = 0; void GetDir(nsAString& aDirection) const; void SetDir(const nsAString& aDirection); + already_AddRefed GetElementsByName(const nsAString & aName) + { + return NS_GetFuncStringNodeList(this, MatchNameAttribute, nullptr, + UseExistingNameString, aName); + } nsPIDOMWindowOuter* GetDefaultView() const { return GetWindow(); @@ -2883,6 +2888,12 @@ protected: // the relevant refresh driver. void UpdateFrameRequestCallbackSchedulingState(nsIPresShell* aOldShell = nullptr); + // Helpers for GetElementsByName. + static bool MatchNameAttribute(mozilla::dom::Element* aElement, + int32_t aNamespaceID, + nsIAtom* aAtom, void* aData); + static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName); + nsCString mReferrer; nsString mLastModified; -- cgit v1.2.3