diff options
-rw-r--r-- | dom/base/nsDocument.cpp | 19 | ||||
-rw-r--r-- | dom/base/nsIDocument.h | 11 | ||||
-rw-r--r-- | dom/html/nsHTMLDocument.cpp | 27 | ||||
-rw-r--r-- | dom/html/nsHTMLDocument.h | 9 | ||||
-rw-r--r-- | dom/interfaces/html/nsIDOMHTMLDocument.idl | 1 | ||||
-rw-r--r-- | dom/webidl/Document.webidl | 3 | ||||
-rw-r--r-- | dom/webidl/HTMLDocument.webidl | 1 | ||||
-rw-r--r-- | layout/base/nsPresShell.cpp | 7 |
8 files changed, 35 insertions, 43 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; diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index bc62f97538..3fb7ddf160 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -1810,33 +1810,6 @@ nsHTMLDocument::Writeln(JSContext* cx, const Sequence<nsString>& aText, WriteCommon(cx, aText, true, rv); } -bool -nsHTMLDocument::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* -nsHTMLDocument::UseExistingNameString(nsINode* aRootNode, const nsString* aName) -{ - return const_cast<nsString*>(aName); -} - -NS_IMETHODIMP -nsHTMLDocument::GetElementsByName(const nsAString& aElementName, - nsIDOMNodeList** aReturn) -{ - *aReturn = GetElementsByName(aElementName).take(); - return NS_OK; -} - void nsHTMLDocument::AddedForm() { diff --git a/dom/html/nsHTMLDocument.h b/dom/html/nsHTMLDocument.h index 8eec4c0c4b..582ac8f5b2 100644 --- a/dom/html/nsHTMLDocument.h +++ b/dom/html/nsHTMLDocument.h @@ -185,11 +185,6 @@ public: return nsHTMLDocument::GetForms(); } nsIHTMLCollection* Scripts(); - already_AddRefed<nsContentList> GetElementsByName(const nsAString & aName) - { - return NS_GetFuncStringNodeList(this, MatchNameAttribute, nullptr, - UseExistingNameString, aName); - } already_AddRefed<nsIDocument> Open(JSContext* cx, const nsAString& aType, const nsAString& aReplace, @@ -260,10 +255,6 @@ protected: nsIAtom* aAtom, void* aData); static bool MatchAnchors(mozilla::dom::Element* aElement, int32_t aNamespaceID, nsIAtom* aAtom, void* aData); - static bool MatchNameAttribute(mozilla::dom::Element* aElement, - int32_t aNamespaceID, - nsIAtom* aAtom, void* aData); - static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName); static void DocumentWriteTerminationFunc(nsISupports *aRef); diff --git a/dom/interfaces/html/nsIDOMHTMLDocument.idl b/dom/interfaces/html/nsIDOMHTMLDocument.idl index 6813ccf2ee..0eede551a9 100644 --- a/dom/interfaces/html/nsIDOMHTMLDocument.idl +++ b/dom/interfaces/html/nsIDOMHTMLDocument.idl @@ -29,7 +29,6 @@ interface nsIDOMHTMLDocument : nsIDOMDocument readonly attribute nsIDOMHTMLCollection links; readonly attribute nsIDOMHTMLCollection forms; readonly attribute nsIDOMHTMLCollection scripts; - nsIDOMNodeList getElementsByName(in DOMString elementName); // If aContentType is not something supported by nsHTMLDocument and // the HTML content sink, trying to write to the document will diff --git a/dom/webidl/Document.webidl b/dom/webidl/Document.webidl index 4cd1c0c269..e5b9f14996 100644 --- a/dom/webidl/Document.webidl +++ b/dom/webidl/Document.webidl @@ -123,7 +123,8 @@ partial interface Document { //(HTML only)readonly attribute HTMLCollection links; //(HTML only)readonly attribute HTMLCollection forms; //(HTML only)readonly attribute HTMLCollection scripts; - //(HTML only)NodeList getElementsByName(DOMString elementName); + [Pure] + NodeList getElementsByName(DOMString elementName); //(Not implemented)readonly attribute DOMElementMap cssElementMap; // dynamic markup insertion diff --git a/dom/webidl/HTMLDocument.webidl b/dom/webidl/HTMLDocument.webidl index ffa38d97d0..159edf7957 100644 --- a/dom/webidl/HTMLDocument.webidl +++ b/dom/webidl/HTMLDocument.webidl @@ -29,7 +29,6 @@ interface HTMLDocument : Document { readonly attribute HTMLCollection forms; [Pure] readonly attribute HTMLCollection scripts; - NodeList getElementsByName(DOMString elementName); // dynamic markup insertion [CEReactions, Throws] diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 23876cc112..f95b14f242 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -2978,11 +2978,10 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll, } // Search for an anchor element with a matching "name" attribute - if (!content && htmlDoc) { - nsCOMPtr<nsIDOMNodeList> list; + if (!content && htmlDoc && mDocument) { // Find a matching list of named nodes - rv = htmlDoc->GetElementsByName(aAnchorName, getter_AddRefs(list)); - if (NS_SUCCEEDED(rv) && list) { + nsCOMPtr<nsIDOMNodeList> list = mDocument->GetElementsByName(aAnchorName); + if (list) { uint32_t i; // Loop through the named nodes looking for the first anchor for (i = 0; true; i++) { |