Backed out changeset 13faabcf8e96 (bug 1425769) for Linux bustage on build/src/dom/base/nsLineBreaker.h

This commit is contained in:
Dorel Luca 2017-12-19 11:07:44 +02:00
parent 5a9ff8849d
commit e968e809aa
16 changed files with 292 additions and 254 deletions

View File

@ -421,22 +421,23 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindowOuter* aWindow)
NS_ENSURE_SUCCESS(rv, rv);
}
size_t count = document->SheetCount();
int32_t count = document->GetNumberOfStyleSheets();
// Build an array of style sheets we need to reload.
nsTArray<RefPtr<StyleSheet>> oldSheets(count);
nsTArray<RefPtr<StyleSheet>> newSheets(count);
// Iterate over the style sheets.
for (size_t i = 0; i < count; i++) {
for (int32_t i = 0; i < count; i++) {
// Get the style sheet
oldSheets.AppendElement(document->SheetAt(i));
StyleSheet* styleSheet = document->GetStyleSheetAt(i);
oldSheets.AppendElement(styleSheet);
}
// 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.
for (StyleSheet* sheet : oldSheets) {
MOZ_ASSERT(sheet, "SheetAt shouldn't return nullptr for "
MOZ_ASSERT(sheet, "GetStyleSheetAt shouldn't return nullptr for "
"in-range sheet indexes");
nsIURI* uri = sheet->GetSheetURI();

View File

@ -27,7 +27,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(ShadowRoot)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ShadowRoot,
DocumentFragment)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMStyleSheets)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleSheetList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAssociatedBinding)
for (auto iter = tmp->mIdentifierMap.ConstIter(); !iter.Done();
iter.Next()) {
@ -39,7 +39,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ShadowRoot)
if (tmp->GetHost()) {
tmp->GetHost()->RemoveMutationObserver(tmp);
}
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDOMStyleSheets)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStyleSheetList)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAssociatedBinding)
tmp->mIdentifierMap.Clear();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(DocumentFragment)
@ -210,37 +210,21 @@ ShadowRoot::InsertSheet(StyleSheet* aSheet,
{
nsCOMPtr<nsIStyleSheetLinkingElement>
linkingElement = do_QueryInterface(aLinkingContent);
// FIXME(emilio, bug 1410578): <link> should probably also be allowed here.
MOZ_ASSERT(linkingElement, "The only styles in a ShadowRoot should come "
"from <style>.");
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
// be in tree order).
for (size_t i = 0; i <= SheetCount(); i++) {
if (i == SheetCount()) {
AppendStyleSheet(*aSheet);
for (size_t i = 0; i <= mProtoBinding->SheetCount(); i++) {
if (i == mProtoBinding->SheetCount()) {
mProtoBinding->AppendStyleSheet(aSheet);
break;
}
nsINode* sheetOwningNode = SheetAt(i)->GetOwnerNode();
nsINode* sheetOwningNode = mProtoBinding->StyleSheetAt(i)->GetOwnerNode();
if (nsContentUtils::PositionIsBefore(aLinkingContent, sheetOwningNode)) {
InsertSheetAt(i, *aSheet);
mProtoBinding->InsertStyleSheetAt(i, aSheet);
break;
}
@ -255,7 +239,6 @@ void
ShadowRoot::RemoveSheet(StyleSheet* aSheet)
{
mProtoBinding->RemoveStyleSheet(aSheet);
StyleScope::RemoveSheet(*aSheet);
if (aSheet->IsApplicable()) {
StyleSheetChanged();
@ -510,6 +493,16 @@ ShadowRoot::SetApplyAuthorStyles(bool aApplyAuthorStyles)
}
}
StyleSheetList*
ShadowRoot::StyleSheets()
{
if (!mStyleSheetList) {
mStyleSheetList = new ShadowRootStyleSheetList(this);
}
return mStyleSheetList;
}
/**
* Returns whether the web components pool population algorithm
* on the host would contain |aContent|. This function ignores
@ -627,3 +620,38 @@ ShadowRoot::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
*aResult = nullptr;
return NS_ERROR_DOM_DATA_CLONE_ERR;
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(ShadowRootStyleSheetList, StyleSheetList,
mShadowRoot)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(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)
{
}
ShadowRootStyleSheetList::~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();
}

View File

@ -8,7 +8,8 @@
#define mozilla_dom_shadowroot_h__
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/StyleScope.h"
#include "mozilla/dom/StyleSheetList.h"
#include "mozilla/StyleSheet.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIContentInlines.h"
@ -26,11 +27,12 @@ class EventChainPreVisitor;
namespace dom {
class Element;
class ShadowRootStyleSheetList;
class ShadowRoot final : public DocumentFragment,
public StyleScope,
public nsStubMutationObserver
{
friend class ShadowRootStyleSheetList;
public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRoot,
DocumentFragment)
@ -47,21 +49,15 @@ public:
// Shadow DOM v1
Element* Host();
ShadowRootMode Mode() const
ShadowRootMode Mode()
{
return mMode;
}
bool IsClosed() const
bool IsClosed()
{
return mMode == ShadowRootMode::Closed;
}
// StyleScope.
nsINode& AsNode() final
{
return *this;
}
// [deprecated] Shadow DOM v0
void AddToIdTable(Element* aElement, nsAtom* aId);
void RemoveFromIdTable(Element* aElement, nsAtom* aId);
@ -69,10 +65,7 @@ public:
void RemoveSheet(StyleSheet* aSheet);
bool ApplyAuthorStyles();
void SetApplyAuthorStyles(bool aApplyAuthorStyles);
StyleSheetList* StyleSheets()
{
return &StyleScope::EnsureDOMStyleSheets();
}
StyleSheetList* StyleSheets();
/**
* Distributes all the explicit children of the pool host to the content
@ -162,6 +155,8 @@ protected:
// owns |mProtoBinding|.
RefPtr<nsXBLBinding> mAssociatedBinding;
RefPtr<ShadowRootStyleSheetList> mStyleSheetList;
// 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
@ -178,6 +173,28 @@ protected:
bool aPreallocateChildren) 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 mozilla

View File

@ -1,27 +0,0 @@
/* -*- 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;
}
}
}

View File

@ -1,81 +0,0 @@
/* -*- 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

View File

@ -8,7 +8,6 @@
#include "mozilla/CSSStyleSheet.h"
#include "mozilla/dom/StyleSheetListBinding.h"
#include "nsStubDocumentObserver.h"
namespace mozilla {
namespace dom {
@ -18,8 +17,7 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(StyleSheetList)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(StyleSheetList)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheetList)
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMStyleSheetList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(StyleSheetList)
@ -45,24 +43,5 @@ StyleSheetList::SlowItem(uint32_t aIndex, nsIDOMStyleSheet** aItem)
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 mozilla

View File

@ -7,10 +7,8 @@
#ifndef mozilla_dom_StyleSheetList_h
#define mozilla_dom_StyleSheetList_h
#include "mozilla/dom/StyleScope.h"
#include "nsIDOMStyleSheetList.h"
#include "nsWrapperCache.h"
#include "nsStubDocumentObserver.h"
class nsINode;
@ -19,54 +17,28 @@ class StyleSheet;
namespace dom {
class StyleSheetList final : public nsIDOMStyleSheetList
, public nsWrapperCache
, public nsStubDocumentObserver
class StyleSheetList : public nsIDOMStyleSheetList
, public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(StyleSheetList, nsIDOMStyleSheetList)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(StyleSheetList)
NS_DECL_NSIDOMSTYLESHEETLIST
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
explicit StyleSheetList(StyleScope& aScope);
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
nsINode* GetParentObject() const
{
return mStyleScope ? &mStyleScope->AsNode() : nullptr;
}
virtual nsINode* GetParentObject() const = 0;
uint32_t Length() const
{
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
virtual uint32_t Length() = 0;
virtual StyleSheet* IndexedGetter(uint32_t aIndex, bool& aFound) = 0;
StyleSheet* Item(uint32_t aIndex)
{
bool dummy = false;
return IndexedGetter(aIndex, dummy);
}
protected:
virtual ~StyleSheetList();
StyleScope* mStyleScope; // Weak, cleared on "NodeWillBeDestroyed".
virtual ~StyleSheetList() {}
};
} // namespace dom

View File

@ -207,7 +207,6 @@ EXPORTS.mozilla.dom += [
'StructuredCloneBlob.h',
'StructuredCloneHolder.h',
'StructuredCloneTags.h',
'StyleScope.h',
'StyleSheetList.h',
'SubtleCrypto.h',
'TabGroup.h',
@ -351,7 +350,6 @@ UNIFIED_SOURCES += [
'ShadowRoot.cpp',
'StructuredCloneBlob.cpp',
'StructuredCloneHolder.cpp',
'StyleScope.cpp',
'StyleSheetList.cpp',
'SubtleCrypto.cpp',
'TabGroup.cpp',

View File

@ -732,6 +732,78 @@ struct nsRadioGroupStruct
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
NS_IMPL_ISUPPORTS(nsOnloadBlocker, nsIRequest)
@ -1288,10 +1360,10 @@ nsDOMStyleSheetSetList::EnsureFresh()
// no document, for sure
}
size_t count = mDocument->SheetCount();
int32_t count = mDocument->GetNumberOfStyleSheets();
nsAutoString title;
for (size_t index = 0; index < count; index++) {
StyleSheet* sheet = mDocument->SheetAt(index);
for (int32_t index = 0; index < count; index++) {
StyleSheet* sheet = mDocument->GetStyleSheetAt(index);
NS_ASSERTION(sheet, "Null sheet in sheet list!");
sheet->GetTitle(title);
if (!title.IsEmpty() && !mNames.Contains(title) && !Add(title)) {
@ -4512,6 +4584,24 @@ nsDocument::AddOnDemandBuiltInUASheet(StyleSheet* aSheet)
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
nsDocument::AddStyleSheetToStyleSets(StyleSheet* aSheet)
{
@ -4651,13 +4741,11 @@ nsDocument::UpdateStyleSheets(nsTArray<RefPtr<StyleSheet>>& aOldSheets,
}
void
nsDocument::InsertStyleSheetAt(StyleSheet* aSheet, size_t aIndex)
nsDocument::InsertStyleSheetAt(StyleSheet* aSheet, int32_t aIndex)
{
MOZ_ASSERT(aSheet);
MOZ_DIAGNOSTIC_ASSERT(aSheet->IsServo() == IsStyledByServo());
NS_PRECONDITION(aSheet, "null ptr");
// FIXME(emilio): Stop touching StyleScope's members directly, and use an
// accessor.
MOZ_DIAGNOSTIC_ASSERT(aSheet->IsServo() == IsStyledByServo());
mStyleSheets.InsertElementAt(aIndex, aSheet);
aSheet->SetAssociatedDocument(this, StyleSheet::OwnedByDocument);
@ -6368,6 +6456,15 @@ nsDocument::GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets)
return NS_OK;
}
StyleSheetList*
nsDocument::StyleSheets()
{
if (!mDOMStyleSheets) {
mDOMStyleSheets = new nsDOMStyleSheetList(this);
}
return mDOMStyleSheets;
}
NS_IMETHODIMP
nsDocument::GetMozSelectedStyleSheetSet(nsAString& aSheetSet)
{
@ -6381,10 +6478,10 @@ nsIDocument::GetSelectedStyleSheetSet(nsAString& aSheetSet)
aSheetSet.Truncate();
// Look through our sheets, find the selected set title
size_t count = SheetCount();
int32_t count = GetNumberOfStyleSheets();
nsAutoString title;
for (size_t index = 0; index < count; index++) {
StyleSheet* sheet = SheetAt(index);
for (int32_t index = 0; index < count; index++) {
StyleSheet* sheet = GetStyleSheetAt(index);
NS_ASSERTION(sheet, "Null sheet in sheet list!");
if (sheet->Disabled()) {
@ -6493,10 +6590,10 @@ nsDocument::EnableStyleSheetsForSetInternal(const nsAString& aSheetSet,
bool aUpdateCSSLoader)
{
BeginUpdate(UPDATE_STYLE);
size_t count = SheetCount();
int32_t count = GetNumberOfStyleSheets();
nsAutoString title;
for (size_t index = 0; index < count; index++) {
StyleSheet* sheet = SheetAt(index);
for (int32_t index = 0; index < count; index++) {
StyleSheet* sheet = GetStyleSheetAt(index);
NS_ASSERTION(sheet, "Null sheet in sheet list!");
sheet->GetTitle(title);
@ -10188,9 +10285,9 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer)
clonedDoc->mOriginalDocument->mStaticCloneCount++;
MOZ_ASSERT(GetStyleBackendType() == clonedDoc->GetStyleBackendType());
size_t sheetsCount = SheetCount();
for (size_t i = 0; i < sheetsCount; ++i) {
RefPtr<StyleSheet> sheet = SheetAt(i);
int32_t sheetsCount = GetNumberOfStyleSheets();
for (int32_t i = 0; i < sheetsCount; ++i) {
RefPtr<StyleSheet> sheet = GetStyleSheetAt(i);
if (sheet) {
if (sheet->IsApplicable()) {
RefPtr<StyleSheet> clonedSheet =

View File

@ -149,6 +149,36 @@ public:
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
{
public:
@ -448,6 +478,14 @@ public:
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 RemoveStyleSheet(mozilla::StyleSheet* aSheet) override;
@ -458,7 +496,7 @@ public:
virtual void RemoveStyleSheetFromStyleSets(mozilla::StyleSheet* aSheet);
virtual void InsertStyleSheetAt(mozilla::StyleSheet* aSheet,
size_t aIndex) override;
int32_t aIndex) override;
virtual void SetStyleSheetApplicableState(mozilla::StyleSheet* aSheet,
bool aApplicable) override;
@ -950,7 +988,7 @@ public:
// WebIDL bits
virtual mozilla::dom::DOMImplementation*
GetImplementation(mozilla::ErrorResult& rv) override;
virtual mozilla::dom::StyleSheetList* StyleSheets() override;
virtual void SetSelectedStyleSheetSet(const nsAString& aSheetSet) override;
virtual void GetLastStyleSheetSet(nsString& aSheetSet) override;
virtual mozilla::dom::DOMStringList* StyleSheetSets() override;
@ -1104,6 +1142,7 @@ protected:
// EndLoad() has already happened.
nsWeakPtr mWeakSink;
nsTArray<RefPtr<mozilla::StyleSheet>> mStyleSheets;
nsTArray<RefPtr<mozilla::StyleSheet>> mOnDemandBuiltInUASheets;
nsTArray<RefPtr<mozilla::StyleSheet>> mAdditionalSheets[AdditionalSheetTypeCount];
@ -1140,6 +1179,7 @@ protected:
public:
RefPtr<mozilla::EventListenerManager> mListenerManager;
RefPtr<mozilla::dom::StyleSheetList> mDOMStyleSheets;
RefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
RefPtr<mozilla::dom::ScriptLoader> mScriptLoader;
nsDocHeaderData* mHeaderData;

View File

@ -34,7 +34,6 @@
#include "nsClassHashtable.h"
#include "mozilla/CORSMode.h"
#include "mozilla/dom/DispatcherTrait.h"
#include "mozilla/dom/StyleScope.h"
#include "mozilla/LinkedList.h"
#include "mozilla/NotNull.h"
#include "mozilla/SegmentedVector.h"
@ -213,7 +212,6 @@ class nsContentList;
// Document interface. This is implemented by all document objects in
// Gecko.
class nsIDocument : public nsINode,
public mozilla::dom::StyleScope,
public mozilla::dom::DispatcherTrait
{
typedef mozilla::dom::GlobalObject GlobalObject;
@ -1324,25 +1322,40 @@ public:
*/
virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet) = 0;
nsINode& AsNode() final
{
return *this;
}
/**
* Get the number of (document) stylesheets
*
* @return the number of stylesheets
* @throws no exceptions
*/
virtual int32_t GetNumberOfStyleSheets() const = 0;
mozilla::dom::StyleSheetList* StyleSheets()
{
return &StyleScope::EnsureDOMStyleSheets();
}
/**
* Get a particular stylesheet
* @param aIndex the index the stylesheet lives at. This is zero-based
* @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)
* @param aSheet the sheet to insert
* @param aIndex the index to insert at.
* @param aIndex the index to insert at. This index will be
* adjusted for the "special" sheets.
* @throws no exceptions
*/
virtual void InsertStyleSheetAt(mozilla::StyleSheet* aSheet,
size_t aIndex) = 0;
int32_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
@ -1399,7 +1412,7 @@ public:
*/
template<typename T>
size_t FindDocStyleSheetInsertionPoint(const nsTArray<T>& aDocSheets,
const mozilla::StyleSheet& aSheet);
mozilla::StyleSheet* aSheet);
/**
* Get this document's CSSLoader. This is guaranteed to not return null.
@ -2971,6 +2984,7 @@ public:
return mVisibilityState;
}
#endif
virtual mozilla::dom::StyleSheetList* StyleSheets() = 0;
void GetSelectedStyleSheetSet(nsAString& aSheetSet);
virtual void SetSelectedStyleSheetSet(const nsAString& aSheetSet) = 0;
virtual void GetLastStyleSheetSet(nsString& aSheetSet) = 0;

View File

@ -21,19 +21,19 @@ template<typename T>
size_t
nsIDocument::FindDocStyleSheetInsertionPoint(
const nsTArray<T>& aDocSheets,
const mozilla::StyleSheet& aSheet)
mozilla::StyleSheet* aSheet)
{
nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance();
// lowest index first
int32_t newDocIndex = IndexOfSheet(aSheet);
int32_t newDocIndex = GetIndexOfStyleSheet(aSheet);
size_t count = aDocSheets.Length();
size_t index = 0;
for (; index < count; index++) {
auto* sheet = static_cast<mozilla::StyleSheet*>(aDocSheets[index]);
MOZ_ASSERT(sheet);
int32_t sheetDocIndex = IndexOfSheet(*sheet);
int32_t count = aDocSheets.Length();
int32_t index;
for (index = 0; index < count; index++) {
mozilla::StyleSheet* sheet = static_cast<mozilla::StyleSheet*>(
aDocSheets[index]);
int32_t sheetDocIndex = GetIndexOfStyleSheet(sheet);
if (sheetDocIndex > newDocIndex)
break;

View File

@ -113,8 +113,8 @@ inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength,
}
// Get the document sheets.
for (size_t i = 0; i < document->SheetCount(); i++) {
sheets.AppendElement(document->SheetAt(i));
for (int32_t i = 0; i < document->GetNumberOfStyleSheets(); i++) {
sheets.AppendElement(document->GetStyleSheetAt(i));
}
nsISupports** ret = static_cast<nsISupports**>(moz_xmalloc(sheets.Length() *

View File

@ -1190,7 +1190,7 @@ Loader::InsertSheetInDoc(StyleSheet* aSheet,
// XXX Need to cancel pending sheet loads for this element, if any
int32_t sheetCount = aDocument->SheetCount();
int32_t sheetCount = aDocument->GetNumberOfStyleSheets();
/*
* Start the walk at the _end_ of the list, since in the typical
@ -1202,7 +1202,7 @@ Loader::InsertSheetInDoc(StyleSheet* aSheet,
*/
int32_t insertionPoint;
for (insertionPoint = sheetCount - 1; insertionPoint >= 0; --insertionPoint) {
StyleSheet* curSheet = aDocument->SheetAt(insertionPoint);
StyleSheet* curSheet = aDocument->GetStyleSheetAt(insertionPoint);
NS_ASSERTION(curSheet, "There must be a sheet here!");
nsCOMPtr<nsINode> sheetOwner = curSheet->GetOwnerNode();
if (sheetOwner && !aLinkingContent) {

View File

@ -837,7 +837,7 @@ ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet,
RemoveSheetOfType(SheetType::Doc, aSheet);
size_t index =
aDocument->FindDocStyleSheetInsertionPoint(mSheets[SheetType::Doc], *aSheet);
aDocument->FindDocStyleSheetInsertionPoint(mSheets[SheetType::Doc], aSheet);
if (index < mSheets[SheetType::Doc].Length()) {
// This case is insert before.

View File

@ -726,7 +726,7 @@ nsStyleSet::AddDocStyleSheet(CSSStyleSheet* aSheet, nsIDocument* aDocument)
bool present = sheets.RemoveElement(aSheet);
size_t index = aDocument->FindDocStyleSheetInsertionPoint(sheets, *aSheet);
size_t index = aDocument->FindDocStyleSheetInsertionPoint(sheets, aSheet);
sheets.InsertElementAt(index, aSheet);
if (!present) {