2019-03-11 03:26:37 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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"
|
2020-05-24 22:50:05 -07:00
|
|
|
#include "mozilla/dom/StyleScope.h"
|
2019-03-11 03:26:37 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIContentInlines.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsDocument.h"
|
|
|
|
|
|
|
|
class nsIAtom;
|
|
|
|
class nsIContent;
|
|
|
|
class nsXBLPrototypeBinding;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2020-05-24 22:50:05 -07:00
|
|
|
|
|
|
|
class EventChainPreVisitor;
|
|
|
|
|
2019-03-11 03:26:37 -07:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Element;
|
|
|
|
|
|
|
|
class ShadowRoot final : public DocumentFragment,
|
2020-05-24 22:50:05 -07:00
|
|
|
public StyleScope,
|
2019-03-11 03:26:37 -07:00
|
|
|
public nsStubMutationObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRoot,
|
|
|
|
DocumentFragment)
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
|
2020-05-24 22:50:05 -07:00
|
|
|
ShadowRoot(Element* aElement, bool aClosed,
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2019-03-11 03:26:37 -07:00
|
|
|
nsXBLPrototypeBinding* aProtoBinding);
|
|
|
|
|
2020-05-24 22:50:05 -07:00
|
|
|
// Shadow DOM v1
|
|
|
|
Element* Host();
|
|
|
|
ShadowRootMode Mode() const
|
|
|
|
{
|
|
|
|
return mMode;
|
|
|
|
}
|
|
|
|
bool IsClosed() const
|
|
|
|
{
|
|
|
|
return mMode == ShadowRootMode::Closed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// StyleScope.
|
|
|
|
nsINode& AsNode() final
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [deprecated] Shadow DOM v0
|
2019-03-11 03:26:37 -07:00
|
|
|
void AddToIdTable(Element* aElement, nsIAtom* aId);
|
|
|
|
void RemoveFromIdTable(Element* aElement, nsIAtom* aId);
|
|
|
|
void InsertSheet(StyleSheet* aSheet, nsIContent* aLinkingContent);
|
|
|
|
void RemoveSheet(StyleSheet* aSheet);
|
|
|
|
bool ApplyAuthorStyles();
|
|
|
|
void SetApplyAuthorStyles(bool aApplyAuthorStyles);
|
2020-05-24 22:50:05 -07:00
|
|
|
StyleSheetList* StyleSheets()
|
|
|
|
{
|
|
|
|
return &StyleScope::EnsureDOMStyleSheets();
|
|
|
|
}
|
2019-03-11 03:26:37 -07:00
|
|
|
|
|
|
|
/**
|
2020-05-24 22:50:05 -07:00
|
|
|
* Distributes all the explicit children of the pool host to the content
|
|
|
|
* insertion points in this ShadowRoot.
|
2019-03-11 03:26:37 -07:00
|
|
|
*/
|
2020-05-24 22:50:05 -07:00
|
|
|
void DistributeAllNodes();
|
2019-03-11 03:26:37 -07:00
|
|
|
|
2020-05-24 22:50:05 -07:00
|
|
|
private:
|
2019-03-11 03:26:37 -07:00
|
|
|
/**
|
2020-05-24 22:50:05 -07:00
|
|
|
* Try to reassign an element to a slot and returns whether the assignment
|
|
|
|
* changed.
|
2019-03-11 03:26:37 -07:00
|
|
|
*/
|
2020-05-24 22:50:05 -07:00
|
|
|
bool MaybeReassignElement(Element* aElement, const nsAttrValue* aOldValue);
|
2019-03-11 03:26:37 -07:00
|
|
|
|
|
|
|
/**
|
2020-05-24 22:50:05 -07:00
|
|
|
* Try to assign aContent to a slot in the shadow tree, returns the assigned
|
|
|
|
* slot if found.
|
2019-03-11 03:26:37 -07:00
|
|
|
*/
|
2020-05-24 22:50:05 -07:00
|
|
|
const HTMLSlotElement* AssignSlotFor(nsIContent* aContent);
|
2019-03-11 03:26:37 -07:00
|
|
|
|
|
|
|
/**
|
2020-05-24 22:50:05 -07:00
|
|
|
* Unassign aContent from the assigned slot in the shadow tree, returns the
|
|
|
|
* assigned slot if found.
|
|
|
|
*
|
|
|
|
* Note: slot attribute of aContent may have changed already, so pass slot
|
|
|
|
* name explicity here.
|
2019-03-11 03:26:37 -07:00
|
|
|
*/
|
2020-05-24 22:50:05 -07:00
|
|
|
const HTMLSlotElement* UnassignSlotFor(nsIContent* aContent,
|
|
|
|
const nsAString& aSlotName);
|
2019-03-11 03:26:37 -07:00
|
|
|
|
|
|
|
/**
|
2020-05-24 22:50:05 -07:00
|
|
|
* Called when we redistribute content after insertion points have changed.
|
2019-03-11 03:26:37 -07:00
|
|
|
*/
|
2020-05-24 22:50:05 -07:00
|
|
|
void DistributionChanged();
|
2019-03-11 03:26:37 -07:00
|
|
|
|
2020-05-24 22:50:05 -07:00
|
|
|
bool IsPooledNode(nsIContent* aChild) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void AddSlot(HTMLSlotElement* aSlot);
|
|
|
|
void RemoveSlot(HTMLSlotElement* aSlot);
|
2019-03-11 03:26:37 -07:00
|
|
|
|
|
|
|
void SetInsertionPointChanged() { mInsertionPointChanged = true; }
|
|
|
|
|
|
|
|
void SetAssociatedBinding(nsXBLBinding* aBinding) { mAssociatedBinding = aBinding; }
|
|
|
|
|
|
|
|
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
static ShadowRoot* FromNode(nsINode* aNode);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
void GetInnerHTML(nsAString& aInnerHTML);
|
|
|
|
void SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError);
|
|
|
|
void StyleSheetChanged();
|
|
|
|
|
|
|
|
bool IsComposedDocParticipant() { return mIsComposedDocParticipant; }
|
|
|
|
void SetIsComposedDocParticipant(bool aIsComposedDocParticipant)
|
|
|
|
{
|
|
|
|
mIsComposedDocParticipant = aIsComposedDocParticipant;
|
|
|
|
}
|
|
|
|
|
2020-05-24 22:50:05 -07:00
|
|
|
nsresult GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
|
|
|
|
2019-03-11 03:26:37 -07:00
|
|
|
protected:
|
|
|
|
virtual ~ShadowRoot();
|
|
|
|
|
2020-05-24 22:50:05 -07:00
|
|
|
ShadowRootMode mMode;
|
2019-03-11 03:26:37 -07:00
|
|
|
|
2020-05-24 22:50:05 -07:00
|
|
|
// Map from name of slot to an array of all slots in the shadow DOM with with
|
|
|
|
// the given name. The slots are stored as a weak pointer because the elements
|
|
|
|
// are in the shadow tree and should be kept alive by its parent.
|
|
|
|
nsClassHashtable<nsStringHashKey, nsTArray<mozilla::dom::HTMLSlotElement*>> mSlotMap;
|
2019-03-11 03:26:37 -07:00
|
|
|
|
|
|
|
nsTHashtable<nsIdentifierMapEntry> mIdentifierMap;
|
|
|
|
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|.
|
|
|
|
RefPtr<nsXBLBinding> mAssociatedBinding;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// Flag to indicate whether the descendants of this shadow root are part of the
|
|
|
|
// composed document. Ideally, we would use a node flag on nodes to
|
|
|
|
// mark whether it is in the composed document, but we have run out of flags
|
|
|
|
// so instead we track it here.
|
|
|
|
bool mIsComposedDocParticipant;
|
|
|
|
|
|
|
|
nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_shadowroot_h__
|
|
|
|
|