Bug 1377196 Part 1 - Store nsBindingManager* in ServoStyleSet.
We need to call nsBindingManager's method from ServoStyleSet in a later
patch.
Also, we call nsStyleSet::SetBindingManager() immediately after we call
nsStyleSet::Init(). Therefore, we could pass binding manager to Init()
directly, and delete SetBindingManager().
MozReview-Commit-ID: 43WTpW3mSKX
--- a/dom/xbl/nsXBLPrototypeResources.cpp
+++ b/dom/xbl/nsXBLPrototypeResources.cpp
@@ -163,17 +163,17 @@ nsXBLPrototypeResources::GatherRuleProce
nullptr,
mRuleProcessor);
}
void
nsXBLPrototypeResources::ComputeServoStyleSet(nsPresContext* aPresContext)
{
mServoStyleSet.reset(new ServoStyleSet());
- mServoStyleSet->Init(aPresContext);
+ mServoStyleSet->Init(aPresContext, nullptr);
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());
}
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -966,24 +966,17 @@ PresShell::Init(nsIDocument* aDocument,
// Bind the context to the presentation shell.
mPresContext = aPresContext;
mPresContext->AttachShell(this, aStyleSet->BackendType());
// Now we can initialize the style set. Make sure to set the member before
// calling Init, since various subroutines need to find the style set off
// the PresContext during initialization.
mStyleSet = aStyleSet;
- mStyleSet->Init(aPresContext);
-
- // Set up our style rule observer. We don't need to inform a ServoStyleSet
- // of the binding manager because it gets XBL style sheets from bindings
- // in a different way.
- if (mStyleSet->IsGecko()) {
- mStyleSet->AsGecko()->SetBindingManager(mDocument->BindingManager());
- }
+ mStyleSet->Init(aPresContext, mDocument->BindingManager());
// Notify our prescontext that it now has a compatibility mode. Note that
// this MUST happen after we set up our style set but before we create any
// frames.
mPresContext->CompatibilityModeChanged();
// Add the preference style sheet.
UpdatePreferenceStyles();
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -58,20 +58,21 @@ ServoStyleSet::~ServoStyleSet()
for (auto& sheetArray : mSheets) {
for (auto& sheet : sheetArray) {
sheet->DropStyleSet(this);
}
}
}
void
-ServoStyleSet::Init(nsPresContext* aPresContext)
+ServoStyleSet::Init(nsPresContext* aPresContext, nsBindingManager* aBindingManager)
{
mPresContext = aPresContext;
mRawSet.reset(Servo_StyleSet_Init(aPresContext));
+ mBindingManager = aBindingManager;
mPresContext->DeviceContext()->InitFontCache();
// Now that we have an mRawSet, go ahead and notify about whatever stylesheets
// we have so far.
for (auto& sheetArray : mSheets) {
for (auto& sheet : sheetArray) {
// There's no guarantee this will create a list on the servo side whose
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -117,17 +117,17 @@ public:
static ServoStyleSet* Current()
{
return sInServoTraversal;
}
ServoStyleSet();
~ServoStyleSet();
- void Init(nsPresContext* aPresContext);
+ void Init(nsPresContext* aPresContext, nsBindingManager* aBindingManager);
void BeginShutdown();
void Shutdown();
void RecordStyleSheetChange(mozilla::ServoStyleSheet*, StyleSheet::ChangeType);
void RecordShadowStyleChange(mozilla::dom::ShadowRoot* aShadowRoot) {
// FIXME(emilio): When we properly support shadow dom we'll need to do
// better.
@@ -619,14 +619,17 @@ private:
// These are similar to Servo's SequentialTasks, except that they are
// posted by C++ code running on style worker threads.
nsTArray<PostTraversalTask> mPostTraversalTasks;
// Map from raw Servo style rule to Gecko's wrapper object.
// Constructed lazily when requested by devtools.
RefPtr<ServoStyleRuleMap> mStyleRuleMap;
+ // This can be null if we are used to hold XBL style sheets.
+ RefPtr<nsBindingManager> mBindingManager;
+
static ServoStyleSet* sInServoTraversal;
};
} // namespace mozilla
#endif // mozilla_ServoStyleSet_h
--- a/layout/style/StyleSetHandle.h
+++ b/layout/style/StyleSetHandle.h
@@ -20,16 +20,17 @@
namespace mozilla {
class CSSStyleSheet;
class ServoStyleSet;
namespace dom {
class Element;
class ShadowRoot;
} // namespace dom
} // namespace mozilla
+class nsBindingManager;
class nsCSSCounterStyleRule;
struct nsFontFaceRuleContainer;
class nsIAtom;
class nsIContent;
class nsIDocument;
class nsStyleContext;
class nsStyleSet;
class nsPresContext;
@@ -104,17 +105,17 @@ public:
// These inline methods are defined in StyleSetHandleInlines.h.
inline void Delete();
// Style set interface. These inline methods are defined in
// StyleSetHandleInlines.h and just forward to the underlying
// nsStyleSet or ServoStyleSet. See corresponding comments in
// nsStyleSet.h for descriptions of these methods.
- inline void Init(nsPresContext* aPresContext);
+ inline void Init(nsPresContext* aPresContext, nsBindingManager* aBindingManager);
inline void BeginShutdown();
inline void Shutdown();
inline bool GetAuthorStyleDisabled() const;
inline nsresult SetAuthorStyleDisabled(bool aStyleDisabled);
inline void BeginUpdate();
inline nsresult EndUpdate();
inline already_AddRefed<nsStyleContext>
ResolveStyleFor(dom::Element* aElement,
--- a/layout/style/StyleSetHandleInlines.h
+++ b/layout/style/StyleSetHandleInlines.h
@@ -30,19 +30,20 @@ StyleSetHandle::Ptr::Delete()
delete AsGecko();
} else {
delete AsServo();
}
}
}
void
-StyleSetHandle::Ptr::Init(nsPresContext* aPresContext)
+StyleSetHandle::Ptr::Init(nsPresContext* aPresContext,
+ nsBindingManager* aBindingManager)
{
- FORWARD(Init, (aPresContext));
+ FORWARD(Init, (aPresContext, aBindingManager));
}
void
StyleSetHandle::Ptr::BeginShutdown()
{
FORWARD(BeginShutdown, ());
}
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -277,24 +277,25 @@ nsStyleSet::SizeOfIncludingThis(MallocSi
n += mScopedDocSheetRuleProcessors[i]->SizeOfIncludingThis(aMallocSizeOf);
}
n += mScopedDocSheetRuleProcessors.ShallowSizeOfExcludingThis(aMallocSizeOf);
return n;
}
void
-nsStyleSet::Init(nsPresContext *aPresContext)
+nsStyleSet::Init(nsPresContext* aPresContext, nsBindingManager* aBindingManager)
{
mFirstLineRule = new nsEmptyStyleRule;
mFirstLetterRule = new nsEmptyStyleRule;
mPlaceholderRule = new nsEmptyStyleRule;
mDisableTextZoomStyleRule = new nsDisableTextZoomStyleRule;
mRuleTree = nsRuleNode::CreateRootNode(aPresContext);
+ mBindingManager = aBindingManager;
// Make an explicit GatherRuleProcessors call for the levels that
// don't have style sheets. The other levels will have their calls
// triggered by DirtyRuleProcessors.
GatherRuleProcessors(SheetType::PresHint);
GatherRuleProcessors(SheetType::StyleAttr);
GatherRuleProcessors(SheetType::Animation);
GatherRuleProcessors(SheetType::Transition);
--- a/layout/style/nsStyleSet.h
+++ b/layout/style/nsStyleSet.h
@@ -103,17 +103,17 @@ public:
class nsStyleSet final
{
public:
nsStyleSet();
~nsStyleSet();
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
- void Init(nsPresContext *aPresContext);
+ void Init(nsPresContext* aPresContext, nsBindingManager* aBindingManager);
nsRuleNode* GetRuleTree() { return mRuleTree; }
// get a style context for a non-pseudo frame.
already_AddRefed<nsStyleContext>
ResolveStyleFor(mozilla::dom::Element* aElement,
nsStyleContext* aParentContext);
@@ -380,23 +380,16 @@ class nsStyleSet final
/*
* Do any processing that needs to happen as a result of a change in
* the characteristics of the medium, and return whether style rules
* may have changed as a result.
*/
bool MediumFeaturesChanged();
- // APIs for registering objects that can supply additional
- // rules during processing.
- void SetBindingManager(nsBindingManager* aBindingManager)
- {
- mBindingManager = aBindingManager;
- }
-
// APIs to manipulate the style sheet lists. The sheets in each
// list are stored with the most significant sheet last.
nsresult AppendStyleSheet(mozilla::SheetType aType,
mozilla::CSSStyleSheet* aSheet);
nsresult PrependStyleSheet(mozilla::SheetType aType,
mozilla::CSSStyleSheet* aSheet);
nsresult RemoveStyleSheet(mozilla::SheetType aType,
mozilla::CSSStyleSheet* aSheet);