Bug 1244074 - Part 4: Use StyleSheetHandle instead of concrete style sheet class in most places. r=dholbert

This commit is contained in:
Cameron McCormack 2016-02-24 18:01:12 +11:00
parent 8b44372832
commit 0ecd5593cc
64 changed files with 1031 additions and 777 deletions

View File

@ -17,7 +17,6 @@
#include "nsString.h" #include "nsString.h"
#include "nsQueryObject.h" #include "nsQueryObject.h"
#include "mozilla/CSSStyleSheet.h"
#include "mozilla/dom/URL.h" #include "mozilla/dom/URL.h"
#include "nsIConsoleService.h" #include "nsIConsoleService.h"
#include "nsIDocument.h" #include "nsIDocument.h"
@ -30,12 +29,14 @@
#include "nsIScriptError.h" #include "nsIScriptError.h"
#include "nsIWindowMediator.h" #include "nsIWindowMediator.h"
#include "nsIPrefService.h" #include "nsIPrefService.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
nsChromeRegistry* nsChromeRegistry::gChromeRegistry; nsChromeRegistry* nsChromeRegistry::gChromeRegistry;
// DO NOT use namespace mozilla; it'll break due to a naming conflict between // DO NOT use namespace mozilla; it'll break due to a naming conflict between
// mozilla::TextRange and a TextRange in OSX headers. // mozilla::TextRange and a TextRange in OSX headers.
using mozilla::CSSStyleSheet; using mozilla::StyleSheetHandle;
using mozilla::dom::IsChromeURI; using mozilla::dom::IsChromeURI;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -401,19 +402,18 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindowOuter* aWindow)
nsCOMPtr<nsIPresShell> shell = document->GetShell(); nsCOMPtr<nsIPresShell> shell = document->GetShell();
if (shell) { if (shell) {
// Reload only the chrome URL agent style sheets. // Reload only the chrome URL agent style sheets.
nsTArray<RefPtr<CSSStyleSheet>> agentSheets; nsTArray<StyleSheetHandle::RefPtr> agentSheets;
rv = shell->GetAgentStyleSheets(agentSheets); rv = shell->GetAgentStyleSheets(agentSheets);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsTArray<RefPtr<CSSStyleSheet>> newAgentSheets; nsTArray<StyleSheetHandle::RefPtr> newAgentSheets;
for (CSSStyleSheet* sheet : agentSheets) { for (StyleSheetHandle sheet : agentSheets) {
nsIURI* uri = sheet->GetSheetURI(); nsIURI* uri = sheet->GetSheetURI();
if (IsChromeURI(uri)) { if (IsChromeURI(uri)) {
// Reload the sheet. // Reload the sheet.
RefPtr<CSSStyleSheet> newSheet; StyleSheetHandle::RefPtr newSheet;
rv = document->LoadChromeSheetSync(uri, true, rv = document->LoadChromeSheetSync(uri, true, &newSheet);
getter_AddRefs(newSheet));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (newSheet) { if (newSheet) {
rv = newAgentSheets.AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE; rv = newAgentSheets.AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE;
@ -433,27 +433,27 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindowOuter* aWindow)
int32_t count = document->GetNumberOfStyleSheets(); int32_t count = document->GetNumberOfStyleSheets();
// Build an array of style sheets we need to reload. // Build an array of style sheets we need to reload.
nsTArray<RefPtr<CSSStyleSheet>> oldSheets(count); nsTArray<StyleSheetHandle::RefPtr> oldSheets(count);
nsTArray<RefPtr<CSSStyleSheet>> newSheets(count); nsTArray<StyleSheetHandle::RefPtr> newSheets(count);
// Iterate over the style sheets. // Iterate over the style sheets.
for (int32_t i = 0; i < count; i++) { for (int32_t i = 0; i < count; i++) {
// Get the style sheet // Get the style sheet
CSSStyleSheet* styleSheet = document->GetStyleSheetAt(i); StyleSheetHandle styleSheet = document->GetStyleSheetAt(i);
oldSheets.AppendElement(styleSheet); 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 chrome URL. // sheet if and only if it's a chrome URL.
for (CSSStyleSheet* sheet : oldSheets) { for (StyleSheetHandle sheet : oldSheets) {
nsIURI* uri = sheet ? sheet->GetOriginalURI() : nullptr; nsIURI* uri = sheet ? sheet->GetOriginalURI() : nullptr;
if (uri && IsChromeURI(uri)) { if (uri && IsChromeURI(uri)) {
// Reload the sheet. // Reload the sheet.
RefPtr<CSSStyleSheet> newSheet; StyleSheetHandle::RefPtr newSheet;
// XXX what about chrome sheets that have a title or are disabled? This // XXX what about chrome sheets that have a title or are disabled? This
// only works by sheer dumb luck. // only works by sheer dumb luck.
document->LoadChromeSheetSync(uri, false, getter_AddRefs(newSheet)); document->LoadChromeSheetSync(uri, false, &newSheet);
// Even if it's null, we put in in there. // Even if it's null, we put in in there.
newSheets.AppendElement(newSheet); newSheets.AppendElement(newSheet);
} else { } else {

View File

@ -17,6 +17,8 @@
#include "mozilla/dom/HTMLContentElement.h" #include "mozilla/dom/HTMLContentElement.h"
#include "mozilla/dom/HTMLShadowElement.h" #include "mozilla/dom/HTMLShadowElement.h"
#include "nsXBLPrototypeBinding.h" #include "nsXBLPrototypeBinding.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
@ -130,7 +132,7 @@ ShadowRoot::StyleSheetChanged()
} }
void void
ShadowRoot::InsertSheet(CSSStyleSheet* aSheet, ShadowRoot::InsertSheet(StyleSheetHandle aSheet,
nsIContent* aLinkingContent) nsIContent* aLinkingContent)
{ {
nsCOMPtr<nsIStyleSheetLinkingElement> nsCOMPtr<nsIStyleSheetLinkingElement>
@ -148,8 +150,8 @@ ShadowRoot::InsertSheet(CSSStyleSheet* aSheet,
break; break;
} }
nsINode* sheetOwnerNode = mProtoBinding->StyleSheetAt(i)->GetOwnerNode(); nsINode* sheetOwningNode = mProtoBinding->StyleSheetAt(i)->GetOwnerNode();
if (nsContentUtils::PositionIsBefore(aLinkingContent, sheetOwnerNode)) { if (nsContentUtils::PositionIsBefore(aLinkingContent, sheetOwningNode)) {
mProtoBinding->InsertStyleSheetAt(i, aSheet); mProtoBinding->InsertStyleSheetAt(i, aSheet);
break; break;
} }
@ -161,7 +163,7 @@ ShadowRoot::InsertSheet(CSSStyleSheet* aSheet,
} }
void void
ShadowRoot::RemoveSheet(CSSStyleSheet* aSheet) ShadowRoot::RemoveSheet(StyleSheetHandle aSheet)
{ {
mProtoBinding->RemoveStyleSheet(aSheet); mProtoBinding->RemoveStyleSheet(aSheet);
@ -752,7 +754,14 @@ ShadowRootStyleSheetList::IndexedGetter(uint32_t aIndex, bool& aFound)
return nullptr; return nullptr;
} }
return mShadowRoot->mProtoBinding->StyleSheetAt(aIndex); // 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();
} }
uint32_t uint32_t

View File

@ -9,6 +9,7 @@
#include "mozilla/dom/DocumentFragment.h" #include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/StyleSheetList.h" #include "mozilla/dom/StyleSheetList.h"
#include "mozilla/StyleSheetHandle.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
#include "nsTHashtable.h" #include "nsTHashtable.h"
@ -45,8 +46,8 @@ public:
void AddToIdTable(Element* aElement, nsIAtom* aId); void AddToIdTable(Element* aElement, nsIAtom* aId);
void RemoveFromIdTable(Element* aElement, nsIAtom* aId); void RemoveFromIdTable(Element* aElement, nsIAtom* aId);
void InsertSheet(CSSStyleSheet* aSheet, nsIContent* aLinkingContent); void InsertSheet(StyleSheetHandle aSheet, nsIContent* aLinkingContent);
void RemoveSheet(CSSStyleSheet* aSheet); void RemoveSheet(StyleSheetHandle aSheet);
bool ApplyAuthorStyles(); bool ApplyAuthorStyles();
void SetApplyAuthorStyles(bool aApplyAuthorStyles); void SetApplyAuthorStyles(bool aApplyAuthorStyles);
StyleSheetList* StyleSheets(); StyleSheetList* StyleSheets();

View File

@ -213,7 +213,7 @@ nsContentSink::Init(nsIDocument* aDoc,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsContentSink::StyleSheetLoaded(CSSStyleSheet* aSheet, nsContentSink::StyleSheetLoaded(StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) nsresult aStatus)
{ {

View File

@ -85,7 +85,7 @@ class nsContentSink : public nsICSSLoaderObserver,
NS_DECL_NSITIMERCALLBACK NS_DECL_NSITIMERCALLBACK
// nsICSSLoaderObserver // nsICSSLoaderObserver
NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet, NS_IMETHOD StyleSheetLoaded(mozilla::StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) override; nsresult aStatus) override;

View File

@ -245,6 +245,8 @@
#include "nsISupportsPrimitives.h" #include "nsISupportsPrimitives.h"
#include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandle.h"
#include "mozilla/StyleSetHandleInlines.h" #include "mozilla/StyleSetHandleInlines.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#include "mozilla/DocLoadingTimelineMarker.h" #include "mozilla/DocLoadingTimelineMarker.h"
@ -733,10 +735,16 @@ nsDOMStyleSheetList::IndexedGetter(uint32_t aIndex, bool& aFound)
} }
aFound = true; aFound = true;
CSSStyleSheet* sheet = mDocument->GetStyleSheetAt(aIndex); StyleSheetHandle sheet = mDocument->GetStyleSheetAt(aIndex);
NS_ASSERTION(sheet, "Must have a sheet"); NS_ASSERTION(sheet, "Must have a sheet");
return static_cast<CSSStyleSheet*>(sheet); // XXXheycam Return null until ServoStyleSheet implements the right DOM
// interfaces.
if (sheet->IsServo()) {
NS_ERROR("stylo: can't return a ServoStyleSheet to the DOM yet");
return nullptr;
}
return sheet->AsGecko();
} }
void void
@ -746,7 +754,7 @@ nsDOMStyleSheetList::NodeWillBeDestroyed(const nsINode *aNode)
} }
void void
nsDOMStyleSheetList::StyleSheetAdded(CSSStyleSheet* aStyleSheet, nsDOMStyleSheetList::StyleSheetAdded(StyleSheetHandle aStyleSheet,
bool aDocumentSheet) bool aDocumentSheet)
{ {
if (aDocumentSheet && -1 != mLength) { if (aDocumentSheet && -1 != mLength) {
@ -755,7 +763,7 @@ nsDOMStyleSheetList::StyleSheetAdded(CSSStyleSheet* aStyleSheet,
} }
void void
nsDOMStyleSheetList::StyleSheetRemoved(CSSStyleSheet* aStyleSheet, nsDOMStyleSheetList::StyleSheetRemoved(StyleSheetHandle aStyleSheet,
bool aDocumentSheet) bool aDocumentSheet)
{ {
if (aDocumentSheet && -1 != mLength) { if (aDocumentSheet && -1 != mLength) {
@ -1322,9 +1330,14 @@ nsDOMStyleSheetSetList::EnsureFresh()
int32_t count = mDocument->GetNumberOfStyleSheets(); int32_t count = mDocument->GetNumberOfStyleSheets();
nsAutoString title; nsAutoString title;
for (int32_t index = 0; index < count; index++) { for (int32_t index = 0; index < count; index++) {
CSSStyleSheet* sheet = mDocument->GetStyleSheetAt(index); StyleSheetHandle sheet = mDocument->GetStyleSheetAt(index);
NS_ASSERTION(sheet, "Null sheet in sheet list!"); NS_ASSERTION(sheet, "Null sheet in sheet list!");
sheet->GetTitle(title); // XXXheycam ServoStyleSheets don't expose their title yet.
if (sheet->IsServo()) {
NS_ERROR("stylo: ServoStyleSets don't expose their title yet");
continue;
}
sheet->AsGecko()->GetTitle(title);
if (!title.IsEmpty() && !mNames.Contains(title) && !Add(title)) { if (!title.IsEmpty() && !mNames.Contains(title) && !Add(title)) {
return; return;
} }
@ -1604,7 +1617,7 @@ nsDocument::~nsDocument()
mCachedRootElement = nullptr; mCachedRootElement = nullptr;
// Let the stylesheets know we're going away // Let the stylesheets know we're going away
for (CSSStyleSheet* sheet : mStyleSheets) { for (StyleSheetHandle sheet : mStyleSheets) {
sheet->SetOwningDocument(nullptr); sheet->SetOwningDocument(nullptr);
} }
if (mAttrStyleSheet) { if (mAttrStyleSheet) {
@ -2282,7 +2295,7 @@ void
nsDocument::RemoveDocStyleSheetsFromStyleSets() nsDocument::RemoveDocStyleSheetsFromStyleSets()
{ {
// The stylesheets should forget us // The stylesheets should forget us
for (CSSStyleSheet* sheet : Reversed(mStyleSheets)) { for (StyleSheetHandle sheet : Reversed(mStyleSheets)) {
sheet->SetOwningDocument(nullptr); sheet->SetOwningDocument(nullptr);
if (sheet->IsApplicable()) { if (sheet->IsApplicable()) {
@ -2297,11 +2310,11 @@ nsDocument::RemoveDocStyleSheetsFromStyleSets()
void void
nsDocument::RemoveStyleSheetsFromStyleSets( nsDocument::RemoveStyleSheetsFromStyleSets(
nsTArray<RefPtr<CSSStyleSheet>>& aSheets, nsTArray<StyleSheetHandle::RefPtr>& aSheets,
SheetType aType) SheetType aType)
{ {
// The stylesheets should forget us // The stylesheets should forget us
for (CSSStyleSheet* sheet : Reversed(aSheets)) { for (StyleSheetHandle sheet : Reversed(aSheets)) {
sheet->SetOwningDocument(nullptr); sheet->SetOwningDocument(nullptr);
if (sheet->IsApplicable()) { if (sheet->IsApplicable()) {
@ -2368,10 +2381,10 @@ nsDocument::ResetStylesheetsToURI(nsIURI* aURI)
static void static void
AppendSheetsToStyleSet(StyleSetHandle aStyleSet, AppendSheetsToStyleSet(StyleSetHandle aStyleSet,
const nsTArray<RefPtr<CSSStyleSheet>>& aSheets, const nsTArray<StyleSheetHandle::RefPtr>& aSheets,
SheetType aType) SheetType aType)
{ {
for (CSSStyleSheet* sheet : Reversed(aSheets)) { for (StyleSheetHandle sheet : Reversed(aSheets)) {
aStyleSet->AppendStyleSheet(aType, sheet); aStyleSet->AppendStyleSheet(aType, sheet);
} }
} }
@ -2384,7 +2397,7 @@ nsDocument::FillStyleSet(StyleSetHandle aStyleSet)
NS_PRECONDITION(aStyleSet->SheetCount(SheetType::Doc) == 0, NS_PRECONDITION(aStyleSet->SheetCount(SheetType::Doc) == 0,
"Style set already has document sheets?"); "Style set already has document sheets?");
for (CSSStyleSheet* sheet : Reversed(mStyleSheets)) { for (StyleSheetHandle sheet : Reversed(mStyleSheets)) {
if (sheet->IsApplicable()) { if (sheet->IsApplicable()) {
aStyleSet->AddDocStyleSheet(sheet, this); aStyleSet->AddDocStyleSheet(sheet, this);
} }
@ -2392,13 +2405,13 @@ nsDocument::FillStyleSet(StyleSetHandle aStyleSet)
nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance(); nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance();
if (sheetService) { if (sheetService) {
for (CSSStyleSheet* sheet : *sheetService->AuthorStyleSheets()) { for (StyleSheetHandle sheet : *sheetService->AuthorStyleSheets()) {
aStyleSet->AppendStyleSheet(SheetType::Doc, sheet); aStyleSet->AppendStyleSheet(SheetType::Doc, sheet);
} }
} }
// Iterate backwards to maintain order // Iterate backwards to maintain order
for (CSSStyleSheet* sheet : Reversed(mOnDemandBuiltInUASheets)) { for (StyleSheetHandle sheet : Reversed(mOnDemandBuiltInUASheets)) {
if (sheet->IsApplicable()) { if (sheet->IsApplicable()) {
aStyleSet->PrependStyleSheet(SheetType::Agent, sheet); aStyleSet->PrependStyleSheet(SheetType::Agent, sheet);
} }
@ -4051,7 +4064,7 @@ nsDocument::RemoveChildAt(uint32_t aIndex, bool aNotify)
} }
void void
nsDocument::EnsureOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) nsDocument::EnsureOnDemandBuiltInUASheet(StyleSheetHandle aSheet)
{ {
if (mOnDemandBuiltInUASheets.Contains(aSheet)) { if (mOnDemandBuiltInUASheets.Contains(aSheet)) {
return; return;
@ -4062,7 +4075,7 @@ nsDocument::EnsureOnDemandBuiltInUASheet(CSSStyleSheet* aSheet)
} }
void void
nsDocument::AddOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) nsDocument::AddOnDemandBuiltInUASheet(StyleSheetHandle aSheet)
{ {
MOZ_ASSERT(!mOnDemandBuiltInUASheets.Contains(aSheet)); MOZ_ASSERT(!mOnDemandBuiltInUASheets.Contains(aSheet));
@ -4091,20 +4104,20 @@ nsDocument::GetNumberOfStyleSheets() const
return mStyleSheets.Length(); return mStyleSheets.Length();
} }
CSSStyleSheet* StyleSheetHandle
nsDocument::GetStyleSheetAt(int32_t aIndex) const nsDocument::GetStyleSheetAt(int32_t aIndex) const
{ {
return mStyleSheets.SafeElementAt(aIndex, nullptr); return mStyleSheets.SafeElementAt(aIndex, StyleSheetHandle());
} }
int32_t int32_t
nsDocument::GetIndexOfStyleSheet(CSSStyleSheet* aSheet) const nsDocument::GetIndexOfStyleSheet(StyleSheetHandle aSheet) const
{ {
return mStyleSheets.IndexOf(aSheet); return mStyleSheets.IndexOf(aSheet);
} }
void void
nsDocument::AddStyleSheetToStyleSets(CSSStyleSheet* aSheet) nsDocument::AddStyleSheetToStyleSets(StyleSheetHandle aSheet)
{ {
nsCOMPtr<nsIPresShell> shell = GetShell(); nsCOMPtr<nsIPresShell> shell = GetShell();
if (shell) { if (shell) {
@ -4117,7 +4130,11 @@ nsDocument::AddStyleSheetToStyleSets(CSSStyleSheet* aSheet)
className##Init init; \ className##Init init; \
init.mBubbles = true; \ init.mBubbles = true; \
init.mCancelable = true; \ init.mCancelable = true; \
init.mStylesheet = aSheet; \ /* XXXheycam ServoStyleSheet doesn't implement DOM interfaces yet */ \
if (aSheet->IsServo()) { \
NS_ERROR("stylo: can't dispatch events for ServoStyleSheets yet"); \
} \
init.mStylesheet = aSheet->IsGecko() ? aSheet->AsGecko() : nullptr; \
init.memberName = argName; \ init.memberName = argName; \
\ \
RefPtr<className> event = \ RefPtr<className> event = \
@ -4131,7 +4148,7 @@ nsDocument::AddStyleSheetToStyleSets(CSSStyleSheet* aSheet)
} while (0); } while (0);
void void
nsDocument::NotifyStyleSheetAdded(CSSStyleSheet* aSheet, bool aDocumentSheet) nsDocument::NotifyStyleSheetAdded(StyleSheetHandle aSheet, bool aDocumentSheet)
{ {
NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetAdded, (aSheet, aDocumentSheet)); NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetAdded, (aSheet, aDocumentSheet));
@ -4144,7 +4161,7 @@ nsDocument::NotifyStyleSheetAdded(CSSStyleSheet* aSheet, bool aDocumentSheet)
} }
void void
nsDocument::NotifyStyleSheetRemoved(CSSStyleSheet* aSheet, bool aDocumentSheet) nsDocument::NotifyStyleSheetRemoved(StyleSheetHandle aSheet, bool aDocumentSheet)
{ {
NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetRemoved, (aSheet, aDocumentSheet)); NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetRemoved, (aSheet, aDocumentSheet));
@ -4157,7 +4174,7 @@ nsDocument::NotifyStyleSheetRemoved(CSSStyleSheet* aSheet, bool aDocumentSheet)
} }
void void
nsDocument::AddStyleSheet(CSSStyleSheet* aSheet) nsDocument::AddStyleSheet(StyleSheetHandle aSheet)
{ {
NS_PRECONDITION(aSheet, "null arg"); NS_PRECONDITION(aSheet, "null arg");
mStyleSheets.AppendElement(aSheet); mStyleSheets.AppendElement(aSheet);
@ -4171,7 +4188,7 @@ nsDocument::AddStyleSheet(CSSStyleSheet* aSheet)
} }
void void
nsDocument::RemoveStyleSheetFromStyleSets(CSSStyleSheet* aSheet) nsDocument::RemoveStyleSheetFromStyleSets(StyleSheetHandle aSheet)
{ {
nsCOMPtr<nsIPresShell> shell = GetShell(); nsCOMPtr<nsIPresShell> shell = GetShell();
if (shell) { if (shell) {
@ -4180,10 +4197,10 @@ nsDocument::RemoveStyleSheetFromStyleSets(CSSStyleSheet* aSheet)
} }
void void
nsDocument::RemoveStyleSheet(CSSStyleSheet* aSheet) nsDocument::RemoveStyleSheet(StyleSheetHandle aSheet)
{ {
NS_PRECONDITION(aSheet, "null arg"); NS_PRECONDITION(aSheet, "null arg");
RefPtr<CSSStyleSheet> sheet = aSheet; // hold ref so it won't die too soon StyleSheetHandle::RefPtr sheet = aSheet; // hold ref so it won't die too soon
if (!mStyleSheets.RemoveElement(aSheet)) { if (!mStyleSheets.RemoveElement(aSheet)) {
NS_ASSERTION(mInUnlinkOrDeletion, "stylesheet not found"); NS_ASSERTION(mInUnlinkOrDeletion, "stylesheet not found");
@ -4202,8 +4219,8 @@ nsDocument::RemoveStyleSheet(CSSStyleSheet* aSheet)
} }
void void
nsDocument::UpdateStyleSheets(nsTArray<RefPtr<CSSStyleSheet>>& aOldSheets, nsDocument::UpdateStyleSheets(nsTArray<StyleSheetHandle::RefPtr>& aOldSheets,
nsTArray<RefPtr<CSSStyleSheet>>& aNewSheets) nsTArray<StyleSheetHandle::RefPtr>& aNewSheets)
{ {
BeginUpdate(UPDATE_STYLE); BeginUpdate(UPDATE_STYLE);
@ -4212,7 +4229,7 @@ nsDocument::UpdateStyleSheets(nsTArray<RefPtr<CSSStyleSheet>>& aOldSheets,
"The lists must be the same length!"); "The lists must be the same length!");
int32_t count = aOldSheets.Length(); int32_t count = aOldSheets.Length();
RefPtr<CSSStyleSheet> oldSheet; StyleSheetHandle::RefPtr oldSheet;
int32_t i; int32_t i;
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
oldSheet = aOldSheets[i]; oldSheet = aOldSheets[i];
@ -4223,7 +4240,7 @@ nsDocument::UpdateStyleSheets(nsTArray<RefPtr<CSSStyleSheet>>& aOldSheets,
RemoveStyleSheet(oldSheet); // This does the right notifications RemoveStyleSheet(oldSheet); // This does the right notifications
// Now put the new one in its place. If it's null, just ignore it. // Now put the new one in its place. If it's null, just ignore it.
CSSStyleSheet* newSheet = aNewSheets[i]; StyleSheetHandle newSheet = aNewSheets[i];
if (newSheet) { if (newSheet) {
mStyleSheets.InsertElementAt(oldIndex, newSheet); mStyleSheets.InsertElementAt(oldIndex, newSheet);
newSheet->SetOwningDocument(this); newSheet->SetOwningDocument(this);
@ -4239,7 +4256,7 @@ nsDocument::UpdateStyleSheets(nsTArray<RefPtr<CSSStyleSheet>>& aOldSheets,
} }
void void
nsDocument::InsertStyleSheetAt(CSSStyleSheet* aSheet, int32_t aIndex) nsDocument::InsertStyleSheetAt(StyleSheetHandle aSheet, int32_t aIndex)
{ {
NS_PRECONDITION(aSheet, "null ptr"); NS_PRECONDITION(aSheet, "null ptr");
@ -4256,7 +4273,7 @@ nsDocument::InsertStyleSheetAt(CSSStyleSheet* aSheet, int32_t aIndex)
void void
nsDocument::SetStyleSheetApplicableState(CSSStyleSheet* aSheet, nsDocument::SetStyleSheetApplicableState(StyleSheetHandle aSheet,
bool aApplicable) bool aApplicable)
{ {
NS_PRECONDITION(aSheet, "null arg"); NS_PRECONDITION(aSheet, "null arg");
@ -4322,7 +4339,7 @@ ConvertAdditionalSheetType(nsIDocument::additionalSheetType aType)
} }
static int32_t static int32_t
FindSheet(const nsTArray<RefPtr<CSSStyleSheet>>& aSheets, nsIURI* aSheetURI) FindSheet(const nsTArray<StyleSheetHandle::RefPtr>& aSheets, nsIURI* aSheetURI)
{ {
for (int32_t i = aSheets.Length() - 1; i >= 0; i-- ) { for (int32_t i = aSheets.Length() - 1; i >= 0; i-- ) {
bool bEqual; bool bEqual;
@ -4366,9 +4383,8 @@ nsDocument::LoadAdditionalStyleSheet(additionalSheetType aType,
MOZ_CRASH("impossible value for aType"); MOZ_CRASH("impossible value for aType");
} }
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet;
nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, &sheet);
getter_AddRefs(sheet));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
sheet->SetOwningDocument(this); sheet->SetOwningDocument(this);
@ -4378,7 +4394,7 @@ nsDocument::LoadAdditionalStyleSheet(additionalSheetType aType,
} }
nsresult nsresult
nsDocument::AddAdditionalStyleSheet(additionalSheetType aType, CSSStyleSheet* aSheet) nsDocument::AddAdditionalStyleSheet(additionalSheetType aType, StyleSheetHandle aSheet)
{ {
if (mAdditionalSheets[aType].Contains(aSheet)) if (mAdditionalSheets[aType].Contains(aSheet))
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
@ -4407,11 +4423,11 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet
{ {
MOZ_ASSERT(aSheetURI); MOZ_ASSERT(aSheetURI);
nsTArray<RefPtr<CSSStyleSheet>>& sheets = mAdditionalSheets[aType]; nsTArray<StyleSheetHandle::RefPtr>& sheets = mAdditionalSheets[aType];
int32_t i = FindSheet(mAdditionalSheets[aType], aSheetURI); int32_t i = FindSheet(mAdditionalSheets[aType], aSheetURI);
if (i >= 0) { if (i >= 0) {
RefPtr<CSSStyleSheet> sheetRef = sheets[i]; StyleSheetHandle::RefPtr sheetRef = sheets[i];
sheets.RemoveElementAt(i); sheets.RemoveElementAt(i);
BeginUpdate(UPDATE_STYLE); BeginUpdate(UPDATE_STYLE);
@ -4433,10 +4449,10 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet
} }
} }
CSSStyleSheet* StyleSheetHandle
nsDocument::FirstAdditionalAuthorSheet() nsDocument::FirstAdditionalAuthorSheet()
{ {
return mAdditionalSheets[eAuthorSheet].SafeElementAt(0, nullptr); return mAdditionalSheets[eAuthorSheet].SafeElementAt(0, StyleSheetHandle());
} }
nsIGlobalObject* nsIGlobalObject*
@ -5192,7 +5208,7 @@ nsDocument::DocumentStatesChanged(EventStates aStateMask)
} }
void void
nsDocument::StyleRuleChanged(CSSStyleSheet* aSheet, nsDocument::StyleRuleChanged(StyleSheetHandle aSheet,
css::Rule* aStyleRule) css::Rule* aStyleRule)
{ {
NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleChanged, (aSheet)); NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleChanged, (aSheet));
@ -5206,7 +5222,7 @@ nsDocument::StyleRuleChanged(CSSStyleSheet* aSheet,
} }
void void
nsDocument::StyleRuleAdded(CSSStyleSheet* aSheet, nsDocument::StyleRuleAdded(StyleSheetHandle aSheet,
css::Rule* aStyleRule) css::Rule* aStyleRule)
{ {
NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleAdded, (aSheet)); NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleAdded, (aSheet));
@ -5221,7 +5237,7 @@ nsDocument::StyleRuleAdded(CSSStyleSheet* aSheet,
} }
void void
nsDocument::StyleRuleRemoved(CSSStyleSheet* aSheet, nsDocument::StyleRuleRemoved(StyleSheetHandle aSheet,
css::Rule* aStyleRule) css::Rule* aStyleRule)
{ {
NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleRemoved, (aSheet)); NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleRemoved, (aSheet));
@ -6462,17 +6478,23 @@ nsIDocument::GetSelectedStyleSheetSet(nsAString& aSheetSet)
int32_t count = GetNumberOfStyleSheets(); int32_t count = GetNumberOfStyleSheets();
nsAutoString title; nsAutoString title;
for (int32_t index = 0; index < count; index++) { for (int32_t index = 0; index < count; index++) {
CSSStyleSheet* sheet = GetStyleSheetAt(index); StyleSheetHandle sheet = GetStyleSheetAt(index);
NS_ASSERTION(sheet, "Null sheet in sheet list!"); NS_ASSERTION(sheet, "Null sheet in sheet list!");
// XXXheycam Make this work with ServoStyleSheets.
if (sheet->IsServo()) {
NS_ERROR("stylo: can't handle alternate ServoStyleSheets yet");
continue;
}
bool disabled; bool disabled;
sheet->GetDisabled(&disabled); sheet->AsGecko()->GetDisabled(&disabled);
if (disabled) { if (disabled) {
// Disabled sheets don't affect the currently selected set // Disabled sheets don't affect the currently selected set
continue; continue;
} }
sheet->GetTitle(title); sheet->AsGecko()->GetTitle(title);
if (aSheetSet.IsEmpty()) { if (aSheetSet.IsEmpty()) {
aSheetSet = title; aSheetSet = title;
@ -6576,11 +6598,18 @@ nsDocument::EnableStyleSheetsForSetInternal(const nsAString& aSheetSet,
int32_t count = GetNumberOfStyleSheets(); int32_t count = GetNumberOfStyleSheets();
nsAutoString title; nsAutoString title;
for (int32_t index = 0; index < count; index++) { for (int32_t index = 0; index < count; index++) {
CSSStyleSheet* sheet = GetStyleSheetAt(index); StyleSheetHandle sheet = GetStyleSheetAt(index);
NS_ASSERTION(sheet, "Null sheet in sheet list!"); NS_ASSERTION(sheet, "Null sheet in sheet list!");
sheet->GetTitle(title);
// XXXheycam Make this work with ServoStyleSheets.
if (sheet->IsServo()) {
NS_ERROR("stylo: can't handle alternate ServoStyleSheets yet");
continue;
}
sheet->AsGecko()->GetTitle(title);
if (!title.IsEmpty()) { if (!title.IsEmpty()) {
sheet->SetEnabled(title.Equals(aSheetSet)); sheet->AsGecko()->SetEnabled(title.Equals(aSheetSet));
} }
} }
if (aUpdateCSSLoader) { if (aUpdateCSSLoader) {
@ -9854,7 +9883,7 @@ class StubCSSLoaderObserver final : public nsICSSLoaderObserver {
~StubCSSLoaderObserver() {} ~StubCSSLoaderObserver() {}
public: public:
NS_IMETHOD NS_IMETHOD
StyleSheetLoaded(CSSStyleSheet*, bool, nsresult) override StyleSheetLoaded(StyleSheetHandle, bool, nsresult) override
{ {
return NS_OK; return NS_OK;
} }
@ -9883,12 +9912,12 @@ nsDocument::PreloadStyle(nsIURI* uri, const nsAString& charset,
nsresult nsresult
nsDocument::LoadChromeSheetSync(nsIURI* uri, bool isAgentSheet, nsDocument::LoadChromeSheetSync(nsIURI* uri, bool isAgentSheet,
CSSStyleSheet** sheet) mozilla::StyleSheetHandle::RefPtr* aSheet)
{ {
css::SheetParsingMode mode = css::SheetParsingMode mode =
isAgentSheet ? css::eAgentSheetFeatures isAgentSheet ? css::eAgentSheetFeatures
: css::eAuthorSheetFeatures; : css::eAuthorSheetFeatures;
return CSSLoader()->LoadSheetSync(uri, mode, isAgentSheet, sheet); return CSSLoader()->LoadSheetSync(uri, mode, isAgentSheet, aSheet);
} }
class nsDelayedEventDispatcher : public nsRunnable class nsDelayedEventDispatcher : public nsRunnable
@ -10214,28 +10243,38 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer)
int32_t sheetsCount = GetNumberOfStyleSheets(); int32_t sheetsCount = GetNumberOfStyleSheets();
for (int32_t i = 0; i < sheetsCount; ++i) { for (int32_t i = 0; i < sheetsCount; ++i) {
RefPtr<CSSStyleSheet> sheet = GetStyleSheetAt(i); StyleSheetHandle::RefPtr sheet = GetStyleSheetAt(i);
if (sheet) { if (sheet) {
if (sheet->IsApplicable()) { if (sheet->IsApplicable()) {
RefPtr<CSSStyleSheet> clonedSheet = // XXXheycam Need to make ServoStyleSheet cloning work.
sheet->Clone(nullptr, nullptr, clonedDoc, nullptr); if (sheet->IsGecko()) {
NS_WARN_IF_FALSE(clonedSheet, "Cloning a stylesheet didn't work!"); RefPtr<CSSStyleSheet> clonedSheet =
if (clonedSheet) { sheet->AsGecko()->Clone(nullptr, nullptr, clonedDoc, nullptr);
clonedDoc->AddStyleSheet(clonedSheet); NS_WARN_IF_FALSE(clonedSheet, "Cloning a stylesheet didn't work!");
if (clonedSheet) {
clonedDoc->AddStyleSheet(clonedSheet);
}
} else {
NS_ERROR("stylo: ServoStyleSheet doesn't support cloning");
} }
} }
} }
} }
// Iterate backwards to maintain order // Iterate backwards to maintain order
for (CSSStyleSheet* sheet : Reversed(thisAsDoc->mOnDemandBuiltInUASheets)) { for (StyleSheetHandle sheet : Reversed(thisAsDoc->mOnDemandBuiltInUASheets)) {
if (sheet) { if (sheet) {
if (sheet->IsApplicable()) { if (sheet->IsApplicable()) {
RefPtr<CSSStyleSheet> clonedSheet = // XXXheycam Need to make ServoStyleSheet cloning work.
sheet->Clone(nullptr, nullptr, clonedDoc, nullptr); if (sheet->IsGecko()) {
NS_WARN_IF_FALSE(clonedSheet, "Cloning a stylesheet didn't work!"); RefPtr<CSSStyleSheet> clonedSheet =
if (clonedSheet) { sheet->AsGecko()->Clone(nullptr, nullptr, clonedDoc, nullptr);
clonedDoc->AddOnDemandBuiltInUASheet(clonedSheet); NS_WARN_IF_FALSE(clonedSheet, "Cloning a stylesheet didn't work!");
if (clonedSheet) {
clonedDoc->AddOnDemandBuiltInUASheet(clonedSheet);
}
} else {
NS_ERROR("stylo: ServoStyleSheet doesn't support cloning");
} }
} }
} }
@ -12366,7 +12405,7 @@ nsDocument::OnAppThemeChanged()
} }
for (int32_t i = 0; i < GetNumberOfStyleSheets(); i++) { for (int32_t i = 0; i < GetNumberOfStyleSheets(); i++) {
RefPtr<CSSStyleSheet> sheet = GetStyleSheetAt(i); StyleSheetHandle::RefPtr sheet = GetStyleSheetAt(i);
if (!sheet) { if (!sheet) {
continue; continue;
} }
@ -12733,12 +12772,12 @@ nsIDocument::DocAddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
} }
static size_t static size_t
SizeOfOwnedSheetArrayExcludingThis(const nsTArray<RefPtr<CSSStyleSheet>>& aSheets, SizeOfOwnedSheetArrayExcludingThis(const nsTArray<StyleSheetHandle::RefPtr>& aSheets,
MallocSizeOf aMallocSizeOf) MallocSizeOf aMallocSizeOf)
{ {
size_t n = 0; size_t n = 0;
n += aSheets.ShallowSizeOfExcludingThis(aMallocSizeOf); n += aSheets.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (CSSStyleSheet* sheet : aSheets) { for (StyleSheetHandle sheet : aSheets) {
if (!sheet->GetOwningDocument()) { if (!sheet->GetOwningDocument()) {
// Avoid over-reporting shared sheets. // Avoid over-reporting shared sheets.
continue; continue;
@ -13419,3 +13458,15 @@ nsIDocument::ReportHasScrollLinkedEffect()
this, nsContentUtils::eLAYOUT_PROPERTIES, this, nsContentUtils::eLAYOUT_PROPERTIES,
"ScrollLinkedEffectFound2"); "ScrollLinkedEffectFound2");
} }
mozilla::StyleBackendType
nsIDocument::GetStyleBackendType() const
{
if (!mPresShell) {
#ifdef MOZ_STYLO
NS_WARNING("GetStyleBackendType() called on document without a pres shell");
#endif
return StyleBackendType::Gecko;
}
return mPresShell->StyleSet()->BackendType();
}

View File

@ -797,36 +797,36 @@ public:
virtual Element* FindContentForSubDocument(nsIDocument *aDocument) const override; virtual Element* FindContentForSubDocument(nsIDocument *aDocument) const override;
virtual Element* GetRootElementInternal() const override; virtual Element* GetRootElementInternal() const override;
virtual void EnsureOnDemandBuiltInUASheet(mozilla::CSSStyleSheet* aSheet) override; virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheetHandle aSheet) override;
/** /**
* Get the (document) style sheets owned by this document. * Get the (document) style sheets owned by this document.
* These are ordered, highest priority last * These are ordered, highest priority last
*/ */
virtual int32_t GetNumberOfStyleSheets() const override; virtual int32_t GetNumberOfStyleSheets() const override;
virtual mozilla::CSSStyleSheet* GetStyleSheetAt(int32_t aIndex) const override; virtual mozilla::StyleSheetHandle GetStyleSheetAt(int32_t aIndex) const override;
virtual int32_t GetIndexOfStyleSheet(mozilla::CSSStyleSheet* aSheet) const override; virtual int32_t GetIndexOfStyleSheet(mozilla::StyleSheetHandle aSheet) const override;
virtual void AddStyleSheet(mozilla::CSSStyleSheet* aSheet) override; virtual void AddStyleSheet(mozilla::StyleSheetHandle aSheet) override;
virtual void RemoveStyleSheet(mozilla::CSSStyleSheet* aSheet) override; virtual void RemoveStyleSheet(mozilla::StyleSheetHandle aSheet) override;
virtual void UpdateStyleSheets( virtual void UpdateStyleSheets(
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aOldSheets, nsTArray<mozilla::StyleSheetHandle::RefPtr>& aOldSheets,
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aNewSheets) override; nsTArray<mozilla::StyleSheetHandle::RefPtr>& aNewSheets) override;
virtual void AddStyleSheetToStyleSets(mozilla::CSSStyleSheet* aSheet); virtual void AddStyleSheetToStyleSets(mozilla::StyleSheetHandle aSheet);
virtual void RemoveStyleSheetFromStyleSets(mozilla::CSSStyleSheet* aSheet); virtual void RemoveStyleSheetFromStyleSets(mozilla::StyleSheetHandle aSheet);
virtual void InsertStyleSheetAt(mozilla::CSSStyleSheet* aSheet, virtual void InsertStyleSheetAt(mozilla::StyleSheetHandle aSheet,
int32_t aIndex) override; int32_t aIndex) override;
virtual void SetStyleSheetApplicableState(mozilla::CSSStyleSheet* aSheet, virtual void SetStyleSheetApplicableState(mozilla::StyleSheetHandle aSheet,
bool aApplicable) override; bool aApplicable) override;
virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType,
nsIURI* aSheetURI) override; nsIURI* aSheetURI) override;
virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType,
mozilla::CSSStyleSheet* aSheet) override; mozilla::StyleSheetHandle aSheet) override;
virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, virtual void RemoveAdditionalStyleSheet(additionalSheetType aType,
nsIURI* sheetURI) override; nsIURI* sheetURI) override;
virtual mozilla::CSSStyleSheet* FirstAdditionalAuthorSheet() override; virtual mozilla::StyleSheetHandle FirstAdditionalAuthorSheet() override;
virtual nsIChannel* GetChannel() const override { virtual nsIChannel* GetChannel() const override {
return mChannel; return mChannel;
@ -886,11 +886,11 @@ public:
virtual void DocumentStatesChanged( virtual void DocumentStatesChanged(
mozilla::EventStates aStateMask) override; mozilla::EventStates aStateMask) override;
virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet, virtual void StyleRuleChanged(mozilla::StyleSheetHandle aStyleSheet,
mozilla::css::Rule* aStyleRule) override; mozilla::css::Rule* aStyleRule) override;
virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet, virtual void StyleRuleAdded(mozilla::StyleSheetHandle aStyleSheet,
mozilla::css::Rule* aStyleRule) override; mozilla::css::Rule* aStyleRule) override;
virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet, virtual void StyleRuleRemoved(mozilla::StyleSheetHandle aStyleSheet,
mozilla::css::Rule* aStyleRule) override; mozilla::css::Rule* aStyleRule) override;
virtual void FlushPendingNotifications(mozFlushType aType) override; virtual void FlushPendingNotifications(mozFlushType aType) override;
@ -962,7 +962,7 @@ public:
void ReportUseCounters(); void ReportUseCounters();
private: private:
void AddOnDemandBuiltInUASheet(mozilla::CSSStyleSheet* aSheet); void AddOnDemandBuiltInUASheet(mozilla::StyleSheetHandle aSheet);
nsRadioGroupStruct* GetRadioGroupInternal(const nsAString& aName) const; nsRadioGroupStruct* GetRadioGroupInternal(const nsAString& aName) const;
void SendToConsole(nsCOMArray<nsISecurityConsoleMessage>& aMessages); void SendToConsole(nsCOMArray<nsISecurityConsoleMessage>& aMessages);
@ -1144,7 +1144,7 @@ public:
const nsAString& aIntegrity) override; const nsAString& aIntegrity) override;
virtual nsresult LoadChromeSheetSync(nsIURI* uri, bool isAgentSheet, virtual nsresult LoadChromeSheetSync(nsIURI* uri, bool isAgentSheet,
mozilla::CSSStyleSheet** sheet) override; mozilla::StyleSheetHandle::RefPtr* aSheet) override;
virtual nsISupports* GetCurrentContentSink() override; virtual nsISupports* GetCurrentContentSink() override;
@ -1494,7 +1494,7 @@ protected:
void RemoveDocStyleSheetsFromStyleSets(); void RemoveDocStyleSheetsFromStyleSets();
void RemoveStyleSheetsFromStyleSets( void RemoveStyleSheetsFromStyleSets(
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aSheets, nsTArray<mozilla::StyleSheetHandle::RefPtr>& aSheets,
mozilla::SheetType aType); mozilla::SheetType aType);
void ResetStylesheetsToURI(nsIURI* aURI); void ResetStylesheetsToURI(nsIURI* aURI);
void FillStyleSet(mozilla::StyleSetHandle aStyleSet); void FillStyleSet(mozilla::StyleSetHandle aStyleSet);
@ -1548,9 +1548,9 @@ protected:
// EndLoad() has already happened. // EndLoad() has already happened.
nsWeakPtr mWeakSink; nsWeakPtr mWeakSink;
nsTArray<RefPtr<mozilla::CSSStyleSheet>> mStyleSheets; nsTArray<mozilla::StyleSheetHandle::RefPtr> mStyleSheets;
nsTArray<RefPtr<mozilla::CSSStyleSheet>> mOnDemandBuiltInUASheets; nsTArray<mozilla::StyleSheetHandle::RefPtr> mOnDemandBuiltInUASheets;
nsTArray<RefPtr<mozilla::CSSStyleSheet>> mAdditionalSheets[AdditionalSheetTypeCount]; nsTArray<mozilla::StyleSheetHandle::RefPtr> mAdditionalSheets[AdditionalSheetTypeCount];
// Array of observers // Array of observers
nsTObserverArray<nsIDocumentObserver*> mObservers; nsTObserverArray<nsIDocumentObserver*> mObservers;
@ -1709,8 +1709,8 @@ private:
friend class nsUnblockOnloadEvent; friend class nsUnblockOnloadEvent;
// Recomputes the visibility state but doesn't set the new value. // Recomputes the visibility state but doesn't set the new value.
mozilla::dom::VisibilityState GetVisibilityState() const; mozilla::dom::VisibilityState GetVisibilityState() const;
void NotifyStyleSheetAdded(mozilla::CSSStyleSheet* aSheet, bool aDocumentSheet); void NotifyStyleSheetAdded(mozilla::StyleSheetHandle aSheet, bool aDocumentSheet);
void NotifyStyleSheetRemoved(mozilla::CSSStyleSheet* aSheet, bool aDocumentSheet); void NotifyStyleSheetRemoved(mozilla::StyleSheetHandle aSheet, bool aDocumentSheet);
void PostUnblockOnloadEvent(); void PostUnblockOnloadEvent();
void DoUnblockOnload(); void DoUnblockOnload();

View File

@ -34,6 +34,8 @@
#include "prclist.h" #include "prclist.h"
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#include "mozilla/CORSMode.h" #include "mozilla/CORSMode.h"
#include "mozilla/StyleBackendType.h"
#include "mozilla/StyleSheetHandle.h"
#include <bitset> // for member #include <bitset> // for member
class gfxUserFontSet; class gfxUserFontSet;
@ -918,7 +920,7 @@ public:
* TODO We can get rid of the whole concept of delayed loading if we fix * TODO We can get rid of the whole concept of delayed loading if we fix
* bug 77999. * bug 77999.
*/ */
virtual void EnsureOnDemandBuiltInUASheet(mozilla::CSSStyleSheet* aSheet) = 0; virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheetHandle aSheet) = 0;
/** /**
* Get the number of (document) stylesheets * Get the number of (document) stylesheets
@ -934,7 +936,7 @@ public:
* @return the stylesheet at aIndex. Null if aIndex is out of range. * @return the stylesheet at aIndex. Null if aIndex is out of range.
* @throws no exceptions * @throws no exceptions
*/ */
virtual mozilla::CSSStyleSheet* GetStyleSheetAt(int32_t aIndex) const = 0; virtual mozilla::StyleSheetHandle 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)
@ -943,7 +945,7 @@ public:
* adjusted for the "special" sheets. * adjusted for the "special" sheets.
* @throws no exceptions * @throws no exceptions
*/ */
virtual void InsertStyleSheetAt(mozilla::CSSStyleSheet* aSheet, virtual void InsertStyleSheetAt(mozilla::StyleSheetHandle aSheet,
int32_t aIndex) = 0; int32_t aIndex) = 0;
/** /**
@ -952,7 +954,7 @@ public:
* @param aSheet the sheet to get the index of * @param aSheet the sheet to get the index of
* @return aIndex the index of the sheet in the full list * @return aIndex the index of the sheet in the full list
*/ */
virtual int32_t GetIndexOfStyleSheet(mozilla::CSSStyleSheet* aSheet) const = 0; virtual int32_t GetIndexOfStyleSheet(mozilla::StyleSheetHandle aSheet) const = 0;
/** /**
* Replace the stylesheets in aOldSheets with the stylesheets in * Replace the stylesheets in aOldSheets with the stylesheets in
@ -963,24 +965,24 @@ public:
* will simply be removed. * will simply be removed.
*/ */
virtual void UpdateStyleSheets( virtual void UpdateStyleSheets(
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aOldSheets, nsTArray<mozilla::StyleSheetHandle::RefPtr>& aOldSheets,
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aNewSheets) = 0; nsTArray<mozilla::StyleSheetHandle::RefPtr>& aNewSheets) = 0;
/** /**
* Add a stylesheet to the document * Add a stylesheet to the document
*/ */
virtual void AddStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; virtual void AddStyleSheet(mozilla::StyleSheetHandle aSheet) = 0;
/** /**
* Remove a stylesheet from the document * Remove a stylesheet from the document
*/ */
virtual void RemoveStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; virtual void RemoveStyleSheet(mozilla::StyleSheetHandle aSheet) = 0;
/** /**
* Notify the document that the applicable state of the sheet changed * Notify the document that the applicable state of the sheet changed
* and that observers should be notified and style sets updated * and that observers should be notified and style sets updated
*/ */
virtual void SetStyleSheetApplicableState(mozilla::CSSStyleSheet* aSheet, virtual void SetStyleSheetApplicableState(mozilla::StyleSheetHandle aSheet,
bool aApplicable) = 0; bool aApplicable) = 0;
enum additionalSheetType { enum additionalSheetType {
@ -993,10 +995,10 @@ public:
virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType,
nsIURI* aSheetURI) = 0; nsIURI* aSheetURI) = 0;
virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType,
mozilla::CSSStyleSheet* aSheet) = 0; mozilla::StyleSheetHandle aSheet) = 0;
virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, virtual void RemoveAdditionalStyleSheet(additionalSheetType aType,
nsIURI* sheetURI) = 0; nsIURI* sheetURI) = 0;
virtual mozilla::CSSStyleSheet* FirstAdditionalAuthorSheet() = 0; virtual mozilla::StyleSheetHandle FirstAdditionalAuthorSheet() = 0;
/** /**
* Get this document's CSSLoader. This is guaranteed to not return null. * Get this document's CSSLoader. This is guaranteed to not return null.
@ -1005,6 +1007,8 @@ public:
return mCSSLoader; return mCSSLoader;
} }
mozilla::StyleBackendType GetStyleBackendType() const;
/** /**
* Get this document's StyleImageLoader. This is guaranteed to not return null. * Get this document's StyleImageLoader. This is guaranteed to not return null.
*/ */
@ -1292,11 +1296,11 @@ public:
// Observation hooks for style data to propagate notifications // Observation hooks for style data to propagate notifications
// to document observers // to document observers
virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet, virtual void StyleRuleChanged(mozilla::StyleSheetHandle aStyleSheet,
mozilla::css::Rule* aStyleRule) = 0; mozilla::css::Rule* aStyleRule) = 0;
virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet, virtual void StyleRuleAdded(mozilla::StyleSheetHandle aStyleSheet,
mozilla::css::Rule* aStyleRule) = 0; mozilla::css::Rule* aStyleRule) = 0;
virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet, virtual void StyleRuleRemoved(mozilla::StyleSheetHandle aStyleSheet,
mozilla::css::Rule* aStyleRule) = 0; mozilla::css::Rule* aStyleRule) = 0;
/** /**
@ -2091,7 +2095,7 @@ public:
* DO NOT USE FOR UNTRUSTED CONTENT. * DO NOT USE FOR UNTRUSTED CONTENT.
*/ */
virtual nsresult LoadChromeSheetSync(nsIURI* aURI, bool aIsAgentSheet, virtual nsresult LoadChromeSheetSync(nsIURI* aURI, bool aIsAgentSheet,
mozilla::CSSStyleSheet** aSheet) = 0; mozilla::StyleSheetHandle::RefPtr* aSheet) = 0;
/** /**
* Returns true if the locale used for the document specifies a direction of * Returns true if the locale used for the document specifies a direction of

View File

@ -7,6 +7,7 @@
#define nsIDocumentObserver_h___ #define nsIDocumentObserver_h___
#include "mozilla/EventStates.h" #include "mozilla/EventStates.h"
#include "mozilla/StyleSheetHandle.h"
#include "nsISupports.h" #include "nsISupports.h"
#include "nsIMutationObserver.h" #include "nsIMutationObserver.h"
@ -14,7 +15,6 @@ class nsIContent;
class nsIDocument; class nsIDocument;
namespace mozilla { namespace mozilla {
class CSSStyleSheet;
namespace css { namespace css {
class Rule; class Rule;
} // namespace css } // namespace css
@ -100,7 +100,7 @@ public:
* @param aDocumentSheet True if sheet is in document's style sheet list, * @param aDocumentSheet True if sheet is in document's style sheet list,
* false if sheet is not (i.e., UA or user sheet) * false if sheet is not (i.e., UA or user sheet)
*/ */
virtual void StyleSheetAdded(mozilla::CSSStyleSheet* aStyleSheet, virtual void StyleSheetAdded(mozilla::StyleSheetHandle aStyleSheet,
bool aDocumentSheet) = 0; bool aDocumentSheet) = 0;
/** /**
@ -113,7 +113,7 @@ public:
* @param aDocumentSheet True if sheet is in document's style sheet list, * @param aDocumentSheet True if sheet is in document's style sheet list,
* false if sheet is not (i.e., UA or user sheet) * false if sheet is not (i.e., UA or user sheet)
*/ */
virtual void StyleSheetRemoved(mozilla::CSSStyleSheet* aStyleSheet, virtual void StyleSheetRemoved(mozilla::StyleSheetHandle aStyleSheet,
bool aDocumentSheet) = 0; bool aDocumentSheet) = 0;
/** /**
@ -125,7 +125,7 @@ public:
* *
* @param aStyleSheet the StyleSheet that has changed state * @param aStyleSheet the StyleSheet that has changed state
*/ */
virtual void StyleSheetApplicableStateChanged(mozilla::CSSStyleSheet* aStyleSheet) = 0; virtual void StyleSheetApplicableStateChanged(mozilla::StyleSheetHandle aStyleSheet) = 0;
/** /**
* A StyleRule has just been modified within a style sheet. * A StyleRule has just been modified within a style sheet.
@ -136,7 +136,7 @@ public:
* *
* @param aStyleSheet the StyleSheet that contians the rule * @param aStyleSheet the StyleSheet that contians the rule
*/ */
virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet) = 0; virtual void StyleRuleChanged(mozilla::StyleSheetHandle aStyleSheet) = 0;
/** /**
* A StyleRule has just been added to a style sheet. * A StyleRule has just been added to a style sheet.
@ -147,7 +147,7 @@ public:
* *
* @param aStyleSheet the StyleSheet that has been modified * @param aStyleSheet the StyleSheet that has been modified
*/ */
virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet) = 0; virtual void StyleRuleAdded(mozilla::StyleSheetHandle aStyleSheet) = 0;
/** /**
* A StyleRule has just been removed from a style sheet. * A StyleRule has just been removed from a style sheet.
@ -158,7 +158,7 @@ public:
* *
* @param aStyleSheet the StyleSheet that has been modified * @param aStyleSheet the StyleSheet that has been modified
*/ */
virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet) = 0; virtual void StyleRuleRemoved(mozilla::StyleSheetHandle aStyleSheet) = 0;
}; };
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID) NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID)
@ -186,25 +186,25 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID)
mozilla::EventStates aStateMask) override; mozilla::EventStates aStateMask) override;
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \ #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \
virtual void StyleSheetAdded(mozilla::CSSStyleSheet* aStyleSheet, \ virtual void StyleSheetAdded(mozilla::StyleSheetHandle aStyleSheet, \
bool aDocumentSheet) override; bool aDocumentSheet) override;
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \ #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \
virtual void StyleSheetRemoved(mozilla::CSSStyleSheet* aStyleSheet, \ virtual void StyleSheetRemoved(mozilla::StyleSheetHandle aStyleSheet, \
bool aDocumentSheet) override; bool aDocumentSheet) override;
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \ #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \
virtual void StyleSheetApplicableStateChanged( \ virtual void StyleSheetApplicableStateChanged( \
mozilla::CSSStyleSheet* aStyleSheet) override; mozilla::StyleSheetHandle aStyleSheet) override;
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \ #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \
virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet) override; virtual void StyleRuleChanged(mozilla::StyleSheetHandle aStyleSheet) override;
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \ #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \
virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet) override; virtual void StyleRuleAdded(mozilla::StyleSheetHandle aStyleSheet) override;
#define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \ #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \
virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet) override; virtual void StyleRuleRemoved(mozilla::StyleSheetHandle aStyleSheet) override;
#define NS_DECL_NSIDOCUMENTOBSERVER \ #define NS_DECL_NSIDOCUMENTOBSERVER \
NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \ NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \
@ -262,29 +262,29 @@ NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class)
#define NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(_class) \ #define NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(_class) \
void \ void \
_class::StyleSheetAdded(mozilla::CSSStyleSheet* aStyleSheet, \ _class::StyleSheetAdded(mozilla::StyleSheetHandle aStyleSheet, \
bool aDocumentSheet) \ bool aDocumentSheet) \
{ \ { \
} \ } \
void \ void \
_class::StyleSheetRemoved(mozilla::CSSStyleSheet* aStyleSheet, \ _class::StyleSheetRemoved(mozilla::StyleSheetHandle aStyleSheet, \
bool aDocumentSheet) \ bool aDocumentSheet) \
{ \ { \
} \ } \
void \ void \
_class::StyleSheetApplicableStateChanged(mozilla::CSSStyleSheet* aStyleSheet) \ _class::StyleSheetApplicableStateChanged(mozilla::StyleSheetHandle aStyleSheet) \
{ \ { \
} \ } \
void \ void \
_class::StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet) \ _class::StyleRuleChanged(mozilla::StyleSheetHandle aStyleSheet) \
{ \ { \
} \ } \
void \ void \
_class::StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet) \ _class::StyleRuleAdded(mozilla::StyleSheetHandle aStyleSheet) \
{ \ { \
} \ } \
void \ void \
_class::StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet) \ _class::StyleRuleRemoved(mozilla::StyleSheetHandle aStyleSheet) \
{ \ { \
} }

View File

@ -8,6 +8,7 @@
#include "nsISupports.h" #include "nsISupports.h"
#include "mozilla/StyleSheetHandle.h"
class nsICSSLoaderObserver; class nsICSSLoaderObserver;
class nsIURI; class nsIURI;
@ -16,10 +17,6 @@ class nsIURI;
{ 0xa8b79f3b, 0x9d18, 0x4f9c, \ { 0xa8b79f3b, 0x9d18, 0x4f9c, \
{ 0xb1, 0xaa, 0x8c, 0x9b, 0x1b, 0xaa, 0xac, 0xad } } { 0xb1, 0xaa, 0x8c, 0x9b, 0x1b, 0xaa, 0xac, 0xad } }
namespace mozilla {
class CSSStyleSheet;
} // namespace mozilla
class nsIStyleSheetLinkingElement : public nsISupports { class nsIStyleSheetLinkingElement : public nsISupports {
public: public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLESHEETLINKINGELEMENT_IID) NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLESHEETLINKINGELEMENT_IID)
@ -31,14 +28,14 @@ public:
* @param aStyleSheet the style sheet associated with this * @param aStyleSheet the style sheet associated with this
* element. * element.
*/ */
NS_IMETHOD SetStyleSheet(mozilla::CSSStyleSheet* aStyleSheet) = 0; NS_IMETHOD SetStyleSheet(mozilla::StyleSheetHandle aStyleSheet) = 0;
/** /**
* Used to obtain the style sheet linked in by this element. * Used to obtain the style sheet linked in by this element.
* *
* @return the style sheet associated with this element. * @return the style sheet associated with this element.
*/ */
NS_IMETHOD_(mozilla::CSSStyleSheet*) GetStyleSheet() = 0; NS_IMETHOD_(mozilla::StyleSheetHandle) GetStyleSheet() = 0;
/** /**
* Initialize the stylesheet linking element. If aDontLoadStyle is * Initialize the stylesheet linking element. If aDontLoadStyle is

View File

@ -12,7 +12,8 @@
#include "nsStyleLinkElement.h" #include "nsStyleLinkElement.h"
#include "mozilla/CSSStyleSheet.h" #include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#include "mozilla/css/Loader.h" #include "mozilla/css/Loader.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "mozilla/dom/FragmentOrElement.h" #include "mozilla/dom/FragmentOrElement.h"
@ -67,7 +68,7 @@ nsStyleLinkElement::Traverse(nsCycleCollectionTraversalCallback &cb)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStyleLinkElement::SetStyleSheet(CSSStyleSheet* aStyleSheet) nsStyleLinkElement::SetStyleSheet(StyleSheetHandle aStyleSheet)
{ {
if (mStyleSheet) { if (mStyleSheet) {
mStyleSheet->SetOwningNode(nullptr); mStyleSheet->SetOwningNode(nullptr);
@ -84,7 +85,7 @@ nsStyleLinkElement::SetStyleSheet(CSSStyleSheet* aStyleSheet)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP_(CSSStyleSheet*) NS_IMETHODIMP_(StyleSheetHandle)
nsStyleLinkElement::GetStyleSheet() nsStyleLinkElement::GetStyleSheet()
{ {
return mStyleSheet; return mStyleSheet;
@ -316,8 +317,15 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
return NS_OK; return NS_OK;
} }
Element* oldScopeElement = // XXXheycam ServoStyleSheets do not support <style scoped>.
mStyleSheet ? mStyleSheet->GetScopeElement() : nullptr; Element* oldScopeElement = nullptr;
if (mStyleSheet) {
if (mStyleSheet->IsServo()) {
NS_ERROR("stylo: ServoStyleSheets don't support <style scoped>");
} else {
oldScopeElement = mStyleSheet->AsGecko()->GetScopeElement();
}
}
if (mStyleSheet && (aOldDocument || aOldShadowRoot)) { if (mStyleSheet && (aOldDocument || aOldShadowRoot)) {
MOZ_ASSERT(!(aOldDocument && aOldShadowRoot), MOZ_ASSERT(!(aOldDocument && aOldShadowRoot),
@ -465,10 +473,18 @@ nsStyleLinkElement::UpdateStyleSheetScopedness(bool aIsNowScoped)
return; return;
} }
if (mStyleSheet->IsServo()) {
// XXXheycam ServoStyleSheets don't support <style scoped>.
NS_ERROR("stylo: ServoStyleSheets don't support <style scoped>");
return;
}
CSSStyleSheet* sheet = mStyleSheet->AsGecko();
nsCOMPtr<nsIContent> thisContent; nsCOMPtr<nsIContent> thisContent;
CallQueryInterface(this, getter_AddRefs(thisContent)); CallQueryInterface(this, getter_AddRefs(thisContent));
Element* oldScopeElement = mStyleSheet->GetScopeElement(); Element* oldScopeElement = sheet->GetScopeElement();
Element* newScopeElement = aIsNowScoped ? Element* newScopeElement = aIsNowScoped ?
thisContent->GetParentElement() : thisContent->GetParentElement() :
nullptr; nullptr;
@ -483,14 +499,14 @@ nsStyleLinkElement::UpdateStyleSheetScopedness(bool aIsNowScoped)
ShadowRoot* containingShadow = thisContent->GetContainingShadow(); ShadowRoot* containingShadow = thisContent->GetContainingShadow();
containingShadow->RemoveSheet(mStyleSheet); containingShadow->RemoveSheet(mStyleSheet);
mStyleSheet->SetScopeElement(newScopeElement); sheet->SetScopeElement(newScopeElement);
containingShadow->InsertSheet(mStyleSheet, thisContent); containingShadow->InsertSheet(mStyleSheet, thisContent);
} else { } else {
document->BeginUpdate(UPDATE_STYLE); document->BeginUpdate(UPDATE_STYLE);
document->RemoveStyleSheet(mStyleSheet); document->RemoveStyleSheet(mStyleSheet);
mStyleSheet->SetScopeElement(newScopeElement); sheet->SetScopeElement(newScopeElement);
document->AddStyleSheet(mStyleSheet); document->AddStyleSheet(mStyleSheet);
document->EndUpdate(UPDATE_STYLE); document->EndUpdate(UPDATE_STYLE);

View File

@ -24,6 +24,7 @@ class nsIDocument;
class nsIURI; class nsIURI;
namespace mozilla { namespace mozilla {
class CSSStyleSheet;
namespace dom { namespace dom {
class ShadowRoot; class ShadowRoot;
} // namespace dom } // namespace dom
@ -37,11 +38,19 @@ public:
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override = 0; NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override = 0;
mozilla::CSSStyleSheet* GetSheet() const { return mStyleSheet; } mozilla::CSSStyleSheet* GetSheet() const
{
// XXXheycam Return nullptr for ServoStyleSheets until we have a way of
// exposing them to script.
NS_ASSERTION(!mStyleSheet || mStyleSheet->IsGecko(),
"stylo: ServoStyleSheets can't be exposed to script yet");
return mStyleSheet && mStyleSheet->IsGecko() ? mStyleSheet->AsGecko() :
nullptr;
}
// nsIStyleSheetLinkingElement // nsIStyleSheetLinkingElement
NS_IMETHOD SetStyleSheet(mozilla::CSSStyleSheet* aStyleSheet) override; NS_IMETHOD SetStyleSheet(mozilla::StyleSheetHandle aStyleSheet) override;
NS_IMETHOD_(mozilla::CSSStyleSheet*) GetStyleSheet() override; NS_IMETHOD_(mozilla::StyleSheetHandle) GetStyleSheet() override;
NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle) override; NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle) override;
NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver, NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
bool* aWillNotify, bool* aWillNotify,
@ -128,7 +137,7 @@ private:
bool* aIsAlternate, bool* aIsAlternate,
bool aForceUpdate); bool aForceUpdate);
RefPtr<mozilla::CSSStyleSheet> mStyleSheet; mozilla::StyleSheetHandle::RefPtr mStyleSheet;
protected: protected:
bool mDontLoadStyle; bool mDontLoadStyle;
bool mUpdatesEnabled; bool mUpdatesEnabled;

View File

@ -114,6 +114,8 @@
#include "nsIFrame.h" #include "nsIFrame.h"
#include "nsIContent.h" #include "nsIContent.h"
#include "nsLayoutStylesheetCache.h" #include "nsLayoutStylesheetCache.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
@ -2641,12 +2643,14 @@ nsHTMLDocument::TearingDownEditor(nsIEditor *aEditor)
if (!presShell) if (!presShell)
return; return;
nsTArray<RefPtr<CSSStyleSheet>> agentSheets; nsTArray<StyleSheetHandle::RefPtr> agentSheets;
presShell->GetAgentStyleSheets(agentSheets); presShell->GetAgentStyleSheets(agentSheets);
agentSheets.RemoveElement(nsLayoutStylesheetCache::ContentEditableSheet()); auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType());
agentSheets.RemoveElement(cache->ContentEditableSheet());
if (oldState == eDesignMode) if (oldState == eDesignMode)
agentSheets.RemoveElement(nsLayoutStylesheetCache::DesignModeSheet()); agentSheets.RemoveElement(cache->DesignModeSheet());
presShell->SetAgentStyleSheets(agentSheets); presShell->SetAgentStyleSheets(agentSheets);
@ -2780,12 +2784,13 @@ nsHTMLDocument::EditingStateChanged()
// Before making this window editable, we need to modify UA style sheet // Before making this window editable, we need to modify UA style sheet
// because new style may change whether focused element will be focusable // because new style may change whether focused element will be focusable
// or not. // or not.
nsTArray<RefPtr<CSSStyleSheet>> agentSheets; nsTArray<StyleSheetHandle::RefPtr> agentSheets;
rv = presShell->GetAgentStyleSheets(agentSheets); rv = presShell->GetAgentStyleSheets(agentSheets);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
CSSStyleSheet* contentEditableSheet = auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType());
nsLayoutStylesheetCache::ContentEditableSheet();
StyleSheetHandle contentEditableSheet = cache->ContentEditableSheet();
if (!agentSheets.Contains(contentEditableSheet)) { if (!agentSheets.Contains(contentEditableSheet)) {
agentSheets.AppendElement(contentEditableSheet); agentSheets.AppendElement(contentEditableSheet);
@ -2796,8 +2801,7 @@ nsHTMLDocument::EditingStateChanged()
// specific states on the elements. // specific states on the elements.
if (designMode) { if (designMode) {
// designMode is being turned on (overrides contentEditable). // designMode is being turned on (overrides contentEditable).
CSSStyleSheet* designModeSheet = StyleSheetHandle designModeSheet = cache->DesignModeSheet();
nsLayoutStylesheetCache::DesignModeSheet();
if (!agentSheets.Contains(designModeSheet)) { if (!agentSheets.Contains(designModeSheet)) {
agentSheets.AppendElement(designModeSheet); agentSheets.AppendElement(designModeSheet);
} }
@ -2807,7 +2811,7 @@ nsHTMLDocument::EditingStateChanged()
} }
else if (oldState == eDesignMode) { else if (oldState == eDesignMode) {
// designMode is being turned off (contentEditable is still on). // designMode is being turned off (contentEditable is still on).
agentSheets.RemoveElement(nsLayoutStylesheetCache::DesignModeSheet()); agentSheets.RemoveElement(cache->DesignModeSheet());
updateState = true; updateState = true;
} }

View File

@ -2584,7 +2584,10 @@ static void
PreloadSlowThings() PreloadSlowThings()
{ {
// This fetches and creates all the built-in stylesheets. // This fetches and creates all the built-in stylesheets.
nsLayoutStylesheetCache::UserContentSheet(); //
// XXXheycam In the future we might want to preload the Servo-flavoured
// UA sheets too, but for now that will be a waste of time.
nsLayoutStylesheetCache::For(StyleBackendType::Gecko)->UserContentSheet();
TabChild::PreloadSlowThings(); TabChild::PreloadSlowThings();

View File

@ -185,6 +185,8 @@
#include "nsPluginHost.h" #include "nsPluginHost.h"
#include "nsPluginTags.h" #include "nsPluginTags.h"
#include "nsIBlocklistService.h" #include "nsIBlocklistService.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#include "nsIBidiKeyboard.h" #include "nsIBidiKeyboard.h"
@ -2697,19 +2699,19 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority,
// This looks like a lot of work, but in a normal browser session we just // This looks like a lot of work, but in a normal browser session we just
// send two loads. // send two loads.
for (CSSStyleSheet* sheet : *sheetService->AgentStyleSheets()) { for (StyleSheetHandle sheet : *sheetService->AgentStyleSheets()) {
URIParams uri; URIParams uri;
SerializeURI(sheet->GetSheetURI(), uri); SerializeURI(sheet->GetSheetURI(), uri);
Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AGENT_SHEET); Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AGENT_SHEET);
} }
for (CSSStyleSheet* sheet : *sheetService->UserStyleSheets()) { for (StyleSheetHandle sheet : *sheetService->UserStyleSheets()) {
URIParams uri; URIParams uri;
SerializeURI(sheet->GetSheetURI(), uri); SerializeURI(sheet->GetSheetURI(), uri);
Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::USER_SHEET); Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::USER_SHEET);
} }
for (CSSStyleSheet* sheet : *sheetService->AuthorStyleSheets()) { for (StyleSheetHandle sheet : *sheetService->AuthorStyleSheets()) {
URIParams uri; URIParams uri;
SerializeURI(sheet->GetSheetURI(), uri); SerializeURI(sheet->GetSheetURI(), uri);
Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AUTHOR_SHEET); Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AUTHOR_SHEET);

View File

@ -111,9 +111,9 @@ nsMathMLElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
// Enable MathML and setup the style sheet during binding, not element // Enable MathML and setup the style sheet during binding, not element
// construction, because we could move a MathML element from the document // construction, because we could move a MathML element from the document
// that created it to another document. // that created it to another document.
auto cache = nsLayoutStylesheetCache::For(doc->GetStyleBackendType());
doc->SetMathMLEnabled(); doc->SetMathMLEnabled();
doc-> doc->EnsureOnDemandBuiltInUASheet(cache->MathMLSheet());
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::MathMLSheet());
// Rebuild style data for the presshell, because style system // Rebuild style data for the presshell, because style system
// optimizations may have taken place assuming MathML was disabled. // optimizations may have taken place assuming MathML was disabled.

View File

@ -20,6 +20,8 @@
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "nsSVGElement.h" #include "nsSVGElement.h"
#include "mozilla/dom/SVGDocumentBinding.h" #include "mozilla/dom/SVGDocumentBinding.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
using namespace mozilla::css; using namespace mozilla::css;
using namespace mozilla::dom; using namespace mozilla::dom;
@ -155,12 +157,12 @@ SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded()
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), spec); NS_NewURI(getter_AddRefs(uri), spec);
if (uri) { if (uri) {
RefPtr<CSSStyleSheet> cssSheet; StyleSheetHandle::RefPtr sheet;
cssLoader->LoadSheetSync(uri, cssLoader->LoadSheetSync(uri,
mozilla::css::eAgentSheetFeatures, mozilla::css::eAgentSheetFeatures,
true, getter_AddRefs(cssSheet)); true, &sheet);
if (cssSheet) { if (sheet) {
EnsureOnDemandBuiltInUASheet(cssSheet); EnsureOnDemandBuiltInUASheet(sheet);
} }
} }
} }
@ -169,21 +171,23 @@ SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded()
} }
} }
CSSStyleSheet* sheet = nsLayoutStylesheetCache::NumberControlSheet(); auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType());
StyleSheetHandle sheet = cache->NumberControlSheet();
if (sheet) { if (sheet) {
// number-control.css can be behind a pref // number-control.css can be behind a pref
EnsureOnDemandBuiltInUASheet(sheet); EnsureOnDemandBuiltInUASheet(sheet);
} }
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::FormsSheet()); EnsureOnDemandBuiltInUASheet(cache->FormsSheet());
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::CounterStylesSheet()); EnsureOnDemandBuiltInUASheet(cache->CounterStylesSheet());
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::HTMLSheet()); EnsureOnDemandBuiltInUASheet(cache->HTMLSheet());
if (nsLayoutUtils::ShouldUseNoFramesSheet(this)) { if (nsLayoutUtils::ShouldUseNoFramesSheet(this)) {
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::NoFramesSheet()); EnsureOnDemandBuiltInUASheet(cache->NoFramesSheet());
} }
if (nsLayoutUtils::ShouldUseNoScriptSheet(this)) { if (nsLayoutUtils::ShouldUseNoScriptSheet(this)) {
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::NoScriptSheet()); EnsureOnDemandBuiltInUASheet(cache->NoScriptSheet());
} }
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::UASheet()); EnsureOnDemandBuiltInUASheet(cache->UASheet());
EndUpdate(UPDATE_STYLE); EndUpdate(UPDATE_STYLE);
} }

View File

@ -752,7 +752,8 @@ SVGSVGElement::BindToTree(nsIDocument* aDocument,
// Setup the style sheet during binding, not element construction, // Setup the style sheet during binding, not element construction,
// because we could move the root SVG element from the document // because we could move the root SVG element from the document
// that created it to another document. // that created it to another document.
doc->EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::SVGSheet()); auto cache = nsLayoutStylesheetCache::For(doc->GetStyleBackendType());
doc->EnsureOnDemandBuiltInUASheet(cache->SVGSheet());
} }
if (mTimedDocumentRoot && smilController) { if (mTimedDocumentRoot && smilController) {

View File

@ -773,7 +773,7 @@ nsBindingManager::MediumFeaturesChanged(nsPresContext* aPresContext,
} }
void void
nsBindingManager::AppendAllSheets(nsTArray<CSSStyleSheet*>& aArray) nsBindingManager::AppendAllSheets(nsTArray<StyleSheetHandle>& aArray)
{ {
if (!mBoundContentSet) { if (!mBoundContentSet) {
return; return;

View File

@ -17,6 +17,7 @@
#include "nsXBLBinding.h" #include "nsXBLBinding.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "mozilla/StyleSheetHandle.h"
struct ElementDependentRuleProcessorData; struct ElementDependentRuleProcessorData;
class nsIXPConnectWrappedJS; class nsIXPConnectWrappedJS;
@ -31,10 +32,6 @@ typedef nsTArray<RefPtr<nsXBLBinding> > nsBindingList;
class nsIPrincipal; class nsIPrincipal;
class nsITimer; class nsITimer;
namespace mozilla {
class CSSStyleSheet;
} // namespace mozilla
class nsBindingManager final : public nsStubMutationObserver class nsBindingManager final : public nsStubMutationObserver
{ {
~nsBindingManager(); ~nsBindingManager();
@ -129,7 +126,7 @@ public:
nsresult MediumFeaturesChanged(nsPresContext* aPresContext, nsresult MediumFeaturesChanged(nsPresContext* aPresContext,
bool* aRulesChanged); bool* aRulesChanged);
void AppendAllSheets(nsTArray<mozilla::CSSStyleSheet*>& aArray); void AppendAllSheets(nsTArray<mozilla::StyleSheetHandle>& aArray);
void Traverse(nsIContent *aContent, void Traverse(nsIContent *aContent,
nsCycleCollectionTraversalCallback &cb); nsCycleCollectionTraversalCallback &cb);

View File

@ -44,6 +44,8 @@
#include "mozilla/dom/CDATASection.h" #include "mozilla/dom/CDATASection.h"
#include "mozilla/dom/Comment.h" #include "mozilla/dom/Comment.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#ifdef MOZ_XUL #ifdef MOZ_XUL
#include "nsXULElement.h" #include "nsXULElement.h"
@ -1630,14 +1632,14 @@ nsXBLPrototypeBinding::EnsureResources()
} }
void void
nsXBLPrototypeBinding::AppendStyleSheet(CSSStyleSheet* aSheet) nsXBLPrototypeBinding::AppendStyleSheet(StyleSheetHandle aSheet)
{ {
EnsureResources(); EnsureResources();
mResources->AppendStyleSheet(aSheet); mResources->AppendStyleSheet(aSheet);
} }
void void
nsXBLPrototypeBinding::RemoveStyleSheet(CSSStyleSheet* aSheet) nsXBLPrototypeBinding::RemoveStyleSheet(StyleSheetHandle aSheet)
{ {
if (!mResources) { if (!mResources) {
MOZ_ASSERT(false, "Trying to remove a sheet that does not exist."); MOZ_ASSERT(false, "Trying to remove a sheet that does not exist.");
@ -1647,13 +1649,13 @@ nsXBLPrototypeBinding::RemoveStyleSheet(CSSStyleSheet* aSheet)
mResources->RemoveStyleSheet(aSheet); mResources->RemoveStyleSheet(aSheet);
} }
void void
nsXBLPrototypeBinding::InsertStyleSheetAt(size_t aIndex, CSSStyleSheet* aSheet) nsXBLPrototypeBinding::InsertStyleSheetAt(size_t aIndex, StyleSheetHandle aSheet)
{ {
EnsureResources(); EnsureResources();
mResources->InsertStyleSheetAt(aIndex, aSheet); mResources->InsertStyleSheetAt(aIndex, aSheet);
} }
CSSStyleSheet* StyleSheetHandle
nsXBLPrototypeBinding::StyleSheetAt(size_t aIndex) const nsXBLPrototypeBinding::StyleSheetAt(size_t aIndex) const
{ {
MOZ_ASSERT(mResources); MOZ_ASSERT(mResources);
@ -1674,7 +1676,7 @@ nsXBLPrototypeBinding::HasStyleSheets() const
void void
nsXBLPrototypeBinding::AppendStyleSheetsTo( nsXBLPrototypeBinding::AppendStyleSheetsTo(
nsTArray<CSSStyleSheet*>& aResult) const nsTArray<StyleSheetHandle>& aResult) const
{ {
if (mResources) { if (mResources) {
mResources->AppendStyleSheetsTo(aResult); mResources->AppendStyleSheetsTo(aResult);

View File

@ -19,6 +19,7 @@
#include "nsXBLPrototypeHandler.h" #include "nsXBLPrototypeHandler.h"
#include "nsXBLPrototypeResources.h" #include "nsXBLPrototypeResources.h"
#include "mozilla/WeakPtr.h" #include "mozilla/WeakPtr.h"
#include "mozilla/StyleSheetHandle.h"
class nsIAtom; class nsIAtom;
class nsIContent; class nsIContent;
@ -27,10 +28,6 @@ class nsXBLAttributeEntry;
class nsXBLBinding; class nsXBLBinding;
class nsXBLProtoImplField; class nsXBLProtoImplField;
namespace mozilla {
class CSSStyleSheet;
} // namespace mozilla
// *********************************************************************/ // *********************************************************************/
// The XBLPrototypeBinding class // The XBLPrototypeBinding class
@ -122,13 +119,13 @@ public:
void SetInitialAttributes(nsIContent* aBoundElement, nsIContent* aAnonymousContent); void SetInitialAttributes(nsIContent* aBoundElement, nsIContent* aAnonymousContent);
void AppendStyleSheet(mozilla::CSSStyleSheet* aSheet); void AppendStyleSheet(mozilla::StyleSheetHandle aSheet);
void RemoveStyleSheet(mozilla::CSSStyleSheet* aSheet); void RemoveStyleSheet(mozilla::StyleSheetHandle aSheet);
void InsertStyleSheetAt(size_t aIndex, mozilla::CSSStyleSheet* aSheet); void InsertStyleSheetAt(size_t aIndex, mozilla::StyleSheetHandle aSheet);
mozilla::CSSStyleSheet* StyleSheetAt(size_t aIndex) const; mozilla::StyleSheetHandle StyleSheetAt(size_t aIndex) const;
size_t SheetCount() const; size_t SheetCount() const;
bool HasStyleSheets() const; bool HasStyleSheets() const;
void AppendStyleSheetsTo(nsTArray<mozilla::CSSStyleSheet*>& aResult) const; void AppendStyleSheetsTo(nsTArray<mozilla::StyleSheetHandle>& aResult) const;
nsIStyleRuleProcessor* GetRuleProcessor(); nsIStyleRuleProcessor* GetRuleProcessor();

View File

@ -19,6 +19,8 @@
#include "nsStyleSet.h" #include "nsStyleSet.h"
#include "mozilla/dom/URL.h" #include "mozilla/dom/URL.h"
#include "mozilla/DebugOnly.h" #include "mozilla/DebugOnly.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
using namespace mozilla; using namespace mozilla;
using mozilla::dom::IsChromeURI; using mozilla::dom::IsChromeURI;
@ -80,20 +82,20 @@ nsXBLPrototypeResources::FlushSkinSheets()
// encounter. (If they aren't skin sheets, it doesn't matter, since // encounter. (If they aren't skin sheets, it doesn't matter, since
// they'll still be in the chrome cache. // they'll still be in the chrome cache.
nsTArray<RefPtr<CSSStyleSheet>> oldSheets; nsTArray<StyleSheetHandle::RefPtr> oldSheets;
oldSheets.SwapElements(mStyleSheetList); oldSheets.SwapElements(mStyleSheetList);
mozilla::css::Loader* cssLoader = doc->CSSLoader(); mozilla::css::Loader* cssLoader = doc->CSSLoader();
for (size_t i = 0, count = oldSheets.Length(); i < count; ++i) { for (size_t i = 0, count = oldSheets.Length(); i < count; ++i) {
CSSStyleSheet* oldSheet = oldSheets[i]; StyleSheetHandle oldSheet = oldSheets[i];
nsIURI* uri = oldSheet->GetSheetURI(); nsIURI* uri = oldSheet->GetSheetURI();
RefPtr<CSSStyleSheet> newSheet; StyleSheetHandle::RefPtr newSheet;
if (IsChromeURI(uri)) { if (IsChromeURI(uri)) {
if (NS_FAILED(cssLoader->LoadSheetSync(uri, getter_AddRefs(newSheet)))) if (NS_FAILED(cssLoader->LoadSheetSync(uri, &newSheet)))
continue; continue;
} }
else { else {
@ -142,31 +144,39 @@ nsXBLPrototypeResources::ClearLoader()
void void
nsXBLPrototypeResources::GatherRuleProcessor() nsXBLPrototypeResources::GatherRuleProcessor()
{ {
mRuleProcessor = new nsCSSRuleProcessor(mStyleSheetList, nsTArray<RefPtr<CSSStyleSheet>> sheets(mStyleSheetList.Length());
for (StyleSheetHandle sheet : mStyleSheetList) {
MOZ_ASSERT(sheet->IsGecko(),
"GatherRuleProcessor must only be called for "
"nsXBLPrototypeResources objects with Gecko-flavored style "
"backends");
sheets.AppendElement(sheet->AsGecko());
}
mRuleProcessor = new nsCSSRuleProcessor(sheets,
SheetType::Doc, SheetType::Doc,
nullptr, nullptr,
mRuleProcessor); mRuleProcessor);
} }
void void
nsXBLPrototypeResources::AppendStyleSheet(CSSStyleSheet* aSheet) nsXBLPrototypeResources::AppendStyleSheet(StyleSheetHandle aSheet)
{ {
mStyleSheetList.AppendElement(aSheet); mStyleSheetList.AppendElement(aSheet);
} }
void void
nsXBLPrototypeResources::RemoveStyleSheet(CSSStyleSheet* aSheet) nsXBLPrototypeResources::RemoveStyleSheet(StyleSheetHandle aSheet)
{ {
mStyleSheetList.RemoveElement(aSheet); mStyleSheetList.RemoveElement(aSheet);
} }
void void
nsXBLPrototypeResources::InsertStyleSheetAt(size_t aIndex, CSSStyleSheet* aSheet) nsXBLPrototypeResources::InsertStyleSheetAt(size_t aIndex, StyleSheetHandle aSheet)
{ {
mStyleSheetList.InsertElementAt(aIndex, aSheet); mStyleSheetList.InsertElementAt(aIndex, aSheet);
} }
CSSStyleSheet* StyleSheetHandle
nsXBLPrototypeResources::StyleSheetAt(size_t aIndex) const nsXBLPrototypeResources::StyleSheetAt(size_t aIndex) const
{ {
return mStyleSheetList[aIndex]; return mStyleSheetList[aIndex];
@ -186,7 +196,7 @@ nsXBLPrototypeResources::HasStyleSheets() const
void void
nsXBLPrototypeResources::AppendStyleSheetsTo( nsXBLPrototypeResources::AppendStyleSheetsTo(
nsTArray<CSSStyleSheet*>& aResult) const nsTArray<StyleSheetHandle>& aResult) const
{ {
aResult.AppendElements(mStyleSheetList); aResult.AppendElements(mStyleSheetList);
} }

View File

@ -7,6 +7,7 @@
#ifndef nsXBLPrototypeResources_h__ #ifndef nsXBLPrototypeResources_h__
#define nsXBLPrototypeResources_h__ #define nsXBLPrototypeResources_h__
#include "mozilla/StyleSheetHandle.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsICSSLoaderObserver.h" #include "nsICSSLoaderObserver.h"
@ -41,13 +42,13 @@ public:
void ClearLoader(); void ClearLoader();
void AppendStyleSheet(mozilla::CSSStyleSheet* aSheet); void AppendStyleSheet(mozilla::StyleSheetHandle aSheet);
void RemoveStyleSheet(mozilla::CSSStyleSheet* aSheet); void RemoveStyleSheet(mozilla::StyleSheetHandle aSheet);
void InsertStyleSheetAt(size_t aIndex, mozilla::CSSStyleSheet* aSheet); void InsertStyleSheetAt(size_t aIndex, mozilla::StyleSheetHandle aSheet);
mozilla::CSSStyleSheet* StyleSheetAt(size_t aIndex) const; mozilla::StyleSheetHandle StyleSheetAt(size_t aIndex) const;
size_t SheetCount() const; size_t SheetCount() const;
bool HasStyleSheets() const; bool HasStyleSheets() const;
void AppendStyleSheetsTo(nsTArray<mozilla::CSSStyleSheet*>& aResult) const; void AppendStyleSheetsTo(nsTArray<mozilla::StyleSheetHandle>& aResult) const;
/** /**
* Recreates mRuleProcessor to represent the current list of style sheets * Recreates mRuleProcessor to represent the current list of style sheets
@ -63,7 +64,7 @@ private:
RefPtr<nsXBLResourceLoader> mLoader; RefPtr<nsXBLResourceLoader> mLoader;
// A list of loaded stylesheets for this binding. // A list of loaded stylesheets for this binding.
nsTArray<RefPtr<mozilla::CSSStyleSheet>> mStyleSheetList; nsTArray<mozilla::StyleSheetHandle::RefPtr> mStyleSheetList;
// The list of stylesheets converted to a rule processor. // The list of stylesheets converted to a rule processor.
RefPtr<nsCSSRuleProcessor> mRuleProcessor; RefPtr<nsCSSRuleProcessor> mRuleProcessor;

View File

@ -17,7 +17,8 @@
#include "nsIDocumentObserver.h" #include "nsIDocumentObserver.h"
#include "imgILoader.h" #include "imgILoader.h"
#include "imgRequestProxy.h" #include "imgRequestProxy.h"
#include "mozilla/CSSStyleSheet.h" #include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#include "mozilla/css/Loader.h" #include "mozilla/css/Loader.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
@ -139,8 +140,8 @@ nsXBLResourceLoader::LoadResources(bool* aResult)
CheckLoadURIWithPrincipal(docPrincipal, url, CheckLoadURIWithPrincipal(docPrincipal, url,
nsIScriptSecurityManager::ALLOW_CHROME); nsIScriptSecurityManager::ALLOW_CHROME);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet;
rv = cssLoader->LoadSheetSync(url, getter_AddRefs(sheet)); rv = cssLoader->LoadSheetSync(url, &sheet);
NS_ASSERTION(NS_SUCCEEDED(rv), "Load failed!!!"); NS_ASSERTION(NS_SUCCEEDED(rv), "Load failed!!!");
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv))
{ {
@ -168,7 +169,7 @@ nsXBLResourceLoader::LoadResources(bool* aResult)
// nsICSSLoaderObserver // nsICSSLoaderObserver
NS_IMETHODIMP NS_IMETHODIMP
nsXBLResourceLoader::StyleSheetLoaded(CSSStyleSheet* aSheet, nsXBLResourceLoader::StyleSheetLoaded(StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) nsresult aStatus)
{ {

View File

@ -30,7 +30,7 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS(nsXBLResourceLoader) NS_DECL_CYCLE_COLLECTION_CLASS(nsXBLResourceLoader)
// nsICSSLoaderObserver // nsICSSLoaderObserver
NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet, NS_IMETHOD StyleSheetLoaded(mozilla::StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) override; nsresult aStatus) override;

View File

@ -411,7 +411,7 @@ nsXMLContentSink::OnTransformDone(nsresult aResult,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXMLContentSink::StyleSheetLoaded(CSSStyleSheet* aSheet, nsXMLContentSink::StyleSheetLoaded(StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) nsresult aStatus)
{ {

View File

@ -82,7 +82,7 @@ public:
NS_IMETHOD OnTransformDone(nsresult aResult, nsIDocument *aResultDocument) override; NS_IMETHOD OnTransformDone(nsresult aResult, nsIDocument *aResultDocument) override;
// nsICSSLoaderObserver // nsICSSLoaderObserver
NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet, NS_IMETHOD StyleSheetLoaded(mozilla::StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) override; nsresult aStatus) override;
static bool ParsePIData(const nsString &aData, nsString &aHref, static bool ParsePIData(const nsString &aData, nsString &aHref,

View File

@ -976,7 +976,7 @@ txTransformNotifier::ScriptEvaluated(nsresult aResult,
} }
NS_IMETHODIMP NS_IMETHODIMP
txTransformNotifier::StyleSheetLoaded(CSSStyleSheet* aSheet, txTransformNotifier::StyleSheetLoaded(StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) nsresult aStatus)
{ {

View File

@ -35,7 +35,7 @@ public:
NS_DECL_NSISCRIPTLOADEROBSERVER NS_DECL_NSISCRIPTLOADEROBSERVER
// nsICSSLoaderObserver // nsICSSLoaderObserver
NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet, NS_IMETHOD StyleSheetLoaded(mozilla::StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) override; nsresult aStatus) override;

View File

@ -93,6 +93,8 @@
#include "mozilla/dom/URL.h" #include "mozilla/dom/URL.h"
#include "nsIContentPolicy.h" #include "nsIContentPolicy.h"
#include "mozAutoDocUpdate.h" #include "mozAutoDocUpdate.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
@ -3098,7 +3100,7 @@ XULDocument::DoneWalking()
} }
NS_IMETHODIMP NS_IMETHODIMP
XULDocument::StyleSheetLoaded(CSSStyleSheet* aSheet, XULDocument::StyleSheetLoaded(StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) nsresult aStatus)
{ {
@ -3727,11 +3729,11 @@ XULDocument::AddPrototypeSheets()
for (int32_t i = 0; i < sheets.Count(); i++) { for (int32_t i = 0; i < sheets.Count(); i++) {
nsCOMPtr<nsIURI> uri = sheets[i]; nsCOMPtr<nsIURI> uri = sheets[i];
RefPtr<CSSStyleSheet> incompleteSheet; StyleSheetHandle::RefPtr incompleteSheet;
rv = CSSLoader()->LoadSheet(uri, rv = CSSLoader()->LoadSheet(uri,
mCurrentPrototype->DocumentPrincipal(), mCurrentPrototype->DocumentPrincipal(),
EmptyCString(), this, EmptyCString(), this,
getter_AddRefs(incompleteSheet)); &incompleteSheet);
// XXXldb We need to prevent bogus sheets from being held in the // XXXldb We need to prevent bogus sheets from being held in the
// prototype's list, but until then, don't propagate the failure // prototype's list, but until then, don't propagate the failure

View File

@ -12,6 +12,7 @@
#include "nsTArray.h" #include "nsTArray.h"
#include "mozilla/dom/XMLDocument.h" #include "mozilla/dom/XMLDocument.h"
#include "mozilla/StyleSheetHandle.h"
#include "nsForwardReference.h" #include "nsForwardReference.h"
#include "nsIContent.h" #include "nsIContent.h"
#include "nsIDOMXULCommandDispatcher.h" #include "nsIDOMXULCommandDispatcher.h"
@ -161,7 +162,7 @@ public:
NS_DECL_NSIDOMXULDOCUMENT NS_DECL_NSIDOMXULDOCUMENT
// nsICSSLoaderObserver // nsICSSLoaderObserver
NS_IMETHOD StyleSheetLoaded(CSSStyleSheet* aSheet, NS_IMETHOD StyleSheetLoaded(mozilla::StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) override; nsresult aStatus) override;
@ -342,7 +343,7 @@ protected:
* An array of style sheets, that will be added (preserving order) to the * An array of style sheets, that will be added (preserving order) to the
* document after all of them are loaded (in DoneWalking). * document after all of them are loaded (in DoneWalking).
*/ */
nsTArray<RefPtr<CSSStyleSheet>> mOverlaySheets; nsTArray<StyleSheetHandle::RefPtr> mOverlaySheets;
nsCOMPtr<nsIDOMXULCommandDispatcher> mCommandDispatcher; // [OWNER] of the focus tracker nsCOMPtr<nsIDOMXULCommandDispatcher> mCommandDispatcher; // [OWNER] of the focus tracker

View File

@ -859,7 +859,8 @@ nsXULElement::BindToTree(nsIDocument* aDocument,
// can be moved from the document that creates them to another document. // can be moved from the document that creates them to another document.
if (!XULElementsRulesInMinimalXULSheet(NodeInfo()->NameAtom())) { if (!XULElementsRulesInMinimalXULSheet(NodeInfo()->NameAtom())) {
doc->EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::XULSheet()); auto cache = nsLayoutStylesheetCache::For(doc->GetStyleBackendType());
doc->EnsureOnDemandBuiltInUASheet(cache->XULSheet());
// To keep memory usage down it is important that we try and avoid // To keep memory usage down it is important that we try and avoid
// pulling xul.css into non-XUL documents. That should be very rare, and // pulling xul.css into non-XUL documents. That should be very rare, and
// for HTML we currently should only pull it in if the document contains // for HTML we currently should only pull it in if the document contains

View File

@ -4253,7 +4253,7 @@ nsEditor::CreateTxnForIMEText(const nsAString& aStringToInsert)
NS_IMETHODIMP NS_IMETHODIMP
nsEditor::CreateTxnForAddStyleSheet(CSSStyleSheet* aSheet, AddStyleSheetTxn* *aTxn) nsEditor::CreateTxnForAddStyleSheet(StyleSheetHandle aSheet, AddStyleSheetTxn* *aTxn)
{ {
RefPtr<AddStyleSheetTxn> txn = new AddStyleSheetTxn(); RefPtr<AddStyleSheetTxn> txn = new AddStyleSheetTxn();
@ -4269,7 +4269,7 @@ nsEditor::CreateTxnForAddStyleSheet(CSSStyleSheet* aSheet, AddStyleSheetTxn* *aT
NS_IMETHODIMP NS_IMETHODIMP
nsEditor::CreateTxnForRemoveStyleSheet(CSSStyleSheet* aSheet, RemoveStyleSheetTxn* *aTxn) nsEditor::CreateTxnForRemoveStyleSheet(StyleSheetHandle aSheet, RemoveStyleSheetTxn* *aTxn)
{ {
RefPtr<RemoveStyleSheetTxn> txn = new RemoveStyleSheetTxn(); RefPtr<RemoveStyleSheetTxn> txn = new RemoveStyleSheetTxn();

View File

@ -8,6 +8,7 @@
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc. #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc.
#include "mozilla/OwningNonNull.h" // for OwningNonNull #include "mozilla/OwningNonNull.h" // for OwningNonNull
#include "mozilla/StyleSheetHandle.h" // for StyleSheetHandle
#include "mozilla/dom/Text.h" #include "mozilla/dom/Text.h"
#include "nsAutoPtr.h" // for nsRefPtr #include "nsAutoPtr.h" // for nsRefPtr
#include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr #include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
@ -55,7 +56,6 @@ class nsTransactionManager;
struct DOMPoint; struct DOMPoint;
namespace mozilla { namespace mozilla {
class CSSStyleSheet;
class ErrorResult; class ErrorResult;
class TextComposition; class TextComposition;
@ -311,12 +311,12 @@ protected:
/** create a transaction for adding a style sheet /** create a transaction for adding a style sheet
*/ */
NS_IMETHOD CreateTxnForAddStyleSheet(mozilla::CSSStyleSheet* aSheet, NS_IMETHOD CreateTxnForAddStyleSheet(mozilla::StyleSheetHandle aSheet,
AddStyleSheetTxn* *aTxn); AddStyleSheetTxn* *aTxn);
/** create a transaction for removing a style sheet /** create a transaction for removing a style sheet
*/ */
NS_IMETHOD CreateTxnForRemoveStyleSheet(mozilla::CSSStyleSheet* aSheet, NS_IMETHOD CreateTxnForRemoveStyleSheet(mozilla::StyleSheetHandle aSheet,
RemoveStyleSheetTxn* *aTxn); RemoveStyleSheetTxn* *aTxn);
nsresult DeleteText(nsGenericDOMDataNode& aElement, nsresult DeleteText(nsGenericDOMDataNode& aElement,

View File

@ -37,7 +37,6 @@
#include "nsILinkHandler.h" #include "nsILinkHandler.h"
#include "nsIInlineSpellChecker.h" #include "nsIInlineSpellChecker.h"
#include "mozilla/CSSStyleSheet.h"
#include "mozilla/css/Loader.h" #include "mozilla/css/Loader.h"
#include "nsIDOMStyleSheet.h" #include "nsIDOMStyleSheet.h"
@ -75,6 +74,8 @@
#include "mozilla/dom/HTMLBodyElement.h" #include "mozilla/dom/HTMLBodyElement.h"
#include "nsTextFragment.h" #include "nsTextFragment.h"
#include "nsContentList.h" #include "nsContentList.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
@ -2825,13 +2826,11 @@ nsHTMLEditor::ReplaceStyleSheet(const nsAString& aURL)
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLEditor::RemoveStyleSheet(const nsAString &aURL) nsHTMLEditor::RemoveStyleSheet(const nsAString &aURL)
{ {
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet = GetStyleSheetForURL(aURL);
nsresult rv = GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(sheet, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(sheet, NS_ERROR_UNEXPECTED);
RefPtr<RemoveStyleSheetTxn> txn; RefPtr<RemoveStyleSheetTxn> txn;
rv = CreateTxnForRemoveStyleSheet(sheet, getter_AddRefs(txn)); nsresult rv = CreateTxnForRemoveStyleSheet(sheet, getter_AddRefs(txn));
if (!txn) rv = NS_ERROR_NULL_POINTER; if (!txn) rv = NS_ERROR_NULL_POINTER;
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv))
{ {
@ -2865,11 +2864,11 @@ nsHTMLEditor::AddOverrideStyleSheet(const nsAString& aURL)
// We MUST ONLY load synchronous local files (no @import) // We MUST ONLY load synchronous local files (no @import)
// XXXbz Except this will actually try to load remote files // XXXbz Except this will actually try to load remote files
// synchronously, of course.. // synchronously, of course..
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet;
// Editor override style sheets may want to style Gecko anonymous boxes // Editor override style sheets may want to style Gecko anonymous boxes
rv = ps->GetDocument()->CSSLoader()-> rv = ps->GetDocument()->CSSLoader()->
LoadSheetSync(uaURI, mozilla::css::eAgentSheetFeatures, true, LoadSheetSync(uaURI, mozilla::css::eAgentSheetFeatures, true,
getter_AddRefs(sheet)); &sheet);
// Synchronous loads should ALWAYS return completed // Synchronous loads should ALWAYS return completed
NS_ENSURE_TRUE(sheet, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(sheet, NS_ERROR_NULL_POINTER);
@ -2910,8 +2909,7 @@ nsHTMLEditor::ReplaceOverrideStyleSheet(const nsAString& aURL)
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLEditor::RemoveOverrideStyleSheet(const nsAString &aURL) nsHTMLEditor::RemoveOverrideStyleSheet(const nsAString &aURL)
{ {
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet = GetStyleSheetForURL(aURL);
GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
// Make sure we remove the stylesheet from our internal list in all // Make sure we remove the stylesheet from our internal list in all
// cases. // cases.
@ -2933,24 +2931,25 @@ nsHTMLEditor::RemoveOverrideStyleSheet(const nsAString &aURL)
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLEditor::EnableStyleSheet(const nsAString &aURL, bool aEnable) nsHTMLEditor::EnableStyleSheet(const nsAString &aURL, bool aEnable)
{ {
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet = GetStyleSheetForURL(aURL);
nsresult rv = GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(sheet, NS_OK); // Don't fail if sheet not found NS_ENSURE_TRUE(sheet, NS_OK); // Don't fail if sheet not found
// Ensure the style sheet is owned by our document. // Ensure the style sheet is owned by our document.
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak); nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
sheet->SetOwningDocument(doc); sheet->SetOwningDocument(doc);
return sheet->SetDisabled(!aEnable); if (sheet->IsServo()) {
// XXXheycam ServoStyleSheets don't support being enabled/disabled yet.
NS_ERROR("stylo: ServoStyleSheets can't be disabled yet");
return NS_ERROR_FAILURE;
}
return sheet->AsGecko()->SetDisabled(!aEnable);
} }
bool bool
nsHTMLEditor::EnableExistingStyleSheet(const nsAString &aURL) nsHTMLEditor::EnableExistingStyleSheet(const nsAString &aURL)
{ {
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet = GetStyleSheetForURL(aURL);
nsresult rv = GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
NS_ENSURE_SUCCESS(rv, false);
// Enable sheet if already loaded. // Enable sheet if already loaded.
if (sheet) if (sheet)
@ -2959,7 +2958,12 @@ nsHTMLEditor::EnableExistingStyleSheet(const nsAString &aURL)
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak); nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
sheet->SetOwningDocument(doc); sheet->SetOwningDocument(doc);
sheet->SetDisabled(false); if (sheet->IsServo()) {
// XXXheycam ServoStyleSheets don't support being enabled/disabled yet.
NS_ERROR("stylo: ServoStyleSheets can't be disabled yet");
return true;
}
sheet->AsGecko()->SetDisabled(false);
return true; return true;
} }
return false; return false;
@ -2967,7 +2971,7 @@ nsHTMLEditor::EnableExistingStyleSheet(const nsAString &aURL)
nsresult nsresult
nsHTMLEditor::AddNewStyleSheetToList(const nsAString &aURL, nsHTMLEditor::AddNewStyleSheetToList(const nsAString &aURL,
CSSStyleSheet* aStyleSheet) StyleSheetHandle aStyleSheet)
{ {
uint32_t countSS = mStyleSheets.Length(); uint32_t countSS = mStyleSheets.Length();
uint32_t countU = mStyleSheetURLs.Length(); uint32_t countU = mStyleSheetURLs.Length();
@ -2997,41 +3001,33 @@ nsHTMLEditor::RemoveStyleSheetFromList(const nsAString &aURL)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP StyleSheetHandle
nsHTMLEditor::GetStyleSheetForURL(const nsAString &aURL, nsHTMLEditor::GetStyleSheetForURL(const nsAString& aURL)
CSSStyleSheet** aStyleSheet)
{ {
NS_ENSURE_ARG_POINTER(aStyleSheet);
*aStyleSheet = 0;
// is it already in the list? // is it already in the list?
size_t foundIndex; size_t foundIndex;
foundIndex = mStyleSheetURLs.IndexOf(aURL); foundIndex = mStyleSheetURLs.IndexOf(aURL);
if (foundIndex == mStyleSheetURLs.NoIndex) if (foundIndex == mStyleSheetURLs.NoIndex) {
return NS_OK; //No sheet -- don't fail! return nullptr;
}
*aStyleSheet = mStyleSheets[foundIndex]; MOZ_ASSERT(mStyleSheets[foundIndex]);
NS_ENSURE_TRUE(*aStyleSheet, NS_ERROR_FAILURE); return mStyleSheets[foundIndex];
NS_ADDREF(*aStyleSheet);
return NS_OK;
} }
NS_IMETHODIMP void
nsHTMLEditor::GetURLForStyleSheet(CSSStyleSheet* aStyleSheet, nsHTMLEditor::GetURLForStyleSheet(StyleSheetHandle aStyleSheet,
nsAString &aURL) nsAString& aURL)
{ {
// is it already in the list? // is it already in the list?
int32_t foundIndex = mStyleSheets.IndexOf(aStyleSheet); int32_t foundIndex = mStyleSheets.IndexOf(aStyleSheet);
// Don't fail if we don't find it in our list // Don't fail if we don't find it in our list
if (foundIndex == -1) if (foundIndex == -1)
return NS_OK; return;
// Found it in the list! // Found it in the list!
aURL = mStyleSheetURLs[foundIndex]; aURL = mStyleSheetURLs[foundIndex];
return NS_OK;
} }
/* /*
@ -3395,7 +3391,7 @@ nsHTMLEditor::DebugUnitTests(int32_t *outNumTests, int32_t *outNumTestsFailed)
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLEditor::StyleSheetLoaded(CSSStyleSheet* aSheet, bool aWasAlternate, nsHTMLEditor::StyleSheetLoaded(StyleSheetHandle aSheet, bool aWasAlternate,
nsresult aStatus) nsresult aStatus)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;

View File

@ -39,6 +39,7 @@
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "mozilla/StyleSheetHandle.h"
class nsDocumentFragment; class nsDocumentFragment;
class nsIDOMKeyEvent; class nsIDOMKeyEvent;
@ -333,7 +334,7 @@ public:
NS_IMETHOD GetRootElement(nsIDOMElement **aRootElement) override; NS_IMETHOD GetRootElement(nsIDOMElement **aRootElement) override;
/* ------------ nsICSSLoaderObserver -------------- */ /* ------------ nsICSSLoaderObserver -------------- */
NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet, NS_IMETHOD StyleSheetLoaded(mozilla::StyleSheetHandle aSheet,
bool aWasAlternate, nsresult aStatus) override; bool aWasAlternate, nsresult aStatus) override;
/* ------------ Utility Routines, not part of public API -------------- */ /* ------------ Utility Routines, not part of public API -------------- */
@ -378,14 +379,13 @@ public:
bool EnableExistingStyleSheet(const nsAString& aURL); bool EnableExistingStyleSheet(const nsAString& aURL);
// Dealing with the internal style sheet lists: // Dealing with the internal style sheet lists:
NS_IMETHOD GetStyleSheetForURL(const nsAString &aURL, mozilla::StyleSheetHandle GetStyleSheetForURL(const nsAString& aURL);
mozilla::CSSStyleSheet** _retval) override; void GetURLForStyleSheet(mozilla::StyleSheetHandle aStyleSheet,
NS_IMETHOD GetURLForStyleSheet(mozilla::CSSStyleSheet* aStyleSheet, nsAString& aURL);
nsAString& aURL) override;
// Add a url + known style sheet to the internal lists: // Add a url + known style sheet to the internal lists:
nsresult AddNewStyleSheetToList(const nsAString &aURL, nsresult AddNewStyleSheetToList(const nsAString &aURL,
mozilla::CSSStyleSheet* aStyleSheet); mozilla::StyleSheetHandle aStyleSheet);
nsresult RemoveStyleSheetFromList(const nsAString &aURL); nsresult RemoveStyleSheetFromList(const nsAString &aURL);
@ -782,7 +782,7 @@ protected:
// Maintain a list of associated style sheets and their urls. // Maintain a list of associated style sheets and their urls.
nsTArray<nsString> mStyleSheetURLs; nsTArray<nsString> mStyleSheetURLs;
nsTArray<RefPtr<mozilla::CSSStyleSheet>> mStyleSheets; nsTArray<mozilla::StyleSheetHandle::RefPtr> mStyleSheets;
// an array for holding default style settings // an array for holding default style settings
nsTArray<PropItem*> mDefaultStyles; nsTArray<PropItem*> mDefaultStyles;

View File

@ -9,7 +9,8 @@
#include "nsAString.h" #include "nsAString.h"
#include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc #include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc
#include "mozilla/CSSStyleSheet.h" // for mozilla::CSSStyleSheet #include "mozilla/StyleSheetHandle.h" // for mozilla::StyleSheetHandle
#include "mozilla/StyleSheetHandleInlines.h"
#include "nsDebug.h" // for NS_ENSURE_TRUE #include "nsDebug.h" // for NS_ENSURE_TRUE
#include "nsError.h" // for NS_OK, etc #include "nsError.h" // for NS_OK, etc
#include "nsIDOMDocument.h" // for nsIDOMDocument #include "nsIDOMDocument.h" // for nsIDOMDocument
@ -20,7 +21,7 @@
using namespace mozilla; using namespace mozilla;
static void static void
AddStyleSheet(nsIEditor* aEditor, CSSStyleSheet* aSheet) AddStyleSheet(nsIEditor* aEditor, StyleSheetHandle aSheet)
{ {
nsCOMPtr<nsIDOMDocument> domDoc; nsCOMPtr<nsIDOMDocument> domDoc;
aEditor->GetDocument(getter_AddRefs(domDoc)); aEditor->GetDocument(getter_AddRefs(domDoc));
@ -33,7 +34,7 @@ AddStyleSheet(nsIEditor* aEditor, CSSStyleSheet* aSheet)
} }
static void static void
RemoveStyleSheet(nsIEditor* aEditor, CSSStyleSheet* aSheet) RemoveStyleSheet(nsIEditor* aEditor, StyleSheetHandle aSheet)
{ {
nsCOMPtr<nsIDOMDocument> domDoc; nsCOMPtr<nsIDOMDocument> domDoc;
aEditor->GetDocument(getter_AddRefs(domDoc)); aEditor->GetDocument(getter_AddRefs(domDoc));
@ -58,7 +59,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AddStyleSheetTxn)
NS_INTERFACE_MAP_END_INHERITING(EditTxn) NS_INTERFACE_MAP_END_INHERITING(EditTxn)
NS_IMETHODIMP NS_IMETHODIMP
AddStyleSheetTxn::Init(nsIEditor *aEditor, CSSStyleSheet *aSheet) AddStyleSheetTxn::Init(nsIEditor* aEditor, StyleSheetHandle aSheet)
{ {
NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG); NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
@ -108,7 +109,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoveStyleSheetTxn)
NS_INTERFACE_MAP_END_INHERITING(EditTxn) NS_INTERFACE_MAP_END_INHERITING(EditTxn)
NS_IMETHODIMP NS_IMETHODIMP
RemoveStyleSheetTxn::Init(nsIEditor *aEditor, CSSStyleSheet *aSheet) RemoveStyleSheetTxn::Init(nsIEditor* aEditor, StyleSheetHandle aSheet)
{ {
NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG); NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);

View File

@ -8,10 +8,9 @@
#include "EditTxn.h" // for EditTxn, NS_DECL_EDITTXN #include "EditTxn.h" // for EditTxn, NS_DECL_EDITTXN
#include "nsAutoPtr.h" // for nsRefPtr #include "nsAutoPtr.h" // for nsRefPtr
#include "mozilla/CSSStyleSheet.h" // for mozilla::CSSStyleSheet #include "mozilla/StyleSheetHandle.h" // for mozilla::StyleSheetHandle
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
#include "nsID.h" // for REFNSIID #include "nsID.h" // for REFNSIID
#include "nsISupportsImpl.h" // for CSSStyleSheet::Release
#include "nscore.h" // for NS_IMETHOD #include "nscore.h" // for NS_IMETHOD
class nsIEditor; class nsIEditor;
@ -23,8 +22,7 @@ public:
* @param aEditor the object providing core editing operations * @param aEditor the object providing core editing operations
* @param aSheet the stylesheet to add * @param aSheet the stylesheet to add
*/ */
NS_IMETHOD Init(nsIEditor* aEditor, NS_IMETHOD Init(nsIEditor* aEditor, mozilla::StyleSheetHandle aSheet);
mozilla::CSSStyleSheet* aSheet);
AddStyleSheetTxn(); AddStyleSheetTxn();
@ -36,7 +34,7 @@ public:
protected: protected:
nsIEditor* mEditor; // the editor that created this transaction nsIEditor* mEditor; // the editor that created this transaction
RefPtr<mozilla::CSSStyleSheet> mSheet; // the style sheet to add mozilla::StyleSheetHandle::RefPtr mSheet; // the style sheet to add
}; };
@ -48,8 +46,7 @@ public:
* @param aEditor the object providing core editing operations * @param aEditor the object providing core editing operations
* @param aSheet the stylesheet to remove * @param aSheet the stylesheet to remove
*/ */
NS_IMETHOD Init(nsIEditor* aEditor, NS_IMETHOD Init(nsIEditor* aEditor, mozilla::StyleSheetHandle aSheet);
mozilla::CSSStyleSheet* aSheet);
RemoveStyleSheetTxn(); RemoveStyleSheetTxn();
@ -61,7 +58,7 @@ public:
protected: protected:
nsIEditor* mEditor; // the editor that created this transaction nsIEditor* mEditor; // the editor that created this transaction
RefPtr<mozilla::CSSStyleSheet> mSheet; // the style sheet to remove mozilla::StyleSheetHandle::RefPtr mSheet; // the style sheet to remove
}; };

View File

@ -5,14 +5,6 @@
#include "nsISupports.idl" #include "nsISupports.idl"
%{C++
namespace mozilla {
class CSSStyleSheet;
} // namespace mozilla
%}
[ptr] native CSSStyleSheet(mozilla::CSSStyleSheet);
[scriptable, uuid(4805e682-49b9-11d3-9ce4-ed60bd6cb5bc)] [scriptable, uuid(4805e682-49b9-11d3-9ce4-ed60bd6cb5bc)]
interface nsIEditorStyleSheets : nsISupports interface nsIEditorStyleSheets : nsISupports
@ -76,18 +68,4 @@ interface nsIEditorStyleSheets : nsISupports
* @param aEnable true to enable, or false to disable the style sheet * @param aEnable true to enable, or false to disable the style sheet
*/ */
void enableStyleSheet(in AString aURL, in boolean aEnable); void enableStyleSheet(in AString aURL, in boolean aEnable);
/** Get the CSSStyleSheet associated with the given URL.
*
* @param aURL The style sheet's URL
* @return the style sheet
*/
[noscript] CSSStyleSheet getStyleSheetForURL(in AString aURL);
/** Get the URL associated with the given CSSStyleSheet.
*
* @param aStyleSheet The style sheet
* @return the style sheet's URL
*/
[noscript] AString getURLForStyleSheet(in CSSStyleSheet aStyleSheet);
}; };

View File

@ -40,6 +40,8 @@
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/dom/EncodingUtils.h" #include "mozilla/dom/EncodingUtils.h"
#include "mozilla/WeakPtr.h" #include "mozilla/WeakPtr.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#include "nsViewManager.h" #include "nsViewManager.h"
#include "nsView.h" #include "nsView.h"
@ -2170,13 +2172,14 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
return NS_OK; return NS_OK;
} }
auto cache = nsLayoutStylesheetCache::For(styleSet->BackendType());
// Handle the user sheets. // Handle the user sheets.
CSSStyleSheet* sheet = nullptr; StyleSheetHandle sheet = nullptr;
if (nsContentUtils::IsInChromeDocshell(aDocument)) { if (nsContentUtils::IsInChromeDocshell(aDocument)) {
sheet = nsLayoutStylesheetCache::UserChromeSheet(); sheet = cache->UserChromeSheet();
} } else {
else { sheet = cache->UserContentSheet();
sheet = nsLayoutStylesheetCache::UserContentSheet();
} }
if (sheet) if (sheet)
@ -2189,7 +2192,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
nsCOMPtr<nsIDocShell> ds(mContainer); nsCOMPtr<nsIDocShell> ds(mContainer);
nsCOMPtr<nsIDOMEventTarget> chromeHandler; nsCOMPtr<nsIDOMEventTarget> chromeHandler;
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
RefPtr<CSSStyleSheet> csssheet; StyleSheetHandle::RefPtr chromeSheet;
if (ds) { if (ds) {
ds->GetChromeEventHandler(getter_AddRefs(chromeHandler)); ds->GetChromeEventHandler(getter_AddRefs(chromeHandler));
@ -2213,10 +2216,10 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
baseURI); baseURI);
if (!uri) continue; if (!uri) continue;
cssLoader->LoadSheetSync(uri, getter_AddRefs(csssheet)); cssLoader->LoadSheetSync(uri, &chromeSheet);
if (!csssheet) continue; if (!chromeSheet) continue;
styleSet->PrependStyleSheet(SheetType::Agent, csssheet); styleSet->PrependStyleSheet(SheetType::Agent, chromeSheet);
shouldOverride = true; shouldOverride = true;
} }
free(str); free(str);
@ -2225,7 +2228,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
} }
if (!shouldOverride) { if (!shouldOverride) {
sheet = nsLayoutStylesheetCache::ScrollbarsSheet(); sheet = cache->ScrollbarsSheet();
if (sheet) { if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet); styleSet->PrependStyleSheet(SheetType::Agent, sheet);
} }
@ -2241,12 +2244,12 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
// an SVG document, and excluding xul.css which will be loaded on demand by // an SVG document, and excluding xul.css which will be loaded on demand by
// nsXULElement::BindToTree.) // nsXULElement::BindToTree.)
sheet = nsLayoutStylesheetCache::NumberControlSheet(); sheet = cache->NumberControlSheet();
if (sheet) { if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet); styleSet->PrependStyleSheet(SheetType::Agent, sheet);
} }
sheet = nsLayoutStylesheetCache::FormsSheet(); sheet = cache->FormsSheet();
if (sheet) { if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet); styleSet->PrependStyleSheet(SheetType::Agent, sheet);
} }
@ -2254,33 +2257,33 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
if (aDocument->LoadsFullXULStyleSheetUpFront()) { if (aDocument->LoadsFullXULStyleSheetUpFront()) {
// nsXULElement::BindToTree loads xul.css on-demand if we don't load it // nsXULElement::BindToTree loads xul.css on-demand if we don't load it
// up-front here. // up-front here.
sheet = nsLayoutStylesheetCache::XULSheet(); sheet = cache->XULSheet();
if (sheet) { if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet); styleSet->PrependStyleSheet(SheetType::Agent, sheet);
} }
} }
sheet = nsLayoutStylesheetCache::MinimalXULSheet(); sheet = cache->MinimalXULSheet();
if (sheet) { if (sheet) {
// Load the minimal XUL rules for scrollbars and a few other XUL things // Load the minimal XUL rules for scrollbars and a few other XUL things
// that non-XUL (typically HTML) documents commonly use. // that non-XUL (typically HTML) documents commonly use.
styleSet->PrependStyleSheet(SheetType::Agent, sheet); styleSet->PrependStyleSheet(SheetType::Agent, sheet);
} }
sheet = nsLayoutStylesheetCache::CounterStylesSheet(); sheet = cache->CounterStylesSheet();
if (sheet) { if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet); styleSet->PrependStyleSheet(SheetType::Agent, sheet);
} }
if (nsLayoutUtils::ShouldUseNoScriptSheet(aDocument)) { if (nsLayoutUtils::ShouldUseNoScriptSheet(aDocument)) {
sheet = nsLayoutStylesheetCache::NoScriptSheet(); sheet = cache->NoScriptSheet();
if (sheet) { if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet); styleSet->PrependStyleSheet(SheetType::Agent, sheet);
} }
} }
if (nsLayoutUtils::ShouldUseNoFramesSheet(aDocument)) { if (nsLayoutUtils::ShouldUseNoFramesSheet(aDocument)) {
sheet = nsLayoutStylesheetCache::NoFramesSheet(); sheet = cache->NoFramesSheet();
if (sheet) { if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet); styleSet->PrependStyleSheet(SheetType::Agent, sheet);
} }
@ -2289,16 +2292,16 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
// We don't add quirk.css here; nsPresContext::CompatibilityModeChanged will // We don't add quirk.css here; nsPresContext::CompatibilityModeChanged will
// append it if needed. // append it if needed.
sheet = nsLayoutStylesheetCache::HTMLSheet(); sheet = cache->HTMLSheet();
if (sheet) { if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet); styleSet->PrependStyleSheet(SheetType::Agent, sheet);
} }
styleSet->PrependStyleSheet(SheetType::Agent, styleSet->PrependStyleSheet(SheetType::Agent,
nsLayoutStylesheetCache::UASheet()); cache->UASheet());
} else { } else {
// SVG documents may have scrollbars and need the scrollbar styling. // SVG documents may have scrollbars and need the scrollbar styling.
sheet = nsLayoutStylesheetCache::MinimalXULSheet(); sheet = cache->MinimalXULSheet();
if (sheet) { if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet); styleSet->PrependStyleSheet(SheetType::Agent, sheet);
} }
@ -2306,10 +2309,10 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance(); nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance();
if (sheetService) { if (sheetService) {
for (CSSStyleSheet* sheet : *sheetService->AgentStyleSheets()) { for (StyleSheetHandle sheet : *sheetService->AgentStyleSheets()) {
styleSet->AppendStyleSheet(SheetType::Agent, sheet); styleSet->AppendStyleSheet(SheetType::Agent, sheet);
} }
for (CSSStyleSheet* sheet : Reversed(*sheetService->UserStyleSheets())) { for (StyleSheetHandle sheet : Reversed(*sheetService->UserStyleSheets())) {
styleSet->PrependStyleSheet(SheetType::User, sheet); styleSet->PrependStyleSheet(SheetType::User, sheet);
} }
} }

View File

@ -25,6 +25,7 @@
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "mozilla/StaticPtr.h" #include "mozilla/StaticPtr.h"
#include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandle.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/WeakPtr.h" #include "mozilla/WeakPtr.h"
#include "gfxPoint.h" #include "gfxPoint.h"
#include "nsTHashtable.h" #include "nsTHashtable.h"
@ -945,23 +946,23 @@ public:
* Get the set of agent style sheets for this presentation * Get the set of agent style sheets for this presentation
*/ */
virtual nsresult GetAgentStyleSheets( virtual nsresult GetAgentStyleSheets(
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aSheets) = 0; nsTArray<mozilla::StyleSheetHandle::RefPtr>& aSheets) = 0;
/** /**
* Replace the set of agent style sheets * Replace the set of agent style sheets
*/ */
virtual nsresult SetAgentStyleSheets( virtual nsresult SetAgentStyleSheets(
const nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aSheets) = 0; const nsTArray<mozilla::StyleSheetHandle::RefPtr>& aSheets) = 0;
/** /**
* Add an override style sheet for this presentation * Add an override style sheet for this presentation
*/ */
virtual nsresult AddOverrideStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; virtual nsresult AddOverrideStyleSheet(mozilla::StyleSheetHandle aSheet) = 0;
/** /**
* Remove an override style sheet * Remove an override style sheet
*/ */
virtual nsresult RemoveOverrideStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; virtual nsresult RemoveOverrideStyleSheet(mozilla::StyleSheetHandle aSheet) = 0;
/** /**
* Reconstruct frames for all elements in the document * Reconstruct frames for all elements in the document

View File

@ -73,6 +73,8 @@
#include "gfxTextRun.h" #include "gfxTextRun.h"
#include "nsFontFaceUtils.h" #include "nsFontFaceUtils.h"
#include "nsLayoutStylesheetCache.h" #include "nsLayoutStylesheetCache.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#if defined(MOZ_WIDGET_GTK) #if defined(MOZ_WIDGET_GTK)
#include "gfxPlatformGtk.h" // xxx - for UseFcFontList #include "gfxPlatformGtk.h" // xxx - for UseFcFontList
@ -1357,7 +1359,8 @@ nsPresContext::CompatibilityModeChanged()
} }
StyleSetHandle styleSet = mShell->StyleSet(); StyleSetHandle styleSet = mShell->StyleSet();
CSSStyleSheet* sheet = nsLayoutStylesheetCache::QuirkSheet(); auto cache = nsLayoutStylesheetCache::For(styleSet->BackendType());
StyleSheetHandle sheet = cache->QuirkSheet();
if (needsQuirkSheet) { if (needsQuirkSheet) {
// quirk.css needs to come after html.css; we just keep it at the end. // quirk.css needs to come after html.css; we just keep it at the end.

View File

@ -186,6 +186,8 @@
#include "mozilla/layers/ScrollInputMethods.h" #include "mozilla/layers/ScrollInputMethods.h"
#include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandle.h"
#include "mozilla/StyleSetHandleInlines.h" #include "mozilla/StyleSetHandleInlines.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#ifdef ANDROID #ifdef ANDROID
#include "nsIDocShellTreeOwner.h" #include "nsIDocShellTreeOwner.h"
@ -1364,10 +1366,11 @@ PresShell::UpdatePreferenceStyles()
// matter which pres context we pass in when it does need to be recreated. // matter which pres context we pass in when it does need to be recreated.
// (See nsPresContext::GetDocumentColorPreferences for how whether we // (See nsPresContext::GetDocumentColorPreferences for how whether we
// are a chrome origin image affects some pref styling information.) // are a chrome origin image affects some pref styling information.)
RefPtr<CSSStyleSheet> newPrefSheet = auto cache = nsLayoutStylesheetCache::For(mStyleSet->BackendType());
StyleSheetHandle::RefPtr newPrefSheet =
mPresContext->IsChromeOriginImage() ? mPresContext->IsChromeOriginImage() ?
nsLayoutStylesheetCache::ChromePreferenceSheet(mPresContext) : cache->ChromePreferenceSheet(mPresContext) :
nsLayoutStylesheetCache::ContentPreferenceSheet(mPresContext); cache->ContentPreferenceSheet(mPresContext);
if (mPrefStyleSheet == newPrefSheet) { if (mPrefStyleSheet == newPrefSheet) {
return; return;
@ -1406,16 +1409,16 @@ PresShell::AddUserSheet(nsISupports* aSheet)
mStyleSet->BeginUpdate(); mStyleSet->BeginUpdate();
nsStyleSheetService* sheetService = nsStyleSheetService::gInstance; nsStyleSheetService* sheetService = nsStyleSheetService::gInstance;
nsTArray<RefPtr<CSSStyleSheet>>& userSheets = *sheetService->UserStyleSheets(); nsTArray<StyleSheetHandle::RefPtr>& userSheets = *sheetService->UserStyleSheets();
// Iterate forwards when removing so the searches for RemoveStyleSheet are as // Iterate forwards when removing so the searches for RemoveStyleSheet are as
// short as possible. // short as possible.
for (CSSStyleSheet* sheet : userSheets) { for (StyleSheetHandle sheet : userSheets) {
mStyleSet->RemoveStyleSheet(SheetType::User, sheet); mStyleSet->RemoveStyleSheet(SheetType::User, sheet);
} }
// Now iterate backwards, so that the order of userSheets will be the same as // Now iterate backwards, so that the order of userSheets will be the same as
// the order of sheets from it in the style set. // the order of sheets from it in the style set.
for (CSSStyleSheet* sheet : Reversed(userSheets)) { for (StyleSheetHandle sheet : Reversed(userSheets)) {
mStyleSet->PrependStyleSheet(SheetType::User, sheet); mStyleSet->PrependStyleSheet(SheetType::User, sheet);
} }
@ -1429,8 +1432,10 @@ PresShell::AddAgentSheet(nsISupports* aSheet)
{ {
// Make sure this does what nsDocumentViewer::CreateStyleSet does // Make sure this does what nsDocumentViewer::CreateStyleSet does
// wrt ordering. // wrt ordering.
// XXXheycam This needs to work with ServoStyleSheets too.
RefPtr<CSSStyleSheet> sheet = do_QueryObject(aSheet); RefPtr<CSSStyleSheet> sheet = do_QueryObject(aSheet);
if (!sheet) { if (!sheet) {
NS_ERROR("stylo: AddAgentSheet needs to support ServoStyleSheets");
return; return;
} }
@ -1441,14 +1446,16 @@ PresShell::AddAgentSheet(nsISupports* aSheet)
void void
PresShell::AddAuthorSheet(nsISupports* aSheet) PresShell::AddAuthorSheet(nsISupports* aSheet)
{ {
// XXXheycam This needs to work with ServoStyleSheets too.
RefPtr<CSSStyleSheet> sheet = do_QueryObject(aSheet); RefPtr<CSSStyleSheet> sheet = do_QueryObject(aSheet);
if (!sheet) { if (!sheet) {
NS_ERROR("stylo: AddAuthorSheet needs to support ServoStyleSheets");
return; return;
} }
// Document specific "additional" Author sheets should be stronger than the ones // Document specific "additional" Author sheets should be stronger than the ones
// added with the StyleSheetService. // added with the StyleSheetService.
CSSStyleSheet* firstAuthorSheet = mDocument->FirstAdditionalAuthorSheet(); StyleSheetHandle firstAuthorSheet = mDocument->FirstAdditionalAuthorSheet();
if (firstAuthorSheet) { if (firstAuthorSheet) {
mStyleSet->InsertStyleSheetBefore(SheetType::Doc, sheet, firstAuthorSheet); mStyleSet->InsertStyleSheetBefore(SheetType::Doc, sheet, firstAuthorSheet);
} else { } else {
@ -1463,6 +1470,7 @@ PresShell::RemoveSheet(SheetType aType, nsISupports* aSheet)
{ {
RefPtr<CSSStyleSheet> sheet = do_QueryObject(aSheet); RefPtr<CSSStyleSheet> sheet = do_QueryObject(aSheet);
if (!sheet) { if (!sheet) {
NS_ERROR("stylo: RemoveSheet needs to support ServoStyleSheets");
return; return;
} }
@ -4424,7 +4432,7 @@ nsIPresShell::ReconstructStyleDataExternal()
} }
void void
PresShell::RecordStyleSheetChange(CSSStyleSheet* aStyleSheet) PresShell::RecordStyleSheetChange(StyleSheetHandle aStyleSheet)
{ {
// too bad we can't check that the update is UPDATE_STYLE // too bad we can't check that the update is UPDATE_STYLE
NS_ASSERTION(mUpdateCount != 0, "must be in an update"); NS_ASSERTION(mUpdateCount != 0, "must be in an update");
@ -4432,20 +4440,22 @@ PresShell::RecordStyleSheetChange(CSSStyleSheet* aStyleSheet)
if (mStylesHaveChanged) if (mStylesHaveChanged)
return; return;
RefPtr<CSSStyleSheet> cssStyleSheet = do_QueryObject(aStyleSheet); if (aStyleSheet->IsGecko()) {
if (cssStyleSheet) { // XXXheycam ServoStyleSheets don't support <style scoped> yet.
Element* scopeElement = cssStyleSheet->GetScopeElement(); Element* scopeElement = aStyleSheet->AsGecko()->GetScopeElement();
if (scopeElement) { if (scopeElement) {
mChangedScopeStyleRoots.AppendElement(scopeElement); mChangedScopeStyleRoots.AppendElement(scopeElement);
return; return;
} }
} else {
NS_ERROR("stylo: ServoStyleSheets don't support <style scoped>");
} }
mStylesHaveChanged = true; mStylesHaveChanged = true;
} }
void void
PresShell::StyleSheetAdded(CSSStyleSheet* aStyleSheet, PresShell::StyleSheetAdded(StyleSheetHandle aStyleSheet,
bool aDocumentSheet) bool aDocumentSheet)
{ {
// We only care when enabled sheets are added // We only care when enabled sheets are added
@ -4457,7 +4467,7 @@ PresShell::StyleSheetAdded(CSSStyleSheet* aStyleSheet,
} }
void void
PresShell::StyleSheetRemoved(CSSStyleSheet* aStyleSheet, PresShell::StyleSheetRemoved(StyleSheetHandle aStyleSheet,
bool aDocumentSheet) bool aDocumentSheet)
{ {
// We only care when enabled sheets are removed // We only care when enabled sheets are removed
@ -4469,7 +4479,7 @@ PresShell::StyleSheetRemoved(CSSStyleSheet* aStyleSheet,
} }
void void
PresShell::StyleSheetApplicableStateChanged(CSSStyleSheet* aStyleSheet) PresShell::StyleSheetApplicableStateChanged(StyleSheetHandle aStyleSheet)
{ {
if (aStyleSheet->HasRules()) { if (aStyleSheet->HasRules()) {
RecordStyleSheetChange(aStyleSheet); RecordStyleSheetChange(aStyleSheet);
@ -4477,19 +4487,19 @@ PresShell::StyleSheetApplicableStateChanged(CSSStyleSheet* aStyleSheet)
} }
void void
PresShell::StyleRuleChanged(CSSStyleSheet* aStyleSheet) PresShell::StyleRuleChanged(StyleSheetHandle aStyleSheet)
{ {
RecordStyleSheetChange(aStyleSheet); RecordStyleSheetChange(aStyleSheet);
} }
void void
PresShell::StyleRuleAdded(CSSStyleSheet* aStyleSheet) PresShell::StyleRuleAdded(StyleSheetHandle aStyleSheet)
{ {
RecordStyleSheetChange(aStyleSheet); RecordStyleSheetChange(aStyleSheet);
} }
void void
PresShell::StyleRuleRemoved(CSSStyleSheet* aStyleSheet) PresShell::StyleRuleRemoved(StyleSheetHandle aStyleSheet)
{ {
RecordStyleSheetChange(aStyleSheet); RecordStyleSheetChange(aStyleSheet);
} }
@ -8501,7 +8511,7 @@ PresShell::IsVisible()
} }
nsresult nsresult
PresShell::GetAgentStyleSheets(nsTArray<RefPtr<CSSStyleSheet>>& aSheets) PresShell::GetAgentStyleSheets(nsTArray<StyleSheetHandle::RefPtr>& aSheets)
{ {
aSheets.Clear(); aSheets.Clear();
int32_t sheetCount = mStyleSet->SheetCount(SheetType::Agent); int32_t sheetCount = mStyleSet->SheetCount(SheetType::Agent);
@ -8511,7 +8521,7 @@ PresShell::GetAgentStyleSheets(nsTArray<RefPtr<CSSStyleSheet>>& aSheets)
} }
for (int32_t i = 0; i < sheetCount; ++i) { for (int32_t i = 0; i < sheetCount; ++i) {
CSSStyleSheet* sheet = mStyleSet->StyleSheetAt(SheetType::Agent, i); StyleSheetHandle sheet = mStyleSet->StyleSheetAt(SheetType::Agent, i);
aSheets.AppendElement(sheet); aSheets.AppendElement(sheet);
} }
@ -8519,19 +8529,19 @@ PresShell::GetAgentStyleSheets(nsTArray<RefPtr<CSSStyleSheet>>& aSheets)
} }
nsresult nsresult
PresShell::SetAgentStyleSheets(const nsTArray<RefPtr<CSSStyleSheet>>& aSheets) PresShell::SetAgentStyleSheets(const nsTArray<StyleSheetHandle::RefPtr>& aSheets)
{ {
return mStyleSet->ReplaceSheets(SheetType::Agent, aSheets); return mStyleSet->ReplaceSheets(SheetType::Agent, aSheets);
} }
nsresult nsresult
PresShell::AddOverrideStyleSheet(CSSStyleSheet* aSheet) PresShell::AddOverrideStyleSheet(StyleSheetHandle aSheet)
{ {
return mStyleSet->PrependStyleSheet(SheetType::Override, aSheet); return mStyleSet->PrependStyleSheet(SheetType::Override, aSheet);
} }
nsresult nsresult
PresShell::RemoveOverrideStyleSheet(CSSStyleSheet* aSheet) PresShell::RemoveOverrideStyleSheet(StyleSheetHandle aSheet)
{ {
return mStyleSet->RemoveStyleSheet(SheetType::Override, aSheet); return mStyleSet->RemoveStyleSheet(SheetType::Override, aSheet);
} }

View File

@ -51,7 +51,6 @@ class nsPresShellEventCB;
class nsAutoCauseReflowNotifier; class nsAutoCauseReflowNotifier;
namespace mozilla { namespace mozilla {
class CSSStyleSheet;
class EventDispatchingCallback; class EventDispatchingCallback;
} // namespace mozilla } // namespace mozilla
@ -155,12 +154,12 @@ public:
virtual void UnsuppressPainting() override; virtual void UnsuppressPainting() override;
virtual nsresult GetAgentStyleSheets( virtual nsresult GetAgentStyleSheets(
nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aSheets) override; nsTArray<mozilla::StyleSheetHandle::RefPtr>& aSheets) override;
virtual nsresult SetAgentStyleSheets( virtual nsresult SetAgentStyleSheets(
const nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aSheets) override; const nsTArray<mozilla::StyleSheetHandle::RefPtr>& aSheets) override;
virtual nsresult AddOverrideStyleSheet(mozilla::CSSStyleSheet* aSheet) override; virtual nsresult AddOverrideStyleSheet(mozilla::StyleSheetHandle aSheet) override;
virtual nsresult RemoveOverrideStyleSheet(mozilla::CSSStyleSheet* aSheet) override; virtual nsresult RemoveOverrideStyleSheet(mozilla::StyleSheetHandle aSheet) override;
virtual nsresult HandleEventWithTarget( virtual nsresult HandleEventWithTarget(
mozilla::WidgetEvent* aEvent, mozilla::WidgetEvent* aEvent,
@ -503,7 +502,7 @@ protected:
void ShowEventTargetDebug(); void ShowEventTargetDebug();
#endif #endif
void RecordStyleSheetChange(mozilla::CSSStyleSheet* aStyleSheet); void RecordStyleSheetChange(mozilla::StyleSheetHandle aStyleSheet);
void RemovePreferenceStyles(); void RemovePreferenceStyles();
@ -781,7 +780,7 @@ protected:
nsPoint mMouseLocation; nsPoint mMouseLocation;
// mStyleSet owns it but we maintain a ref, may be null // mStyleSet owns it but we maintain a ref, may be null
RefPtr<mozilla::CSSStyleSheet> mPrefStyleSheet; mozilla::StyleSheetHandle::RefPtr mPrefStyleSheet;
// Set of frames that we should mark with NS_FRAME_HAS_DIRTY_CHILDREN after // Set of frames that we should mark with NS_FRAME_HAS_DIRTY_CHILDREN after
// we finish reflowing mCurrentReflowRoot. // we finish reflowing mCurrentReflowRoot.

View File

@ -9,6 +9,8 @@
#include "nsStyleSheetService.h" #include "nsStyleSheetService.h"
#include "mozilla/CSSStyleSheet.h" #include "mozilla/CSSStyleSheet.h"
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#include "mozilla/unused.h" #include "mozilla/unused.h"
#include "mozilla/css/Loader.h" #include "mozilla/css/Loader.h"
#include "mozilla/dom/ContentParent.h" #include "mozilla/dom/ContentParent.h"
@ -78,7 +80,7 @@ nsStyleSheetService::RegisterFromEnumerator(nsICategoryManager *aManager,
} }
int32_t int32_t
nsStyleSheetService::FindSheetByURI(const nsTArray<RefPtr<CSSStyleSheet>>& aSheets, nsStyleSheetService::FindSheetByURI(const nsTArray<StyleSheetHandle::RefPtr>& aSheets,
nsIURI* aSheetURI) nsIURI* aSheetURI)
{ {
for (int32_t i = aSheets.Length() - 1; i >= 0; i-- ) { for (int32_t i = aSheets.Length() - 1; i >= 0; i-- ) {
@ -152,9 +154,17 @@ nsStyleSheetService::LoadAndRegisterSheet(nsIURI *aSheetURI,
if (serv) { if (serv) {
// We're guaranteed that the new sheet is the last sheet in // We're guaranteed that the new sheet is the last sheet in
// mSheets[aSheetType] // mSheets[aSheetType]
CSSStyleSheet* sheet = mSheets[aSheetType].LastElement();
serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, sheet), // XXXheycam Once the nsStyleSheetService can hold ServoStyleSheets too,
message, nullptr); // we'll need to include them in the notification.
StyleSheetHandle sheet = mSheets[aSheetType].LastElement();
if (sheet->IsGecko()) {
CSSStyleSheet* cssSheet = sheet->AsGecko();
serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, cssSheet),
message, nullptr);
} else {
NS_ERROR("stylo: can't notify observers of ServoStyleSheets");
}
} }
if (XRE_IsParentProcess()) { if (XRE_IsParentProcess()) {
@ -203,9 +213,8 @@ nsStyleSheetService::LoadAndRegisterSheetInternal(nsIURI *aSheetURI,
RefPtr<css::Loader> loader = new css::Loader(); RefPtr<css::Loader> loader = new css::Loader();
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet;
nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, &sheet);
getter_AddRefs(sheet));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
mSheets[aSheetType].AppendElement(sheet); mSheets[aSheetType].AppendElement(sheet);
@ -253,13 +262,21 @@ nsStyleSheetService::PreloadSheet(nsIURI *aSheetURI, uint32_t aSheetType,
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
// XXXheycam PreloadSheet can't support ServoStyleSheets until they implement
// nsIDOMStyleSheet.
RefPtr<css::Loader> loader = new css::Loader(); RefPtr<css::Loader> loader = new css::Loader();
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet;
nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, &sheet);
getter_AddRefs(sheet));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
sheet.forget(aSheet);
MOZ_ASSERT(sheet->IsGecko(),
"stylo: didn't expect Loader to create a ServoStyleSheet");
RefPtr<CSSStyleSheet> cssSheet = sheet->AsGecko();
cssSheet.forget(aSheet);
return NS_OK; return NS_OK;
} }
@ -273,7 +290,7 @@ nsStyleSheetService::UnregisterSheet(nsIURI *aSheetURI, uint32_t aSheetType)
int32_t foundIndex = FindSheetByURI(mSheets[aSheetType], aSheetURI); int32_t foundIndex = FindSheetByURI(mSheets[aSheetType], aSheetURI);
NS_ENSURE_TRUE(foundIndex >= 0, NS_ERROR_INVALID_ARG); NS_ENSURE_TRUE(foundIndex >= 0, NS_ERROR_INVALID_ARG);
RefPtr<CSSStyleSheet> sheet = mSheets[aSheetType][foundIndex]; StyleSheetHandle::RefPtr sheet = mSheets[aSheetType][foundIndex];
mSheets[aSheetType].RemoveElementAt(foundIndex); mSheets[aSheetType].RemoveElementAt(foundIndex);
const char* message; const char* message;
@ -291,8 +308,15 @@ nsStyleSheetService::UnregisterSheet(nsIURI *aSheetURI, uint32_t aSheetType)
nsCOMPtr<nsIObserverService> serv = services::GetObserverService(); nsCOMPtr<nsIObserverService> serv = services::GetObserverService();
if (serv) { if (serv) {
serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, sheet), // XXXheycam Once the nsStyleSheetService can hold ServoStyleSheets too,
message, nullptr); // we'll need to include them in the notification.
if (sheet->IsGecko()) {
CSSStyleSheet* cssSheet = sheet->AsGecko();
serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, cssSheet),
message, nullptr);
} else {
NS_ERROR("stylo: can't notify observers of ServoStyleSheets");
}
} }
if (XRE_IsParentProcess()) { if (XRE_IsParentProcess()) {
@ -347,7 +371,7 @@ nsStyleSheetService::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) co
size_t n = aMallocSizeOf(this); size_t n = aMallocSizeOf(this);
for (auto& sheetArray : mSheets) { for (auto& sheetArray : mSheets) {
n += sheetArray.ShallowSizeOfExcludingThis(aMallocSizeOf); n += sheetArray.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (CSSStyleSheet* sheet : sheetArray) { for (StyleSheetHandle sheet : sheetArray) {
n += sheet->SizeOfIncludingThis(aMallocSizeOf); n += sheet->SizeOfIncludingThis(aMallocSizeOf);
} }
} }

View File

@ -15,10 +15,8 @@
#include "nsIStyleSheetService.h" #include "nsIStyleSheetService.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "mozilla/StyleSheetHandle.h"
namespace mozilla {
class CSSStyleSheet;
}
class nsICategoryManager; class nsICategoryManager;
class nsIMemoryReporter; class nsIMemoryReporter;
class nsISimpleEnumerator; class nsISimpleEnumerator;
@ -43,15 +41,15 @@ class nsStyleSheetService final
nsresult Init(); nsresult Init();
nsTArray<RefPtr<mozilla::CSSStyleSheet>>* AgentStyleSheets() nsTArray<mozilla::StyleSheetHandle::RefPtr>* AgentStyleSheets()
{ {
return &mSheets[AGENT_SHEET]; return &mSheets[AGENT_SHEET];
} }
nsTArray<RefPtr<mozilla::CSSStyleSheet>>* UserStyleSheets() nsTArray<mozilla::StyleSheetHandle::RefPtr>* UserStyleSheets()
{ {
return &mSheets[USER_SHEET]; return &mSheets[USER_SHEET];
} }
nsTArray<RefPtr<mozilla::CSSStyleSheet>>* AuthorStyleSheets() nsTArray<mozilla::StyleSheetHandle::RefPtr>* AuthorStyleSheets()
{ {
return &mSheets[AUTHOR_SHEET]; return &mSheets[AUTHOR_SHEET];
} }
@ -69,7 +67,7 @@ class nsStyleSheetService final
nsISimpleEnumerator *aEnumerator, nsISimpleEnumerator *aEnumerator,
uint32_t aSheetType); uint32_t aSheetType);
int32_t FindSheetByURI(const nsTArray<RefPtr<mozilla::CSSStyleSheet>>& aSheets, int32_t FindSheetByURI(const nsTArray<mozilla::StyleSheetHandle::RefPtr>& aSheets,
nsIURI* aSheetURI); nsIURI* aSheetURI);
// Like LoadAndRegisterSheet, but doesn't notify. If successful, the // Like LoadAndRegisterSheet, but doesn't notify. If successful, the
@ -77,7 +75,7 @@ class nsStyleSheetService final
nsresult LoadAndRegisterSheetInternal(nsIURI *aSheetURI, nsresult LoadAndRegisterSheetInternal(nsIURI *aSheetURI,
uint32_t aSheetType); uint32_t aSheetType);
nsTArray<RefPtr<mozilla::CSSStyleSheet>> mSheets[3]; nsTArray<mozilla::StyleSheetHandle::RefPtr> mSheets[3];
}; };
#endif #endif

View File

@ -114,7 +114,9 @@ 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 (int32_t i = 0; i < document->GetNumberOfStyleSheets(); i++) {
sheets.AppendElement(document->GetStyleSheetAt(i)); // XXXheycam ServoStyleSets don't have the ability to expose their
// sheets in a script-accessible way yet.
sheets.AppendElement(document->GetStyleSheetAt(i)->AsGecko());
} }
nsISupports** ret = static_cast<nsISupports**>(moz_xmalloc(sheets.Length() * nsISupports** ret = static_cast<nsISupports**>(moz_xmalloc(sheets.Length() *

View File

@ -2203,14 +2203,19 @@ CSSStyleSheet::InsertRuleIntoGroup(const nsAString & aRule,
// nsICSSLoaderObserver implementation // nsICSSLoaderObserver implementation
NS_IMETHODIMP NS_IMETHODIMP
CSSStyleSheet::StyleSheetLoaded(CSSStyleSheet* aSheet, CSSStyleSheet::StyleSheetLoaded(StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) nsresult aStatus)
{ {
if (aSheet->GetParentSheet() == nullptr) { MOZ_ASSERT(aSheet->IsGecko(),
"why we were called back with a ServoStyleSheet?");
CSSStyleSheet* sheet = aSheet->AsGecko();
if (sheet->GetParentSheet() == nullptr) {
return NS_OK; // ignore if sheet has been detached already (see parseSheet) return NS_OK; // ignore if sheet has been detached already (see parseSheet)
} }
NS_ASSERTION(this == aSheet->GetParentSheet(), NS_ASSERTION(this == sheet->GetParentSheet(),
"We are being notified of a sheet load for a sheet that is not our child!"); "We are being notified of a sheet load for a sheet that is not our child!");
if (mDocument && NS_SUCCEEDED(aStatus)) { if (mDocument && NS_SUCCEEDED(aStatus)) {
@ -2218,7 +2223,7 @@ CSSStyleSheet::StyleSheetLoaded(CSSStyleSheet* aSheet,
// XXXldb @import rules shouldn't even implement nsIStyleRule (but // XXXldb @import rules shouldn't even implement nsIStyleRule (but
// they do)! // they do)!
mDocument->StyleRuleAdded(this, aSheet->GetOwnerRule()); mDocument->StyleRuleAdded(this, sheet->GetOwnerRule());
} }
return NS_OK; return NS_OK;

View File

@ -248,7 +248,7 @@ public:
nsIURI* GetOriginalURI() const { return mInner->mOriginalSheetURI; } nsIURI* GetOriginalURI() const { return mInner->mOriginalSheetURI; }
// nsICSSLoaderObserver interface // nsICSSLoaderObserver interface
NS_IMETHOD StyleSheetLoaded(CSSStyleSheet* aSheet, bool aWasAlternate, NS_IMETHOD StyleSheetLoaded(StyleSheetHandle aSheet, bool aWasAlternate,
nsresult aStatus) override; nsresult aStatus) override;
void EnsureUniqueInner(); void EnsureUniqueInner();
@ -282,7 +282,7 @@ public:
ReferrerPolicy GetReferrerPolicy() const { return mInner->mReferrerPolicy; } ReferrerPolicy GetReferrerPolicy() const { return mInner->mReferrerPolicy; }
// Get this style sheet's integrity metadata // Get this style sheet's integrity metadata
dom::SRIMetadata GetIntegrity() const { return mInner->mIntegrity; } void GetIntegrity(dom::SRIMetadata& aResult) const { aResult = mInner->mIntegrity; }
dom::Element* GetScopeElement() const { return mScopeElement; } dom::Element* GetScopeElement() const { return mScopeElement; }
void SetScopeElement(dom::Element* aScopeElement) void SetScopeElement(dom::Element* aScopeElement)

View File

@ -1694,7 +1694,7 @@ FontFaceSet::PrefEnabled()
// nsICSSLoaderObserver // nsICSSLoaderObserver
NS_IMETHODIMP NS_IMETHODIMP
FontFaceSet::StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet, FontFaceSet::StyleSheetLoaded(StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) nsresult aStatus)
{ {

View File

@ -144,7 +144,7 @@ public:
static bool PrefEnabled(); static bool PrefEnabled();
// nsICSSLoaderObserver // nsICSSLoaderObserver
NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet, NS_IMETHOD StyleSheetLoaded(mozilla::StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) override; nsresult aStatus) override;

View File

@ -51,6 +51,8 @@
#include "nsINetworkPredictor.h" #include "nsINetworkPredictor.h"
#include "mozilla/dom/ShadowRoot.h" #include "mozilla/dom/ShadowRoot.h"
#include "mozilla/dom/URL.h" #include "mozilla/dom/URL.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#ifdef MOZ_XUL #ifdef MOZ_XUL
#include "nsXULPrototypeCache.h" #include "nsXULPrototypeCache.h"
@ -119,7 +121,7 @@ public:
SheetLoadData(Loader* aLoader, SheetLoadData(Loader* aLoader,
const nsSubstring& aTitle, const nsSubstring& aTitle,
nsIURI* aURI, nsIURI* aURI,
CSSStyleSheet* aSheet, StyleSheetHandle aSheet,
nsIStyleSheetLinkingElement* aOwningElement, nsIStyleSheetLinkingElement* aOwningElement,
bool aIsAlternate, bool aIsAlternate,
nsICSSLoaderObserver* aObserver, nsICSSLoaderObserver* aObserver,
@ -129,7 +131,7 @@ public:
// Data for loading a sheet linked from an @import rule // Data for loading a sheet linked from an @import rule
SheetLoadData(Loader* aLoader, SheetLoadData(Loader* aLoader,
nsIURI* aURI, nsIURI* aURI,
CSSStyleSheet* aSheet, StyleSheetHandle aSheet,
SheetLoadData* aParentData, SheetLoadData* aParentData,
nsICSSLoaderObserver* aObserver, nsICSSLoaderObserver* aObserver,
nsIPrincipal* aLoaderPrincipal, nsIPrincipal* aLoaderPrincipal,
@ -138,7 +140,7 @@ public:
// Data for loading a non-document sheet // Data for loading a non-document sheet
SheetLoadData(Loader* aLoader, SheetLoadData(Loader* aLoader,
nsIURI* aURI, nsIURI* aURI,
CSSStyleSheet* aSheet, StyleSheetHandle aSheet,
bool aSyncLoad, bool aSyncLoad,
SheetParsingMode aParsingMode, SheetParsingMode aParsingMode,
bool aUseSystemPrincipal, bool aUseSystemPrincipal,
@ -174,7 +176,7 @@ public:
uint32_t mLineNumber; uint32_t mLineNumber;
// The sheet we're loading data for // The sheet we're loading data for
RefPtr<CSSStyleSheet> mSheet; StyleSheetHandle::RefPtr mSheet;
// Linked list of datas for the same URI as us // Linked list of datas for the same URI as us
SheetLoadData* mNext; // strong ref SheetLoadData* mNext; // strong ref
@ -305,7 +307,7 @@ NS_IMPL_ISUPPORTS(SheetLoadData, nsIUnicharStreamLoaderObserver, nsIRunnable,
SheetLoadData::SheetLoadData(Loader* aLoader, SheetLoadData::SheetLoadData(Loader* aLoader,
const nsSubstring& aTitle, const nsSubstring& aTitle,
nsIURI* aURI, nsIURI* aURI,
CSSStyleSheet* aSheet, StyleSheetHandle aSheet,
nsIStyleSheetLinkingElement* aOwningElement, nsIStyleSheetLinkingElement* aOwningElement,
bool aIsAlternate, bool aIsAlternate,
nsICSSLoaderObserver* aObserver, nsICSSLoaderObserver* aObserver,
@ -337,7 +339,7 @@ SheetLoadData::SheetLoadData(Loader* aLoader,
SheetLoadData::SheetLoadData(Loader* aLoader, SheetLoadData::SheetLoadData(Loader* aLoader,
nsIURI* aURI, nsIURI* aURI,
CSSStyleSheet* aSheet, StyleSheetHandle aSheet,
SheetLoadData* aParentData, SheetLoadData* aParentData,
nsICSSLoaderObserver* aObserver, nsICSSLoaderObserver* aObserver,
nsIPrincipal* aLoaderPrincipal, nsIPrincipal* aLoaderPrincipal,
@ -378,7 +380,7 @@ SheetLoadData::SheetLoadData(Loader* aLoader,
SheetLoadData::SheetLoadData(Loader* aLoader, SheetLoadData::SheetLoadData(Loader* aLoader,
nsIURI* aURI, nsIURI* aURI,
CSSStyleSheet* aSheet, StyleSheetHandle aSheet,
bool aSyncLoad, bool aSyncLoad,
SheetParsingMode aParsingMode, SheetParsingMode aParsingMode,
bool aUseSystemPrincipal, bool aUseSystemPrincipal,
@ -950,7 +952,8 @@ SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader,
} }
} }
SRIMetadata sriMetadata = mSheet->GetIntegrity(); SRIMetadata sriMetadata;
mSheet->GetIntegrity(sriMetadata);
if (!sriMetadata.IsEmpty() && if (!sriMetadata.IsEmpty() &&
NS_FAILED(SRICheck::VerifyIntegrity(sriMetadata, aLoader, NS_FAILED(SRICheck::VerifyIntegrity(sriMetadata, aLoader,
mSheet->GetCORSMode(), aBuffer, mSheet->GetCORSMode(), aBuffer,
@ -1068,7 +1071,7 @@ Loader::CreateSheet(nsIURI* aURI,
const nsAString& aTitle, const nsAString& aTitle,
StyleSheetState& aSheetState, StyleSheetState& aSheetState,
bool *aIsAlternate, bool *aIsAlternate,
CSSStyleSheet** aSheet) StyleSheetHandle::RefPtr* aSheet)
{ {
LOG(("css::Loader::CreateSheet")); LOG(("css::Loader::CreateSheet"));
NS_PRECONDITION(aSheet, "Null out param!"); NS_PRECONDITION(aSheet, "Null out param!");
@ -1084,9 +1087,10 @@ Loader::CreateSheet(nsIURI* aURI,
// can mess with our hashtables. // can mess with our hashtables.
*aIsAlternate = IsAlternate(aTitle, aHasAlternateRel); *aIsAlternate = IsAlternate(aTitle, aHasAlternateRel);
// XXXheycam Cached sheets currently must be CSSStyleSheets.
if (aURI) { if (aURI) {
aSheetState = eSheetComplete; aSheetState = eSheetComplete;
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet;
// First, the XUL cache // First, the XUL cache
#ifdef MOZ_XUL #ifdef MOZ_XUL
@ -1095,7 +1099,7 @@ Loader::CreateSheet(nsIURI* aURI,
if (cache) { if (cache) {
if (cache->IsEnabled()) { if (cache->IsEnabled()) {
sheet = cache->GetStyleSheet(aURI); sheet = cache->GetStyleSheet(aURI);
LOG((" From XUL cache: %p", sheet.get())); LOG((" From XUL cache: %p", sheet->AsVoidPtr()));
} }
} }
} }
@ -1106,22 +1110,28 @@ Loader::CreateSheet(nsIURI* aURI,
// Then our per-document complete sheets. // Then our per-document complete sheets.
URIPrincipalReferrerPolicyAndCORSModeHashKey key(aURI, aLoaderPrincipal, aCORSMode, aReferrerPolicy); URIPrincipalReferrerPolicyAndCORSModeHashKey key(aURI, aLoaderPrincipal, aCORSMode, aReferrerPolicy);
mSheets->mCompleteSheets.Get(&key, getter_AddRefs(sheet)); StyleSheetHandle completeSheet;
LOG((" From completed: %p", sheet.get())); mSheets->mCompleteSheets.Get(&key, &completeSheet);
sheet = completeSheet;
LOG((" From completed: %p", sheet->AsVoidPtr()));
fromCompleteSheets = !!sheet; fromCompleteSheets = !!sheet;
} }
if (sheet) { if (sheet) {
if (sheet->IsServo()) {
MOZ_CRASH("stylo: can't clone ServoStyleSheets yet");
}
// This sheet came from the XUL cache or our per-document hashtable; it // This sheet came from the XUL cache or our per-document hashtable; it
// better be a complete sheet. // better be a complete sheet.
NS_ASSERTION(sheet->IsComplete(), NS_ASSERTION(sheet->AsGecko()->IsComplete(),
"Sheet thinks it's not complete while we think it is"); "Sheet thinks it's not complete while we think it is");
// Make sure it hasn't been modified; if it has, we can't use it // Make sure it hasn't been modified; if it has, we can't use it
if (sheet->IsModified()) { if (sheet->AsGecko()->IsModified()) {
LOG((" Not cloning completed sheet %p because it's been modified", LOG((" Not cloning completed sheet %p because it's been modified",
sheet.get())); sheet->AsVoidPtr()));
sheet = nullptr; sheet = nullptr;
fromCompleteSheets = false; fromCompleteSheets = false;
} }
@ -1135,7 +1145,7 @@ Loader::CreateSheet(nsIURI* aURI,
mSheets->mLoadingDatas.Get(&key, &loadData); mSheets->mLoadingDatas.Get(&key, &loadData);
if (loadData) { if (loadData) {
sheet = loadData->mSheet; sheet = loadData->mSheet;
LOG((" From loading: %p", sheet.get())); LOG((" From loading: %p", sheet->AsVoidPtr()));
#ifdef DEBUG #ifdef DEBUG
bool debugEqual; bool debugEqual;
@ -1155,7 +1165,7 @@ Loader::CreateSheet(nsIURI* aURI,
mSheets->mPendingDatas.Get(&key, &loadData); mSheets->mPendingDatas.Get(&key, &loadData);
if (loadData) { if (loadData) {
sheet = loadData->mSheet; sheet = loadData->mSheet;
LOG((" From pending: %p", sheet.get())); LOG((" From pending: %p", sheet->AsVoidPtr()));
#ifdef DEBUG #ifdef DEBUG
bool debugEqual; bool debugEqual;
@ -1172,20 +1182,28 @@ Loader::CreateSheet(nsIURI* aURI,
if (sheet) { if (sheet) {
// The sheet we have now should be either incomplete or unmodified // The sheet we have now should be either incomplete or unmodified
NS_ASSERTION(!sheet->IsModified() || !sheet->IsComplete(), if (sheet->IsServo()) {
MOZ_CRASH("stylo: can't clone ServoStyleSheets yet");
}
NS_ASSERTION(!sheet->AsGecko()->IsModified() ||
!sheet->AsGecko()->IsComplete(),
"Unexpected modified complete sheet"); "Unexpected modified complete sheet");
NS_ASSERTION(sheet->IsComplete() || aSheetState != eSheetComplete, NS_ASSERTION(sheet->AsGecko()->IsComplete() ||
aSheetState != eSheetComplete,
"Sheet thinks it's not complete while we think it is"); "Sheet thinks it's not complete while we think it is");
*aSheet = sheet->Clone(nullptr, nullptr, nullptr, nullptr).take(); RefPtr<CSSStyleSheet> clonedSheet =
sheet->AsGecko()->Clone(nullptr, nullptr, nullptr, nullptr);
*aSheet = Move(clonedSheet);
if (*aSheet && fromCompleteSheets && if (*aSheet && fromCompleteSheets &&
!sheet->GetOwnerNode() && !sheet->GetParentSheet()) { !sheet->AsGecko()->GetOwnerNode() &&
!sheet->AsGecko()->GetParentSheet()) {
// The sheet we're cloning isn't actually referenced by // The sheet we're cloning isn't actually referenced by
// anyone. Replace it in the cache, so that if our CSSOM is // anyone. Replace it in the cache, so that if our CSSOM is
// later modified we don't end up with two copies of our inner // later modified we don't end up with two copies of our inner
// hanging around. // hanging around.
URIPrincipalReferrerPolicyAndCORSModeHashKey key(aURI, aLoaderPrincipal, aCORSMode, aReferrerPolicy); URIPrincipalReferrerPolicyAndCORSModeHashKey key(aURI, aLoaderPrincipal, aCORSMode, aReferrerPolicy);
NS_ASSERTION((*aSheet)->IsComplete(), NS_ASSERTION((*aSheet)->AsGecko()->IsComplete(),
"Should only be caching complete sheets"); "Should only be caching complete sheets");
mSheets->mCompleteSheets.Put(&key, *aSheet); mSheets->mCompleteSheets.Put(&key, *aSheet);
} }
@ -1218,11 +1236,8 @@ Loader::CreateSheet(nsIURI* aURI,
SRICheck::IntegrityMetadata(aIntegrity, mDocument, &sriMetadata); SRICheck::IntegrityMetadata(aIntegrity, mDocument, &sriMetadata);
} }
RefPtr<CSSStyleSheet> sheet = new CSSStyleSheet(aCORSMode, *aSheet = new CSSStyleSheet(aCORSMode, aReferrerPolicy, sriMetadata);
aReferrerPolicy, (*aSheet)->SetURIs(sheetURI, originalURI, baseURI);
sriMetadata);
sheet->SetURIs(sheetURI, originalURI, baseURI);
sheet.forget(aSheet);
} }
NS_ASSERTION(*aSheet, "We should have a sheet by now!"); NS_ASSERTION(*aSheet, "We should have a sheet by now!");
@ -1238,7 +1253,7 @@ Loader::CreateSheet(nsIURI* aURI,
* the sheet had "alternate" in its rel. * the sheet had "alternate" in its rel.
*/ */
void void
Loader::PrepareSheet(CSSStyleSheet* aSheet, Loader::PrepareSheet(StyleSheetHandle aSheet,
const nsSubstring& aTitle, const nsSubstring& aTitle,
const nsSubstring& aMediaString, const nsSubstring& aMediaString,
nsMediaList* aMediaList, nsMediaList* aMediaList,
@ -1247,6 +1262,14 @@ Loader::PrepareSheet(CSSStyleSheet* aSheet,
{ {
NS_PRECONDITION(aSheet, "Must have a sheet!"); NS_PRECONDITION(aSheet, "Must have a sheet!");
// XXXheycam Need to set media, title, etc. on ServoStyleSheets.
if (aSheet->IsServo()) {
NS_ERROR("stylo: should set metadata on ServoStyleSheets");
return;
}
CSSStyleSheet* sheet = aSheet->AsGecko();
RefPtr<nsMediaList> mediaList(aMediaList); RefPtr<nsMediaList> mediaList(aMediaList);
if (!aMediaString.IsEmpty()) { if (!aMediaString.IsEmpty()) {
@ -1261,11 +1284,11 @@ Loader::PrepareSheet(CSSStyleSheet* aSheet,
mediumParser.ParseMediaList(aMediaString, nullptr, 0, mediaList, true); mediumParser.ParseMediaList(aMediaString, nullptr, 0, mediaList, true);
} }
aSheet->SetMedia(mediaList); sheet->SetMedia(mediaList);
aSheet->SetTitle(aTitle); sheet->SetTitle(aTitle);
aSheet->SetEnabled(! isAlternate); sheet->SetEnabled(!isAlternate);
aSheet->SetScopeElement(aScopeElement); sheet->SetScopeElement(aScopeElement);
} }
/** /**
@ -1282,7 +1305,7 @@ Loader::PrepareSheet(CSSStyleSheet* aSheet,
* as determined by CompareDocumentPosition. * as determined by CompareDocumentPosition.
*/ */
nsresult nsresult
Loader::InsertSheetInDoc(CSSStyleSheet* aSheet, Loader::InsertSheetInDoc(StyleSheetHandle aSheet,
nsIContent* aLinkingContent, nsIContent* aLinkingContent,
nsIDocument* aDocument) nsIDocument* aDocument)
{ {
@ -1304,10 +1327,9 @@ Loader::InsertSheetInDoc(CSSStyleSheet* aSheet,
*/ */
int32_t insertionPoint; int32_t insertionPoint;
for (insertionPoint = sheetCount - 1; insertionPoint >= 0; --insertionPoint) { for (insertionPoint = sheetCount - 1; insertionPoint >= 0; --insertionPoint) {
CSSStyleSheet* curSheet = aDocument->GetStyleSheetAt(insertionPoint); StyleSheetHandle curSheet = aDocument->GetStyleSheetAt(insertionPoint);
NS_ASSERTION(curSheet, "There must be a sheet here!"); NS_ASSERTION(curSheet, "There must be a sheet here!");
nsCOMPtr<nsIDOMNode> sheetOwner; nsCOMPtr<nsINode> sheetOwner = curSheet->GetOwnerNode();
curSheet->GetOwnerNode(getter_AddRefs(sheetOwner));
if (sheetOwner && !aLinkingContent) { if (sheetOwner && !aLinkingContent) {
// Keep moving; all sheets with a sheetOwner come after all // Keep moving; all sheets with a sheetOwner come after all
// sheets without a linkingNode // sheets without a linkingNode
@ -1320,12 +1342,11 @@ Loader::InsertSheetInDoc(CSSStyleSheet* aSheet,
break; break;
} }
nsCOMPtr<nsINode> sheetOwnerNode = do_QueryInterface(sheetOwner); NS_ASSERTION(aLinkingContent != sheetOwner,
NS_ASSERTION(aLinkingContent != sheetOwnerNode,
"Why do we still have our old sheet?"); "Why do we still have our old sheet?");
// Have to compare // Have to compare
if (nsContentUtils::PositionIsBefore(sheetOwnerNode, aLinkingContent)) { if (nsContentUtils::PositionIsBefore(sheetOwner, aLinkingContent)) {
// The current sheet comes before us, and it better be the first // The current sheet comes before us, and it better be the first
// such, because now we break // such, because now we break
break; break;
@ -1363,8 +1384,8 @@ Loader::InsertSheetInDoc(CSSStyleSheet* aSheet,
* bug 1220506.) * bug 1220506.)
*/ */
nsresult nsresult
Loader::InsertChildSheet(CSSStyleSheet* aSheet, Loader::InsertChildSheet(StyleSheetHandle aSheet,
CSSStyleSheet* aParentSheet, StyleSheetHandle aParentSheet,
ImportRule* aParentRule) ImportRule* aParentRule)
{ {
LOG(("css::Loader::InsertChildSheet")); LOG(("css::Loader::InsertChildSheet"));
@ -1372,12 +1393,18 @@ Loader::InsertChildSheet(CSSStyleSheet* aSheet,
NS_PRECONDITION(aParentSheet, "Need a parent to insert into"); NS_PRECONDITION(aParentSheet, "Need a parent to insert into");
NS_PRECONDITION(aParentSheet, "How did we get imported?"); NS_PRECONDITION(aParentSheet, "How did we get imported?");
// XXXheycam The InsertChildSheet API doesn't work with ServoStyleSheets,
// since they won't have Gecko ImportRules in them.
if (aSheet->IsServo()) {
return NS_ERROR_FAILURE;
}
// child sheets should always start out enabled, even if they got // child sheets should always start out enabled, even if they got
// cloned off of top-level sheets which were disabled // cloned off of top-level sheets which were disabled
aSheet->SetEnabled(true); aSheet->AsGecko()->SetEnabled(true);
aParentSheet->AppendStyleSheet(aSheet); aParentSheet->AppendStyleSheet(aSheet);
aParentRule->SetSheet(aSheet); // This sets the ownerRule on the sheet aParentRule->SetSheet(aSheet->AsGecko()); // This sets the ownerRule on the sheet
LOG((" Inserting into parent sheet")); LOG((" Inserting into parent sheet"));
// LOG((" Inserting into parent sheet at position %d", insertionPoint)); // LOG((" Inserting into parent sheet at position %d", insertionPoint));
@ -1418,7 +1445,8 @@ Loader::LoadSheet(SheetLoadData* aLoadData,
return NS_BINDING_ABORTED; return NS_BINDING_ABORTED;
} }
SRIMetadata sriMetadata = aLoadData->mSheet->GetIntegrity(); SRIMetadata sriMetadata;
aLoadData->mSheet->GetIntegrity(sriMetadata);
if (aLoadData->mSyncLoad) { if (aLoadData->mSyncLoad) {
LOG((" Synchronous load")); LOG((" Synchronous load"));
@ -1709,7 +1737,10 @@ Loader::ParseSheet(const nsAString& aInput,
aCompleted = false; aCompleted = false;
nsCSSParser parser(this, aLoadData->mSheet); // XXXheycam ServoStyleSheets don't support parsing their contents yet.
MOZ_ASSERT(aLoadData->mSheet->IsGecko(),
"stylo: can't parse ServoStyleSheets contents yet");
nsCSSParser parser(this, aLoadData->mSheet->AsGecko());
// Push our load data on the stack so any kids can pick it up // Push our load data on the stack so any kids can pick it up
mParsingDatas.AppendElement(aLoadData); mParsingDatas.AppendElement(aLoadData);
@ -1830,7 +1861,8 @@ Loader::DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
// If mSheetAlreadyComplete, then the sheet could well be modified between // If mSheetAlreadyComplete, then the sheet could well be modified between
// when we posted the async call to SheetComplete and now, since the sheet // when we posted the async call to SheetComplete and now, since the sheet
// was page-accessible during that whole time. // was page-accessible during that whole time.
MOZ_ASSERT(!data->mSheet->IsModified(), MOZ_ASSERT(!(data->mSheet->IsGecko() &&
data->mSheet->AsGecko()->IsModified()),
"should not get marked modified during parsing"); "should not get marked modified during parsing");
data->mSheet->SetComplete(); data->mSheet->SetComplete();
data->ScheduleLoadEventIfNeeded(aStatus); data->ScheduleLoadEventIfNeeded(aStatus);
@ -1871,39 +1903,43 @@ Loader::DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
// one of the sheets that will be kept alive by a document or // one of the sheets that will be kept alive by a document or
// parent sheet anyway, so that if someone then accesses it via // parent sheet anyway, so that if someone then accesses it via
// CSSOM we won't have extra clones of the inner lying around. // CSSOM we won't have extra clones of the inner lying around.
data = aLoadData; if (aLoadData->mSheet->IsGecko()) {
CSSStyleSheet* sheet = aLoadData->mSheet; data = aLoadData;
while (data) { CSSStyleSheet* sheet = aLoadData->mSheet->AsGecko();
if (data->mSheet->GetParentSheet() || data->mSheet->GetOwnerNode()) { while (data) {
sheet = data->mSheet; if (data->mSheet->GetParentSheet() || data->mSheet->GetOwnerNode()) {
break; sheet = data->mSheet->AsGecko();
break;
}
data = data->mNext;
} }
data = data->mNext;
}
#ifdef MOZ_XUL #ifdef MOZ_XUL
if (IsChromeURI(aLoadData->mURI)) { if (IsChromeURI(aLoadData->mURI)) {
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance(); nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
if (cache && cache->IsEnabled()) { if (cache && cache->IsEnabled()) {
if (!cache->GetStyleSheet(aLoadData->mURI)) { if (!cache->GetStyleSheet(aLoadData->mURI)) {
LOG((" Putting sheet in XUL prototype cache")); LOG((" Putting sheet in XUL prototype cache"));
NS_ASSERTION(sheet->IsComplete(), NS_ASSERTION(sheet->IsComplete(),
"Should only be caching complete sheets"); "Should only be caching complete sheets");
cache->PutStyleSheet(sheet); cache->PutStyleSheet(sheet);
}
} }
} }
} else {
else {
#endif #endif
URIPrincipalReferrerPolicyAndCORSModeHashKey key(aLoadData->mURI, URIPrincipalReferrerPolicyAndCORSModeHashKey key(aLoadData->mURI,
aLoadData->mLoaderPrincipal, aLoadData->mLoaderPrincipal,
aLoadData->mSheet->GetCORSMode(), aLoadData->mSheet->GetCORSMode(),
aLoadData->mSheet->GetReferrerPolicy()); aLoadData->mSheet->GetReferrerPolicy());
NS_ASSERTION(sheet->IsComplete(), NS_ASSERTION(sheet->IsComplete(),
"Should only be caching complete sheets"); "Should only be caching complete sheets");
mSheets->mCompleteSheets.Put(&key, sheet); mSheets->mCompleteSheets.Put(&key, sheet);
#ifdef MOZ_XUL #ifdef MOZ_XUL
} }
#endif #endif
} else {
NS_ERROR("stylo: not caching ServoStyleSheet");
}
} }
NS_RELEASE(aLoadData); // this will release parents and siblings and all that NS_RELEASE(aLoadData); // this will release parents and siblings and all that
@ -1939,12 +1975,12 @@ Loader::LoadInlineStyle(nsIContent* aElement,
// load data or to CreateSheet(). Also, OK to use CORS_NONE for the CORS // load data or to CreateSheet(). Also, OK to use CORS_NONE for the CORS
// mode and mDocument's ReferrerPolicy. // mode and mDocument's ReferrerPolicy.
StyleSheetState state; StyleSheetState state;
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet;
nsresult rv = CreateSheet(nullptr, aElement, nullptr, CORS_NONE, nsresult rv = CreateSheet(nullptr, aElement, nullptr, CORS_NONE,
mDocument->GetReferrerPolicy(), mDocument->GetReferrerPolicy(),
EmptyString(), // no inline integrity checks EmptyString(), // no inline integrity checks
false, false, aTitle, state, aIsAlternate, false, false, aTitle, state, aIsAlternate,
getter_AddRefs(sheet)); &sheet);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(state == eSheetNeedsParser, NS_ASSERTION(state == eSheetNeedsParser,
"Inline sheets should not be cached"); "Inline sheets should not be cached");
@ -2022,11 +2058,11 @@ Loader::LoadStyleLink(nsIContent* aElement,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
StyleSheetState state; StyleSheetState state;
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet;
rv = CreateSheet(aURL, aElement, principal, aCORSMode, rv = CreateSheet(aURL, aElement, principal, aCORSMode,
aReferrerPolicy, aIntegrity, false, aReferrerPolicy, aIntegrity, false,
aHasAlternateRel, aTitle, state, aIsAlternate, aHasAlternateRel, aTitle, state, aIsAlternate,
getter_AddRefs(sheet)); &sheet);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
LOG((" Sheet is alternate: %d", *aIsAlternate)); LOG((" Sheet is alternate: %d", *aIsAlternate));
@ -2039,8 +2075,7 @@ Loader::LoadStyleLink(nsIContent* aElement,
nsCOMPtr<nsIStyleSheetLinkingElement> owningElement(do_QueryInterface(aElement)); nsCOMPtr<nsIStyleSheetLinkingElement> owningElement(do_QueryInterface(aElement));
if (state == eSheetComplete) { if (state == eSheetComplete) {
LOG((" Sheet already complete: 0x%p", LOG((" Sheet already complete: 0x%p", sheet->AsVoidPtr()));
static_cast<void*>(sheet.get())));
if (aObserver || !mObservers.IsEmpty() || owningElement) { if (aObserver || !mObservers.IsEmpty() || owningElement) {
rv = PostLoadEvent(aURL, sheet, aObserver, *aIsAlternate, rv = PostLoadEvent(aURL, sheet, aObserver, *aIsAlternate,
owningElement); owningElement);
@ -2110,7 +2145,7 @@ HaveAncestorDataWithURI(SheetLoadData *aData, nsIURI *aURI)
} }
nsresult nsresult
Loader::LoadChildSheet(CSSStyleSheet* aParentSheet, Loader::LoadChildSheet(StyleSheetHandle aParentSheet,
nsIURI* aURL, nsIURI* aURL,
nsMediaList* aMedia, nsMediaList* aMedia,
ImportRule* aParentRule, ImportRule* aParentRule,
@ -2127,22 +2162,16 @@ Loader::LoadChildSheet(CSSStyleSheet* aParentSheet,
LOG_URI(" Child uri: '%s'", aURL); LOG_URI(" Child uri: '%s'", aURL);
nsCOMPtr<nsIDOMNode> owningNode; nsCOMPtr<nsINode> owningNode;
// check for an owning document: if none, don't bother walking up the parent // check for an owning document: if none, don't bother walking up the parent
// sheets // sheets
if (aParentSheet->GetOwningDocument()) { if (aParentSheet->GetOwningDocument()) {
nsCOMPtr<nsIDOMStyleSheet> nextParentSheet(aParentSheet); StyleSheetHandle topSheet = aParentSheet;
NS_ENSURE_TRUE(nextParentSheet, NS_ERROR_FAILURE); //Not a stylesheet!? while (StyleSheetHandle parent = topSheet->GetParentSheet()) {
topSheet = parent;
nsCOMPtr<nsIDOMStyleSheet> topSheet; }
//traverse our way to the top-most sheet owningNode = topSheet->GetOwnerNode();
do {
topSheet.swap(nextParentSheet);
topSheet->GetParentStyleSheet(getter_AddRefs(nextParentSheet));
} while (nextParentSheet);
topSheet->GetOwnerNode(getter_AddRefs(owningNode));
} }
nsISupports* context = owningNode; nsISupports* context = owningNode;
@ -2175,15 +2204,20 @@ Loader::LoadChildSheet(CSSStyleSheet* aParentSheet,
LOG((" No parent load; must be CSSOM")); LOG((" No parent load; must be CSSOM"));
// No parent load data, so the sheet will need to be notified when // No parent load data, so the sheet will need to be notified when
// we finish, if it can be, if we do the load asynchronously. // we finish, if it can be, if we do the load asynchronously.
observer = aParentSheet; // XXXheycam ServoStyleSheet doesn't implement nsICSSLoaderObserver yet.
MOZ_ASSERT(aParentSheet->IsGecko(),
"stylo: ServoStyleSheets don't support child sheet loading yet");
observer = aParentSheet->AsGecko();
} }
// Now that we know it's safe to load this (passes security check and not a // Now that we know it's safe to load this (passes security check and not a
// loop) do so. // loop) do so.
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet;
RefPtr<CSSStyleSheet> reusableSheet;
StyleSheetState state; StyleSheetState state;
if (aReusableSheets && aReusableSheets->FindReusableStyleSheet(aURL, sheet)) { if (aReusableSheets && aReusableSheets->FindReusableStyleSheet(aURL, reusableSheet)) {
aParentRule->SetSheet(sheet); sheet = reusableSheet;
aParentRule->SetSheet(reusableSheet);
state = eSheetComplete; state = eSheetComplete;
} else { } else {
bool isAlternate; bool isAlternate;
@ -2193,7 +2227,7 @@ Loader::LoadChildSheet(CSSStyleSheet* aParentSheet,
aParentSheet->GetReferrerPolicy(), aParentSheet->GetReferrerPolicy(),
EmptyString(), // integrity is only checked on main sheet EmptyString(), // integrity is only checked on main sheet
parentData ? parentData->mSyncLoad : false, parentData ? parentData->mSyncLoad : false,
false, empty, state, &isAlternate, getter_AddRefs(sheet)); false, empty, state, &isAlternate, &sheet);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
PrepareSheet(sheet, empty, empty, aMedia, nullptr, isAlternate); PrepareSheet(sheet, empty, empty, aMedia, nullptr, isAlternate);
@ -2232,7 +2266,7 @@ nsresult
Loader::LoadSheetSync(nsIURI* aURL, Loader::LoadSheetSync(nsIURI* aURL,
SheetParsingMode aParsingMode, SheetParsingMode aParsingMode,
bool aUseSystemPrincipal, bool aUseSystemPrincipal,
CSSStyleSheet** aSheet) StyleSheetHandle::RefPtr* aSheet)
{ {
LOG(("css::Loader::LoadSheetSync")); LOG(("css::Loader::LoadSheetSync"));
return InternalLoadNonDocumentSheet(aURL, return InternalLoadNonDocumentSheet(aURL,
@ -2246,7 +2280,7 @@ Loader::LoadSheet(nsIURI* aURL,
nsIPrincipal* aOriginPrincipal, nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset, const nsCString& aCharset,
nsICSSLoaderObserver* aObserver, nsICSSLoaderObserver* aObserver,
CSSStyleSheet** aSheet) StyleSheetHandle::RefPtr* aSheet)
{ {
LOG(("css::Loader::LoadSheet(aURL, aObserver, aSheet) api call")); LOG(("css::Loader::LoadSheet(aURL, aObserver, aSheet) api call"));
NS_PRECONDITION(aSheet, "aSheet is null"); NS_PRECONDITION(aSheet, "aSheet is null");
@ -2281,7 +2315,7 @@ Loader::InternalLoadNonDocumentSheet(nsIURI* aURL,
bool aUseSystemPrincipal, bool aUseSystemPrincipal,
nsIPrincipal* aOriginPrincipal, nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset, const nsCString& aCharset,
CSSStyleSheet** aSheet, StyleSheetHandle::RefPtr* aSheet,
nsICSSLoaderObserver* aObserver, nsICSSLoaderObserver* aObserver,
CORSMode aCORSMode, CORSMode aCORSMode,
ReferrerPolicy aReferrerPolicy, ReferrerPolicy aReferrerPolicy,
@ -2309,13 +2343,13 @@ Loader::InternalLoadNonDocumentSheet(nsIURI* aURL,
StyleSheetState state; StyleSheetState state;
bool isAlternate; bool isAlternate;
RefPtr<CSSStyleSheet> sheet; StyleSheetHandle::RefPtr sheet;
bool syncLoad = (aObserver == nullptr); bool syncLoad = (aObserver == nullptr);
const nsSubstring& empty = EmptyString(); const nsSubstring& empty = EmptyString();
rv = CreateSheet(aURL, nullptr, aOriginPrincipal, aCORSMode, rv = CreateSheet(aURL, nullptr, aOriginPrincipal, aCORSMode,
aReferrerPolicy, aIntegrity, syncLoad, false, aReferrerPolicy, aIntegrity, syncLoad, false,
empty, state, &isAlternate, getter_AddRefs(sheet)); empty, state, &isAlternate, &sheet);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
PrepareSheet(sheet, empty, empty, nullptr, nullptr, isAlternate); PrepareSheet(sheet, empty, empty, nullptr, nullptr, isAlternate);
@ -2352,7 +2386,7 @@ Loader::InternalLoadNonDocumentSheet(nsIURI* aURL,
nsresult nsresult
Loader::PostLoadEvent(nsIURI* aURI, Loader::PostLoadEvent(nsIURI* aURI,
CSSStyleSheet* aSheet, StyleSheetHandle aSheet,
nsICSSLoaderObserver* aObserver, nsICSSLoaderObserver* aObserver,
bool aWasAlternate, bool aWasAlternate,
nsIStyleSheetLinkingElement* aElement) nsIStyleSheetLinkingElement* aElement)
@ -2535,7 +2569,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Loader)
!iter.Done(); !iter.Done();
iter.Next()) { iter.Next()) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "Sheet cache nsCSSLoader"); NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "Sheet cache nsCSSLoader");
cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, iter.UserData())); if (iter.UserData()->IsGecko()) {
CSSStyleSheet* sheet = iter.UserData()->AsGecko();
cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, sheet));
}
} }
} }
nsTObserverArray<nsCOMPtr<nsICSSLoaderObserver>>::ForwardIterator nsTObserverArray<nsCOMPtr<nsICSSLoaderObserver>>::ForwardIterator
@ -2569,10 +2606,10 @@ Loader::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
// If aSheet has a parent, then its parent will report it so we don't // If aSheet has a parent, then its parent will report it so we don't
// have to worry about it here. Likewise, if aSheet has an owning node, // have to worry about it here. Likewise, if aSheet has an owning node,
// then the document that node is in will report it. // then the document that node is in will report it.
const RefPtr<CSSStyleSheet>& aSheet = iter.Data(); const StyleSheetHandle sheet = iter.UserData();
n += (aSheet->GetOwnerNode() || aSheet->GetParentSheet()) n += (sheet->GetOwnerNode() || sheet->GetParentSheet())
? 0 ? 0
: aSheet->SizeOfIncludingThis(aMallocSizeOf); : sheet->SizeOfIncludingThis(aMallocSizeOf);
} }
} }
n += mObservers.ShallowSizeOfExcludingThis(aMallocSizeOf); n += mObservers.ShallowSizeOfExcludingThis(aMallocSizeOf);

View File

@ -22,6 +22,7 @@
#include "mozilla/CORSMode.h" #include "mozilla/CORSMode.h"
#include "mozilla/CSSStyleSheet.h" #include "mozilla/CSSStyleSheet.h"
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/net/ReferrerPolicy.h" #include "mozilla/net/ReferrerPolicy.h"
class nsICSSLoaderObserver; class nsICSSLoaderObserver;
@ -286,7 +287,7 @@ public:
* @param aSavedSheets any saved style sheets which could be reused * @param aSavedSheets any saved style sheets which could be reused
* for this load * for this load
*/ */
nsresult LoadChildSheet(CSSStyleSheet* aParentSheet, nsresult LoadChildSheet(StyleSheetHandle aParentSheet,
nsIURI* aURL, nsIURI* aURL,
nsMediaList* aMedia, nsMediaList* aMedia,
ImportRule* aRule, ImportRule* aRule,
@ -317,13 +318,13 @@ public:
nsresult LoadSheetSync(nsIURI* aURL, nsresult LoadSheetSync(nsIURI* aURL,
SheetParsingMode aParsingMode, SheetParsingMode aParsingMode,
bool aUseSystemPrincipal, bool aUseSystemPrincipal,
CSSStyleSheet** aSheet); StyleSheetHandle::RefPtr* aSheet);
/** /**
* As above, but defaults aParsingMode to eAuthorSheetFeatures and * As above, but defaults aParsingMode to eAuthorSheetFeatures and
* aUseSystemPrincipal to false. * aUseSystemPrincipal to false.
*/ */
nsresult LoadSheetSync(nsIURI* aURL, CSSStyleSheet** aSheet) { nsresult LoadSheetSync(nsIURI* aURL, StyleSheetHandle::RefPtr* aSheet) {
return LoadSheetSync(aURL, eAuthorSheetFeatures, false, aSheet); return LoadSheetSync(aURL, eAuthorSheetFeatures, false, aSheet);
} }
@ -352,7 +353,7 @@ public:
nsIPrincipal* aOriginPrincipal, nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset, const nsCString& aCharset,
nsICSSLoaderObserver* aObserver, nsICSSLoaderObserver* aObserver,
CSSStyleSheet** aSheet); StyleSheetHandle::RefPtr* aSheet);
/** /**
* Same as above, to be used when the caller doesn't care about the * Same as above, to be used when the caller doesn't care about the
@ -461,24 +462,24 @@ private:
const nsAString& aTitle, const nsAString& aTitle,
StyleSheetState& aSheetState, StyleSheetState& aSheetState,
bool *aIsAlternate, bool *aIsAlternate,
CSSStyleSheet** aSheet); StyleSheetHandle::RefPtr* aSheet);
// Pass in either a media string or the nsMediaList from the // Pass in either a media string or the nsMediaList from the
// CSSParser. Don't pass both. // CSSParser. Don't pass both.
// This method will set the sheet's enabled state based on isAlternate // This method will set the sheet's enabled state based on isAlternate
void PrepareSheet(CSSStyleSheet* aSheet, void PrepareSheet(StyleSheetHandle aSheet,
const nsAString& aTitle, const nsAString& aTitle,
const nsAString& aMediaString, const nsAString& aMediaString,
nsMediaList* aMediaList, nsMediaList* aMediaList,
dom::Element* aScopeElement, dom::Element* aScopeElement,
bool isAlternate); bool isAlternate);
nsresult InsertSheetInDoc(CSSStyleSheet* aSheet, nsresult InsertSheetInDoc(StyleSheetHandle aSheet,
nsIContent* aLinkingContent, nsIContent* aLinkingContent,
nsIDocument* aDocument); nsIDocument* aDocument);
nsresult InsertChildSheet(CSSStyleSheet* aSheet, nsresult InsertChildSheet(StyleSheetHandle aSheet,
CSSStyleSheet* aParentSheet, StyleSheetHandle aParentSheet,
ImportRule* aParentRule); ImportRule* aParentRule);
nsresult InternalLoadNonDocumentSheet(nsIURI* aURL, nsresult InternalLoadNonDocumentSheet(nsIURI* aURL,
@ -487,7 +488,7 @@ private:
bool aUseSystemPrincipal, bool aUseSystemPrincipal,
nsIPrincipal* aOriginPrincipal, nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset, const nsCString& aCharset,
CSSStyleSheet** aSheet, StyleSheetHandle::RefPtr* aSheet,
nsICSSLoaderObserver* aObserver, nsICSSLoaderObserver* aObserver,
CORSMode aCORSMode = CORS_NONE, CORSMode aCORSMode = CORS_NONE,
ReferrerPolicy aReferrerPolicy = mozilla::net::RP_Default, ReferrerPolicy aReferrerPolicy = mozilla::net::RP_Default,
@ -501,7 +502,7 @@ private:
// sheet was loaded from (may be null for inline sheets). aElement is the // sheet was loaded from (may be null for inline sheets). aElement is the
// owning element for this sheet. // owning element for this sheet.
nsresult PostLoadEvent(nsIURI* aURI, nsresult PostLoadEvent(nsIURI* aURI,
CSSStyleSheet* aSheet, StyleSheetHandle aSheet,
nsICSSLoaderObserver* aObserver, nsICSSLoaderObserver* aObserver,
bool aWasAlternate, bool aWasAlternate,
nsIStyleSheetLinkingElement* aElement); nsIStyleSheetLinkingElement* aElement);
@ -537,8 +538,9 @@ private:
LoadDataArray& aDatasToNotify); LoadDataArray& aDatasToNotify);
struct Sheets { struct Sheets {
nsRefPtrHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey, CSSStyleSheet> nsBaseHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey,
mCompleteSheets; StyleSheetHandle::RefPtr,
StyleSheetHandle> mCompleteSheets;
nsDataHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey, SheetLoadData*> nsDataHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey, SheetLoadData*>
mLoadingDatas; // weak refs mLoadingDatas; // weak refs
nsDataHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey, SheetLoadData*> nsDataHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey, SheetLoadData*>

View File

@ -96,36 +96,36 @@ ServoStyleSet::ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag,
// manage the set of style sheets in the style set // manage the set of style sheets in the style set
nsresult nsresult
ServoStyleSet::AppendStyleSheet(SheetType aType, ServoStyleSet::AppendStyleSheet(SheetType aType,
CSSStyleSheet* aSheet) ServoStyleSheet* aSheet)
{ {
MOZ_CRASH("stylo: not implemented"); MOZ_CRASH("stylo: not implemented");
} }
nsresult nsresult
ServoStyleSet::PrependStyleSheet(SheetType aType, ServoStyleSet::PrependStyleSheet(SheetType aType,
CSSStyleSheet* aSheet) ServoStyleSheet* aSheet)
{ {
MOZ_CRASH("stylo: not implemented"); MOZ_CRASH("stylo: not implemented");
} }
nsresult nsresult
ServoStyleSet::RemoveStyleSheet(SheetType aType, ServoStyleSet::RemoveStyleSheet(SheetType aType,
CSSStyleSheet* aSheet) ServoStyleSheet* aSheet)
{ {
MOZ_CRASH("stylo: not implemented"); MOZ_CRASH("stylo: not implemented");
} }
nsresult nsresult
ServoStyleSet::ReplaceSheets(SheetType aType, ServoStyleSet::ReplaceSheets(SheetType aType,
const nsTArray<RefPtr<CSSStyleSheet>>& aNewSheets) const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets)
{ {
MOZ_CRASH("stylo: not implemented"); MOZ_CRASH("stylo: not implemented");
} }
nsresult nsresult
ServoStyleSet::InsertStyleSheetBefore(SheetType aType, ServoStyleSet::InsertStyleSheetBefore(SheetType aType,
CSSStyleSheet* aNewSheet, ServoStyleSheet* aNewSheet,
CSSStyleSheet* aReferenceSheet) ServoStyleSheet* aReferenceSheet)
{ {
MOZ_CRASH("stylo: not implemented"); MOZ_CRASH("stylo: not implemented");
} }
@ -136,7 +136,7 @@ ServoStyleSet::SheetCount(SheetType aType) const
MOZ_CRASH("stylo: not implemented"); MOZ_CRASH("stylo: not implemented");
} }
CSSStyleSheet* ServoStyleSheet*
ServoStyleSet::StyleSheetAt(SheetType aType, ServoStyleSet::StyleSheetAt(SheetType aType,
int32_t aIndex) const int32_t aIndex) const
{ {
@ -144,13 +144,13 @@ ServoStyleSet::StyleSheetAt(SheetType aType,
} }
nsresult nsresult
ServoStyleSet::RemoveDocStyleSheet(CSSStyleSheet* aSheet) ServoStyleSet::RemoveDocStyleSheet(ServoStyleSheet* aSheet)
{ {
MOZ_CRASH("stylo: not implemented"); MOZ_CRASH("stylo: not implemented");
} }
nsresult nsresult
ServoStyleSet::AddDocStyleSheet(CSSStyleSheet* aSheet, ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet,
nsIDocument* aDocument) nsIDocument* aDocument)
{ {
MOZ_CRASH("stylo: not implemented"); MOZ_CRASH("stylo: not implemented");

View File

@ -20,6 +20,7 @@ namespace dom {
class Element; class Element;
} // namespace dom } // namespace dom
class CSSStyleSheet; class CSSStyleSheet;
class ServoStyleSheet;
} // namespace mozilla } // namespace mozilla
class nsStyleContext; class nsStyleContext;
class nsPresContext; class nsPresContext;
@ -69,20 +70,20 @@ public:
uint32_t aFlags = 0); uint32_t aFlags = 0);
// manage the set of style sheets in the style set // manage the set of style sheets in the style set
nsresult AppendStyleSheet(SheetType aType, CSSStyleSheet* aSheet); nsresult AppendStyleSheet(SheetType aType, ServoStyleSheet* aSheet);
nsresult PrependStyleSheet(SheetType aType, CSSStyleSheet* aSheet); nsresult PrependStyleSheet(SheetType aType, ServoStyleSheet* aSheet);
nsresult RemoveStyleSheet(SheetType aType, CSSStyleSheet* aSheet); nsresult RemoveStyleSheet(SheetType aType, ServoStyleSheet* aSheet);
nsresult ReplaceSheets(SheetType aType, nsresult ReplaceSheets(SheetType aType,
const nsTArray<RefPtr<CSSStyleSheet>>& aNewSheets); const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets);
nsresult InsertStyleSheetBefore(SheetType aType, nsresult InsertStyleSheetBefore(SheetType aType,
CSSStyleSheet* aNewSheet, ServoStyleSheet* aNewSheet,
CSSStyleSheet* aReferenceSheet); ServoStyleSheet* aReferenceSheet);
int32_t SheetCount(SheetType aType) const; int32_t SheetCount(SheetType aType) const;
CSSStyleSheet* StyleSheetAt(SheetType aType, int32_t aIndex) const; ServoStyleSheet* StyleSheetAt(SheetType aType, int32_t aIndex) const;
nsresult RemoveDocStyleSheet(CSSStyleSheet* aSheet); nsresult RemoveDocStyleSheet(ServoStyleSheet* aSheet);
nsresult AddDocStyleSheet(CSSStyleSheet* aSheet, nsIDocument* aDocument); nsresult AddDocStyleSheet(ServoStyleSheet* aSheet, nsIDocument* aDocument);
// check whether there is ::before/::after style for an element // check whether there is ::before/::after style for an element
already_AddRefed<nsStyleContext> already_AddRefed<nsStyleContext>

View File

@ -11,6 +11,7 @@
#include "mozilla/RefPtr.h" #include "mozilla/RefPtr.h"
#include "mozilla/SheetType.h" #include "mozilla/SheetType.h"
#include "mozilla/StyleBackendType.h" #include "mozilla/StyleBackendType.h"
#include "mozilla/StyleSheetHandle.h"
#include "nsChangeHint.h" #include "nsChangeHint.h"
#include "nsCSSPseudoElements.h" #include "nsCSSPseudoElements.h"
#include "nsTArray.h" #include "nsTArray.h"
@ -127,18 +128,18 @@ public:
inline already_AddRefed<nsStyleContext> inline already_AddRefed<nsStyleContext>
ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag, nsStyleContext* aParentContext, ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag, nsStyleContext* aParentContext,
uint32_t aFlags = 0); uint32_t aFlags = 0);
inline nsresult AppendStyleSheet(SheetType aType, CSSStyleSheet* aSheet); inline nsresult AppendStyleSheet(SheetType aType, StyleSheetHandle aSheet);
inline nsresult PrependStyleSheet(SheetType aType, CSSStyleSheet* aSheet); inline nsresult PrependStyleSheet(SheetType aType, StyleSheetHandle aSheet);
inline nsresult RemoveStyleSheet(SheetType aType, CSSStyleSheet* aSheet); inline nsresult RemoveStyleSheet(SheetType aType, StyleSheetHandle aSheet);
inline nsresult ReplaceSheets(SheetType aType, inline nsresult ReplaceSheets(SheetType aType,
const nsTArray<RefPtr<CSSStyleSheet>>& aNewSheets); const nsTArray<StyleSheetHandle::RefPtr>& aNewSheets);
inline nsresult InsertStyleSheetBefore(SheetType aType, inline nsresult InsertStyleSheetBefore(SheetType aType,
CSSStyleSheet* aNewSheet, StyleSheetHandle aNewSheet,
CSSStyleSheet* aReferenceSheet); StyleSheetHandle aReferenceSheet);
inline int32_t SheetCount(SheetType aType) const; inline int32_t SheetCount(SheetType aType) const;
inline CSSStyleSheet* StyleSheetAt(SheetType aType, int32_t aIndex) const; inline StyleSheetHandle StyleSheetAt(SheetType aType, int32_t aIndex) const;
inline nsresult RemoveDocStyleSheet(CSSStyleSheet* aSheet); inline nsresult RemoveDocStyleSheet(StyleSheetHandle aSheet);
inline nsresult AddDocStyleSheet(CSSStyleSheet* aSheet, nsIDocument* aDocument); inline nsresult AddDocStyleSheet(StyleSheetHandle aSheet, nsIDocument* aDocument);
inline already_AddRefed<nsStyleContext> inline already_AddRefed<nsStyleContext>
ProbePseudoElementStyle(dom::Element* aParentElement, ProbePseudoElementStyle(dom::Element* aParentElement,
mozilla::CSSPseudoElementType aType, mozilla::CSSPseudoElementType aType,

View File

@ -7,11 +7,19 @@
#ifndef mozilla_StyleSetHandleInlines_h #ifndef mozilla_StyleSetHandleInlines_h
#define mozilla_StyleSetHandleInlines_h #define mozilla_StyleSetHandleInlines_h
#include "mozilla/CSSStyleSheet.h"
#include "mozilla/ServoStyleSet.h" #include "mozilla/ServoStyleSet.h"
#include "mozilla/ServoStyleSheet.h"
#include "nsStyleSet.h" #include "nsStyleSet.h"
#define FORWARD(method_, args_) \ #define FORWARD_CONCRETE(method_, geckoargs_, servoargs_) \
return IsGecko() ? AsGecko()->method_ args_ : AsServo()->method_ args_; if (IsGecko()) { \
return AsGecko()->method_ geckoargs_; \
} else { \
return AsServo()->method_ servoargs_; \
}
#define FORWARD(method_, args_) FORWARD_CONCRETE(method_, args_, args_)
namespace mozilla { namespace mozilla {
@ -112,36 +120,54 @@ StyleSetHandle::Ptr::ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag,
// manage the set of style sheets in the style set // manage the set of style sheets in the style set
nsresult nsresult
StyleSetHandle::Ptr::AppendStyleSheet(SheetType aType, CSSStyleSheet* aSheet) StyleSetHandle::Ptr::AppendStyleSheet(SheetType aType, StyleSheetHandle aSheet)
{ {
FORWARD(AppendStyleSheet, (aType, aSheet)); FORWARD_CONCRETE(AppendStyleSheet, (aType, aSheet->AsGecko()),
(aType, aSheet->AsServo()));
} }
nsresult nsresult
StyleSetHandle::Ptr::PrependStyleSheet(SheetType aType, CSSStyleSheet* aSheet) StyleSetHandle::Ptr::PrependStyleSheet(SheetType aType, StyleSheetHandle aSheet)
{ {
FORWARD(PrependStyleSheet, (aType, aSheet)); FORWARD_CONCRETE(PrependStyleSheet, (aType, aSheet->AsGecko()),
(aType, aSheet->AsServo()));
} }
nsresult nsresult
StyleSetHandle::Ptr::RemoveStyleSheet(SheetType aType, CSSStyleSheet* aSheet) StyleSetHandle::Ptr::RemoveStyleSheet(SheetType aType, StyleSheetHandle aSheet)
{ {
FORWARD(RemoveStyleSheet, (aType, aSheet)); FORWARD_CONCRETE(RemoveStyleSheet, (aType, aSheet->AsGecko()),
(aType, aSheet->AsServo()));
} }
nsresult nsresult
StyleSetHandle::Ptr::ReplaceSheets(SheetType aType, StyleSetHandle::Ptr::ReplaceSheets(SheetType aType,
const nsTArray<RefPtr<CSSStyleSheet>>& aNewSheets) const nsTArray<StyleSheetHandle::RefPtr>& aNewSheets)
{ {
FORWARD(ReplaceSheets, (aType, aNewSheets)); if (IsGecko()) {
nsTArray<RefPtr<CSSStyleSheet>> newSheets(aNewSheets.Length());
for (auto& sheet : aNewSheets) {
newSheets.AppendElement(sheet->AsGecko());
}
return AsGecko()->ReplaceSheets(aType, newSheets);
} else {
nsTArray<RefPtr<ServoStyleSheet>> newSheets(aNewSheets.Length());
for (auto& sheet : aNewSheets) {
newSheets.AppendElement(sheet->AsServo());
}
return AsServo()->ReplaceSheets(aType, newSheets);
}
} }
nsresult nsresult
StyleSetHandle::Ptr::InsertStyleSheetBefore(SheetType aType, StyleSetHandle::Ptr::InsertStyleSheetBefore(SheetType aType,
CSSStyleSheet* aNewSheet, StyleSheetHandle aNewSheet,
CSSStyleSheet* aReferenceSheet) StyleSheetHandle aReferenceSheet)
{ {
FORWARD(InsertStyleSheetBefore, (aType, aNewSheet, aReferenceSheet)); FORWARD_CONCRETE(
InsertStyleSheetBefore,
(aType, aNewSheet->AsGecko(), aReferenceSheet->AsGecko()),
(aType, aReferenceSheet->AsServo(), aReferenceSheet->AsServo()));
} }
int32_t int32_t
@ -150,23 +176,25 @@ StyleSetHandle::Ptr::SheetCount(SheetType aType) const
FORWARD(SheetCount, (aType)); FORWARD(SheetCount, (aType));
} }
CSSStyleSheet* StyleSheetHandle
StyleSetHandle::Ptr::StyleSheetAt(SheetType aType, int32_t aIndex) const StyleSetHandle::Ptr::StyleSheetAt(SheetType aType, int32_t aIndex) const
{ {
FORWARD(StyleSheetAt, (aType, aIndex)); FORWARD(StyleSheetAt, (aType, aIndex));
} }
nsresult nsresult
StyleSetHandle::Ptr::RemoveDocStyleSheet(CSSStyleSheet* aSheet) StyleSetHandle::Ptr::RemoveDocStyleSheet(StyleSheetHandle aSheet)
{ {
FORWARD(RemoveDocStyleSheet, (aSheet)); FORWARD_CONCRETE(RemoveDocStyleSheet, (aSheet->AsGecko()),
(aSheet->AsServo()));
} }
nsresult nsresult
StyleSetHandle::Ptr::AddDocStyleSheet(CSSStyleSheet* aSheet, StyleSetHandle::Ptr::AddDocStyleSheet(StyleSheetHandle aSheet,
nsIDocument* aDocument) nsIDocument* aDocument)
{ {
FORWARD(AddDocStyleSheet, (aSheet, aDocument)); FORWARD_CONCRETE(AddDocStyleSheet, (aSheet->AsGecko(), aDocument),
(aSheet->AsServo(), aDocument));
} }
// check whether there is ::before/::after style for an element // check whether there is ::before/::after style for an element

View File

@ -9,14 +9,11 @@
#define nsICSSLoaderObserver_h___ #define nsICSSLoaderObserver_h___
#include "nsISupports.h" #include "nsISupports.h"
#include "mozilla/StyleSheetHandle.h"
#define NS_ICSSLOADEROBSERVER_IID \ #define NS_ICSSLOADEROBSERVER_IID \
{ 0x7eb90c74, 0xea0c, 0x4df5, \ { 0xf51fbf2c, 0xfe4b, 0x4a15, \
{0xa1, 0x5f, 0x95, 0xf0, 0x6a, 0x98, 0xb9, 0x40} } { 0xaf, 0x7e, 0x5e, 0x20, 0x64, 0x5f, 0xaf, 0x58 } }
namespace mozilla {
class CSSStyleSheet;
} // namespace mozilla
class nsICSSLoaderObserver : public nsISupports { class nsICSSLoaderObserver : public nsISupports {
public: public:
@ -37,7 +34,7 @@ public:
* as CSS, and doesn't indicate anything about the status of any child * as CSS, and doesn't indicate anything about the status of any child
* sheets of aSheet. * sheets of aSheet.
*/ */
NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet, NS_IMETHOD StyleSheetLoaded(mozilla::StyleSheetHandle aSheet,
bool aWasAlternate, bool aWasAlternate,
nsresult aStatus) = 0; nsresult aStatus) = 0;
}; };

View File

@ -10,6 +10,8 @@
#include "mozilla/CSSStyleSheet.h" #include "mozilla/CSSStyleSheet.h"
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#include "mozilla/css/Loader.h" #include "mozilla/css/Loader.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
@ -65,217 +67,185 @@ nsLayoutStylesheetCache::Observe(nsISupports* aSubject,
return NS_OK; return NS_OK;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::ScrollbarsSheet() nsLayoutStylesheetCache::ScrollbarsSheet()
{ {
EnsureGlobal(); if (!mScrollbarsSheet) {
if (!gStyleCache->mScrollbarsSheet) {
// Scrollbars don't need access to unsafe rules // Scrollbars don't need access to unsafe rules
LoadSheetURL("chrome://global/skin/scrollbars.css", LoadSheetURL("chrome://global/skin/scrollbars.css",
gStyleCache->mScrollbarsSheet, eAuthorSheetFeatures); mScrollbarsSheet, eAuthorSheetFeatures);
} }
return gStyleCache->mScrollbarsSheet; return mScrollbarsSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::FormsSheet() nsLayoutStylesheetCache::FormsSheet()
{ {
EnsureGlobal(); if (!mFormsSheet) {
if (!gStyleCache->mFormsSheet) {
// forms.css needs access to unsafe rules // forms.css needs access to unsafe rules
LoadSheetURL("resource://gre-resources/forms.css", LoadSheetURL("resource://gre-resources/forms.css",
gStyleCache->mFormsSheet, eAgentSheetFeatures); mFormsSheet, eAgentSheetFeatures);
} }
return gStyleCache->mFormsSheet; return mFormsSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::NumberControlSheet() nsLayoutStylesheetCache::NumberControlSheet()
{ {
EnsureGlobal();
if (!sNumberControlEnabled) { if (!sNumberControlEnabled) {
return nullptr; return nullptr;
} }
if (!gStyleCache->mNumberControlSheet) { if (!mNumberControlSheet) {
LoadSheetURL("resource://gre-resources/number-control.css", LoadSheetURL("resource://gre-resources/number-control.css",
gStyleCache->mNumberControlSheet, eAgentSheetFeatures); mNumberControlSheet, eAgentSheetFeatures);
} }
return gStyleCache->mNumberControlSheet; return mNumberControlSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::UserContentSheet() nsLayoutStylesheetCache::UserContentSheet()
{ {
EnsureGlobal(); return mUserContentSheet;
return gStyleCache->mUserContentSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::UserChromeSheet() nsLayoutStylesheetCache::UserChromeSheet()
{ {
EnsureGlobal(); return mUserChromeSheet;
return gStyleCache->mUserChromeSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::UASheet() nsLayoutStylesheetCache::UASheet()
{ {
EnsureGlobal(); if (!mUASheet) {
if (!gStyleCache->mUASheet) {
LoadSheetURL("resource://gre-resources/ua.css", LoadSheetURL("resource://gre-resources/ua.css",
gStyleCache->mUASheet, eAgentSheetFeatures); mUASheet, eAgentSheetFeatures);
} }
return gStyleCache->mUASheet; return mUASheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::HTMLSheet() nsLayoutStylesheetCache::HTMLSheet()
{ {
EnsureGlobal(); return mHTMLSheet;
return gStyleCache->mHTMLSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::MinimalXULSheet() nsLayoutStylesheetCache::MinimalXULSheet()
{ {
EnsureGlobal(); return mMinimalXULSheet;
return gStyleCache->mMinimalXULSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::XULSheet() nsLayoutStylesheetCache::XULSheet()
{ {
EnsureGlobal(); return mXULSheet;
return gStyleCache->mXULSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::QuirkSheet() nsLayoutStylesheetCache::QuirkSheet()
{ {
EnsureGlobal(); return mQuirkSheet;
return gStyleCache->mQuirkSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::SVGSheet() nsLayoutStylesheetCache::SVGSheet()
{ {
EnsureGlobal(); return mSVGSheet;
return gStyleCache->mSVGSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::MathMLSheet() nsLayoutStylesheetCache::MathMLSheet()
{ {
EnsureGlobal(); if (!mMathMLSheet) {
if (!gStyleCache->mMathMLSheet) {
LoadSheetURL("resource://gre-resources/mathml.css", LoadSheetURL("resource://gre-resources/mathml.css",
gStyleCache->mMathMLSheet, eAgentSheetFeatures); mMathMLSheet, eAgentSheetFeatures);
} }
return gStyleCache->mMathMLSheet; return mMathMLSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::CounterStylesSheet() nsLayoutStylesheetCache::CounterStylesSheet()
{ {
EnsureGlobal(); return mCounterStylesSheet;
return gStyleCache->mCounterStylesSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::NoScriptSheet() nsLayoutStylesheetCache::NoScriptSheet()
{ {
EnsureGlobal(); if (!mNoScriptSheet) {
if (!gStyleCache->mNoScriptSheet) {
LoadSheetURL("resource://gre-resources/noscript.css", LoadSheetURL("resource://gre-resources/noscript.css",
gStyleCache->mNoScriptSheet, eAgentSheetFeatures); mNoScriptSheet, eAgentSheetFeatures);
} }
return gStyleCache->mNoScriptSheet; return mNoScriptSheet;
} }
CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::NoFramesSheet() nsLayoutStylesheetCache::NoFramesSheet()
{ {
EnsureGlobal(); if (!mNoFramesSheet) {
if (!gStyleCache->mNoFramesSheet) {
LoadSheetURL("resource://gre-resources/noframes.css", LoadSheetURL("resource://gre-resources/noframes.css",
gStyleCache->mNoFramesSheet, eAgentSheetFeatures); mNoFramesSheet, eAgentSheetFeatures);
} }
return gStyleCache->mNoFramesSheet; return mNoFramesSheet;
} }
/* static */ CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::ChromePreferenceSheet(nsPresContext* aPresContext) nsLayoutStylesheetCache::ChromePreferenceSheet(nsPresContext* aPresContext)
{ {
EnsureGlobal(); if (!mChromePreferenceSheet) {
BuildPreferenceSheet(mChromePreferenceSheet, aPresContext);
if (!gStyleCache->mChromePreferenceSheet) {
gStyleCache->BuildPreferenceSheet(gStyleCache->mChromePreferenceSheet,
aPresContext);
} }
return gStyleCache->mChromePreferenceSheet; return mChromePreferenceSheet;
} }
/* static */ CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::ContentPreferenceSheet(nsPresContext* aPresContext) nsLayoutStylesheetCache::ContentPreferenceSheet(nsPresContext* aPresContext)
{ {
EnsureGlobal(); if (!mContentPreferenceSheet) {
BuildPreferenceSheet(mContentPreferenceSheet, aPresContext);
if (!gStyleCache->mContentPreferenceSheet) {
gStyleCache->BuildPreferenceSheet(gStyleCache->mContentPreferenceSheet,
aPresContext);
} }
return gStyleCache->mContentPreferenceSheet; return mContentPreferenceSheet;
} }
/* static */ CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::ContentEditableSheet() nsLayoutStylesheetCache::ContentEditableSheet()
{ {
EnsureGlobal(); if (!mContentEditableSheet) {
if (!gStyleCache->mContentEditableSheet) {
LoadSheetURL("resource://gre/res/contenteditable.css", LoadSheetURL("resource://gre/res/contenteditable.css",
gStyleCache->mContentEditableSheet, eAgentSheetFeatures); mContentEditableSheet, eAgentSheetFeatures);
} }
return gStyleCache->mContentEditableSheet; return mContentEditableSheet;
} }
/* static */ CSSStyleSheet* StyleSheetHandle
nsLayoutStylesheetCache::DesignModeSheet() nsLayoutStylesheetCache::DesignModeSheet()
{ {
EnsureGlobal(); if (!mDesignModeSheet) {
if (!gStyleCache->mDesignModeSheet) {
LoadSheetURL("resource://gre/res/designmode.css", LoadSheetURL("resource://gre/res/designmode.css",
gStyleCache->mDesignModeSheet, eAgentSheetFeatures); mDesignModeSheet, eAgentSheetFeatures);
} }
return gStyleCache->mDesignModeSheet; return mDesignModeSheet;
} }
void void
nsLayoutStylesheetCache::Shutdown() nsLayoutStylesheetCache::Shutdown()
{ {
NS_IF_RELEASE(gCSSLoader); NS_IF_RELEASE(gCSSLoader);
gStyleCache = nullptr; gStyleCache_Gecko = nullptr;
gStyleCache_Servo = nullptr;
} }
MOZ_DEFINE_MALLOC_SIZE_OF(LayoutStylesheetCacheMallocSizeOf) MOZ_DEFINE_MALLOC_SIZE_OF(LayoutStylesheetCacheMallocSizeOf)
@ -325,7 +295,8 @@ nsLayoutStylesheetCache::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
return n; return n;
} }
nsLayoutStylesheetCache::nsLayoutStylesheetCache() nsLayoutStylesheetCache::nsLayoutStylesheetCache(StyleBackendType aType)
: mBackendType(aType)
{ {
nsCOMPtr<nsIObserverService> obsSvc = nsCOMPtr<nsIObserverService> obsSvc =
mozilla::services::GetObserverService(); mozilla::services::GetObserverService();
@ -363,7 +334,6 @@ nsLayoutStylesheetCache::nsLayoutStylesheetCache()
nsLayoutStylesheetCache::~nsLayoutStylesheetCache() nsLayoutStylesheetCache::~nsLayoutStylesheetCache()
{ {
mozilla::UnregisterWeakMemoryReporter(this); mozilla::UnregisterWeakMemoryReporter(this);
MOZ_ASSERT(!gStyleCache);
} }
void void
@ -372,28 +342,38 @@ nsLayoutStylesheetCache::InitMemoryReporter()
mozilla::RegisterWeakMemoryReporter(this); mozilla::RegisterWeakMemoryReporter(this);
} }
void /* static */ nsLayoutStylesheetCache*
nsLayoutStylesheetCache::EnsureGlobal() nsLayoutStylesheetCache::For(StyleBackendType aType)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
if (gStyleCache) return; bool mustInit = !gStyleCache_Gecko && !gStyleCache_Servo;
auto& cache = aType == StyleBackendType::Gecko ? gStyleCache_Gecko :
gStyleCache_Servo;
gStyleCache = new nsLayoutStylesheetCache(); if (!cache) {
cache = new nsLayoutStylesheetCache(aType);
cache->InitMemoryReporter();
}
gStyleCache->InitMemoryReporter(); if (mustInit) {
// Initialization that only needs to be done once for both
// nsLayoutStylesheetCaches.
Preferences::AddBoolVarCache(&sNumberControlEnabled, NUMBER_CONTROL_PREF, Preferences::AddBoolVarCache(&sNumberControlEnabled, NUMBER_CONTROL_PREF,
true); true);
// For each pref that controls a CSS feature that a UA style sheet depends // For each pref that controls a CSS feature that a UA style sheet depends
// on (such as a pref that enables a property that a UA style sheet uses), // on (such as a pref that enables a property that a UA style sheet uses),
// register DependentPrefChanged as a callback to ensure that the relevant // register DependentPrefChanged as a callback to ensure that the relevant
// style sheets will be re-parsed. // style sheets will be re-parsed.
// Preferences::RegisterCallback(&DependentPrefChanged, // Preferences::RegisterCallback(&DependentPrefChanged,
// "layout.css.example-pref.enabled"); // "layout.css.example-pref.enabled");
Preferences::RegisterCallback(&DependentPrefChanged, Preferences::RegisterCallback(&DependentPrefChanged,
"layout.css.grid.enabled"); "layout.css.grid.enabled");
}
return cache;
} }
void void
@ -428,7 +408,7 @@ nsLayoutStylesheetCache::InitFromProfile()
/* static */ void /* static */ void
nsLayoutStylesheetCache::LoadSheetURL(const char* aURL, nsLayoutStylesheetCache::LoadSheetURL(const char* aURL,
RefPtr<CSSStyleSheet>& aSheet, StyleSheetHandle::RefPtr& aSheet,
SheetParsingMode aParsingMode) SheetParsingMode aParsingMode)
{ {
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
@ -441,7 +421,7 @@ nsLayoutStylesheetCache::LoadSheetURL(const char* aURL,
void void
nsLayoutStylesheetCache::LoadSheetFile(nsIFile* aFile, nsLayoutStylesheetCache::LoadSheetFile(nsIFile* aFile,
RefPtr<CSSStyleSheet>& aSheet, StyleSheetHandle::RefPtr& aSheet,
SheetParsingMode aParsingMode) SheetParsingMode aParsingMode)
{ {
bool exists = false; bool exists = false;
@ -747,7 +727,7 @@ ErrorLoadingBuiltinSheet(nsIURI* aURI, const char* aMsg)
void void
nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI, nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI,
RefPtr<CSSStyleSheet>& aSheet, StyleSheetHandle::RefPtr& aSheet,
SheetParsingMode aParsingMode) SheetParsingMode aParsingMode)
{ {
if (!aURI) { if (!aURI) {
@ -768,8 +748,7 @@ nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI,
#ifdef MOZ_CRASHREPORTER #ifdef MOZ_CRASHREPORTER
nsZipArchive::sFileCorruptedReason = nullptr; nsZipArchive::sFileCorruptedReason = nullptr;
#endif #endif
nsresult rv = gCSSLoader->LoadSheetSync(aURI, aParsingMode, true, nsresult rv = gCSSLoader->LoadSheetSync(aURI, aParsingMode, true, &aSheet);
getter_AddRefs(aSheet));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
ErrorLoadingBuiltinSheet(aURI, ErrorLoadingBuiltinSheet(aURI,
nsPrintfCString("LoadSheetSync failed with error %x", rv).get()); nsPrintfCString("LoadSheetSync failed with error %x", rv).get());
@ -777,43 +756,78 @@ nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI,
} }
/* static */ void /* static */ void
nsLayoutStylesheetCache::InvalidateSheet(RefPtr<CSSStyleSheet>& aSheet) nsLayoutStylesheetCache::InvalidateSheet(StyleSheetHandle::RefPtr* aGeckoSheet,
StyleSheetHandle::RefPtr* aServoSheet)
{ {
MOZ_ASSERT(gCSSLoader, "pref changed before we loaded a sheet?"); MOZ_ASSERT(gCSSLoader, "pref changed before we loaded a sheet?");
if (aSheet) { // Make sure sheets have the expected types
gCSSLoader->ObsoleteSheet(aSheet->GetSheetURI()); MOZ_ASSERT(!aGeckoSheet || (*aGeckoSheet)->IsGecko());
aSheet = nullptr; MOZ_ASSERT(!aServoSheet || (*aServoSheet)->IsServo());
// Make sure the URIs match
MOZ_ASSERT(!aGeckoSheet || !aServoSheet ||
(*aGeckoSheet)->GetSheetURI() == (*aServoSheet)->GetSheetURI(),
"Sheets passed should have the same URI");
nsIURI* uri;
if (aGeckoSheet && *aGeckoSheet) {
uri = (*aGeckoSheet)->GetSheetURI();
} else if (aServoSheet && *aServoSheet) {
uri = (*aServoSheet)->GetSheetURI();
} else {
return;
}
gCSSLoader->ObsoleteSheet(uri);
if (aGeckoSheet) {
*aGeckoSheet = nullptr;
}
if (aServoSheet) {
*aServoSheet = nullptr;
} }
} }
/* static */ void /* static */ void
nsLayoutStylesheetCache::DependentPrefChanged(const char* aPref, void* aData) nsLayoutStylesheetCache::DependentPrefChanged(const char* aPref, void* aData)
{ {
MOZ_ASSERT(gStyleCache, "pref changed after shutdown?"); MOZ_ASSERT(gStyleCache_Gecko || gStyleCache_Servo,
"pref changed after shutdown?");
// Cause any UA style sheets whose parsing depends on the value of prefs // Cause any UA style sheets whose parsing depends on the value of prefs
// to be re-parsed by dropping the sheet from gCSSLoader's cache then // to be re-parsed by dropping the sheet from gCSSLoader's cache then
// setting our cached sheet pointer to null. This will only work for sheets // setting our cached sheet pointer to null. This will only work for sheets
// that are loaded lazily. // that are loaded lazily.
InvalidateSheet(gStyleCache->mUASheet); // for layout.css.grid.enabled
#define INVALIDATE(sheet_) \
InvalidateSheet(gStyleCache_Gecko ? &gStyleCache_Gecko->sheet_ : nullptr, \
gStyleCache_Servo ? &gStyleCache_Servo->sheet_ : nullptr);
INVALIDATE(mUASheet); // for layout.css.grid.enabled
#undef INVALIDATE
} }
/* static */ void /* static */ void
nsLayoutStylesheetCache::InvalidatePreferenceSheets() nsLayoutStylesheetCache::InvalidatePreferenceSheets()
{ {
if (!gStyleCache) { if (gStyleCache_Gecko) {
return; gStyleCache_Gecko->mContentPreferenceSheet = nullptr;
gStyleCache_Gecko->mChromePreferenceSheet = nullptr;
}
if (gStyleCache_Servo) {
gStyleCache_Servo->mContentPreferenceSheet = nullptr;
gStyleCache_Servo->mChromePreferenceSheet = nullptr;
} }
gStyleCache->mContentPreferenceSheet = nullptr;
gStyleCache->mChromePreferenceSheet = nullptr;
} }
void void
nsLayoutStylesheetCache::BuildPreferenceSheet(RefPtr<CSSStyleSheet>& aSheet, nsLayoutStylesheetCache::BuildPreferenceSheet(StyleSheetHandle::RefPtr& aSheet,
nsPresContext* aPresContext) nsPresContext* aPresContext)
{ {
if (mBackendType == StyleBackendType::Servo) {
MOZ_CRASH("not implemented");
}
aSheet = new CSSStyleSheet(CORS_NONE, mozilla::net::RP_Default); aSheet = new CSSStyleSheet(CORS_NONE, mozilla::net::RP_Default);
aSheet->SetParsingMode(eAgentSheetFeatures); aSheet->SetParsingMode(eAgentSheetFeatures);
@ -909,13 +923,16 @@ nsLayoutStylesheetCache::BuildPreferenceSheet(RefPtr<CSSStyleSheet>& aSheet,
"kPreallocSize should be big enough to build preference style " "kPreallocSize should be big enough to build preference style "
"sheet without reallocation"); "sheet without reallocation");
aSheet->ReparseSheet(sheetText); aSheet->AsGecko()->ReparseSheet(sheetText);
#undef NS_GET_R_G_B #undef NS_GET_R_G_B
} }
mozilla::StaticRefPtr<nsLayoutStylesheetCache> mozilla::StaticRefPtr<nsLayoutStylesheetCache>
nsLayoutStylesheetCache::gStyleCache; nsLayoutStylesheetCache::gStyleCache_Gecko;
mozilla::StaticRefPtr<nsLayoutStylesheetCache>
nsLayoutStylesheetCache::gStyleCache_Servo;
mozilla::css::Loader* mozilla::css::Loader*
nsLayoutStylesheetCache::gCSSLoader = nullptr; nsLayoutStylesheetCache::gCSSLoader = nullptr;

View File

@ -13,6 +13,7 @@
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "mozilla/StaticPtr.h" #include "mozilla/StaticPtr.h"
#include "mozilla/StyleBackendType.h"
#include "mozilla/css/Loader.h" #include "mozilla/css/Loader.h"
class nsIFile; class nsIFile;
@ -30,27 +31,37 @@ class nsLayoutStylesheetCache final
NS_DECL_NSIOBSERVER NS_DECL_NSIOBSERVER
NS_DECL_NSIMEMORYREPORTER NS_DECL_NSIMEMORYREPORTER
static mozilla::CSSStyleSheet* ScrollbarsSheet(); /**
static mozilla::CSSStyleSheet* FormsSheet(); * Returns the nsLayoutStylesheetCache for the given style backend type.
* Callers should pass in a value for aType that matches the style system
* backend type for the style set in use. (A process may call For
* and obtain nsLayoutStylesheetCache objects for both backend types,
* and a particular UA style sheet might be cached in both, one or neither
* nsLayoutStylesheetCache.)
*/
static nsLayoutStylesheetCache* For(mozilla::StyleBackendType aType);
mozilla::StyleSheetHandle ScrollbarsSheet();
mozilla::StyleSheetHandle FormsSheet();
// This function is expected to return nullptr when the dom.forms.number // This function is expected to return nullptr when the dom.forms.number
// pref is disabled. // pref is disabled.
static mozilla::CSSStyleSheet* NumberControlSheet(); mozilla::StyleSheetHandle NumberControlSheet();
static mozilla::CSSStyleSheet* UserContentSheet(); mozilla::StyleSheetHandle UserContentSheet();
static mozilla::CSSStyleSheet* UserChromeSheet(); mozilla::StyleSheetHandle UserChromeSheet();
static mozilla::CSSStyleSheet* UASheet(); mozilla::StyleSheetHandle UASheet();
static mozilla::CSSStyleSheet* HTMLSheet(); mozilla::StyleSheetHandle HTMLSheet();
static mozilla::CSSStyleSheet* MinimalXULSheet(); mozilla::StyleSheetHandle MinimalXULSheet();
static mozilla::CSSStyleSheet* XULSheet(); mozilla::StyleSheetHandle XULSheet();
static mozilla::CSSStyleSheet* QuirkSheet(); mozilla::StyleSheetHandle QuirkSheet();
static mozilla::CSSStyleSheet* SVGSheet(); mozilla::StyleSheetHandle SVGSheet();
static mozilla::CSSStyleSheet* MathMLSheet(); mozilla::StyleSheetHandle MathMLSheet();
static mozilla::CSSStyleSheet* CounterStylesSheet(); mozilla::StyleSheetHandle CounterStylesSheet();
static mozilla::CSSStyleSheet* NoScriptSheet(); mozilla::StyleSheetHandle NoScriptSheet();
static mozilla::CSSStyleSheet* NoFramesSheet(); mozilla::StyleSheetHandle NoFramesSheet();
static mozilla::CSSStyleSheet* ChromePreferenceSheet(nsPresContext* aPresContext); mozilla::StyleSheetHandle ChromePreferenceSheet(nsPresContext* aPresContext);
static mozilla::CSSStyleSheet* ContentPreferenceSheet(nsPresContext* aPresContext); mozilla::StyleSheetHandle ContentPreferenceSheet(nsPresContext* aPresContext);
static mozilla::CSSStyleSheet* ContentEditableSheet(); mozilla::StyleSheetHandle ContentEditableSheet();
static mozilla::CSSStyleSheet* DesignModeSheet(); mozilla::StyleSheetHandle DesignModeSheet();
static void InvalidatePreferenceSheets(); static void InvalidatePreferenceSheets();
@ -59,46 +70,48 @@ class nsLayoutStylesheetCache final
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
private: private:
nsLayoutStylesheetCache(); explicit nsLayoutStylesheetCache(mozilla::StyleBackendType aImpl);
~nsLayoutStylesheetCache(); ~nsLayoutStylesheetCache();
static void EnsureGlobal();
void InitFromProfile(); void InitFromProfile();
void InitMemoryReporter(); void InitMemoryReporter();
static void LoadSheetURL(const char* aURL, static void LoadSheetURL(const char* aURL,
RefPtr<mozilla::CSSStyleSheet>& aSheet, mozilla::StyleSheetHandle::RefPtr& aSheet,
mozilla::css::SheetParsingMode aParsingMode); mozilla::css::SheetParsingMode aParsingMode);
static void LoadSheetFile(nsIFile* aFile, static void LoadSheetFile(nsIFile* aFile,
RefPtr<mozilla::CSSStyleSheet>& aSheet, mozilla::StyleSheetHandle::RefPtr& aSheet,
mozilla::css::SheetParsingMode aParsingMode); mozilla::css::SheetParsingMode aParsingMode);
static void LoadSheet(nsIURI* aURI, RefPtr<mozilla::CSSStyleSheet>& aSheet, static void LoadSheet(nsIURI* aURI, mozilla::StyleSheetHandle::RefPtr& aSheet,
mozilla::css::SheetParsingMode aParsingMode); mozilla::css::SheetParsingMode aParsingMode);
static void InvalidateSheet(RefPtr<mozilla::CSSStyleSheet>& aSheet); static void InvalidateSheet(mozilla::StyleSheetHandle::RefPtr* aGeckoSheet,
mozilla::StyleSheetHandle::RefPtr* aServoSheet);
static void DependentPrefChanged(const char* aPref, void* aData); static void DependentPrefChanged(const char* aPref, void* aData);
void BuildPreferenceSheet(RefPtr<mozilla::CSSStyleSheet>& aSheet, void BuildPreferenceSheet(mozilla::StyleSheetHandle::RefPtr& aSheet,
nsPresContext* aPresContext); nsPresContext* aPresContext);
static mozilla::StaticRefPtr<nsLayoutStylesheetCache> gStyleCache; static mozilla::StaticRefPtr<nsLayoutStylesheetCache> gStyleCache_Gecko;
static mozilla::StaticRefPtr<nsLayoutStylesheetCache> gStyleCache_Servo;
static mozilla::css::Loader* gCSSLoader; static mozilla::css::Loader* gCSSLoader;
RefPtr<mozilla::CSSStyleSheet> mChromePreferenceSheet; mozilla::StyleBackendType mBackendType;
RefPtr<mozilla::CSSStyleSheet> mContentEditableSheet; mozilla::StyleSheetHandle::RefPtr mChromePreferenceSheet;
RefPtr<mozilla::CSSStyleSheet> mContentPreferenceSheet; mozilla::StyleSheetHandle::RefPtr mContentEditableSheet;
RefPtr<mozilla::CSSStyleSheet> mCounterStylesSheet; mozilla::StyleSheetHandle::RefPtr mContentPreferenceSheet;
RefPtr<mozilla::CSSStyleSheet> mDesignModeSheet; mozilla::StyleSheetHandle::RefPtr mCounterStylesSheet;
RefPtr<mozilla::CSSStyleSheet> mFormsSheet; mozilla::StyleSheetHandle::RefPtr mDesignModeSheet;
RefPtr<mozilla::CSSStyleSheet> mHTMLSheet; mozilla::StyleSheetHandle::RefPtr mFormsSheet;
RefPtr<mozilla::CSSStyleSheet> mMathMLSheet; mozilla::StyleSheetHandle::RefPtr mHTMLSheet;
RefPtr<mozilla::CSSStyleSheet> mMinimalXULSheet; mozilla::StyleSheetHandle::RefPtr mMathMLSheet;
RefPtr<mozilla::CSSStyleSheet> mNoFramesSheet; mozilla::StyleSheetHandle::RefPtr mMinimalXULSheet;
RefPtr<mozilla::CSSStyleSheet> mNoScriptSheet; mozilla::StyleSheetHandle::RefPtr mNoFramesSheet;
RefPtr<mozilla::CSSStyleSheet> mNumberControlSheet; mozilla::StyleSheetHandle::RefPtr mNoScriptSheet;
RefPtr<mozilla::CSSStyleSheet> mQuirkSheet; mozilla::StyleSheetHandle::RefPtr mNumberControlSheet;
RefPtr<mozilla::CSSStyleSheet> mSVGSheet; mozilla::StyleSheetHandle::RefPtr mQuirkSheet;
RefPtr<mozilla::CSSStyleSheet> mScrollbarsSheet; mozilla::StyleSheetHandle::RefPtr mSVGSheet;
RefPtr<mozilla::CSSStyleSheet> mUASheet; mozilla::StyleSheetHandle::RefPtr mScrollbarsSheet;
RefPtr<mozilla::CSSStyleSheet> mUserChromeSheet; mozilla::StyleSheetHandle::RefPtr mUASheet;
RefPtr<mozilla::CSSStyleSheet> mUserContentSheet; mozilla::StyleSheetHandle::RefPtr mUserChromeSheet;
RefPtr<mozilla::CSSStyleSheet> mXULSheet; mozilla::StyleSheetHandle::RefPtr mUserContentSheet;
mozilla::StyleSheetHandle::RefPtr mXULSheet;
}; };
#endif #endif

View File

@ -19,6 +19,8 @@
#include "nsDeviceContext.h" #include "nsDeviceContext.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
using namespace mozilla; using namespace mozilla;

View File

@ -745,11 +745,15 @@ nsStyleSet::AddDocStyleSheet(CSSStyleSheet* aSheet, nsIDocument* aDocument)
if (sheetDocIndex < 0) { if (sheetDocIndex < 0) {
if (sheetService) { if (sheetService) {
auto& authorSheets = *sheetService->AuthorStyleSheets(); auto& authorSheets = *sheetService->AuthorStyleSheets();
if (authorSheets.IndexOf(sheet) != authorSheets.NoIndex) { StyleSheetHandle handle = sheet;
if (authorSheets.IndexOf(handle) != authorSheets.NoIndex) {
break; break;
} }
} }
if (sheet == aDocument->FirstAdditionalAuthorSheet()) { MOZ_ASSERT(!aDocument->FirstAdditionalAuthorSheet() ||
aDocument->FirstAdditionalAuthorSheet()->IsGecko(),
"why do we have a ServoStyleSheet for an nsStyleSet?");
if (sheet == aDocument->FirstAdditionalAuthorSheet()->GetAsGecko()) {
break; break;
} }
} }
@ -764,6 +768,23 @@ nsStyleSet::AddDocStyleSheet(CSSStyleSheet* aSheet, nsIDocument* aDocument)
return DirtyRuleProcessors(type); return DirtyRuleProcessors(type);
} }
void
nsStyleSet::AppendAllXBLStyleSheets(nsTArray<mozilla::CSSStyleSheet*>& aArray) const
{
if (mBindingManager) {
// XXXheycam stylo: AppendAllSheets will need to be able to return either
// CSSStyleSheets or ServoStyleSheets, on request (and then here requesting
// CSSStyleSheets).
AutoTArray<StyleSheetHandle, 32> sheets;
mBindingManager->AppendAllSheets(sheets);
for (StyleSheetHandle handle : sheets) {
MOZ_ASSERT(handle->IsGecko(), "stylo: AppendAllSheets shouldn't give us "
"ServoStyleSheets yet");
aArray.AppendElement(handle->AsGecko());
}
}
}
nsresult nsresult
nsStyleSet::RemoveDocStyleSheet(CSSStyleSheet* aSheet) nsStyleSet::RemoveDocStyleSheet(CSSStyleSheet* aSheet)
{ {
@ -2497,7 +2518,16 @@ nsStyleSet::EnsureUniqueInnerOnCSSSheets()
} }
if (mBindingManager) { if (mBindingManager) {
mBindingManager->AppendAllSheets(queue); AutoTArray<StyleSheetHandle, 32> sheets;
// XXXheycam stylo: AppendAllSheets will need to be able to return either
// CSSStyleSheets or ServoStyleSheets, on request (and then here requesting
// CSSStyleSheets).
mBindingManager->AppendAllSheets(sheets);
for (StyleSheetHandle sheet : sheets) {
MOZ_ASSERT(sheet->IsGecko(), "stylo: AppendAllSheets shouldn't give us "
"ServoStyleSheets yet");
queue.AppendElement(sheet->AsGecko());
}
} }
while (!queue.IsEmpty()) { while (!queue.IsEmpty()) {

View File

@ -338,11 +338,7 @@ class nsStyleSet final
return mSheets[aType][aIndex]; return mSheets[aType][aIndex];
} }
void AppendAllXBLStyleSheets(nsTArray<mozilla::CSSStyleSheet*>& aArray) const { void AppendAllXBLStyleSheets(nsTArray<mozilla::CSSStyleSheet*>& aArray) const;
if (mBindingManager) {
mBindingManager->AppendAllSheets(aArray);
}
}
nsresult RemoveDocStyleSheet(mozilla::CSSStyleSheet* aSheet); nsresult RemoveDocStyleSheet(mozilla::CSSStyleSheet* aSheet);
nsresult AddDocStyleSheet(mozilla::CSSStyleSheet* aSheet, nsresult AddDocStyleSheet(mozilla::CSSStyleSheet* aSheet,