Bug 1341721 Part 1: ServoStyleSet implementation of SetAuthorStyleDisabled.
MozReview-Commit-ID: Bd0TJDfcj94
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -4603,17 +4603,19 @@ nsIPresShell::RestyleForCSSRuleChanges()
// Tell Servo that the contents of style sheets have changed.
//
// NB: It's important to do so before bailing out.
//
// Even if we have no frames, we can end up styling those when creating
// them, and it's important for Servo to know that it needs to use the
// correct styles.
- if (mStyleSet->IsServo()) {
+ // We don't do this notification if author styles are disabled, because
+ // the ServoStyleSet has already taken care of it.
+ if (mStyleSet->IsServo() && !mStyleSet->AsServo()->GetAuthorStyleDisabled()) {
mStyleSet->AsServo()->NoteStyleSheetsChanged();
}
Element* root = mDocument->GetRootElement();
if (!mDidInitialize) {
// Nothing to do here, since we have no frames yet
return;
}
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -25,16 +25,17 @@
using namespace mozilla;
using namespace mozilla::dom;
ServoStyleSet::ServoStyleSet()
: mPresContext(nullptr)
, mBatching(0)
, mAllowResolveStaleStyles(false)
+ , mAuthorStyleDisabled(false)
{
}
ServoStyleSet::~ServoStyleSet()
{
}
void
@@ -119,23 +120,38 @@ ServoStyleSet::SizeOfIncludingThis(Mallo
// - mPresContext, because it a non-owning pointer
return n;
}
bool
ServoStyleSet::GetAuthorStyleDisabled() const
{
- return false;
+ return mAuthorStyleDisabled;
}
nsresult
ServoStyleSet::SetAuthorStyleDisabled(bool aStyleDisabled)
{
- MOZ_CRASH("stylo: not implemented");
+ if (mAuthorStyleDisabled == aStyleDisabled) {
+ return NS_OK;
+ }
+
+ mAuthorStyleDisabled = aStyleDisabled;
+
+ // If we've just disabled, we have to note the stylesheets have changed and
+ // call flush directly, since the PresShell won't.
+ if (mAuthorStyleDisabled) {
+ NoteStyleSheetsChanged();
+ Servo_StyleSet_FlushStyleSheets(mRawSet.get());
+ }
+ // If we've just enabled, then PresShell will trigger the notification and
+ // later flush when the stylesheet objects are enabled in JS.
+
+ return NS_OK;
}
void
ServoStyleSet::BeginUpdate()
{
++mBatching;
}
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -339,16 +339,17 @@ private:
nsIAtom* aPseudoTag);
nsPresContext* mPresContext;
UniquePtr<RawServoStyleSet> mRawSet;
EnumeratedArray<SheetType, SheetType::Count,
nsTArray<RefPtr<ServoStyleSheet>>> mSheets;
int32_t mBatching;
bool mAllowResolveStaleStyles;
+ bool mAuthorStyleDisabled;
// Stores pointers to our cached style contexts for non-inheriting anonymous
// boxes.
EnumeratedArray<nsCSSAnonBoxes::NonInheriting,
nsCSSAnonBoxes::NonInheriting::_Count,
RefPtr<nsStyleContext>> mNonInheritingStyleContexts;
static bool sInServoTraversal;