2015-05-03 22:32:37 +03: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 14:26:11 +04: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/. */
|
|
|
|
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
|
|
|
#include "mozilla/dom/ShadowRootBinding.h"
|
|
|
|
#include "mozilla/dom/DocumentFragment.h"
|
2013-12-02 14:26:12 +04:00
|
|
|
#include "ChildIterator.h"
|
2013-12-02 14:26:11 +04:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDOMClassInfoID.h"
|
|
|
|
#include "nsIDOMHTMLElement.h"
|
2013-12-02 14:26:12 +04:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
2013-12-02 14:26:11 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-12-02 14:26:12 +04:00
|
|
|
#include "mozilla/dom/HTMLContentElement.h"
|
2013-12-21 10:43:58 +04:00
|
|
|
#include "mozilla/dom/HTMLShadowElement.h"
|
2013-12-02 14:26:11 +04:00
|
|
|
#include "nsXBLPrototypeBinding.h"
|
2016-02-24 10:01:12 +03:00
|
|
|
#include "mozilla/StyleSheetHandle.h"
|
|
|
|
#include "mozilla/StyleSheetHandleInlines.h"
|
2013-12-02 14:26:11 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(ShadowRoot)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ShadowRoot,
|
|
|
|
DocumentFragment)
|
2013-12-21 10:43:58 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPoolHost)
|
2013-12-02 14:26:12 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleSheetList)
|
2013-12-21 10:43:58 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOlderShadow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mYoungerShadow)
|
2013-12-02 14:26:12 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAssociatedBinding)
|
2015-07-22 19:42:01 +03:00
|
|
|
for (auto iter = tmp->mIdentifierMap.ConstIter(); !iter.Done();
|
|
|
|
iter.Next()) {
|
|
|
|
iter.Get()->Traverse(&cb);
|
|
|
|
}
|
2013-12-02 14:26:11 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ShadowRoot,
|
|
|
|
DocumentFragment)
|
2013-12-21 10:43:58 +04:00
|
|
|
if (tmp->mPoolHost) {
|
|
|
|
tmp->mPoolHost->RemoveMutationObserver(tmp);
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
2013-12-21 10:43:58 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPoolHost)
|
2013-12-02 14:26:12 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStyleSheetList)
|
2013-12-21 10:43:58 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOlderShadow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mYoungerShadow)
|
2013-12-02 14:26:12 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAssociatedBinding)
|
2013-12-02 14:26:11 +04:00
|
|
|
tmp->mIdentifierMap.Clear();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ShadowRoot)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
|
2013-12-02 14:26:12 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
2013-12-02 14:26:11 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DocumentFragment)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(ShadowRoot, DocumentFragment)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(ShadowRoot, DocumentFragment)
|
|
|
|
|
|
|
|
ShadowRoot::ShadowRoot(nsIContent* aContent,
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2013-12-02 14:26:12 +04:00
|
|
|
nsXBLPrototypeBinding* aProtoBinding)
|
2013-12-21 10:43:58 +04:00
|
|
|
: DocumentFragment(aNodeInfo), mPoolHost(aContent),
|
|
|
|
mProtoBinding(aProtoBinding), mShadowElement(nullptr),
|
2015-02-09 21:01:23 +03:00
|
|
|
mInsertionPointChanged(false), mIsComposedDocParticipant(false)
|
2013-12-02 14:26:11 +04:00
|
|
|
{
|
|
|
|
SetHost(aContent);
|
2014-06-07 12:42:53 +04:00
|
|
|
|
|
|
|
// Nodes in a shadow tree should never store a value
|
|
|
|
// in the subtree root pointer, nodes in the shadow tree
|
|
|
|
// track the subtree root using GetContainingShadow().
|
|
|
|
ClearSubtreeRootPointer();
|
|
|
|
|
2013-12-02 14:26:11 +04:00
|
|
|
SetFlags(NODE_IS_IN_SHADOW_TREE);
|
2014-06-07 12:42:53 +04:00
|
|
|
|
2013-12-02 14:26:11 +04:00
|
|
|
DOMSlots()->mBindingParent = aContent;
|
|
|
|
DOMSlots()->mContainingShadow = this;
|
2013-12-02 14:26:12 +04:00
|
|
|
|
|
|
|
// Add the ShadowRoot as a mutation observer on the host to watch
|
|
|
|
// for mutations because the insertion points in this ShadowRoot
|
|
|
|
// may need to be updated when the host children are modified.
|
2013-12-21 10:43:58 +04:00
|
|
|
mPoolHost->AddMutationObserver(this);
|
2013-12-02 14:26:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ShadowRoot::~ShadowRoot()
|
|
|
|
{
|
2013-12-21 10:43:58 +04:00
|
|
|
if (mPoolHost) {
|
|
|
|
// mPoolHost may have been unlinked or a new ShadowRoot may have been
|
|
|
|
// creating, making this one obsolete.
|
|
|
|
mPoolHost->RemoveMutationObserver(this);
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
|
|
|
|
2014-06-07 12:42:53 +04:00
|
|
|
UnsetFlags(NODE_IS_IN_SHADOW_TREE);
|
|
|
|
|
|
|
|
// nsINode destructor expects mSubtreeRoot == this.
|
|
|
|
SetSubtreeRootPointer(this);
|
|
|
|
|
2013-12-02 14:26:11 +04:00
|
|
|
SetHost(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
ShadowRoot::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-12-02 14:26:11 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return mozilla::dom::ShadowRootBinding::Wrap(aCx, this, aGivenProto);
|
2013-12-02 14:26:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ShadowRoot*
|
|
|
|
ShadowRoot::FromNode(nsINode* aNode)
|
|
|
|
{
|
2014-07-03 21:02:07 +04:00
|
|
|
if (aNode->IsInShadowTree() && !aNode->GetParentNode()) {
|
2013-12-02 14:26:11 +04:00
|
|
|
MOZ_ASSERT(aNode->NodeType() == nsIDOMNode::DOCUMENT_FRAGMENT_NODE,
|
|
|
|
"ShadowRoot is a document fragment.");
|
|
|
|
return static_cast<ShadowRoot*>(aNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
void
|
2014-06-07 12:42:54 +04:00
|
|
|
ShadowRoot::StyleSheetChanged()
|
2013-12-02 14:26:12 +04:00
|
|
|
{
|
|
|
|
mProtoBinding->FlushSkinSheets();
|
|
|
|
|
|
|
|
nsIPresShell* shell = OwnerDoc()->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
OwnerDoc()->BeginUpdate(UPDATE_STYLE);
|
2014-06-07 12:42:54 +04:00
|
|
|
shell->RecordShadowStyleChange(this);
|
2013-12-02 14:26:12 +04:00
|
|
|
OwnerDoc()->EndUpdate(UPDATE_STYLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-02-24 10:01:12 +03:00
|
|
|
ShadowRoot::InsertSheet(StyleSheetHandle aSheet,
|
2013-12-02 14:26:12 +04:00
|
|
|
nsIContent* aLinkingContent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement>
|
|
|
|
linkingElement = do_QueryInterface(aLinkingContent);
|
|
|
|
MOZ_ASSERT(linkingElement, "The only styles in a ShadowRoot should come "
|
|
|
|
"from <style>.");
|
|
|
|
|
|
|
|
linkingElement->SetStyleSheet(aSheet); // This sets the ownerNode on the sheet
|
|
|
|
|
|
|
|
// Find the correct position to insert into the style sheet list (must
|
|
|
|
// be in tree order).
|
2014-06-19 11:02:56 +04:00
|
|
|
for (size_t i = 0; i <= mProtoBinding->SheetCount(); i++) {
|
|
|
|
if (i == mProtoBinding->SheetCount()) {
|
|
|
|
mProtoBinding->AppendStyleSheet(aSheet);
|
2013-12-02 14:26:12 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
nsINode* sheetOwningNode = mProtoBinding->StyleSheetAt(i)->GetOwnerNode();
|
|
|
|
if (nsContentUtils::PositionIsBefore(aLinkingContent, sheetOwningNode)) {
|
2014-06-19 11:02:56 +04:00
|
|
|
mProtoBinding->InsertStyleSheetAt(i, aSheet);
|
2013-12-02 14:26:12 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-07 12:42:54 +04:00
|
|
|
if (aSheet->IsApplicable()) {
|
|
|
|
StyleSheetChanged();
|
|
|
|
}
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-02-24 10:01:12 +03:00
|
|
|
ShadowRoot::RemoveSheet(StyleSheetHandle aSheet)
|
2013-12-02 14:26:12 +04:00
|
|
|
{
|
2014-06-19 11:02:56 +04:00
|
|
|
mProtoBinding->RemoveStyleSheet(aSheet);
|
2013-12-02 14:26:12 +04:00
|
|
|
|
2014-06-07 12:42:54 +04:00
|
|
|
if (aSheet->IsApplicable()) {
|
|
|
|
StyleSheetChanged();
|
|
|
|
}
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:11 +04:00
|
|
|
Element*
|
|
|
|
ShadowRoot::GetElementById(const nsAString& aElementId)
|
|
|
|
{
|
|
|
|
nsIdentifierMapEntry *entry = mIdentifierMap.GetEntry(aElementId);
|
|
|
|
return entry ? entry->GetIdElement() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
ShadowRoot::GetElementsByTagName(const nsAString& aTagName)
|
|
|
|
{
|
|
|
|
return NS_GetContentList(this, kNameSpaceID_Unknown, aTagName);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
ShadowRoot::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aLocalName)
|
|
|
|
{
|
|
|
|
int32_t nameSpaceId = kNameSpaceID_Wildcard;
|
|
|
|
|
|
|
|
if (!aNamespaceURI.EqualsLiteral("*")) {
|
|
|
|
nsresult rv =
|
|
|
|
nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURI,
|
|
|
|
nameSpaceId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(nameSpaceId != kNameSpaceID_Unknown, "Unexpected namespace ID!");
|
|
|
|
|
|
|
|
return NS_GetContentList(this, nameSpaceId, aLocalName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::AddToIdTable(Element* aElement, nsIAtom* aId)
|
|
|
|
{
|
|
|
|
nsIdentifierMapEntry *entry =
|
|
|
|
mIdentifierMap.PutEntry(nsDependentAtomString(aId));
|
|
|
|
if (entry) {
|
|
|
|
entry->AddIdElement(aElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::RemoveFromIdTable(Element* aElement, nsIAtom* aId)
|
|
|
|
{
|
|
|
|
nsIdentifierMapEntry *entry =
|
|
|
|
mIdentifierMap.GetEntry(nsDependentAtomString(aId));
|
|
|
|
if (entry) {
|
|
|
|
entry->RemoveIdElement(aElement);
|
|
|
|
if (entry->IsEmpty()) {
|
2016-02-09 05:52:21 +03:00
|
|
|
mIdentifierMap.RemoveEntry(entry);
|
2013-12-02 14:26:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
ShadowRoot::GetElementsByClassName(const nsAString& aClasses)
|
|
|
|
{
|
|
|
|
return nsContentUtils::GetElementsByClassName(this, aClasses);
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
void
|
|
|
|
ShadowRoot::AddInsertionPoint(HTMLContentElement* aInsertionPoint)
|
|
|
|
{
|
|
|
|
TreeOrderComparator comparator;
|
|
|
|
mInsertionPoints.InsertElementSorted(aInsertionPoint, comparator);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::RemoveInsertionPoint(HTMLContentElement* aInsertionPoint)
|
|
|
|
{
|
|
|
|
mInsertionPoints.RemoveElement(aInsertionPoint);
|
|
|
|
}
|
|
|
|
|
2013-12-21 10:43:58 +04:00
|
|
|
void
|
|
|
|
ShadowRoot::SetYoungerShadow(ShadowRoot* aYoungerShadow)
|
|
|
|
{
|
|
|
|
mYoungerShadow = aYoungerShadow;
|
|
|
|
mYoungerShadow->mOlderShadow = this;
|
|
|
|
|
|
|
|
ChangePoolHost(mYoungerShadow->GetShadowElement());
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:11:53 +04:00
|
|
|
void
|
|
|
|
ShadowRoot::RemoveDestInsertionPoint(nsIContent* aInsertionPoint,
|
|
|
|
nsTArray<nsIContent*>& aDestInsertionPoints)
|
|
|
|
{
|
|
|
|
// Remove the insertion point from the destination insertion points.
|
|
|
|
// Also remove all succeeding insertion points because it is no longer
|
|
|
|
// possible for the content to be distributed into deeper node trees.
|
|
|
|
int32_t index = aDestInsertionPoints.IndexOf(aInsertionPoint);
|
|
|
|
|
|
|
|
// It's possible that we already removed the insertion point while processing
|
|
|
|
// other insertion point removals.
|
|
|
|
if (index >= 0) {
|
|
|
|
aDestInsertionPoints.SetLength(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
void
|
|
|
|
ShadowRoot::DistributeSingleNode(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
// Find the insertion point to which the content belongs.
|
|
|
|
HTMLContentElement* insertionPoint = nullptr;
|
|
|
|
for (uint32_t i = 0; i < mInsertionPoints.Length(); i++) {
|
|
|
|
if (mInsertionPoints[i]->Match(aContent)) {
|
2013-12-21 10:43:58 +04:00
|
|
|
if (mInsertionPoints[i]->MatchedNodes().Contains(aContent)) {
|
|
|
|
// Node is already matched into the insertion point. We are done.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
// Matching may cause the insertion point to drop fallback content.
|
|
|
|
if (mInsertionPoints[i]->MatchedNodes().IsEmpty() &&
|
|
|
|
static_cast<nsINode*>(mInsertionPoints[i])->GetFirstChild()) {
|
|
|
|
// This match will cause the insertion point to drop all fallback
|
|
|
|
// content and used matched nodes instead. Give up on the optimization
|
|
|
|
// and just distribute all nodes.
|
|
|
|
DistributeAllNodes();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
insertionPoint = mInsertionPoints[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the index into the insertion point.
|
|
|
|
if (insertionPoint) {
|
|
|
|
nsCOMArray<nsIContent>& matchedNodes = insertionPoint->MatchedNodes();
|
|
|
|
// Find the appropriate position in the matched node list for the
|
|
|
|
// newly distributed content.
|
|
|
|
bool isIndexFound = false;
|
2013-12-21 10:43:58 +04:00
|
|
|
MOZ_ASSERT(mPoolHost, "Where did the content come from if there is no pool host?");
|
|
|
|
ExplicitChildIterator childIterator(mPoolHost);
|
2013-12-02 14:26:12 +04:00
|
|
|
for (uint32_t i = 0; i < matchedNodes.Length(); i++) {
|
|
|
|
// Seek through the host's explicit children until the inserted content
|
|
|
|
// is found or when the current matched node is reached.
|
|
|
|
if (childIterator.Seek(aContent, matchedNodes[i])) {
|
|
|
|
// aContent was found before the current matched node.
|
2014-05-22 10:11:53 +04:00
|
|
|
insertionPoint->InsertMatchedNode(i, aContent);
|
2013-12-02 14:26:12 +04:00
|
|
|
isIndexFound = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isIndexFound) {
|
|
|
|
// We have still not found an index in the insertion point,
|
|
|
|
// thus it must be at the end.
|
2015-09-09 04:23:55 +03:00
|
|
|
MOZ_ASSERT(childIterator.Seek(aContent, nullptr),
|
2013-12-02 14:26:12 +04:00
|
|
|
"Trying to match a node that is not a candidate to be matched");
|
2014-05-22 10:11:53 +04:00
|
|
|
insertionPoint->AppendMatchedNode(aContent);
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
|
|
|
|
2013-12-21 10:43:58 +04:00
|
|
|
// Handle the case where the parent of the insertion point is a ShadowRoot
|
|
|
|
// that is projected into the younger ShadowRoot's shadow insertion point.
|
|
|
|
// The node distributed into the insertion point must be reprojected
|
|
|
|
// to the shadow insertion point.
|
|
|
|
if (insertionPoint->GetParent() == this &&
|
|
|
|
mYoungerShadow && mYoungerShadow->GetShadowElement()) {
|
|
|
|
mYoungerShadow->GetShadowElement()->DistributeSingleNode(aContent);
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
// Handle the case where the parent of the insertion point has a ShadowRoot.
|
|
|
|
// The node distributed into the insertion point must be reprojected to the
|
|
|
|
// insertion points of the parent's ShadowRoot.
|
|
|
|
ShadowRoot* parentShadow = insertionPoint->GetParent()->GetShadowRoot();
|
|
|
|
if (parentShadow) {
|
|
|
|
parentShadow->DistributeSingleNode(aContent);
|
|
|
|
}
|
2013-12-21 10:43:58 +04:00
|
|
|
|
|
|
|
// Handle the case where the parent of the insertion point is the <shadow>
|
|
|
|
// element. The node distributed into the insertion point must be reprojected
|
|
|
|
// into the older ShadowRoot's insertion points.
|
|
|
|
if (mShadowElement && mShadowElement == insertionPoint->GetParent()) {
|
|
|
|
ShadowRoot* olderShadow = mShadowElement->GetOlderShadowRoot();
|
|
|
|
if (olderShadow) {
|
|
|
|
olderShadow->DistributeSingleNode(aContent);
|
|
|
|
}
|
|
|
|
}
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::RemoveDistributedNode(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
// Find insertion point containing the content and remove the node.
|
|
|
|
for (uint32_t i = 0; i < mInsertionPoints.Length(); i++) {
|
|
|
|
if (mInsertionPoints[i]->MatchedNodes().Contains(aContent)) {
|
|
|
|
// Removing the matched node may cause the insertion point to use
|
|
|
|
// fallback content.
|
|
|
|
if (mInsertionPoints[i]->MatchedNodes().Length() == 1 &&
|
|
|
|
static_cast<nsINode*>(mInsertionPoints[i])->GetFirstChild()) {
|
|
|
|
// Removing the matched node will cause fallback content to be
|
|
|
|
// used instead. Give up optimization and distribute all nodes.
|
|
|
|
DistributeAllNodes();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:11:53 +04:00
|
|
|
mInsertionPoints[i]->RemoveMatchedNode(aContent);
|
2013-12-02 14:26:12 +04:00
|
|
|
|
2013-12-21 10:43:58 +04:00
|
|
|
// Handle the case where the parent of the insertion point is a ShadowRoot
|
|
|
|
// that is projected into the younger ShadowRoot's shadow insertion point.
|
|
|
|
// The removed node needs to be removed from the shadow insertion point.
|
|
|
|
if (mInsertionPoints[i]->GetParent() == this) {
|
|
|
|
if (mYoungerShadow && mYoungerShadow->GetShadowElement()) {
|
|
|
|
mYoungerShadow->GetShadowElement()->RemoveDistributedNode(aContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
// Handle the case where the parent of the insertion point has a ShadowRoot.
|
|
|
|
// The removed node needs to be removed from the insertion points of the
|
|
|
|
// parent's ShadowRoot.
|
|
|
|
ShadowRoot* parentShadow = mInsertionPoints[i]->GetParent()->GetShadowRoot();
|
|
|
|
if (parentShadow) {
|
|
|
|
parentShadow->RemoveDistributedNode(aContent);
|
|
|
|
}
|
|
|
|
|
2013-12-21 10:43:58 +04:00
|
|
|
// Handle the case where the parent of the insertion point is the <shadow>
|
|
|
|
// element. The removed node must be removed from the older ShadowRoot's
|
|
|
|
// insertion points.
|
|
|
|
if (mShadowElement && mShadowElement == mInsertionPoints[i]->GetParent()) {
|
|
|
|
ShadowRoot* olderShadow = mShadowElement->GetOlderShadowRoot();
|
|
|
|
if (olderShadow) {
|
|
|
|
olderShadow->RemoveDistributedNode(aContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::DistributeAllNodes()
|
|
|
|
{
|
|
|
|
// Create node pool.
|
|
|
|
nsTArray<nsIContent*> nodePool;
|
2013-12-21 10:43:58 +04:00
|
|
|
|
|
|
|
// Make sure there is a pool host, an older shadow may not have
|
|
|
|
// one if the younger shadow does not have a <shadow> element.
|
|
|
|
if (mPoolHost) {
|
|
|
|
ExplicitChildIterator childIterator(mPoolHost);
|
|
|
|
for (nsIContent* content = childIterator.GetNextChild();
|
|
|
|
content;
|
|
|
|
content = childIterator.GetNextChild()) {
|
|
|
|
nodePool.AppendElement(content);
|
|
|
|
}
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
|
|
|
|
2013-12-21 10:43:58 +04:00
|
|
|
nsTArray<ShadowRoot*> shadowsToUpdate;
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
for (uint32_t i = 0; i < mInsertionPoints.Length(); i++) {
|
|
|
|
mInsertionPoints[i]->ClearMatchedNodes();
|
|
|
|
// Assign matching nodes from node pool.
|
|
|
|
for (uint32_t j = 0; j < nodePool.Length(); j++) {
|
|
|
|
if (mInsertionPoints[i]->Match(nodePool[j])) {
|
2014-05-22 10:11:53 +04:00
|
|
|
mInsertionPoints[i]->AppendMatchedNode(nodePool[j]);
|
2013-12-02 14:26:12 +04:00
|
|
|
nodePool.RemoveElementAt(j--);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-21 10:43:58 +04:00
|
|
|
// Keep track of instances where the content insertion point is distributed
|
|
|
|
// (parent of insertion point has a ShadowRoot).
|
2013-12-02 14:26:12 +04:00
|
|
|
nsIContent* insertionParent = mInsertionPoints[i]->GetParent();
|
|
|
|
MOZ_ASSERT(insertionParent, "The only way for an insertion point to be in the"
|
|
|
|
"mInsertionPoints array is to be a descendant of a"
|
|
|
|
"ShadowRoot, in which case, it should have a parent");
|
|
|
|
|
2014-05-22 10:11:53 +04:00
|
|
|
// If the parent of the insertion point has a ShadowRoot, the nodes distributed
|
2013-12-02 14:26:12 +04:00
|
|
|
// to the insertion point must be reprojected to the insertion points of the
|
|
|
|
// parent's ShadowRoot.
|
|
|
|
ShadowRoot* parentShadow = insertionParent->GetShadowRoot();
|
2013-12-21 10:43:58 +04:00
|
|
|
if (parentShadow && !shadowsToUpdate.Contains(parentShadow)) {
|
|
|
|
shadowsToUpdate.AppendElement(parentShadow);
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
|
|
|
}
|
2013-12-21 10:43:58 +04:00
|
|
|
|
|
|
|
// If there is a shadow insertion point in this ShadowRoot, the children
|
|
|
|
// of the shadow insertion point needs to be distributed into the insertion
|
|
|
|
// points of the older ShadowRoot.
|
|
|
|
if (mShadowElement && mOlderShadow) {
|
|
|
|
mOlderShadow->DistributeAllNodes();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is a younger ShadowRoot with a shadow insertion point,
|
|
|
|
// then the children of this ShadowRoot needs to be distributed to
|
|
|
|
// the younger ShadowRoot's shadow insertion point.
|
|
|
|
if (mYoungerShadow && mYoungerShadow->GetShadowElement()) {
|
|
|
|
mYoungerShadow->GetShadowElement()->DistributeAllNodes();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < shadowsToUpdate.Length(); i++) {
|
|
|
|
shadowsToUpdate[i]->DistributeAllNodes();
|
|
|
|
}
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
void
|
|
|
|
ShadowRoot::GetInnerHTML(nsAString& aInnerHTML)
|
|
|
|
{
|
|
|
|
GetMarkup(false, aInnerHTML);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetInnerHTMLInternal(aInnerHTML, aError);
|
|
|
|
}
|
|
|
|
|
2014-10-16 05:25:45 +04:00
|
|
|
Element*
|
|
|
|
ShadowRoot::Host()
|
|
|
|
{
|
|
|
|
nsIContent* host = GetHost();
|
|
|
|
MOZ_ASSERT(host && host->IsElement(),
|
|
|
|
"ShadowRoot host should always be an element, "
|
|
|
|
"how else did we create this ShadowRoot?");
|
|
|
|
return host->AsElement();
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
bool
|
|
|
|
ShadowRoot::ApplyAuthorStyles()
|
|
|
|
{
|
|
|
|
return mProtoBinding->InheritsStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::SetApplyAuthorStyles(bool aApplyAuthorStyles)
|
|
|
|
{
|
|
|
|
mProtoBinding->SetInheritsStyle(aApplyAuthorStyles);
|
|
|
|
|
|
|
|
nsIPresShell* shell = OwnerDoc()->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
OwnerDoc()->BeginUpdate(UPDATE_STYLE);
|
2014-06-07 12:42:54 +04:00
|
|
|
shell->RecordShadowStyleChange(this);
|
2013-12-02 14:26:12 +04:00
|
|
|
OwnerDoc()->EndUpdate(UPDATE_STYLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-12 12:18:54 +04:00
|
|
|
StyleSheetList*
|
2013-12-02 14:26:12 +04:00
|
|
|
ShadowRoot::StyleSheets()
|
|
|
|
{
|
|
|
|
if (!mStyleSheetList) {
|
|
|
|
mStyleSheetList = new ShadowRootStyleSheetList(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mStyleSheetList;
|
|
|
|
}
|
|
|
|
|
2013-12-21 10:43:58 +04:00
|
|
|
void
|
|
|
|
ShadowRoot::SetShadowElement(HTMLShadowElement* aShadowElement)
|
|
|
|
{
|
|
|
|
// If there is already a shadow element point, remove
|
|
|
|
// the projected shadow because it is no longer an insertion
|
|
|
|
// point.
|
|
|
|
if (mShadowElement) {
|
|
|
|
mShadowElement->SetProjectedShadow(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOlderShadow) {
|
|
|
|
// Nodes for distribution will come from the new shadow element.
|
|
|
|
mOlderShadow->ChangePoolHost(aShadowElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the new shadow element to project the older ShadowRoot because
|
|
|
|
// it is the current shadow insertion point.
|
|
|
|
mShadowElement = aShadowElement;
|
|
|
|
if (mShadowElement) {
|
|
|
|
mShadowElement->SetProjectedShadow(mOlderShadow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::ChangePoolHost(nsIContent* aNewHost)
|
|
|
|
{
|
|
|
|
if (mPoolHost) {
|
|
|
|
mPoolHost->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the nodes matched to content insertion points
|
|
|
|
// because it is no longer relevant.
|
|
|
|
for (uint32_t i = 0; i < mInsertionPoints.Length(); i++) {
|
|
|
|
mInsertionPoints[i]->ClearMatchedNodes();
|
|
|
|
}
|
|
|
|
|
|
|
|
mPoolHost = aNewHost;
|
|
|
|
if (mPoolHost) {
|
|
|
|
mPoolHost->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ShadowRoot::IsShadowInsertionPoint(nsIContent* aContent)
|
|
|
|
{
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aContent && aContent->IsHTMLElement(nsGkAtoms::shadow)) {
|
2013-12-21 10:43:58 +04:00
|
|
|
HTMLShadowElement* shadowElem = static_cast<HTMLShadowElement*>(aContent);
|
|
|
|
return shadowElem->IsInsertionPoint();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
/**
|
|
|
|
* Returns whether the web components pool population algorithm
|
|
|
|
* on the host would contain |aContent|. This function ignores
|
|
|
|
* insertion points in the pool, thus should only be used to
|
|
|
|
* test nodes that have not yet been distributed.
|
|
|
|
*/
|
2013-12-21 10:43:58 +04:00
|
|
|
bool
|
|
|
|
ShadowRoot::IsPooledNode(nsIContent* aContent, nsIContent* aContainer,
|
|
|
|
nsIContent* aHost)
|
2013-12-02 14:26:12 +04:00
|
|
|
{
|
2013-12-21 10:43:58 +04:00
|
|
|
if (nsContentUtils::IsContentInsertionPoint(aContent) ||
|
|
|
|
IsShadowInsertionPoint(aContent)) {
|
2013-12-02 14:26:12 +04:00
|
|
|
// Insertion points never end up in the pool.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-09 00:49:51 +03:00
|
|
|
if (aContainer == aHost &&
|
|
|
|
nsContentUtils::IsInSameAnonymousTree(aContainer, aContent)) {
|
|
|
|
// Children of the host will end up in the pool. We check to ensure
|
|
|
|
// that the content is in the same anonymous tree as the container
|
|
|
|
// because anonymous content may report its container as the host
|
|
|
|
// but it may not be in the host's child list.
|
2014-05-22 10:11:53 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aContainer && aContainer->IsHTMLElement(nsGkAtoms::content)) {
|
2013-12-02 14:26:12 +04:00
|
|
|
// Fallback content will end up in pool if its parent is a child of the host.
|
|
|
|
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer);
|
|
|
|
return content->IsInsertionPoint() && content->MatchedNodes().IsEmpty() &&
|
|
|
|
aContainer->GetParentNode() == aHost;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
2015-07-25 09:01:19 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue)
|
2013-12-02 14:26:12 +04:00
|
|
|
{
|
2013-12-21 10:43:58 +04:00
|
|
|
if (!IsPooledNode(aElement, aElement->GetParent(), mPoolHost)) {
|
2013-12-02 14:26:12 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attributes may change insertion point matching, find its new distribution.
|
|
|
|
RemoveDistributedNode(aElement);
|
|
|
|
DistributeSingleNode(aElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
|
|
|
int32_t aNewIndexInContainer)
|
|
|
|
{
|
|
|
|
if (mInsertionPointChanged) {
|
|
|
|
DistributeAllNodes();
|
|
|
|
mInsertionPointChanged = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Watch for new nodes added to the pool because the node
|
|
|
|
// may need to be added to an insertion point.
|
|
|
|
nsIContent* currentChild = aFirstNewContent;
|
|
|
|
while (currentChild) {
|
2014-05-22 10:11:53 +04:00
|
|
|
// Add insertion point to destination insertion points of fallback content.
|
|
|
|
if (nsContentUtils::IsContentInsertionPoint(aContainer)) {
|
|
|
|
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer);
|
|
|
|
if (content->MatchedNodes().IsEmpty()) {
|
|
|
|
currentChild->DestInsertionPoints().AppendElement(aContainer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-21 10:43:58 +04:00
|
|
|
if (IsPooledNode(currentChild, aContainer, mPoolHost)) {
|
2013-12-02 14:26:12 +04:00
|
|
|
DistributeSingleNode(currentChild);
|
|
|
|
}
|
2014-05-22 10:11:53 +04:00
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
currentChild = currentChild->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer)
|
|
|
|
{
|
|
|
|
if (mInsertionPointChanged) {
|
|
|
|
DistributeAllNodes();
|
|
|
|
mInsertionPointChanged = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Watch for new nodes added to the pool because the node
|
|
|
|
// may need to be added to an insertion point.
|
2013-12-21 10:43:58 +04:00
|
|
|
if (IsPooledNode(aChild, aContainer, mPoolHost)) {
|
2014-05-22 10:11:53 +04:00
|
|
|
// Add insertion point to destination insertion points of fallback content.
|
|
|
|
if (nsContentUtils::IsContentInsertionPoint(aContainer)) {
|
|
|
|
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer);
|
|
|
|
if (content->MatchedNodes().IsEmpty()) {
|
|
|
|
aChild->DestInsertionPoints().AppendElement(aContainer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
DistributeSingleNode(aChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowRoot::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer,
|
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
|
|
|
if (mInsertionPointChanged) {
|
|
|
|
DistributeAllNodes();
|
|
|
|
mInsertionPointChanged = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:11:53 +04:00
|
|
|
// Clear destination insertion points for removed
|
|
|
|
// fallback content.
|
|
|
|
if (nsContentUtils::IsContentInsertionPoint(aContainer)) {
|
|
|
|
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer);
|
|
|
|
if (content->MatchedNodes().IsEmpty()) {
|
|
|
|
aChild->DestInsertionPoints().Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
// Watch for node that is removed from the pool because
|
|
|
|
// it may need to be removed from an insertion point.
|
2013-12-21 10:43:58 +04:00
|
|
|
if (IsPooledNode(aChild, aContainer, mPoolHost)) {
|
2013-12-02 14:26:12 +04:00
|
|
|
RemoveDistributedNode(aChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 04:26:29 +03:00
|
|
|
nsresult
|
|
|
|
ShadowRoot::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const
|
|
|
|
{
|
|
|
|
*aResult = nullptr;
|
|
|
|
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
|
|
|
}
|
|
|
|
|
2015-02-24 17:41:43 +03:00
|
|
|
void
|
|
|
|
ShadowRoot::DestroyContent()
|
|
|
|
{
|
|
|
|
if (mOlderShadow) {
|
|
|
|
mOlderShadow->DestroyContent();
|
|
|
|
}
|
|
|
|
DocumentFragment::DestroyContent();
|
|
|
|
}
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(ShadowRootStyleSheetList, StyleSheetList,
|
|
|
|
mShadowRoot)
|
2013-12-02 14:26:12 +04:00
|
|
|
|
2014-04-12 12:18:54 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ShadowRootStyleSheetList)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(StyleSheetList)
|
2013-12-02 14:26:12 +04:00
|
|
|
|
2014-04-12 12:18:54 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(ShadowRootStyleSheetList, StyleSheetList)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(ShadowRootStyleSheetList, StyleSheetList)
|
2013-12-02 14:26:12 +04:00
|
|
|
|
|
|
|
ShadowRootStyleSheetList::ShadowRootStyleSheetList(ShadowRoot* aShadowRoot)
|
|
|
|
: mShadowRoot(aShadowRoot)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ShadowRootStyleSheetList);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShadowRootStyleSheetList::~ShadowRootStyleSheetList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ShadowRootStyleSheetList);
|
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet*
|
2014-04-12 12:18:54 +04:00
|
|
|
ShadowRootStyleSheetList::IndexedGetter(uint32_t aIndex, bool& aFound)
|
2013-12-02 14:26:12 +04:00
|
|
|
{
|
2014-06-19 11:02:56 +04:00
|
|
|
aFound = aIndex < mShadowRoot->mProtoBinding->SheetCount();
|
2013-12-02 14:26:12 +04:00
|
|
|
|
2014-06-19 11:02:56 +04:00
|
|
|
if (!aFound) {
|
2014-04-12 12:15:59 +04:00
|
|
|
return nullptr;
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
// XXXheycam Return null until ServoStyleSheet implements the right
|
|
|
|
// DOM interfaces.
|
|
|
|
StyleSheetHandle sheet = mShadowRoot->mProtoBinding->StyleSheetAt(aIndex);
|
|
|
|
if (sheet->IsServo()) {
|
|
|
|
NS_ERROR("stylo: can't return ServoStyleSheets to script yet");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return sheet->AsGecko();
|
2014-04-12 12:15:59 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 12:18:54 +04:00
|
|
|
uint32_t
|
|
|
|
ShadowRootStyleSheetList::Length()
|
2013-12-02 14:26:12 +04:00
|
|
|
{
|
2014-06-19 11:02:56 +04:00
|
|
|
return mShadowRoot->mProtoBinding->SheetCount();
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
|
|
|
|