diff options
author | FranklinDM <mrmineshafter17@gmail.com> | 2023-04-05 14:04:43 +0800 |
---|---|---|
committer | FranklinDM <mrmineshafter17@gmail.com> | 2023-04-07 22:08:20 +0800 |
commit | c2b9a9e0057964d9ec96933cc02a11c60b234698 (patch) | |
tree | c6761c7a0194dc134d479e9cc1c7cf03de8ca389 /dom/base | |
parent | 8e2788496d325b4b50b86d98125376b5dbdf7554 (diff) | |
download | uxp-c2b9a9e0057964d9ec96933cc02a11c60b234698.tar.gz |
Issue #252 - Move getElementsByName from HTMLDocument to Document
Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1415176
Diffstat (limited to 'dom/base')
-rw-r--r-- | dom/base/nsDocument.cpp | 19 | ||||
-rw-r--r-- | dom/base/nsIDocument.h | 11 |
2 files changed, 30 insertions, 0 deletions
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<nsString*>(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<nsString*>(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<nsContentList> 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; |