diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index f1a258240c69..843d1f7fe65d 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1410,23 +1410,18 @@ Loader::InsertSheetInDoc(StyleSheet* aSheet, nsresult Loader::InsertChildSheet(StyleSheet* aSheet, StyleSheet* aParentSheet, - ImportRule* aGeckoParentRule, - const RawServoStyleSheet* aServoChildSheet) + ImportRule* aGeckoParentRule) { LOG(("css::Loader::InsertChildSheet")); MOZ_ASSERT(aSheet, "Nothing to insert"); MOZ_ASSERT(aParentSheet, "Need a parent to insert into"); - MOZ_ASSERT(!aSheet->IsGecko() || (aGeckoParentRule && !aServoChildSheet)); - MOZ_ASSERT(!aSheet->IsServo() || (aServoChildSheet && !aGeckoParentRule)); + MOZ_ASSERT(aSheet->IsGecko() == !!aGeckoParentRule); + // child sheets should always start out enabled, even if they got // cloned off of top-level sheets which were disabled aSheet->SetEnabled(true); - if (aSheet->IsGecko()) { + if (aGeckoParentRule) { aGeckoParentRule->SetSheet(aSheet->AsGecko()); // This sets the ownerRule on the sheet - } else { - if (!aSheet->AsServo()->RawSheet()) { - aSheet->AsServo()->SetSheetForImport(aServoChildSheet); - } } aParentSheet->PrependStyleSheet(aSheet); @@ -2204,15 +2199,12 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet, nsIURI* aURL, dom::MediaList* aMedia, ImportRule* aGeckoParentRule, - const RawServoStyleSheet* aServoChildSheet, LoaderReusableStyleSheets* aReusableSheets) { LOG(("css::Loader::LoadChildSheet")); NS_PRECONDITION(aURL, "Must have a URI to load"); NS_PRECONDITION(aParentSheet, "Must have a parent sheet"); - - MOZ_ASSERT(!aParentSheet->IsGecko() || (aGeckoParentRule && !aServoChildSheet)); - MOZ_ASSERT(!aParentSheet->IsServo() || (aServoChildSheet && !aGeckoParentRule)); + MOZ_ASSERT(aParentSheet->IsGecko() == !!aGeckoParentRule); if (!mEnabled) { LOG_WARN((" Not enabled")); @@ -2225,11 +2217,7 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet, // check for an associated document: if none, don't bother walking up the // parent sheets - // - // FIXME(emilio): Figure out whether this walk up is necessary (try seems - // green without it), and fix the parenting of stylesheets in the servo case - // if that's the case. - if (aParentSheet->GetAssociatedDocument() && aParentSheet->IsGecko()) { + if (aParentSheet->GetAssociatedDocument()) { StyleSheet* topSheet = aParentSheet; while (StyleSheet* parent = topSheet->GetParentSheet()) { topSheet = parent; @@ -2294,8 +2282,7 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet, PrepareSheet(sheet, empty, empty, aMedia, nullptr, isAlternate); } - rv = InsertChildSheet(sheet, aParentSheet, aGeckoParentRule, - aServoChildSheet); + rv = InsertChildSheet(sheet, aParentSheet, aGeckoParentRule); NS_ENSURE_SUCCESS(rv, rv); if (state == eSheetComplete) { diff --git a/layout/style/Loader.h b/layout/style/Loader.h index d6cee7eb2a45..5a00852cda1f 100644 --- a/layout/style/Loader.h +++ b/layout/style/Loader.h @@ -292,8 +292,6 @@ public: * @param aGeckoParentRule the @import rule importing this child, when using * Gecko's style system. This is used to properly * order the child sheet list of aParentSheet. - * @param aServoChildSheet the child stylesheet of the @import rule, when - * using Servo's style system. * @param aSavedSheets any saved style sheets which could be reused * for this load */ @@ -301,7 +299,6 @@ public: nsIURI* aURL, dom::MediaList* aMedia, ImportRule* aGeckoParentRule, - const RawServoStyleSheet* aServoChildSheet, LoaderReusableStyleSheets* aSavedSheets); /** @@ -519,8 +516,7 @@ private: nsresult InsertChildSheet(StyleSheet* aSheet, StyleSheet* aParentSheet, - ImportRule* aGeckoParentRule, - const RawServoStyleSheet* aServoChildSheet); + ImportRule* aGeckoParentRule); nsresult InternalLoadNonDocumentSheet(nsIURI* aURL, bool aIsPreload, diff --git a/layout/style/ServoArcTypeList.h b/layout/style/ServoArcTypeList.h index 41f49d6e2161..6fa2040618f4 100644 --- a/layout/style/ServoArcTypeList.h +++ b/layout/style/ServoArcTypeList.h @@ -7,7 +7,7 @@ /* a list of all Servo Arc types used in stylo bindings for preprocessing */ SERVO_ARC_TYPE(CssRules, ServoCssRules) -SERVO_ARC_TYPE(StyleSheet, RawServoStyleSheet) +SERVO_ARC_TYPE(StyleSheetContents, RawServoStyleSheetContents) SERVO_ARC_TYPE(ComputedValues, ServoComputedValues) SERVO_ARC_TYPE(DeclarationBlock, RawServoDeclarationBlock) SERVO_ARC_TYPE(StyleRule, RawServoStyleRule) diff --git a/layout/style/ServoBindingList.h b/layout/style/ServoBindingList.h index 7488367f1821..1cecd25314ee 100644 --- a/layout/style/ServoBindingList.h +++ b/layout/style/ServoBindingList.h @@ -22,20 +22,19 @@ SERVO_BINDING_FUNC(Servo_Element_ClearData, void, RawGeckoElementBorrowed node) // Styleset and Stylesheet management -SERVO_BINDING_FUNC(Servo_StyleSheet_Empty, RawServoStyleSheetStrong, - mozilla::css::SheetParsingMode parsing_mode) -SERVO_BINDING_FUNC(Servo_StyleSheet_FromUTF8Bytes, RawServoStyleSheetStrong, +SERVO_BINDING_FUNC(Servo_StyleSheet_FromUTF8Bytes, RawServoStyleSheetContentsStrong, mozilla::css::Loader* loader, mozilla::ServoStyleSheet* gecko_stylesheet, const nsACString* data, mozilla::css::SheetParsingMode parsing_mode, - const RawServoMediaList* media_list, RawGeckoURLExtraData* extra_data, uint32_t line_number_offset, nsCompatibility quirks_mode) +SERVO_BINDING_FUNC(Servo_StyleSheet_Empty, RawServoStyleSheetContentsStrong, + mozilla::css::SheetParsingMode parsing_mode) SERVO_BINDING_FUNC(Servo_StyleSheet_ClearAndUpdate, void, - RawServoStyleSheetBorrowed stylesheet, + RawServoStyleSheetContentsBorrowed stylesheet, mozilla::css::Loader* loader, mozilla::ServoStyleSheet* gecko_stylesheet, const nsACString* data, @@ -43,13 +42,14 @@ SERVO_BINDING_FUNC(Servo_StyleSheet_ClearAndUpdate, uint32_t line_number_offset, mozilla::css::LoaderReusableStyleSheets* reusable_sheets) SERVO_BINDING_FUNC(Servo_StyleSheet_HasRules, bool, - RawServoStyleSheetBorrowed sheet) + RawServoStyleSheetContentsBorrowed sheet) SERVO_BINDING_FUNC(Servo_StyleSheet_GetRules, ServoCssRulesStrong, - RawServoStyleSheetBorrowed sheet) -SERVO_BINDING_FUNC(Servo_StyleSheet_Clone, RawServoStyleSheetStrong, - RawServoStyleSheetBorrowed sheet) + RawServoStyleSheetContentsBorrowed sheet) +SERVO_BINDING_FUNC(Servo_StyleSheet_Clone, RawServoStyleSheetContentsStrong, + RawServoStyleSheetContentsBorrowed sheet) SERVO_BINDING_FUNC(Servo_StyleSheet_SizeOfIncludingThis, size_t, - mozilla::MallocSizeOf malloc_size_of, RawServoStyleSheetBorrowed sheet) + mozilla::MallocSizeOf malloc_size_of, + RawServoStyleSheetContentsBorrowed sheet) SERVO_BINDING_FUNC(Servo_StyleSet_Init, RawServoStyleSetOwned, RawGeckoPresContextOwned pres_context) SERVO_BINDING_FUNC(Servo_StyleSet_Clear, void, RawServoStyleSetBorrowed set) @@ -62,24 +62,17 @@ SERVO_BINDING_FUNC(Servo_StyleSet_CompatModeChanged, void, RawServoStyleSetBorrowed raw_data) SERVO_BINDING_FUNC(Servo_StyleSet_AppendStyleSheet, void, RawServoStyleSetBorrowed set, - RawServoStyleSheetBorrowed sheet, - uint64_t unique_id) + const mozilla::ServoStyleSheet* gecko_sheet) SERVO_BINDING_FUNC(Servo_StyleSet_PrependStyleSheet, void, RawServoStyleSetBorrowed set, - RawServoStyleSheetBorrowed sheet, - uint64_t unique_id) + const mozilla::ServoStyleSheet* gecko_sheet) SERVO_BINDING_FUNC(Servo_StyleSet_RemoveStyleSheet, void, RawServoStyleSetBorrowed set, - uint64_t unique_id) + const mozilla::ServoStyleSheet* gecko_sheet) SERVO_BINDING_FUNC(Servo_StyleSet_InsertStyleSheetBefore, void, RawServoStyleSetBorrowed set, - RawServoStyleSheetBorrowed sheet, - uint64_t unique_id, - uint64_t before_unique_id) -SERVO_BINDING_FUNC(Servo_StyleSet_UpdateStyleSheet, void, - RawServoStyleSetBorrowed set, - RawServoStyleSheetBorrowed sheet, - uint64_t unique_id) + const mozilla::ServoStyleSheet* gecko_sheet, + const mozilla::ServoStyleSheet* before) SERVO_BINDING_FUNC(Servo_StyleSet_FlushStyleSheets, void, RawServoStyleSetBorrowed set, RawGeckoElementBorrowedOrNull doc_elem) SERVO_BINDING_FUNC(Servo_StyleSet_NoteStyleSheetsChanged, void, @@ -115,8 +108,11 @@ SERVO_BINDING_FUNC(Servo_CssRules_ListTypes, void, nsTArrayBorrowed_uintptr_t result) SERVO_BINDING_FUNC(Servo_CssRules_InsertRule, nsresult, ServoCssRulesBorrowed rules, - RawServoStyleSheetBorrowed sheet, const nsACString* rule, - uint32_t index, bool nested, mozilla::css::Loader* loader, + RawServoStyleSheetContentsBorrowed sheet, + const nsACString* rule, + uint32_t index, + bool nested, + mozilla::css::Loader* loader, mozilla::ServoStyleSheet* gecko_stylesheet, uint16_t* rule_type) SERVO_BINDING_FUNC(Servo_CssRules_DeleteRule, nsresult, @@ -171,7 +167,8 @@ SERVO_BINDING_FUNC(Servo_StyleRule_GetSelectorCount, void, RawServoStyleRuleBorrowed rule, uint32_t* count) SERVO_BINDING_FUNC(Servo_ImportRule_GetHref, void, RawServoImportRuleBorrowed rule, nsAString* result) -SERVO_BINDING_FUNC(Servo_ImportRule_GetSheet, const RawServoStyleSheet*, +SERVO_BINDING_FUNC(Servo_ImportRule_GetSheet, + const mozilla::ServoStyleSheet*, RawServoImportRuleBorrowed rule) SERVO_BINDING_FUNC(Servo_Keyframe_GetKeyText, void, RawServoKeyframeBorrowed keyframe, nsAString* result) @@ -198,7 +195,8 @@ SERVO_BINDING_FUNC(Servo_KeyframesRule_FindRule, uint32_t, // Returns whether it successfully appends the rule. SERVO_BINDING_FUNC(Servo_KeyframesRule_AppendRule, bool, RawServoKeyframesRuleBorrowed rule, - RawServoStyleSheetBorrowed sheet, const nsACString* css) + RawServoStyleSheetContentsBorrowed sheet, + const nsACString* css) SERVO_BINDING_FUNC(Servo_KeyframesRule_DeleteRule, void, RawServoKeyframesRuleBorrowed rule, uint32_t index) SERVO_BINDING_FUNC(Servo_MediaRule_GetMedia, RawServoMediaListStrong, diff --git a/layout/style/ServoBindings.cpp b/layout/style/ServoBindings.cpp index 6246bbac8ef6..0a70ea9940a0 100644 --- a/layout/style/ServoBindings.cpp +++ b/layout/style/ServoBindings.cpp @@ -2341,7 +2341,6 @@ void Gecko_LoadStyleSheet(css::Loader* aLoader, ServoStyleSheet* aParent, css::LoaderReusableStyleSheets* aReusableSheets, - RawServoStyleSheetBorrowed aChildSheet, RawGeckoURLExtraData* aBaseURLData, const uint8_t* aURLString, uint32_t aURLStringLength, @@ -2368,7 +2367,7 @@ Gecko_LoadStyleSheet(css::Loader* aLoader, return; } - aLoader->LoadChildSheet(aParent, uri, media, nullptr, aChildSheet, aReusableSheets); + aLoader->LoadChildSheet(aParent, uri, media, nullptr, aReusableSheets); } const nsMediaFeature* diff --git a/layout/style/ServoBindings.h b/layout/style/ServoBindings.h index 3ba8c3f14afd..91a01411b33b 100644 --- a/layout/style/ServoBindings.h +++ b/layout/style/ServoBindings.h @@ -146,7 +146,6 @@ RawGeckoNodeBorrowedOrNull Gecko_GetNextStyleChild(RawGeckoStyleChildrenIterator void Gecko_LoadStyleSheet(mozilla::css::Loader* loader, mozilla::ServoStyleSheet* parent, mozilla::css::LoaderReusableStyleSheets* reusable_sheets, - RawServoStyleSheetBorrowed child_sheet, RawGeckoURLExtraData* base_url_data, const uint8_t* url_bytes, uint32_t url_length, diff --git a/layout/style/ServoBindings.toml b/layout/style/ServoBindings.toml index 2f9754db9823..dc18d35d0782 100644 --- a/layout/style/ServoBindings.toml +++ b/layout/style/ServoBindings.toml @@ -61,6 +61,7 @@ headers = [ "mozilla/dom/NameSpaceConstants.h", "mozilla/LookAndFeel.h", "mozilla/ServoBindings.h", + "mozilla/ServoMediaList.h", "nsCSSCounterStyleRule.h", "nsCSSFontFaceRule.h", "nsMediaFeatures.h", @@ -118,8 +119,8 @@ whitelist-types = [ "mozilla::ComputedTiming", "mozilla::ComputedTimingFunction", "mozilla::ComputedTimingFunction::BeforeFlag", - "mozilla::ServoStyleSheet", "mozilla::ServoElementSnapshot.*", + "mozilla::ServoStyleSheetInner", "mozilla::CSSPseudoClassType", "mozilla::css::SheetParsingMode", "mozilla::css::URLMatchingFunction", @@ -258,6 +259,7 @@ whitelist-types = [ "mozilla::binding_danger::AssertAndSuppressCleanupPolicy", "mozilla::ParsingMode", "mozilla::InheritTarget", + "mozilla::ServoMediaList", "mozilla::StyleRuleInclusion", "nsStyleTransformMatrix::MatrixTransformOperator", ] @@ -345,6 +347,8 @@ structs-types = [ "RawGeckoNode", "RawServoAnimationValue", "RawGeckoServoAnimationValueList", + "RawServoMediaList", + "RawServoStyleSheetContents", "RawServoDeclarationBlock", "RawServoStyleRule", "RawGeckoPresContext", diff --git a/layout/style/ServoCSSRuleList.cpp b/layout/style/ServoCSSRuleList.cpp index c11a82e13f7e..44bfc92775d1 100644 --- a/layout/style/ServoCSSRuleList.cpp +++ b/layout/style/ServoCSSRuleList.cpp @@ -30,31 +30,6 @@ ServoCSSRuleList::ServoCSSRuleList(already_AddRefed aRawRules, , mRawRules(aRawRules) { Servo_CssRules_ListTypes(mRawRules, &mRules); - // Only top level rule list can have @import rules. - if (aDirectOwnerStyleSheet) { - nsDataHashtable, - ServoStyleSheet*> stylesheets; - aDirectOwnerStyleSheet->EnumerateChildSheets( - [&stylesheets](StyleSheet* child) { - ServoStyleSheet* servoSheet = child->AsServo(); - const RawServoStyleSheet* rawSheet = servoSheet->RawSheet(); - MOZ_ASSERT(!stylesheets.Get(rawSheet, nullptr), - "Multiple child sheets with same raw sheet?"); - stylesheets.Put(rawSheet, servoSheet); - }); - for (auto i : IntegerRange(mRules.Length())) { - if (mRules[i] != nsIDOMCSSRule::IMPORT_RULE) { - // Only @charset can be put before @import rule, but @charset - // rules don't have corresponding object, so if a rule is not - // @import rule, there is definitely no @import rule after it. - break; - } - ConstructImportRule(i, [&stylesheets](const RawServoStyleSheet* raw) { - // Child sheet will not be constructed if the import rule has a bad URL. - return stylesheets.GetAndRemove(raw).valueOr(nullptr); - }); - } - } } // QueryInterface implementation for ServoCSSRuleList @@ -210,9 +185,8 @@ ServoCSSRuleList::DropReference() DropAllRules(); } -template void -ServoCSSRuleList::ConstructImportRule(uint32_t aIndex, ChildSheetGetter aGetter) +ServoCSSRuleList::ConstructImportRule(uint32_t aIndex) { MOZ_ASSERT(mRules[aIndex] == nsIDOMCSSRule::IMPORT_RULE); @@ -220,15 +194,9 @@ ServoCSSRuleList::ConstructImportRule(uint32_t aIndex, ChildSheetGetter aGetter) RefPtr rawRule = Servo_CssRules_GetImportRuleAt(mRawRules, aIndex, &line, &column).Consume(); - const RawServoStyleSheet* - rawChildSheet = Servo_ImportRule_GetSheet(rawRule); - ServoStyleSheet* childSheet = aGetter(rawChildSheet); - // There is one case where we don't construct a child sheet for an import - // rule: when the URL doesn't resolve. In that cases we still want to create - // an import rule object, though we note it as an exceptional condition - // in debug builds. - NS_WARNING_ASSERTION(childSheet, - "stylo: failed to get child sheet for @import rule"); + auto* childSheet = + const_cast(Servo_ImportRule_GetSheet(rawRule)); + MOZ_ASSERT(childSheet); RefPtr ruleObj = new ServoImportRule(Move(rawRule), childSheet, line, column); if (childSheet) { @@ -253,7 +221,7 @@ ServoCSSRuleList::InsertRule(const nsAString& aRule, uint32_t aIndex) loader = doc->CSSLoader(); } uint16_t type; - nsresult rv = Servo_CssRules_InsertRule(mRawRules, mStyleSheet->RawSheet(), + nsresult rv = Servo_CssRules_InsertRule(mRawRules, mStyleSheet->RawContents(), &rule, aIndex, nested, loader, mStyleSheet, &type); if (NS_FAILED(rv)) { @@ -262,40 +230,7 @@ ServoCSSRuleList::InsertRule(const nsAString& aRule, uint32_t aIndex) mRules.InsertElementAt(aIndex, type); if (type == nsIDOMCSSRule::IMPORT_RULE) { MOZ_ASSERT(!nested, "@import rule cannot be nested"); - ConstructImportRule(aIndex, [this](const RawServoStyleSheet* raw) { - // Our goal is to find a ServoStyleSheet that is a child of mStyleSheet - // that has a RawSheet equal to raw. This will be true when the call - // to Gecko_LoadStyleSheet finished successfully. But that function - // might have failed. A malformed URL will cause an early exit - // where no ServoStyleSheet is created and added as a child - // to mStyleSheet. In that case, we return a null ServoStyleSheet. - - // See if there are any child sheets. - StyleSheet* sheet = mStyleSheet->GetMostRecentlyAddedChildSheet(); - if (sheet) { - ServoStyleSheet* firstChild = sheet->AsServo(); - - // See if this first child has a RawSheet of raw. - if (firstChild->RawSheet() == raw) { - // This is the one we expected to find, so return it. - return firstChild; - } -#if DEBUG - // See if the child sheet was added in another position, - // which would be incorrect behavior. - mStyleSheet->EnumerateChildSheets([raw](StyleSheet* child) { - ServoStyleSheet* servoChild = child->AsServo(); - MOZ_ASSERT(servoChild->RawSheet() != raw, - "New child sheet should either be first on the list or not present"); - }); -#endif - } - - // The raw sheet wasn't found in mStyleSheets child sheet list at all. - // This is probably a result of a bad URL in the import rule. - NS_WARNING("Import rule didn't create a ServoStyleSheet... bad URL?"); - return static_cast(nullptr); - }); + ConstructImportRule(aIndex); } return rv; } diff --git a/layout/style/ServoCSSRuleList.h b/layout/style/ServoCSSRuleList.h index d31474261ab7..52cf58fbbf69 100644 --- a/layout/style/ServoCSSRuleList.h +++ b/layout/style/ServoCSSRuleList.h @@ -71,9 +71,6 @@ private: void DropAllRules(); - template - inline void ConstructImportRule(uint32_t aIndex, ChildSheetGetter aGetter); - // mStyleSheet may be nullptr when it drops the reference to us. ServoStyleSheet* mStyleSheet = nullptr; // mParentRule is nullptr if it isn't a nested rule list. diff --git a/layout/style/ServoKeyframesRule.cpp b/layout/style/ServoKeyframesRule.cpp index aeb4b9efde4c..058cde2196ed 100644 --- a/layout/style/ServoKeyframesRule.cpp +++ b/layout/style/ServoKeyframesRule.cpp @@ -75,6 +75,7 @@ public: void AppendRule() { mRules.AppendObject(nullptr); } + void RemoveRule(uint32_t aIndex) { mRules.RemoveObjectAt(aIndex); } @@ -279,11 +280,10 @@ ServoKeyframesRule::AppendRule(const nsAString& aRule) NS_ConvertUTF16toUTF8 rule(aRule); UpdateRule([this, sheet, &rule]() { - if (Servo_KeyframesRule_AppendRule(mRawRule, sheet->AsServo()->RawSheet(), - &rule)) { - if (mKeyframeList) { - mKeyframeList->AppendRule(); - } + bool parsedOk = Servo_KeyframesRule_AppendRule( + mRawRule, sheet->AsServo()->RawContents(), &rule); + if (parsedOk && mKeyframeList) { + mKeyframeList->AppendRule(); } }); return NS_OK; diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index 87e8d66a73e9..0564b76566d0 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -34,15 +34,6 @@ using namespace mozilla; using namespace mozilla::dom; -static inline uint64_t UniqueIDForSheet(ServoStyleSheet* aSheet) -{ - // Servo tracks sheets by unique ID, and it's important that a given - // ServoStyleSheet has the same unique ID throughout its lifetime. - // Instead of tracking an arbitrary unique ID for each sheet, - // we use the sheet address as a unique ID. - return reinterpret_cast(aSheet); -} - ServoStyleSet::ServoStyleSet() : mPresContext(nullptr) , mAllowResolveStaleStyles(false) @@ -81,10 +72,9 @@ ServoStyleSet::Init(nsPresContext* aPresContext, nsBindingManager* aBindingManag // because Servo only needs to maintain relative ordering within a sheet // type, which this preserves. - MOZ_ASSERT(sheet->RawSheet(), "We should only append non-null raw sheets."); - Servo_StyleSet_AppendStyleSheet(mRawSet.get(), - sheet->RawSheet(), - UniqueIDForSheet(sheet)); + MOZ_ASSERT(sheet->RawContents(), + "We should only append non-null raw sheets."); + Servo_StyleSet_AppendStyleSheet(mRawSet.get(), sheet); } } @@ -709,7 +699,7 @@ ServoStyleSet::AppendStyleSheet(SheetType aType, MOZ_ASSERT(aSheet); MOZ_ASSERT(aSheet->IsApplicable()); MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType)); - MOZ_ASSERT(aSheet->RawSheet(), "Raw sheet should be in place before insertion."); + MOZ_ASSERT(aSheet->RawContents(), "Raw sheet should be in place before insertion."); RemoveSheetOfType(aType, aSheet); AppendSheetOfType(aType, aSheet); @@ -718,9 +708,7 @@ ServoStyleSet::AppendStyleSheet(SheetType aType, // Maintain a mirrored list of sheets on the servo side. // Servo will remove aSheet from its original position as part of the call // to Servo_StyleSet_AppendStyleSheet. - Servo_StyleSet_AppendStyleSheet(mRawSet.get(), - aSheet->RawSheet(), - UniqueIDForSheet(aSheet)); + Servo_StyleSet_AppendStyleSheet(mRawSet.get(), aSheet); SetStylistStyleSheetsDirty(); } @@ -734,7 +722,8 @@ ServoStyleSet::PrependStyleSheet(SheetType aType, MOZ_ASSERT(aSheet); MOZ_ASSERT(aSheet->IsApplicable()); MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType)); - MOZ_ASSERT(aSheet->RawSheet(), "Raw sheet should be in place before insertion."); + MOZ_ASSERT(aSheet->RawContents(), + "Raw sheet should be in place before insertion."); RemoveSheetOfType(aType, aSheet); PrependSheetOfType(aType, aSheet); @@ -743,9 +732,7 @@ ServoStyleSet::PrependStyleSheet(SheetType aType, // Maintain a mirrored list of sheets on the servo side. // Servo will remove aSheet from its original position as part of the call // to Servo_StyleSet_PrependStyleSheet. - Servo_StyleSet_PrependStyleSheet(mRawSet.get(), - aSheet->RawSheet(), - UniqueIDForSheet(aSheet)); + Servo_StyleSet_PrependStyleSheet(mRawSet.get(), aSheet); SetStylistStyleSheetsDirty(); } @@ -762,7 +749,7 @@ ServoStyleSet::RemoveStyleSheet(SheetType aType, RemoveSheetOfType(aType, aSheet); if (mRawSet) { // Maintain a mirrored list of sheets on the servo side. - Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), UniqueIDForSheet(aSheet)); + Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), aSheet); SetStylistStyleSheetsDirty(); } @@ -784,7 +771,7 @@ ServoStyleSet::ReplaceSheets(SheetType aType, for (const auto& sheet : mSheets[aType]) { sheet->DropStyleSet(this); if (mRawSet) { - Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), UniqueIDForSheet(sheet)); + Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), sheet); } } mSheets[aType].Clear(); @@ -793,10 +780,8 @@ ServoStyleSet::ReplaceSheets(SheetType aType, for (auto& sheet : aNewSheets) { AppendSheetOfType(aType, sheet); if (mRawSet) { - MOZ_ASSERT(sheet->RawSheet(), "Raw sheet should be in place before replacement."); - Servo_StyleSet_AppendStyleSheet(mRawSet.get(), - sheet->RawSheet(), - UniqueIDForSheet(sheet)); + MOZ_ASSERT(sheet->RawContents(), "Raw sheet should be in place before replacement."); + Servo_StyleSet_AppendStyleSheet(mRawSet.get(), sheet); } } @@ -812,8 +797,8 @@ ServoStyleSet::InsertStyleSheetBefore(SheetType aType, MOZ_ASSERT(aReferenceSheet); MOZ_ASSERT(aNewSheet->IsApplicable()); MOZ_ASSERT(aNewSheet != aReferenceSheet, "Can't place sheet before itself."); - MOZ_ASSERT(aNewSheet->RawSheet(), "Raw sheet should be in place before insertion."); - MOZ_ASSERT(aReferenceSheet->RawSheet(), "Reference sheet should have a raw sheet."); + MOZ_ASSERT(aNewSheet->RawContents(), "Raw sheet should be in place before insertion."); + MOZ_ASSERT(aReferenceSheet->RawContents(), "Reference sheet should have a raw sheet."); // Servo will remove aNewSheet from its original position as part of the // call to Servo_StyleSet_InsertStyleSheetBefore. @@ -822,10 +807,8 @@ ServoStyleSet::InsertStyleSheetBefore(SheetType aType, if (mRawSet) { // Maintain a mirrored list of sheets on the servo side. - Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(), - aNewSheet->RawSheet(), - UniqueIDForSheet(aNewSheet), - UniqueIDForSheet(aReferenceSheet)); + Servo_StyleSet_InsertStyleSheetBefore( + mRawSet.get(), aNewSheet, aReferenceSheet); SetStylistStyleSheetsDirty(); } @@ -836,16 +819,7 @@ void ServoStyleSet::UpdateStyleSheet(ServoStyleSheet* aSheet) { MOZ_ASSERT(aSheet); - - if (mRawSet) { - // Inform servo that the underlying raw sheet has changed. - Servo_StyleSet_UpdateStyleSheet(mRawSet.get(), - aSheet->RawSheet(), - UniqueIDForSheet(aSheet)); - // No need to set the stylesheets as dirty, since this is only - // used to notify servo of a cloned raw sheet. It styles the - // same until the sheet is changed through other methods. - } + // TODO(emilio): Get rid of this. } int32_t @@ -856,8 +830,7 @@ ServoStyleSet::SheetCount(SheetType aType) const } ServoStyleSheet* -ServoStyleSet::StyleSheetAt(SheetType aType, - int32_t aIndex) const +ServoStyleSet::StyleSheetAt(SheetType aType, int32_t aIndex) const { MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType)); return mSheets[aType][aIndex]; @@ -882,7 +855,7 @@ ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet, nsIDocument* aDocument) { MOZ_ASSERT(aSheet->IsApplicable()); - MOZ_ASSERT(aSheet->RawSheet(), "Raw sheet should be in place by this point."); + MOZ_ASSERT(aSheet->RawContents(), "Raw sheet should be in place by this point."); RefPtr strong(aSheet); @@ -898,10 +871,7 @@ ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet, if (mRawSet) { // Maintain a mirrored list of sheets on the servo side. - Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(), - aSheet->RawSheet(), - UniqueIDForSheet(aSheet), - UniqueIDForSheet(beforeSheet)); + Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(), aSheet, beforeSheet); SetStylistStyleSheetsDirty(); } } else { @@ -910,9 +880,7 @@ ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet, if (mRawSet) { // Maintain a mirrored list of sheets on the servo side. - Servo_StyleSet_AppendStyleSheet(mRawSet.get(), - aSheet->RawSheet(), - UniqueIDForSheet(aSheet)); + Servo_StyleSet_AppendStyleSheet(mRawSet.get(), aSheet); SetStylistStyleSheetsDirty(); } } diff --git a/layout/style/ServoStyleSheet.cpp b/layout/style/ServoStyleSheet.cpp index a19587e7cef7..ea75a074c521 100644 --- a/layout/style/ServoStyleSheet.cpp +++ b/layout/style/ServoStyleSheet.cpp @@ -44,8 +44,8 @@ ServoStyleSheetInner::ServoStyleSheetInner(ServoStyleSheetInner& aCopy, { MOZ_COUNT_CTOR(ServoStyleSheetInner); - // Actually clone aCopy's mSheet and use that as our mSheet. - mSheet = Servo_StyleSheet_Clone(aCopy.mSheet).Consume(); + // Actually clone aCopy's mContents and use that as ours. + mContents = Servo_StyleSheet_Clone(aCopy.mContents).Consume(); mURLData = aCopy.mURLData; } @@ -68,10 +68,10 @@ size_t ServoStyleSheetInner::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { size_t n = aMallocSizeOf(this); - // mSheet will be null if the parsing has not completed. - if (mSheet) { - n += Servo_StyleSheet_SizeOfIncludingThis(ServoStyleSheetMallocSizeOf, - mSheet); + // mContents will be null if the parsing has not completed. + if (mContents) { + n += Servo_StyleSheet_SizeOfIncludingThis( + ServoStyleSheetMallocSizeOf, mContents); } return n; } @@ -141,7 +141,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END bool ServoStyleSheet::HasRules() const { - return Inner()->mSheet && Servo_StyleSheet_HasRules(Inner()->mSheet); + return Inner()->mContents && Servo_StyleSheet_HasRules(Inner()->mContents); } nsresult @@ -159,23 +159,11 @@ ServoStyleSheet::ParseSheet(css::Loader* aLoader, new URLExtraData(aBaseURI, aSheetURI, aSheetPrincipal); NS_ConvertUTF16toUTF8 input(aInput); - if (!Inner()->mSheet) { - auto* mediaList = static_cast(mMedia.get()); - RawServoMediaList* media = mediaList ? &mediaList->RawList() : nullptr; - - Inner()->mSheet = - Servo_StyleSheet_FromUTF8Bytes( - aLoader, this, &input, mParsingMode, media, extraData, - aLineNumber, aCompatMode - ).Consume(); - } else { - // TODO(emilio): Once we have proper inner cloning (which we don't right - // now) we should update the mediaList here too, though it's slightly - // tricky. - Servo_StyleSheet_ClearAndUpdate(Inner()->mSheet, aLoader, - this, &input, extraData, aLineNumber, - aReusableSheets); - } + Inner()->mContents = + Servo_StyleSheet_FromUTF8Bytes( + aLoader, this, &input, mParsingMode, extraData, + aLineNumber, aCompatMode + ).Consume(); Inner()->mURLData = extraData.forget(); return NS_OK; @@ -184,11 +172,11 @@ ServoStyleSheet::ParseSheet(css::Loader* aLoader, void ServoStyleSheet::LoadFailed() { - if (!Inner()->mSheet) { + if (!Inner()->mContents) { // Only create empty stylesheet if this is a top level stylesheet. // The raw sheet for stylesheet of @import rule is already set in // loader, and we should not touch it. - Inner()->mSheet = Servo_StyleSheet_Empty(mParsingMode).Consume(); + Inner()->mContents = Servo_StyleSheet_Empty(mParsingMode).Consume(); } Inner()->mURLData = URLExtraData::Dummy(); } @@ -354,7 +342,7 @@ ServoStyleSheet::GetCssRulesInternal() EnsureUniqueInner(); RefPtr rawRules = - Servo_StyleSheet_GetRules(Inner()->mSheet).Consume(); + Servo_StyleSheet_GetRules(Inner()->mContents).Consume(); MOZ_ASSERT(rawRules); mRuleList = new ServoCSSRuleList(rawRules.forget(), this); } diff --git a/layout/style/ServoStyleSheet.h b/layout/style/ServoStyleSheet.h index 007298abe2e2..e43d39ad67a2 100644 --- a/layout/style/ServoStyleSheet.h +++ b/layout/style/ServoStyleSheet.h @@ -29,7 +29,7 @@ class LoaderReusableStyleSheets; // Servo Style Sheet Inner Data Container // -struct ServoStyleSheetInner : public StyleSheetInfo +struct ServoStyleSheetInner final : public StyleSheetInfo { ServoStyleSheetInner(CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy, @@ -42,7 +42,8 @@ struct ServoStyleSheetInner : public StyleSheetInfo size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; - RefPtr mSheet; + RefPtr mContents; + // XXX StyleSheetInfo already has mSheetURI, mBaseURI, and mPrincipal. // Can we somehow replace them with URLExtraData directly? The issue // is currently URLExtraData is immutable, but URIs in StyleSheetInfo @@ -97,12 +98,13 @@ public: nsresult ReparseSheet(const nsAString& aInput); - const RawServoStyleSheet* RawSheet() const { - return Inner()->mSheet; + const RawServoStyleSheetContents* RawContents() const { + return Inner()->mContents; } - void SetSheetForImport(const RawServoStyleSheet* aSheet) { - MOZ_ASSERT(!Inner()->mSheet); - Inner()->mSheet = aSheet; + + void SetContentsForImport(const RawServoStyleSheetContents* aContents) { + MOZ_ASSERT(!Inner()->mContents); + Inner()->mContents = aContents; } URLExtraData* URLData() const { return Inner()->mURLData; } diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index abc89d459692..20e21962f357 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -3698,9 +3698,7 @@ CSSParserImpl::ProcessImport(const nsString& aURLSpec, } if (mChildLoader) { - mChildLoader->LoadChildSheet(mSheet, url, aMedia, rule, - /* aServoParentRule = */ nullptr, - mReusableSheets); + mChildLoader->LoadChildSheet(mSheet, url, aMedia, rule, mReusableSheets); } } diff --git a/layout/style/test/gtest/StyloParsingBench.cpp b/layout/style/test/gtest/StyloParsingBench.cpp index 0e8d16ad1f26..3558c8779395 100644 --- a/layout/style/test/gtest/StyloParsingBench.cpp +++ b/layout/style/test/gtest/StyloParsingBench.cpp @@ -27,10 +27,11 @@ static void ServoParsingBench() { RefPtr data = new URLExtraData( NullPrincipalURI::Create(), nullptr, NullPrincipal::Create()); for (int i = 0; i < PARSING_REPETITIONS; i++) { - RefPtr stylesheet = Servo_StyleSheet_FromUTF8Bytes( - nullptr, nullptr, &css, eAuthorSheetFeatures, nullptr, - data, 0, eCompatibility_FullStandards - ).Consume(); + RefPtr stylesheet = + Servo_StyleSheet_FromUTF8Bytes( + nullptr, nullptr, &css, eAuthorSheetFeatures, + data, 0, eCompatibility_FullStandards + ).Consume(); } }