2013-12-02 02:26:11 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_shadowroot_h__
|
|
|
|
#define mozilla_dom_shadowroot_h__
|
|
|
|
|
|
|
|
#include "mozilla/dom/DocumentFragment.h"
|
2014-04-12 01:15:59 -07:00
|
|
|
#include "mozilla/dom/StyleSheetList.h"
|
2013-12-02 02:26:11 -08:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsDocument.h"
|
|
|
|
|
|
|
|
class nsIAtom;
|
|
|
|
class nsIContent;
|
|
|
|
class nsIDocument;
|
|
|
|
class nsPIDOMWindow;
|
|
|
|
class nsXBLPrototypeBinding;
|
|
|
|
class nsTagNameMapEntry;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Element;
|
2013-12-02 02:26:12 -08:00
|
|
|
class HTMLContentElement;
|
2013-12-20 22:43:58 -08:00
|
|
|
class HTMLShadowElement;
|
2013-12-02 02:26:12 -08:00
|
|
|
class ShadowRootStyleSheetList;
|
2013-12-02 02:26:11 -08:00
|
|
|
|
2013-12-02 02:26:12 -08:00
|
|
|
class ShadowRoot : public DocumentFragment,
|
|
|
|
public nsStubMutationObserver
|
2013-12-02 02:26:11 -08:00
|
|
|
{
|
2013-12-02 02:26:12 -08:00
|
|
|
friend class ShadowRootStyleSheetList;
|
2013-12-02 02:26:11 -08:00
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRoot,
|
|
|
|
DocumentFragment)
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2013-12-02 02:26:12 -08:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
ShadowRoot(nsIContent* aContent, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2013-12-02 02:26:12 -08:00
|
|
|
nsXBLPrototypeBinding* aProtoBinding);
|
2013-12-02 02:26:11 -08:00
|
|
|
|
|
|
|
void AddToIdTable(Element* aElement, nsIAtom* aId);
|
|
|
|
void RemoveFromIdTable(Element* aElement, nsIAtom* aId);
|
2014-06-20 03:32:49 -07:00
|
|
|
void InsertSheet(CSSStyleSheet* aSheet, nsIContent* aLinkingContent);
|
|
|
|
void RemoveSheet(CSSStyleSheet* aSheet);
|
2013-12-02 02:26:12 -08:00
|
|
|
bool ApplyAuthorStyles();
|
|
|
|
void SetApplyAuthorStyles(bool aApplyAuthorStyles);
|
2014-04-12 01:18:54 -07:00
|
|
|
StyleSheetList* StyleSheets();
|
2013-12-20 22:43:58 -08:00
|
|
|
HTMLShadowElement* GetShadowElement() { return mShadowElement; }
|
2013-12-02 02:26:11 -08:00
|
|
|
|
2013-12-02 02:26:12 -08:00
|
|
|
/**
|
2013-12-20 22:43:58 -08:00
|
|
|
* Sets the current shadow insertion point where the older
|
|
|
|
* ShadowRoot will be projected.
|
|
|
|
*/
|
|
|
|
void SetShadowElement(HTMLShadowElement* aShadowElement);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the node that populates the distribution pool with
|
|
|
|
* its children. This is distinct from the ShadowRoot host described
|
|
|
|
* in the specifications. The ShadowRoot host is the element
|
|
|
|
* which created this ShadowRoot and does not change. The pool host
|
|
|
|
* is the same as the ShadowRoot host if this is the youngest
|
|
|
|
* ShadowRoot. If this is an older ShadowRoot, the pool host is
|
|
|
|
* the <shadow> element in the younger ShadowRoot (if it exists).
|
|
|
|
*/
|
|
|
|
void ChangePoolHost(nsIContent* aNewHost);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Distributes a single explicit child of the pool host to the content
|
2013-12-02 02:26:12 -08:00
|
|
|
* insertion points in this ShadowRoot.
|
|
|
|
*/
|
|
|
|
void DistributeSingleNode(nsIContent* aContent);
|
|
|
|
|
|
|
|
/**
|
2013-12-20 22:43:58 -08:00
|
|
|
* Removes a single explicit child of the pool host from the content
|
2013-12-02 02:26:12 -08:00
|
|
|
* insertion points in this ShadowRoot.
|
|
|
|
*/
|
|
|
|
void RemoveDistributedNode(nsIContent* aContent);
|
|
|
|
|
|
|
|
/**
|
2013-12-20 22:43:58 -08:00
|
|
|
* Distributes all the explicit children of the pool host to the content
|
2013-12-02 02:26:12 -08:00
|
|
|
* insertion points in this ShadowRoot.
|
|
|
|
*/
|
|
|
|
void DistributeAllNodes();
|
|
|
|
|
|
|
|
void AddInsertionPoint(HTMLContentElement* aInsertionPoint);
|
|
|
|
void RemoveInsertionPoint(HTMLContentElement* aInsertionPoint);
|
|
|
|
|
2013-12-20 22:43:58 -08:00
|
|
|
void SetYoungerShadow(ShadowRoot* aYoungerShadow);
|
2014-10-15 18:25:45 -07:00
|
|
|
ShadowRoot* GetYoungerShadowRoot() { return mYoungerShadow; }
|
2013-12-02 02:26:12 -08:00
|
|
|
void SetInsertionPointChanged() { mInsertionPointChanged = true; }
|
|
|
|
|
2013-12-20 22:43:58 -08:00
|
|
|
void SetAssociatedBinding(nsXBLBinding* aBinding) { mAssociatedBinding = aBinding; }
|
2013-12-02 02:26:12 -08:00
|
|
|
|
2013-12-20 22:43:58 -08:00
|
|
|
nsISupports* GetParentObject() const { return mPoolHost; }
|
2013-12-02 02:26:11 -08:00
|
|
|
|
2013-12-20 22:43:58 -08:00
|
|
|
nsIContent* GetPoolHost() { return mPoolHost; }
|
|
|
|
nsTArray<HTMLShadowElement*>& ShadowDescendants() { return mShadowDescendants; }
|
2013-12-02 02:26:12 -08:00
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-12-02 02:26:11 -08:00
|
|
|
|
2013-12-20 22:43:58 -08:00
|
|
|
static bool IsPooledNode(nsIContent* aChild, nsIContent* aContainer,
|
|
|
|
nsIContent* aHost);
|
2013-12-02 02:26:11 -08:00
|
|
|
static ShadowRoot* FromNode(nsINode* aNode);
|
2013-12-20 22:43:58 -08:00
|
|
|
static bool IsShadowInsertionPoint(nsIContent* aContent);
|
2013-12-02 02:26:11 -08:00
|
|
|
|
2014-05-21 23:11:53 -07:00
|
|
|
static void RemoveDestInsertionPoint(nsIContent* aInsertionPoint,
|
|
|
|
nsTArray<nsIContent*>& aDestInsertionPoints);
|
|
|
|
|
2013-12-02 02:26:11 -08:00
|
|
|
// WebIDL methods.
|
|
|
|
Element* GetElementById(const nsAString& aElementId);
|
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
GetElementsByTagName(const nsAString& aNamespaceURI);
|
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
GetElementsByTagNameNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aLocalName);
|
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
GetElementsByClassName(const nsAString& aClasses);
|
2013-12-02 02:26:12 -08:00
|
|
|
void GetInnerHTML(nsAString& aInnerHTML);
|
|
|
|
void SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError);
|
2014-10-15 18:25:45 -07:00
|
|
|
Element* Host();
|
|
|
|
ShadowRoot* GetOlderShadowRoot() { return mOlderShadow; }
|
2014-06-07 01:42:54 -07:00
|
|
|
void StyleSheetChanged();
|
2013-12-02 02:26:11 -08:00
|
|
|
protected:
|
2014-07-08 14:23:16 -07:00
|
|
|
virtual ~ShadowRoot();
|
2013-12-02 02:26:12 -08:00
|
|
|
|
2013-12-20 22:43:58 -08:00
|
|
|
// The pool host is the parent of the nodes that will be distributed
|
|
|
|
// into the insertion points in this ShadowRoot. See |ChangeShadowRoot|.
|
|
|
|
nsCOMPtr<nsIContent> mPoolHost;
|
2013-12-02 02:26:12 -08:00
|
|
|
|
|
|
|
// An array of content insertion points that are a descendant of the ShadowRoot
|
|
|
|
// sorted in tree order. Insertion points are responsible for notifying
|
|
|
|
// the ShadowRoot when they are removed or added as a descendant. The insertion
|
|
|
|
// points are kept alive by the parent node, thus weak references are held
|
|
|
|
// by the array.
|
|
|
|
nsTArray<HTMLContentElement*> mInsertionPoints;
|
|
|
|
|
2013-12-20 22:43:58 -08:00
|
|
|
// An array of the <shadow> elements that are descendant of the ShadowRoot
|
|
|
|
// sorted in tree order. Only the first may be a shadow insertion point.
|
|
|
|
nsTArray<HTMLShadowElement*> mShadowDescendants;
|
|
|
|
|
2013-12-02 02:26:11 -08:00
|
|
|
nsTHashtable<nsIdentifierMapEntry> mIdentifierMap;
|
2013-12-02 02:26:12 -08:00
|
|
|
nsXBLPrototypeBinding* mProtoBinding;
|
|
|
|
|
|
|
|
// It is necessary to hold a reference to the associated nsXBLBinding
|
|
|
|
// because the binding holds a reference on the nsXBLDocumentInfo that
|
|
|
|
// owns |mProtoBinding|.
|
|
|
|
nsRefPtr<nsXBLBinding> mAssociatedBinding;
|
|
|
|
|
|
|
|
nsRefPtr<ShadowRootStyleSheetList> mStyleSheetList;
|
2013-12-02 02:26:12 -08:00
|
|
|
|
2013-12-20 22:43:58 -08:00
|
|
|
// The current shadow insertion point of this ShadowRoot.
|
|
|
|
HTMLShadowElement* mShadowElement;
|
|
|
|
|
|
|
|
// The ShadowRoot that was created by the host element before
|
|
|
|
// this ShadowRoot was created.
|
|
|
|
nsRefPtr<ShadowRoot> mOlderShadow;
|
|
|
|
|
|
|
|
// The ShadowRoot that was created by the host element after
|
|
|
|
// this ShadowRoot was created.
|
|
|
|
nsRefPtr<ShadowRoot> mYoungerShadow;
|
|
|
|
|
2013-12-02 02:26:12 -08:00
|
|
|
// A boolean that indicates that an insertion point was added or removed
|
|
|
|
// from this ShadowRoot and that the nodes need to be redistributed into
|
|
|
|
// the insertion points. After this flag is set, nodes will be distributed
|
|
|
|
// on the next mutation event.
|
|
|
|
bool mInsertionPointChanged;
|
2013-12-02 02:26:11 -08:00
|
|
|
};
|
|
|
|
|
2014-04-12 01:15:59 -07:00
|
|
|
class ShadowRootStyleSheetList : public StyleSheetList
|
2013-12-02 02:26:12 -08:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit ShadowRootStyleSheetList(ShadowRoot* aShadowRoot);
|
2013-12-02 02:26:12 -08:00
|
|
|
|
2014-04-12 01:18:54 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRootStyleSheetList, StyleSheetList)
|
2013-12-02 02:26:12 -08:00
|
|
|
|
2014-04-12 01:18:54 -07:00
|
|
|
virtual nsINode* GetParentObject() const MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return mShadowRoot;
|
|
|
|
}
|
2013-12-02 02:26:12 -08:00
|
|
|
|
2014-04-12 01:18:54 -07:00
|
|
|
virtual uint32_t Length() MOZ_OVERRIDE;
|
2014-06-20 03:32:49 -07:00
|
|
|
virtual CSSStyleSheet* IndexedGetter(uint32_t aIndex, bool& aFound) MOZ_OVERRIDE;
|
2014-04-12 01:15:59 -07:00
|
|
|
|
2013-12-02 02:26:12 -08:00
|
|
|
protected:
|
2014-07-08 14:23:16 -07:00
|
|
|
virtual ~ShadowRootStyleSheetList();
|
|
|
|
|
2013-12-02 02:26:12 -08:00
|
|
|
nsRefPtr<ShadowRoot> mShadowRoot;
|
|
|
|
};
|
|
|
|
|
2013-12-02 02:26:11 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_shadowroot_h__
|
|
|
|
|