2015-05-03 19:32:37 +00: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: */
|
2013-12-02 10:26:11 +00:00
|
|
|
/* 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"
|
2017-12-21 01:09:22 +00:00
|
|
|
#include "mozilla/dom/StyleScope.h"
|
2013-12-02 10:26:11 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2016-08-19 02:30:53 +00:00
|
|
|
#include "nsIContentInlines.h"
|
2017-06-20 13:57:08 +00:00
|
|
|
#include "nsIdentifierMapEntry.h"
|
2013-12-02 10:26:11 +00:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
class nsAtom;
|
2013-12-02 10:26:11 +00:00
|
|
|
class nsIContent;
|
|
|
|
class nsXBLPrototypeBinding;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2017-12-04 08:06:40 +00:00
|
|
|
|
|
|
|
class EventChainPreVisitor;
|
|
|
|
|
2013-12-02 10:26:11 +00:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Element;
|
|
|
|
|
2015-03-21 18:35:18 +00:00
|
|
|
class ShadowRoot final : public DocumentFragment,
|
2017-12-21 01:09:22 +00:00
|
|
|
public StyleScope,
|
2015-03-21 18:35:18 +00:00
|
|
|
public nsStubMutationObserver
|
2013-12-02 10:26:11 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRoot,
|
|
|
|
DocumentFragment)
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2013-12-02 10:26:12 +00:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
|
2017-10-19 06:44:35 +00:00
|
|
|
ShadowRoot(Element* aElement, bool aClosed,
|
2017-09-25 15:09:26 +00:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2013-12-02 10:26:12 +00:00
|
|
|
nsXBLPrototypeBinding* aProtoBinding);
|
2013-12-02 10:26:11 +00:00
|
|
|
|
2017-10-19 06:44:35 +00:00
|
|
|
// Shadow DOM v1
|
|
|
|
Element* Host();
|
2017-12-17 21:29:10 +00:00
|
|
|
ShadowRootMode Mode() const
|
2017-10-19 06:44:35 +00:00
|
|
|
{
|
|
|
|
return mMode;
|
|
|
|
}
|
2017-12-17 21:29:10 +00:00
|
|
|
bool IsClosed() const
|
2017-11-02 08:53:44 +00:00
|
|
|
{
|
|
|
|
return mMode == ShadowRootMode::Closed;
|
|
|
|
}
|
2017-10-19 06:44:35 +00:00
|
|
|
|
|
|
|
// [deprecated] Shadow DOM v0
|
2016-09-26 12:03:25 +00:00
|
|
|
void InsertSheet(StyleSheet* aSheet, nsIContent* aLinkingContent);
|
|
|
|
void RemoveSheet(StyleSheet* aSheet);
|
2013-12-02 10:26:12 +00:00
|
|
|
bool ApplyAuthorStyles();
|
|
|
|
void SetApplyAuthorStyles(bool aApplyAuthorStyles);
|
2017-12-17 21:29:10 +00:00
|
|
|
StyleSheetList* StyleSheets()
|
|
|
|
{
|
2017-12-21 01:09:22 +00:00
|
|
|
return &StyleScope::EnsureDOMStyleSheets();
|
2017-12-17 21:29:10 +00:00
|
|
|
}
|
2013-12-21 06:43:58 +00:00
|
|
|
|
2017-10-17 16:28:42 +00:00
|
|
|
/**
|
|
|
|
* Distributes all the explicit children of the pool host to the content
|
|
|
|
* insertion points in this ShadowRoot.
|
|
|
|
*/
|
|
|
|
void DistributeAllNodes();
|
|
|
|
|
|
|
|
private:
|
2013-12-02 10:26:12 +00:00
|
|
|
|
2017-10-18 13:24:53 +00:00
|
|
|
/**
|
2017-12-04 08:06:34 +00:00
|
|
|
* Try to reassign an element to a slot and returns whether the assignment
|
2017-10-18 14:03:41 +00:00
|
|
|
* changed.
|
|
|
|
*/
|
2017-12-04 08:06:34 +00:00
|
|
|
bool MaybeReassignElement(Element* aElement, const nsAttrValue* aOldValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to assign aContent to a slot in the shadow tree, returns the assigned
|
|
|
|
* slot if found.
|
|
|
|
*/
|
|
|
|
const HTMLSlotElement* AssignSlotFor(nsIContent* aContent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
const HTMLSlotElement* UnassignSlotFor(nsIContent* aContent,
|
|
|
|
const nsAString& aSlotName);
|
2017-10-18 14:03:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when we redistribute content after insertion points have changed.
|
2017-10-18 13:24:53 +00:00
|
|
|
*/
|
|
|
|
void DistributionChanged();
|
|
|
|
|
2017-10-18 13:02:16 +00:00
|
|
|
bool IsPooledNode(nsIContent* aChild) const;
|
2013-12-02 10:26:12 +00:00
|
|
|
|
2017-10-17 16:28:42 +00:00
|
|
|
public:
|
2017-12-04 08:06:34 +00:00
|
|
|
void AddSlot(HTMLSlotElement* aSlot);
|
|
|
|
void RemoveSlot(HTMLSlotElement* aSlot);
|
|
|
|
|
2013-12-02 10:26:12 +00:00
|
|
|
void SetInsertionPointChanged() { mInsertionPointChanged = true; }
|
|
|
|
|
2013-12-21 06:43:58 +00:00
|
|
|
void SetAssociatedBinding(nsXBLBinding* aBinding) { mAssociatedBinding = aBinding; }
|
2013-12-02 10:26:12 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-12-02 10:26:11 +00:00
|
|
|
|
|
|
|
static ShadowRoot* FromNode(nsINode* aNode);
|
|
|
|
|
2017-12-20 05:46:01 +00:00
|
|
|
void AddToIdTable(Element* aElement, nsAtom* aId);
|
|
|
|
void RemoveFromIdTable(Element* aElement, nsAtom* aId);
|
|
|
|
|
2013-12-02 10:26:11 +00:00
|
|
|
// WebIDL methods.
|
2017-12-20 05:46:01 +00:00
|
|
|
using mozilla::dom::StyleScope::GetElementById;
|
2013-12-02 10:26:12 +00:00
|
|
|
void GetInnerHTML(nsAString& aInnerHTML);
|
|
|
|
void SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError);
|
2014-06-07 08:42:54 +00:00
|
|
|
void StyleSheetChanged();
|
2015-02-09 18:01:23 +00:00
|
|
|
|
|
|
|
bool IsComposedDocParticipant() { return mIsComposedDocParticipant; }
|
|
|
|
void SetIsComposedDocParticipant(bool aIsComposedDocParticipant)
|
|
|
|
{
|
|
|
|
mIsComposedDocParticipant = aIsComposedDocParticipant;
|
|
|
|
}
|
2015-02-24 14:41:43 +00:00
|
|
|
|
2017-12-04 08:06:40 +00:00
|
|
|
nsresult GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
|
|
|
|
2013-12-02 10:26:11 +00:00
|
|
|
protected:
|
2014-07-08 21:23:16 +00:00
|
|
|
virtual ~ShadowRoot();
|
2013-12-02 10:26:12 +00:00
|
|
|
|
2017-10-19 06:44:35 +00:00
|
|
|
ShadowRootMode mMode;
|
|
|
|
|
2017-12-04 08:06:34 +00: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;
|
2013-12-02 10:26:12 +00: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|.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsXBLBinding> mAssociatedBinding;
|
2013-12-02 10:26:12 +00:00
|
|
|
|
2013-12-02 10:26:12 +00: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;
|
2015-02-09 18:01:23 +00:00
|
|
|
|
|
|
|
// 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;
|
2015-07-07 01:26:29 +00:00
|
|
|
|
2017-04-20 19:57:48 +00:00
|
|
|
nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
|
|
|
|
bool aPreallocateChildren) const override;
|
2013-12-02 10:26:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_shadowroot_h__
|
|
|
|
|