Bug 1290276 Part 5 - Add XBL stylesheets to ServoStyleSet so that it can be used in servo cascading later.
In gecko style backend, nsXBLPrototypeResources calls GatherRuleProcessor()
after all the XBL stylesheets are loaded. We use ServoStyleSet to implement
the similar functionality for stylo.
MozReview-Commit-ID: 431XGFALtDY
--- a/dom/xbl/nsXBLPrototypeResources.cpp
+++ b/dom/xbl/nsXBLPrototypeResources.cpp
@@ -33,16 +33,19 @@ nsXBLPrototypeResources::nsXBLPrototypeR
}
nsXBLPrototypeResources::~nsXBLPrototypeResources()
{
MOZ_COUNT_DTOR(nsXBLPrototypeResources);
if (mLoader) {
mLoader->mResources = nullptr;
}
+ if (mServoStyleSet) {
+ mServoStyleSet->Shutdown();
+ }
}
void
nsXBLPrototypeResources::AddResource(nsIAtom* aResourceType, const nsAString& aSrc)
{
if (mLoader)
mLoader->AddResource(aResourceType, aSrc);
}
@@ -157,16 +160,32 @@ nsXBLPrototypeResources::GatherRuleProce
}
mRuleProcessor = new nsCSSRuleProcessor(Move(sheets),
SheetType::Doc,
nullptr,
mRuleProcessor);
}
void
+nsXBLPrototypeResources::ComputeServoStyleSet(nsPresContext* aPresContext)
+{
+ mServoStyleSet.reset(new ServoStyleSet());
+ mServoStyleSet->Init(aPresContext);
+ for (StyleSheet* sheet : mStyleSheetList) {
+ MOZ_ASSERT(sheet->IsServo(),
+ "This should only be called with Servo-flavored style backend!");
+ // The sheets aren't document sheets, but we need to decide a particular
+ // SheetType so that we can pull them out from the right place on the
+ // Servo side.
+ mServoStyleSet->AppendStyleSheet(SheetType::Doc, sheet->AsServo());
+ }
+ mServoStyleSet->UpdateStylistIfNeeded();
+}
+
+void
nsXBLPrototypeResources::AppendStyleSheet(StyleSheet* aSheet)
{
mStyleSheetList.AppendElement(aSheet);
}
void
nsXBLPrototypeResources::RemoveStyleSheet(StyleSheet* aSheet)
{
--- a/dom/xbl/nsXBLPrototypeResources.h
+++ b/dom/xbl/nsXBLPrototypeResources.h
@@ -13,16 +13,17 @@
class nsCSSRuleProcessor;
class nsIAtom;
class nsIContent;
class nsXBLPrototypeBinding;
class nsXBLResourceLoader;
namespace mozilla {
class CSSStyleSheet;
+class ServoStyleSet;
} // namespace mozilla
// *********************************************************************/
// The XBLPrototypeResources class
class nsXBLPrototypeResources
{
public:
@@ -53,20 +54,31 @@ public:
* Recreates mRuleProcessor to represent the current list of style sheets
* stored in mStyleSheetList. (Named GatherRuleProcessor to parallel
* nsStyleSet::GatherRuleProcessors.)
*/
void GatherRuleProcessor();
nsCSSRuleProcessor* GetRuleProcessor() const { return mRuleProcessor; }
+ // Updates the ServoStyleSet object that holds the result of cascading the
+ // sheets in mStyleSheetList. Equivalent to GatherRuleProcessor(), but for
+ // the Servo style backend.
+ void ComputeServoStyleSet(nsPresContext* aPresContext);
+
private:
// A loader object. Exists only long enough to load resources, and then it dies.
RefPtr<nsXBLResourceLoader> mLoader;
// A list of loaded stylesheets for this binding.
nsTArray<RefPtr<mozilla::StyleSheet>> mStyleSheetList;
// The list of stylesheets converted to a rule processor.
RefPtr<nsCSSRuleProcessor> mRuleProcessor;
+
+ // The result of cascading the XBL style sheets like mRuleProcessor, but
+ // for the Servo style backend.
+ // XXX: We might want to design a better representation for the result of
+ // cascading the XBL style sheets, like a collection of SelectorMaps.
+ mozilla::UniquePtr<mozilla::ServoStyleSet> mServoStyleSet;
};
#endif
--- a/dom/xbl/nsXBLResourceLoader.cpp
+++ b/dom/xbl/nsXBLResourceLoader.cpp
@@ -90,22 +90,22 @@ nsXBLResourceLoader::LoadResources(nsICo
mInLoadResourcesFunc = false;
return mPendingSheets == 0;
}
mLoadingResources = true;
// Declare our loaders.
nsCOMPtr<nsIDocument> doc = mBinding->XBLDocumentInfo()->GetDocument();
- nsIDocument* boundDoc = aBoundElement->OwnerDoc();
+ mBoundDocument = aBoundElement->OwnerDoc();
mozilla::css::Loader* cssLoader = doc->CSSLoader();
MOZ_ASSERT(cssLoader->GetDocument() &&
cssLoader->GetDocument()->GetStyleBackendType()
- == boundDoc->GetStyleBackendType(),
+ == mBoundDocument->GetStyleBackendType(),
"The style backends of the loader and bound document are mismatched!");
nsIURI *docURL = doc->GetDocumentURI();
nsIPrincipal* docPrincipal = doc->NodePrincipal();
nsCOMPtr<nsIURI> url;
for (nsXBLResource* curr = mResourceList; curr; curr = curr->mNext) {
@@ -182,16 +182,19 @@ nsXBLResourceLoader::StyleSheetLoaded(St
if (!mInLoadResourcesFunc)
mPendingSheets--;
if (mPendingSheets == 0) {
// All stylesheets are loaded.
if (aSheet->IsGecko()) {
mResources->GatherRuleProcessor();
+ } else {
+ mResources->ComputeServoStyleSet(
+ mBoundDocument->GetShell()->GetPresContext());
}
// XXX Check for mPendingScripts when scripts also come online.
if (!mInLoadResourcesFunc)
NotifyBoundElements();
}
return NS_OK;
}
--- a/dom/xbl/nsXBLResourceLoader.h
+++ b/dom/xbl/nsXBLResourceLoader.h
@@ -14,16 +14,17 @@
#include "nsCycleCollectionParticipant.h"
class nsIContent;
class nsIAtom;
class nsXBLPrototypeResources;
class nsXBLPrototypeBinding;
struct nsXBLResource;
class nsIObjectOutputStream;
+class nsIDocument;
// *********************************************************************/
// The XBLResourceLoader class
class nsXBLResourceLoader : public nsICSSLoaderObserver
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@@ -61,11 +62,16 @@ public:
bool mInLoadResourcesFunc;
int16_t mPendingSheets; // The number of stylesheets that have yet to load.
// Bound elements that are waiting on the stylesheets and scripts.
nsCOMArray<nsIContent> mBoundElements;
protected:
virtual ~nsXBLResourceLoader();
+
+private:
+ // The bound document is needed in StyleSheetLoaded() for servo style
+ // backend, which will be set in LoadResources().
+ nsIDocument* MOZ_NON_OWNING_REF mBoundDocument;
};
#endif