Bug 1426494 - Share more code between nsIDocument and ShadowRoot

Tag #1375
This commit is contained in:
Matt A. Tobin 2020-06-13 08:21:48 -04:00 • committed by Roy Tam
commit db72493615
23 changed files with 369 additions and 335 deletions

View file

@ -34,7 +34,7 @@
#include "prclist.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/CORSMode.h"
#include "mozilla/dom/StyleScope.h"
#include "mozilla/dom/DocumentOrShadowRoot.h"
#include "mozilla/LinkedList.h"
#include "mozilla/StyleBackendType.h"
#include "mozilla/StyleSheet.h"
@ -198,7 +198,7 @@ class nsContentList;
// Document interface. This is implemented by all document objects in
// Gecko.
class nsIDocument : public nsINode,
public mozilla::dom::StyleScope
public mozilla::dom::DocumentOrShadowRoot
{
typedef mozilla::dom::GlobalObject GlobalObject;
@ -499,7 +499,7 @@ public:
* to remove it.
*/
typedef bool (* IDTargetObserver)(Element* aOldElement,
Element* aNewelement, void* aData);
Element* aNewelement, void* aData);
/**
* Add an IDTargetObserver for a specific ID. The IDTargetObserver
@ -1071,14 +1071,9 @@ public:
*/
virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet) = 0;
nsINode& AsNode() final
{
return *this;
}
mozilla::dom::StyleSheetList* StyleSheets()
{
return &StyleScope::EnsureDOMStyleSheets();
return &DocumentOrShadowRoot::EnsureDOMStyleSheets();
}
/**
@ -2362,19 +2357,10 @@ public:
virtual void ResetScrolledToRefAlready() = 0;
virtual void SetChangeScrollPosWhenScrollingToRef(bool aValue) = 0;
/**
* This method is similar to GetElementById() from nsIDOMDocument but it
* returns a mozilla::dom::Element instead of a nsIDOMElement.
* It prevents converting nsIDOMElement to mozilla::dom::Element which is
* already converted from mozilla::dom::Element.
*/
virtual Element* GetElementById(const nsAString& aElementId) = 0;
/**
* This method returns _all_ the elements in this document which
* have id aElementId, if there are any. Otherwise it returns null.
*/
virtual const nsTArray<Element*>* GetAllElementsForId(const nsAString& aElementId) const = 0;
using mozilla::dom::DocumentOrShadowRoot::GetElementById;
using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagName;
using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagNameNS;
using mozilla::dom::DocumentOrShadowRoot::GetElementsByClassName;
/**
* Lookup an image element using its associated ID, which is usually provided
@ -2574,18 +2560,6 @@ public:
nsIDocument* GetTopLevelContentDocument();
already_AddRefed<nsContentList>
GetElementsByTagName(const nsAString& aTagName)
{
return NS_GetContentList(this, kNameSpaceID_Unknown, aTagName);
}
already_AddRefed<nsContentList>
GetElementsByTagNameNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName,
mozilla::ErrorResult& aResult);
already_AddRefed<nsContentList>
GetElementsByClassName(const nsAString& aClasses);
// GetElementById defined above
virtual already_AddRefed<Element>
CreateElement(const nsAString& aTagName,
const mozilla::dom::ElementCreationOptionsOrString& aOptions,