mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-21 22:57:31 +09:00
Bug 1425769 - Base class for ShadowRoot and Document to manage style state
Tag #1375
This commit is contained in:
parent
9fdf69e567
commit
b8260c664a
16 changed files with 250 additions and 296 deletions
|
|
@ -436,23 +436,22 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindowOuter* aWindow)
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t count = document->GetNumberOfStyleSheets();
|
size_t count = document->SheetCount();
|
||||||
|
|
||||||
// Build an array of style sheets we need to reload.
|
// Build an array of style sheets we need to reload.
|
||||||
nsTArray<RefPtr<StyleSheet>> oldSheets(count);
|
nsTArray<RefPtr<StyleSheet>> oldSheets(count);
|
||||||
nsTArray<RefPtr<StyleSheet>> newSheets(count);
|
nsTArray<RefPtr<StyleSheet>> newSheets(count);
|
||||||
|
|
||||||
// Iterate over the style sheets.
|
// Iterate over the style sheets.
|
||||||
for (int32_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
// Get the style sheet
|
// Get the style sheet
|
||||||
StyleSheet* styleSheet = document->GetStyleSheetAt(i);
|
oldSheets.AppendElement(document->SheetAt(i));
|
||||||
oldSheets.AppendElement(styleSheet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over our old sheets and kick off a sync load of the new
|
// Iterate over our old sheets and kick off a sync load of the new
|
||||||
// sheet if and only if it's a non-inline sheet with a chrome URL.
|
// sheet if and only if it's a non-inline sheet with a chrome URL.
|
||||||
for (StyleSheet* sheet : oldSheets) {
|
for (StyleSheet* sheet : oldSheets) {
|
||||||
MOZ_ASSERT(sheet, "GetStyleSheetAt shouldn't return nullptr for "
|
MOZ_ASSERT(sheet, "SheetAt shouldn't return nullptr for "
|
||||||
"in-range sheet indexes");
|
"in-range sheet indexes");
|
||||||
nsIURI* uri = sheet->GetSheetURI();
|
nsIURI* uri = sheet->GetSheetURI();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(ShadowRoot)
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ShadowRoot,
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ShadowRoot,
|
||||||
DocumentFragment)
|
DocumentFragment)
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleSheetList)
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMStyleSheets)
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAssociatedBinding)
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAssociatedBinding)
|
||||||
for (auto iter = tmp->mIdentifierMap.ConstIter(); !iter.Done();
|
for (auto iter = tmp->mIdentifierMap.ConstIter(); !iter.Done();
|
||||||
iter.Next()) {
|
iter.Next()) {
|
||||||
|
|
@ -39,7 +39,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ShadowRoot)
|
||||||
if (tmp->GetHost()) {
|
if (tmp->GetHost()) {
|
||||||
tmp->GetHost()->RemoveMutationObserver(tmp);
|
tmp->GetHost()->RemoveMutationObserver(tmp);
|
||||||
}
|
}
|
||||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStyleSheetList)
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDOMStyleSheets)
|
||||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAssociatedBinding)
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAssociatedBinding)
|
||||||
tmp->mIdentifierMap.Clear();
|
tmp->mIdentifierMap.Clear();
|
||||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(DocumentFragment)
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(DocumentFragment)
|
||||||
|
|
@ -238,16 +238,30 @@ ShadowRoot::InsertSheet(StyleSheet* aSheet,
|
||||||
|
|
||||||
linkingElement->SetStyleSheet(aSheet); // This sets the ownerNode on the sheet
|
linkingElement->SetStyleSheet(aSheet); // This sets the ownerNode on the sheet
|
||||||
|
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(mProtoBinding->SheetCount() == StyleScope::SheetCount());
|
||||||
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
||||||
|
// FIXME(emilio, bug 1425759): For now we keep them duplicated, the proto
|
||||||
|
// binding will disappear soon (tm).
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
for (RefPtr<StyleSheet>& sheet : mStyleSheets) {
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(sheet.get() == mProtoBinding->StyleSheetAt(i++));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Find the correct position to insert into the style sheet list (must
|
// Find the correct position to insert into the style sheet list (must
|
||||||
// be in tree order).
|
// be in tree order).
|
||||||
for (size_t i = 0; i <= mProtoBinding->SheetCount(); i++) {
|
for (size_t i = 0; i <= SheetCount(); i++) {
|
||||||
if (i == mProtoBinding->SheetCount()) {
|
if (i == SheetCount()) {
|
||||||
|
AppendStyleSheet(*aSheet);
|
||||||
mProtoBinding->AppendStyleSheet(aSheet);
|
mProtoBinding->AppendStyleSheet(aSheet);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsINode* sheetOwningNode = mProtoBinding->StyleSheetAt(i)->GetOwnerNode();
|
nsINode* sheetOwningNode = SheetAt(i)->GetOwnerNode();
|
||||||
if (nsContentUtils::PositionIsBefore(aLinkingContent, sheetOwningNode)) {
|
if (nsContentUtils::PositionIsBefore(aLinkingContent, sheetOwningNode)) {
|
||||||
|
InsertSheetAt(i, *aSheet);
|
||||||
mProtoBinding->InsertStyleSheetAt(i, aSheet);
|
mProtoBinding->InsertStyleSheetAt(i, aSheet);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -262,6 +276,7 @@ void
|
||||||
ShadowRoot::RemoveSheet(StyleSheet* aSheet)
|
ShadowRoot::RemoveSheet(StyleSheet* aSheet)
|
||||||
{
|
{
|
||||||
mProtoBinding->RemoveStyleSheet(aSheet);
|
mProtoBinding->RemoveStyleSheet(aSheet);
|
||||||
|
StyleScope::RemoveSheet(*aSheet);
|
||||||
|
|
||||||
if (aSheet->IsApplicable()) {
|
if (aSheet->IsApplicable()) {
|
||||||
StyleSheetChanged();
|
StyleSheetChanged();
|
||||||
|
|
@ -523,16 +538,6 @@ ShadowRoot::SetApplyAuthorStyles(bool aApplyAuthorStyles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StyleSheetList*
|
|
||||||
ShadowRoot::StyleSheets()
|
|
||||||
{
|
|
||||||
if (!mStyleSheetList) {
|
|
||||||
mStyleSheetList = new ShadowRootStyleSheetList(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mStyleSheetList;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShadowRoot::AttributeChanged(nsIDocument* aDocument,
|
ShadowRoot::AttributeChanged(nsIDocument* aDocument,
|
||||||
Element* aElement,
|
Element* aElement,
|
||||||
|
|
@ -651,40 +656,3 @@ ShadowRoot::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const
|
||||||
*aResult = nullptr;
|
*aResult = nullptr;
|
||||||
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(ShadowRootStyleSheetList, StyleSheetList,
|
|
||||||
mShadowRoot)
|
|
||||||
|
|
||||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ShadowRootStyleSheetList)
|
|
||||||
NS_INTERFACE_MAP_END_INHERITING(StyleSheetList)
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(ShadowRootStyleSheetList, StyleSheetList)
|
|
||||||
NS_IMPL_RELEASE_INHERITED(ShadowRootStyleSheetList, StyleSheetList)
|
|
||||||
|
|
||||||
ShadowRootStyleSheetList::ShadowRootStyleSheetList(ShadowRoot* aShadowRoot)
|
|
||||||
: mShadowRoot(aShadowRoot)
|
|
||||||
{
|
|
||||||
MOZ_COUNT_CTOR(ShadowRootStyleSheetList);
|
|
||||||
}
|
|
||||||
|
|
||||||
ShadowRootStyleSheetList::~ShadowRootStyleSheetList()
|
|
||||||
{
|
|
||||||
MOZ_COUNT_DTOR(ShadowRootStyleSheetList);
|
|
||||||
}
|
|
||||||
|
|
||||||
StyleSheet*
|
|
||||||
ShadowRootStyleSheetList::IndexedGetter(uint32_t aIndex, bool& aFound)
|
|
||||||
{
|
|
||||||
aFound = aIndex < mShadowRoot->mProtoBinding->SheetCount();
|
|
||||||
if (!aFound) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return mShadowRoot->mProtoBinding->StyleSheetAt(aIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t
|
|
||||||
ShadowRootStyleSheetList::Length()
|
|
||||||
{
|
|
||||||
return mShadowRoot->mProtoBinding->SheetCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,7 @@
|
||||||
#define mozilla_dom_shadowroot_h__
|
#define mozilla_dom_shadowroot_h__
|
||||||
|
|
||||||
#include "mozilla/dom/DocumentFragment.h"
|
#include "mozilla/dom/DocumentFragment.h"
|
||||||
#include "mozilla/dom/StyleSheetList.h"
|
#include "mozilla/dom/StyleScope.h"
|
||||||
#include "mozilla/StyleSheet.h"
|
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsCycleCollectionParticipant.h"
|
#include "nsCycleCollectionParticipant.h"
|
||||||
#include "nsIContentInlines.h"
|
#include "nsIContentInlines.h"
|
||||||
|
|
@ -27,12 +26,11 @@ class EventChainPreVisitor;
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
class Element;
|
class Element;
|
||||||
class ShadowRootStyleSheetList;
|
|
||||||
|
|
||||||
class ShadowRoot final : public DocumentFragment,
|
class ShadowRoot final : public DocumentFragment,
|
||||||
|
public StyleScope,
|
||||||
public nsStubMutationObserver
|
public nsStubMutationObserver
|
||||||
{
|
{
|
||||||
friend class ShadowRootStyleSheetList;
|
|
||||||
public:
|
public:
|
||||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRoot,
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRoot,
|
||||||
DocumentFragment)
|
DocumentFragment)
|
||||||
|
|
@ -49,15 +47,20 @@ public:
|
||||||
|
|
||||||
// Shadow DOM v1
|
// Shadow DOM v1
|
||||||
Element* Host();
|
Element* Host();
|
||||||
ShadowRootMode Mode()
|
ShadowRootMode Mode() const
|
||||||
{
|
{
|
||||||
return mMode;
|
return mMode;
|
||||||
}
|
}
|
||||||
bool IsClosed()
|
bool IsClosed() const
|
||||||
{
|
{
|
||||||
return mMode == ShadowRootMode::Closed;
|
return mMode == ShadowRootMode::Closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StyleScope.
|
||||||
|
nsINode& AsNode() final
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// [deprecated] Shadow DOM v0
|
// [deprecated] Shadow DOM v0
|
||||||
void AddToIdTable(Element* aElement, nsIAtom* aId);
|
void AddToIdTable(Element* aElement, nsIAtom* aId);
|
||||||
|
|
@ -66,7 +69,10 @@ public:
|
||||||
void RemoveSheet(StyleSheet* aSheet);
|
void RemoveSheet(StyleSheet* aSheet);
|
||||||
bool ApplyAuthorStyles();
|
bool ApplyAuthorStyles();
|
||||||
void SetApplyAuthorStyles(bool aApplyAuthorStyles);
|
void SetApplyAuthorStyles(bool aApplyAuthorStyles);
|
||||||
StyleSheetList* StyleSheets();
|
StyleSheetList* StyleSheets()
|
||||||
|
{
|
||||||
|
return &StyleScope::EnsureDOMStyleSheets();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Distributes all the explicit children of the pool host to the content
|
* Distributes all the explicit children of the pool host to the content
|
||||||
|
|
@ -155,8 +161,6 @@ protected:
|
||||||
// owns |mProtoBinding|.
|
// owns |mProtoBinding|.
|
||||||
RefPtr<nsXBLBinding> mAssociatedBinding;
|
RefPtr<nsXBLBinding> mAssociatedBinding;
|
||||||
|
|
||||||
RefPtr<ShadowRootStyleSheetList> mStyleSheetList;
|
|
||||||
|
|
||||||
// A boolean that indicates that an insertion point was added or removed
|
// A boolean that indicates that an insertion point was added or removed
|
||||||
// from this ShadowRoot and that the nodes need to be redistributed into
|
// from this ShadowRoot and that the nodes need to be redistributed into
|
||||||
// the insertion points. After this flag is set, nodes will be distributed
|
// the insertion points. After this flag is set, nodes will be distributed
|
||||||
|
|
@ -172,28 +176,6 @@ protected:
|
||||||
nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
|
nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ShadowRootStyleSheetList : public StyleSheetList
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit ShadowRootStyleSheetList(ShadowRoot* aShadowRoot);
|
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRootStyleSheetList, StyleSheetList)
|
|
||||||
|
|
||||||
virtual nsINode* GetParentObject() const override
|
|
||||||
{
|
|
||||||
return mShadowRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t Length() override;
|
|
||||||
StyleSheet* IndexedGetter(uint32_t aIndex, bool& aFound) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual ~ShadowRootStyleSheetList();
|
|
||||||
|
|
||||||
RefPtr<ShadowRoot> mShadowRoot;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
|
|
||||||
27
dom/base/StyleScope.cpp
Normal file
27
dom/base/StyleScope.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* -*- 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/. */
|
||||||
|
|
||||||
|
#include "StyleScope.h"
|
||||||
|
#include "mozilla/dom/StyleSheetList.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
StyleScope::~StyleScope()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
StyleSheetList&
|
||||||
|
StyleScope::EnsureDOMStyleSheets()
|
||||||
|
{
|
||||||
|
if (!mDOMStyleSheets) {
|
||||||
|
mDOMStyleSheets = new StyleSheetList(*this);
|
||||||
|
}
|
||||||
|
return *mDOMStyleSheets;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
81
dom/base/StyleScope.h
Normal file
81
dom/base/StyleScope.h
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
/* -*- 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_StyleScope_h__
|
||||||
|
#define mozilla_dom_StyleScope_h__
|
||||||
|
|
||||||
|
#include "nsTArray.h"
|
||||||
|
|
||||||
|
class nsINode;
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
class StyleSheet;
|
||||||
|
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
class StyleSheetList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class meant to be shared by ShadowRoot and Document, that holds a list of
|
||||||
|
* stylesheets.
|
||||||
|
*
|
||||||
|
* TODO(emilio, bug 1418159): In the future this should hold most of the
|
||||||
|
* relevant style state, this should allow us to fix bug 548397.
|
||||||
|
*/
|
||||||
|
class StyleScope
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual nsINode& AsNode() = 0;
|
||||||
|
|
||||||
|
const nsINode& AsNode() const
|
||||||
|
{
|
||||||
|
return const_cast<StyleScope&>(*this).AsNode();
|
||||||
|
}
|
||||||
|
|
||||||
|
StyleSheet* SheetAt(size_t aIndex) const
|
||||||
|
{
|
||||||
|
return mStyleSheets.SafeElementAt(aIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t SheetCount() const
|
||||||
|
{
|
||||||
|
return mStyleSheets.Length();
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t IndexOfSheet(const StyleSheet& aSheet) const
|
||||||
|
{
|
||||||
|
return mStyleSheets.IndexOf(&aSheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InsertSheetAt(size_t aIndex, StyleSheet& aSheet)
|
||||||
|
{
|
||||||
|
mStyleSheets.InsertElementAt(aIndex, &aSheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveSheet(StyleSheet& aSheet)
|
||||||
|
{
|
||||||
|
mStyleSheets.RemoveElement(&aSheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppendStyleSheet(StyleSheet& aSheet)
|
||||||
|
{
|
||||||
|
mStyleSheets.AppendElement(&aSheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
StyleSheetList& EnsureDOMStyleSheets();
|
||||||
|
|
||||||
|
~StyleScope();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
nsTArray<RefPtr<mozilla::StyleSheet>> mStyleSheets;
|
||||||
|
RefPtr<mozilla::dom::StyleSheetList> mDOMStyleSheets;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "mozilla/CSSStyleSheet.h"
|
#include "mozilla/CSSStyleSheet.h"
|
||||||
#include "mozilla/dom/StyleSheetListBinding.h"
|
#include "mozilla/dom/StyleSheetListBinding.h"
|
||||||
|
#include "nsStubDocumentObserver.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
@ -17,7 +18,8 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(StyleSheetList)
|
||||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(StyleSheetList)
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(StyleSheetList)
|
||||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheetList)
|
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheetList)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
||||||
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMStyleSheetList)
|
||||||
NS_INTERFACE_MAP_END
|
NS_INTERFACE_MAP_END
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(StyleSheetList)
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(StyleSheetList)
|
||||||
|
|
@ -43,5 +45,24 @@ StyleSheetList::SlowItem(uint32_t aIndex, nsIDOMStyleSheet** aItem)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
StyleSheetList::NodeWillBeDestroyed(const nsINode* aNode)
|
||||||
|
{
|
||||||
|
mStyleScope = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyleSheetList::StyleSheetList(StyleScope& aScope)
|
||||||
|
: mStyleScope(&aScope)
|
||||||
|
{
|
||||||
|
mStyleScope->AsNode().AddMutationObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
StyleSheetList::~StyleSheetList()
|
||||||
|
{
|
||||||
|
if (mStyleScope) {
|
||||||
|
mStyleScope->AsNode().RemoveMutationObserver(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,10 @@
|
||||||
#ifndef mozilla_dom_StyleSheetList_h
|
#ifndef mozilla_dom_StyleSheetList_h
|
||||||
#define mozilla_dom_StyleSheetList_h
|
#define mozilla_dom_StyleSheetList_h
|
||||||
|
|
||||||
|
#include "mozilla/dom/StyleScope.h"
|
||||||
#include "nsIDOMStyleSheetList.h"
|
#include "nsIDOMStyleSheetList.h"
|
||||||
#include "nsWrapperCache.h"
|
#include "nsWrapperCache.h"
|
||||||
|
#include "nsStubDocumentObserver.h"
|
||||||
|
|
||||||
class nsINode;
|
class nsINode;
|
||||||
|
|
||||||
|
|
@ -17,28 +19,54 @@ class StyleSheet;
|
||||||
|
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
class StyleSheetList : public nsIDOMStyleSheetList
|
class StyleSheetList final : public nsIDOMStyleSheetList
|
||||||
, public nsWrapperCache
|
, public nsWrapperCache
|
||||||
|
, public nsStubDocumentObserver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(StyleSheetList)
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(StyleSheetList, nsIDOMStyleSheetList)
|
||||||
|
|
||||||
NS_DECL_NSIDOMSTYLESHEETLIST
|
NS_DECL_NSIDOMSTYLESHEETLIST
|
||||||
|
|
||||||
|
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
|
||||||
|
|
||||||
|
explicit StyleSheetList(StyleScope& aScope);
|
||||||
|
|
||||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||||
|
|
||||||
virtual nsINode* GetParentObject() const = 0;
|
nsINode* GetParentObject() const
|
||||||
|
{
|
||||||
|
return mStyleScope ? &mStyleScope->AsNode() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
virtual uint32_t Length() = 0;
|
uint32_t Length() const
|
||||||
virtual StyleSheet* IndexedGetter(uint32_t aIndex, bool& aFound) = 0;
|
{
|
||||||
StyleSheet* Item(uint32_t aIndex)
|
return mStyleScope ? mStyleScope->SheetCount() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyleSheet* IndexedGetter(uint32_t aIndex, bool& aFound) const
|
||||||
|
{
|
||||||
|
if (!mStyleScope) {
|
||||||
|
aFound = false;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyleSheet* sheet = mStyleScope->SheetAt(aIndex);
|
||||||
|
aFound = !!sheet;
|
||||||
|
return sheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyleSheet* Item(uint32_t aIndex) const
|
||||||
{
|
{
|
||||||
bool dummy = false;
|
bool dummy = false;
|
||||||
return IndexedGetter(aIndex, dummy);
|
return IndexedGetter(aIndex, dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~StyleSheetList() {}
|
virtual ~StyleSheetList();
|
||||||
|
|
||||||
|
StyleScope* mStyleScope; // Weak, cleared on "NodeWillBeDestroyed".
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,7 @@ EXPORTS.mozilla.dom += [
|
||||||
'SimpleTreeIterator.h',
|
'SimpleTreeIterator.h',
|
||||||
'StructuredCloneHolder.h',
|
'StructuredCloneHolder.h',
|
||||||
'StructuredCloneTags.h',
|
'StructuredCloneTags.h',
|
||||||
|
'StyleScope.h',
|
||||||
'StyleSheetList.h',
|
'StyleSheetList.h',
|
||||||
'SubtleCrypto.h',
|
'SubtleCrypto.h',
|
||||||
'TabGroup.h',
|
'TabGroup.h',
|
||||||
|
|
@ -359,6 +360,7 @@ SOURCES += [
|
||||||
'ScriptSettings.cpp',
|
'ScriptSettings.cpp',
|
||||||
'ShadowRoot.cpp',
|
'ShadowRoot.cpp',
|
||||||
'StructuredCloneHolder.cpp',
|
'StructuredCloneHolder.cpp',
|
||||||
|
'StyleScope.cpp',
|
||||||
'StyleSheetList.cpp',
|
'StyleSheetList.cpp',
|
||||||
'SubtleCrypto.cpp',
|
'SubtleCrypto.cpp',
|
||||||
'TabGroup.cpp',
|
'TabGroup.cpp',
|
||||||
|
|
|
||||||
|
|
@ -570,78 +570,6 @@ struct nsRadioGroupStruct
|
||||||
bool mGroupSuffersFromValueMissing;
|
bool mGroupSuffersFromValueMissing;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
nsDOMStyleSheetList::nsDOMStyleSheetList(nsIDocument *aDocument)
|
|
||||||
{
|
|
||||||
mLength = -1;
|
|
||||||
// Not reference counted to avoid circular references.
|
|
||||||
// The document will tell us when its going away.
|
|
||||||
mDocument = aDocument;
|
|
||||||
mDocument->AddObserver(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsDOMStyleSheetList::~nsDOMStyleSheetList()
|
|
||||||
{
|
|
||||||
if (mDocument) {
|
|
||||||
mDocument->RemoveObserver(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS_INHERITED(nsDOMStyleSheetList, StyleSheetList,
|
|
||||||
nsIDocumentObserver,
|
|
||||||
nsIMutationObserver)
|
|
||||||
|
|
||||||
uint32_t
|
|
||||||
nsDOMStyleSheetList::Length()
|
|
||||||
{
|
|
||||||
if (!mDocument) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX Find the number and then cache it. We'll use the
|
|
||||||
// observer notification to figure out if new ones have
|
|
||||||
// been added or removed.
|
|
||||||
if (-1 == mLength) {
|
|
||||||
mLength = mDocument->GetNumberOfStyleSheets();
|
|
||||||
}
|
|
||||||
return mLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
StyleSheet*
|
|
||||||
nsDOMStyleSheetList::IndexedGetter(uint32_t aIndex, bool& aFound)
|
|
||||||
{
|
|
||||||
if (!mDocument || aIndex >= (uint32_t)mDocument->GetNumberOfStyleSheets()) {
|
|
||||||
aFound = false;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
aFound = true;
|
|
||||||
return mDocument->GetStyleSheetAt(aIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
nsDOMStyleSheetList::NodeWillBeDestroyed(const nsINode *aNode)
|
|
||||||
{
|
|
||||||
mDocument = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
nsDOMStyleSheetList::StyleSheetAdded(StyleSheet* aStyleSheet,
|
|
||||||
bool aDocumentSheet)
|
|
||||||
{
|
|
||||||
if (aDocumentSheet && -1 != mLength) {
|
|
||||||
mLength++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
nsDOMStyleSheetList::StyleSheetRemoved(StyleSheet* aStyleSheet,
|
|
||||||
bool aDocumentSheet)
|
|
||||||
{
|
|
||||||
if (aDocumentSheet && -1 != mLength) {
|
|
||||||
mLength--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// nsOnloadBlocker implementation
|
// nsOnloadBlocker implementation
|
||||||
NS_IMPL_ISUPPORTS(nsOnloadBlocker, nsIRequest)
|
NS_IMPL_ISUPPORTS(nsOnloadBlocker, nsIRequest)
|
||||||
|
|
||||||
|
|
@ -1199,10 +1127,10 @@ nsDOMStyleSheetSetList::EnsureFresh()
|
||||||
// no document, for sure
|
// no document, for sure
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t count = mDocument->GetNumberOfStyleSheets();
|
size_t count = mDocument->SheetCount();
|
||||||
nsAutoString title;
|
nsAutoString title;
|
||||||
for (int32_t index = 0; index < count; index++) {
|
for (size_t index = 0; index < count; index++) {
|
||||||
StyleSheet* sheet = mDocument->GetStyleSheetAt(index);
|
StyleSheet* sheet = mDocument->SheetAt(index);
|
||||||
NS_ASSERTION(sheet, "Null sheet in sheet list!");
|
NS_ASSERTION(sheet, "Null sheet in sheet list!");
|
||||||
// XXXheycam ServoStyleSheets don't expose their title yet.
|
// XXXheycam ServoStyleSheets don't expose their title yet.
|
||||||
if (sheet->IsServo()) {
|
if (sheet->IsServo()) {
|
||||||
|
|
@ -3930,24 +3858,6 @@ nsDocument::AddOnDemandBuiltInUASheet(StyleSheet* aSheet)
|
||||||
NotifyStyleSheetAdded(aSheet, false);
|
NotifyStyleSheetAdded(aSheet, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t
|
|
||||||
nsDocument::GetNumberOfStyleSheets() const
|
|
||||||
{
|
|
||||||
return mStyleSheets.Length();
|
|
||||||
}
|
|
||||||
|
|
||||||
StyleSheet*
|
|
||||||
nsDocument::GetStyleSheetAt(int32_t aIndex) const
|
|
||||||
{
|
|
||||||
return mStyleSheets.SafeElementAt(aIndex, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t
|
|
||||||
nsDocument::GetIndexOfStyleSheet(const StyleSheet* aSheet) const
|
|
||||||
{
|
|
||||||
return mStyleSheets.IndexOf(aSheet);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
nsDocument::AddStyleSheetToStyleSets(StyleSheet* aSheet)
|
nsDocument::AddStyleSheetToStyleSets(StyleSheet* aSheet)
|
||||||
{
|
{
|
||||||
|
|
@ -4088,9 +3998,9 @@ nsDocument::UpdateStyleSheets(nsTArray<RefPtr<StyleSheet>>& aOldSheets,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsDocument::InsertStyleSheetAt(StyleSheet* aSheet, int32_t aIndex)
|
nsDocument::InsertStyleSheetAt(StyleSheet* aSheet, size_t aIndex)
|
||||||
{
|
{
|
||||||
NS_PRECONDITION(aSheet, "null ptr");
|
MOZ_ASSERT(aSheet);
|
||||||
|
|
||||||
mStyleSheets.InsertElementAt(aIndex, aSheet);
|
mStyleSheets.InsertElementAt(aIndex, aSheet);
|
||||||
|
|
||||||
|
|
@ -5815,15 +5725,6 @@ nsDocument::GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
StyleSheetList*
|
|
||||||
nsDocument::StyleSheets()
|
|
||||||
{
|
|
||||||
if (!mDOMStyleSheets) {
|
|
||||||
mDOMStyleSheets = new nsDOMStyleSheetList(this);
|
|
||||||
}
|
|
||||||
return mDOMStyleSheets;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsDocument::GetMozSelectedStyleSheetSet(nsAString& aSheetSet)
|
nsDocument::GetMozSelectedStyleSheetSet(nsAString& aSheetSet)
|
||||||
{
|
{
|
||||||
|
|
@ -5837,10 +5738,10 @@ nsIDocument::GetSelectedStyleSheetSet(nsAString& aSheetSet)
|
||||||
aSheetSet.Truncate();
|
aSheetSet.Truncate();
|
||||||
|
|
||||||
// Look through our sheets, find the selected set title
|
// Look through our sheets, find the selected set title
|
||||||
int32_t count = GetNumberOfStyleSheets();
|
size_t count = SheetCount();
|
||||||
nsAutoString title;
|
nsAutoString title;
|
||||||
for (int32_t index = 0; index < count; index++) {
|
for (size_t index = 0; index < count; index++) {
|
||||||
StyleSheet* sheet = GetStyleSheetAt(index);
|
StyleSheet* sheet = SheetAt(index);
|
||||||
NS_ASSERTION(sheet, "Null sheet in sheet list!");
|
NS_ASSERTION(sheet, "Null sheet in sheet list!");
|
||||||
|
|
||||||
// XXXheycam Make this work with ServoStyleSheets.
|
// XXXheycam Make this work with ServoStyleSheets.
|
||||||
|
|
@ -5957,10 +5858,10 @@ nsDocument::EnableStyleSheetsForSetInternal(const nsAString& aSheetSet,
|
||||||
bool aUpdateCSSLoader)
|
bool aUpdateCSSLoader)
|
||||||
{
|
{
|
||||||
BeginUpdate(UPDATE_STYLE);
|
BeginUpdate(UPDATE_STYLE);
|
||||||
int32_t count = GetNumberOfStyleSheets();
|
size_t count = SheetCount();
|
||||||
nsAutoString title;
|
nsAutoString title;
|
||||||
for (int32_t index = 0; index < count; index++) {
|
for (size_t index = 0; index < count; index++) {
|
||||||
StyleSheet* sheet = GetStyleSheetAt(index);
|
StyleSheet* sheet = SheetAt(index);
|
||||||
NS_ASSERTION(sheet, "Null sheet in sheet list!");
|
NS_ASSERTION(sheet, "Null sheet in sheet list!");
|
||||||
|
|
||||||
// XXXheycam Make this work with ServoStyleSheets.
|
// XXXheycam Make this work with ServoStyleSheets.
|
||||||
|
|
@ -9668,9 +9569,9 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer)
|
||||||
|
|
||||||
clonedDoc->mOriginalDocument->mStaticCloneCount++;
|
clonedDoc->mOriginalDocument->mStaticCloneCount++;
|
||||||
|
|
||||||
int32_t sheetsCount = GetNumberOfStyleSheets();
|
size_t sheetsCount = SheetCount();
|
||||||
for (int32_t i = 0; i < sheetsCount; ++i) {
|
for (size_t i = 0; i < sheetsCount; ++i) {
|
||||||
RefPtr<StyleSheet> sheet = GetStyleSheetAt(i);
|
RefPtr<StyleSheet> sheet = SheetAt(i);
|
||||||
if (sheet) {
|
if (sheet) {
|
||||||
if (sheet->IsApplicable()) {
|
if (sheet->IsApplicable()) {
|
||||||
// XXXheycam Need to make ServoStyleSheet cloning work.
|
// XXXheycam Need to make ServoStyleSheet cloning work.
|
||||||
|
|
|
||||||
|
|
@ -293,36 +293,6 @@ public:
|
||||||
nsDocHeaderData* mNext;
|
nsDocHeaderData* mNext;
|
||||||
};
|
};
|
||||||
|
|
||||||
class nsDOMStyleSheetList : public mozilla::dom::StyleSheetList,
|
|
||||||
public nsStubDocumentObserver
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit nsDOMStyleSheetList(nsIDocument* aDocument);
|
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDocumentObserver
|
|
||||||
NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED
|
|
||||||
NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED
|
|
||||||
|
|
||||||
// nsIMutationObserver
|
|
||||||
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
|
|
||||||
|
|
||||||
virtual nsINode* GetParentObject() const override
|
|
||||||
{
|
|
||||||
return mDocument;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t Length() override;
|
|
||||||
mozilla::StyleSheet* IndexedGetter(uint32_t aIndex, bool& aFound) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual ~nsDOMStyleSheetList();
|
|
||||||
|
|
||||||
int32_t mLength;
|
|
||||||
nsIDocument* mDocument;
|
|
||||||
};
|
|
||||||
|
|
||||||
class nsOnloadBlocker final : public nsIRequest
|
class nsOnloadBlocker final : public nsIRequest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -624,14 +594,6 @@ public:
|
||||||
|
|
||||||
virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet) override;
|
virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet) override;
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the (document) style sheets owned by this document.
|
|
||||||
* These are ordered, highest priority last
|
|
||||||
*/
|
|
||||||
virtual int32_t GetNumberOfStyleSheets() const override;
|
|
||||||
virtual mozilla::StyleSheet* GetStyleSheetAt(int32_t aIndex) const override;
|
|
||||||
virtual int32_t GetIndexOfStyleSheet(
|
|
||||||
const mozilla::StyleSheet* aSheet) const override;
|
|
||||||
virtual void AddStyleSheet(mozilla::StyleSheet* aSheet) override;
|
virtual void AddStyleSheet(mozilla::StyleSheet* aSheet) override;
|
||||||
virtual void RemoveStyleSheet(mozilla::StyleSheet* aSheet) override;
|
virtual void RemoveStyleSheet(mozilla::StyleSheet* aSheet) override;
|
||||||
|
|
||||||
|
|
@ -642,7 +604,7 @@ public:
|
||||||
virtual void RemoveStyleSheetFromStyleSets(mozilla::StyleSheet* aSheet);
|
virtual void RemoveStyleSheetFromStyleSets(mozilla::StyleSheet* aSheet);
|
||||||
|
|
||||||
virtual void InsertStyleSheetAt(mozilla::StyleSheet* aSheet,
|
virtual void InsertStyleSheetAt(mozilla::StyleSheet* aSheet,
|
||||||
int32_t aIndex) override;
|
size_t aIndex) override;
|
||||||
virtual void SetStyleSheetApplicableState(mozilla::StyleSheet* aSheet,
|
virtual void SetStyleSheetApplicableState(mozilla::StyleSheet* aSheet,
|
||||||
bool aApplicable) override;
|
bool aApplicable) override;
|
||||||
|
|
||||||
|
|
@ -1128,7 +1090,7 @@ public:
|
||||||
// WebIDL bits
|
// WebIDL bits
|
||||||
virtual mozilla::dom::DOMImplementation*
|
virtual mozilla::dom::DOMImplementation*
|
||||||
GetImplementation(mozilla::ErrorResult& rv) override;
|
GetImplementation(mozilla::ErrorResult& rv) override;
|
||||||
virtual mozilla::dom::StyleSheetList* StyleSheets() override;
|
|
||||||
virtual void SetSelectedStyleSheetSet(const nsAString& aSheetSet) override;
|
virtual void SetSelectedStyleSheetSet(const nsAString& aSheetSet) override;
|
||||||
virtual void GetLastStyleSheetSet(nsString& aSheetSet) override;
|
virtual void GetLastStyleSheetSet(nsString& aSheetSet) override;
|
||||||
virtual mozilla::dom::DOMStringList* StyleSheetSets() override;
|
virtual mozilla::dom::DOMStringList* StyleSheetSets() override;
|
||||||
|
|
@ -1350,7 +1312,6 @@ protected:
|
||||||
// EndLoad() has already happened.
|
// EndLoad() has already happened.
|
||||||
nsWeakPtr mWeakSink;
|
nsWeakPtr mWeakSink;
|
||||||
|
|
||||||
nsTArray<RefPtr<mozilla::StyleSheet>> mStyleSheets;
|
|
||||||
nsTArray<RefPtr<mozilla::StyleSheet>> mOnDemandBuiltInUASheets;
|
nsTArray<RefPtr<mozilla::StyleSheet>> mOnDemandBuiltInUASheets;
|
||||||
nsTArray<RefPtr<mozilla::StyleSheet>> mAdditionalSheets[AdditionalSheetTypeCount];
|
nsTArray<RefPtr<mozilla::StyleSheet>> mAdditionalSheets[AdditionalSheetTypeCount];
|
||||||
|
|
||||||
|
|
@ -1392,7 +1353,6 @@ public:
|
||||||
static bool IsWebComponentsEnabled(nsPIDOMWindowInner* aWindow);
|
static bool IsWebComponentsEnabled(nsPIDOMWindowInner* aWindow);
|
||||||
|
|
||||||
RefPtr<mozilla::EventListenerManager> mListenerManager;
|
RefPtr<mozilla::EventListenerManager> mListenerManager;
|
||||||
RefPtr<mozilla::dom::StyleSheetList> mDOMStyleSheets;
|
|
||||||
RefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
|
RefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
|
||||||
RefPtr<nsScriptLoader> mScriptLoader;
|
RefPtr<nsScriptLoader> mScriptLoader;
|
||||||
nsDocHeaderData* mHeaderData;
|
nsDocHeaderData* mHeaderData;
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
#include "prclist.h"
|
#include "prclist.h"
|
||||||
#include "mozilla/UniquePtr.h"
|
#include "mozilla/UniquePtr.h"
|
||||||
#include "mozilla/CORSMode.h"
|
#include "mozilla/CORSMode.h"
|
||||||
|
#include "mozilla/dom/StyleScope.h"
|
||||||
#include "mozilla/LinkedList.h"
|
#include "mozilla/LinkedList.h"
|
||||||
#include "mozilla/StyleBackendType.h"
|
#include "mozilla/StyleBackendType.h"
|
||||||
#include "mozilla/StyleSheet.h"
|
#include "mozilla/StyleSheet.h"
|
||||||
|
|
@ -196,7 +197,8 @@ class nsContentList;
|
||||||
|
|
||||||
// Document interface. This is implemented by all document objects in
|
// Document interface. This is implemented by all document objects in
|
||||||
// Gecko.
|
// Gecko.
|
||||||
class nsIDocument : public nsINode
|
class nsIDocument : public nsINode,
|
||||||
|
public mozilla::dom::StyleScope
|
||||||
{
|
{
|
||||||
typedef mozilla::dom::GlobalObject GlobalObject;
|
typedef mozilla::dom::GlobalObject GlobalObject;
|
||||||
|
|
||||||
|
|
@ -1069,40 +1071,24 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet) = 0;
|
virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet) = 0;
|
||||||
|
|
||||||
/**
|
nsINode& AsNode() final
|
||||||
* Get the number of (document) stylesheets
|
{
|
||||||
*
|
return *this;
|
||||||
* @return the number of stylesheets
|
}
|
||||||
* @throws no exceptions
|
|
||||||
*/
|
|
||||||
virtual int32_t GetNumberOfStyleSheets() const = 0;
|
|
||||||
|
|
||||||
/**
|
mozilla::dom::StyleSheetList* StyleSheets()
|
||||||
* Get a particular stylesheet
|
{
|
||||||
* @param aIndex the index the stylesheet lives at. This is zero-based
|
return &StyleScope::EnsureDOMStyleSheets();
|
||||||
* @return the stylesheet at aIndex. Null if aIndex is out of range.
|
}
|
||||||
* @throws no exceptions
|
|
||||||
*/
|
|
||||||
virtual mozilla::StyleSheet* GetStyleSheetAt(int32_t aIndex) const = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a sheet at a particular spot in the stylesheet list (zero-based)
|
* Insert a sheet at a particular spot in the stylesheet list (zero-based)
|
||||||
* @param aSheet the sheet to insert
|
* @param aSheet the sheet to insert
|
||||||
* @param aIndex the index to insert at. This index will be
|
* @param aIndex the index to insert at.
|
||||||
* adjusted for the "special" sheets.
|
|
||||||
* @throws no exceptions
|
* @throws no exceptions
|
||||||
*/
|
*/
|
||||||
virtual void InsertStyleSheetAt(mozilla::StyleSheet* aSheet,
|
virtual void InsertStyleSheetAt(mozilla::StyleSheet* aSheet,
|
||||||
int32_t aIndex) = 0;
|
size_t aIndex) = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the index of a particular stylesheet. This will _always_
|
|
||||||
* consider the "special" sheets as part of the sheet list.
|
|
||||||
* @param aSheet the sheet to get the index of
|
|
||||||
* @return aIndex the index of the sheet in the full list
|
|
||||||
*/
|
|
||||||
virtual int32_t GetIndexOfStyleSheet(
|
|
||||||
const mozilla::StyleSheet* aSheet) const = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace the stylesheets in aOldSheets with the stylesheets in
|
* Replace the stylesheets in aOldSheets with the stylesheets in
|
||||||
|
|
@ -1159,7 +1145,7 @@ public:
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
size_t FindDocStyleSheetInsertionPoint(const nsTArray<T>& aDocSheets,
|
size_t FindDocStyleSheetInsertionPoint(const nsTArray<T>& aDocSheets,
|
||||||
mozilla::StyleSheet* aSheet);
|
const mozilla::StyleSheet& aSheet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get this document's CSSLoader. This is guaranteed to not return null.
|
* Get this document's CSSLoader. This is guaranteed to not return null.
|
||||||
|
|
@ -2699,7 +2685,6 @@ public:
|
||||||
return mVisibilityState;
|
return mVisibilityState;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
virtual mozilla::dom::StyleSheetList* StyleSheets() = 0;
|
|
||||||
void GetSelectedStyleSheetSet(nsAString& aSheetSet);
|
void GetSelectedStyleSheetSet(nsAString& aSheetSet);
|
||||||
virtual void SetSelectedStyleSheetSet(const nsAString& aSheetSet) = 0;
|
virtual void SetSelectedStyleSheetSet(const nsAString& aSheetSet) = 0;
|
||||||
virtual void GetLastStyleSheetSet(nsString& aSheetSet) = 0;
|
virtual void GetLastStyleSheetSet(nsString& aSheetSet) = 0;
|
||||||
|
|
|
||||||
|
|
@ -20,19 +20,19 @@ template<typename T>
|
||||||
size_t
|
size_t
|
||||||
nsIDocument::FindDocStyleSheetInsertionPoint(
|
nsIDocument::FindDocStyleSheetInsertionPoint(
|
||||||
const nsTArray<T>& aDocSheets,
|
const nsTArray<T>& aDocSheets,
|
||||||
mozilla::StyleSheet* aSheet)
|
const mozilla::StyleSheet& aSheet)
|
||||||
{
|
{
|
||||||
nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance();
|
nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance();
|
||||||
|
|
||||||
// lowest index first
|
// lowest index first
|
||||||
int32_t newDocIndex = GetIndexOfStyleSheet(aSheet);
|
int32_t newDocIndex = IndexOfSheet(aSheet);
|
||||||
|
|
||||||
int32_t count = aDocSheets.Length();
|
size_t count = aDocSheets.Length();
|
||||||
int32_t index;
|
size_t index = 0;
|
||||||
for (index = 0; index < count; index++) {
|
for (; index < count; index++) {
|
||||||
mozilla::StyleSheet* sheet = static_cast<mozilla::StyleSheet*>(
|
auto* sheet = static_cast<mozilla::StyleSheet*>(aDocSheets[index]);
|
||||||
aDocSheets[index]);
|
MOZ_ASSERT(sheet);
|
||||||
int32_t sheetDocIndex = GetIndexOfStyleSheet(sheet);
|
int32_t sheetDocIndex = IndexOfSheet(*sheet);
|
||||||
if (sheetDocIndex > newDocIndex)
|
if (sheetDocIndex > newDocIndex)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,8 +114,8 @@ inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the document sheets.
|
// Get the document sheets.
|
||||||
for (int32_t i = 0; i < document->GetNumberOfStyleSheets(); i++) {
|
for (size_t i = 0; i < document->SheetCount(); i++) {
|
||||||
sheets.AppendElement(document->GetStyleSheetAt(i));
|
sheets.AppendElement(document->SheetAt(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
nsISupports** ret = static_cast<nsISupports**>(moz_xmalloc(sheets.Length() *
|
nsISupports** ret = static_cast<nsISupports**>(moz_xmalloc(sheets.Length() *
|
||||||
|
|
|
||||||
|
|
@ -1334,7 +1334,7 @@ Loader::InsertSheetInDoc(StyleSheet* aSheet,
|
||||||
|
|
||||||
// XXX Need to cancel pending sheet loads for this element, if any
|
// XXX Need to cancel pending sheet loads for this element, if any
|
||||||
|
|
||||||
int32_t sheetCount = aDocument->GetNumberOfStyleSheets();
|
int32_t sheetCount = aDocument->SheetCount();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start the walk at the _end_ of the list, since in the typical
|
* Start the walk at the _end_ of the list, since in the typical
|
||||||
|
|
@ -1346,7 +1346,7 @@ Loader::InsertSheetInDoc(StyleSheet* aSheet,
|
||||||
*/
|
*/
|
||||||
int32_t insertionPoint;
|
int32_t insertionPoint;
|
||||||
for (insertionPoint = sheetCount - 1; insertionPoint >= 0; --insertionPoint) {
|
for (insertionPoint = sheetCount - 1; insertionPoint >= 0; --insertionPoint) {
|
||||||
StyleSheet* curSheet = aDocument->GetStyleSheetAt(insertionPoint);
|
StyleSheet* curSheet = aDocument->SheetAt(insertionPoint);
|
||||||
NS_ASSERTION(curSheet, "There must be a sheet here!");
|
NS_ASSERTION(curSheet, "There must be a sheet here!");
|
||||||
nsCOMPtr<nsINode> sheetOwner = curSheet->GetOwnerNode();
|
nsCOMPtr<nsINode> sheetOwner = curSheet->GetOwnerNode();
|
||||||
if (sheetOwner && !aLinkingContent) {
|
if (sheetOwner && !aLinkingContent) {
|
||||||
|
|
|
||||||
|
|
@ -339,7 +339,7 @@ ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet,
|
||||||
mSheets[SheetType::Doc].RemoveElement(aSheet);
|
mSheets[SheetType::Doc].RemoveElement(aSheet);
|
||||||
|
|
||||||
size_t index =
|
size_t index =
|
||||||
aDocument->FindDocStyleSheetInsertionPoint(mSheets[SheetType::Doc], aSheet);
|
aDocument->FindDocStyleSheetInsertionPoint(mSheets[SheetType::Doc], *aSheet);
|
||||||
mSheets[SheetType::Doc].InsertElementAt(index, aSheet);
|
mSheets[SheetType::Doc].InsertElementAt(index, aSheet);
|
||||||
|
|
||||||
// Maintain a mirrored list of sheets on the servo side.
|
// Maintain a mirrored list of sheets on the servo side.
|
||||||
|
|
|
||||||
|
|
@ -734,7 +734,7 @@ nsStyleSet::AddDocStyleSheet(CSSStyleSheet* aSheet, nsIDocument* aDocument)
|
||||||
|
|
||||||
bool present = sheets.RemoveElement(aSheet);
|
bool present = sheets.RemoveElement(aSheet);
|
||||||
|
|
||||||
size_t index = aDocument->FindDocStyleSheetInsertionPoint(sheets, aSheet);
|
size_t index = aDocument->FindDocStyleSheetInsertionPoint(sheets, *aSheet);
|
||||||
sheets.InsertElementAt(index, aSheet);
|
sheets.InsertElementAt(index, aSheet);
|
||||||
|
|
||||||
if (!present) {
|
if (!present) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue