Commit 60812fc6 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1711437 - Don't EnsureUniqueInner from the cssRules getter. r=layout-reviewers,jfkthame

Instead, fix up the various content data structures when the stylesheet
is mutated. This makes reading a stylesheet not disable style sharing.

Differential Revision: https://phabricator.services.mozilla.com/D115203
parent 98cb1062
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -13003,8 +13003,7 @@ already_AddRefed<Document> Document::CreateStaticClone(
    RefPtr<StyleSheet> sheet = SheetAt(i);
    if (sheet) {
      if (sheet->IsApplicable()) {
        RefPtr<StyleSheet> clonedSheet =
            sheet->Clone(nullptr, nullptr, clonedDoc, nullptr);
        RefPtr<StyleSheet> clonedSheet = sheet->Clone(nullptr, clonedDoc);
        NS_WARNING_ASSERTION(clonedSheet, "Cloning a stylesheet didn't work!");
        if (clonedSheet) {
          clonedDoc->AddStyleSheet(clonedSheet);
@@ -13018,8 +13017,7 @@ already_AddRefed<Document> Document::CreateStaticClone(
    auto& sheets = mAdditionalSheets[additionalSheetType(t)];
    for (StyleSheet* sheet : sheets) {
      if (sheet->IsApplicable()) {
        RefPtr<StyleSheet> clonedSheet =
            sheet->Clone(nullptr, nullptr, clonedDoc, nullptr);
        RefPtr<StyleSheet> clonedSheet = sheet->Clone(nullptr, clonedDoc);
        NS_WARNING_ASSERTION(clonedSheet, "Cloning a stylesheet didn't work!");
        if (clonedSheet) {
          clonedDoc->AddAdditionalStyleSheet(additionalSheetType(t),
+1 −2
Original line number Diff line number Diff line
@@ -104,8 +104,7 @@ void ShadowRoot::CloneInternalDataFrom(ShadowRoot* aOther) {
  for (size_t i = 0; i < sheetCount; ++i) {
    StyleSheet* sheet = aOther->SheetAt(i);
    if (sheet->IsApplicable()) {
      RefPtr<StyleSheet> clonedSheet =
          sheet->Clone(nullptr, nullptr, this, nullptr);
      RefPtr<StyleSheet> clonedSheet = sheet->Clone(nullptr, this);
      if (clonedSheet) {
        AppendStyleSheet(*clonedSheet.get());
      }
+1 −1
Original line number Diff line number Diff line
@@ -17,5 +17,5 @@ interface CSSImportRule : CSSRule {
  [SameObject, PutForwards=mediaText] readonly attribute MediaList? media;
  // Per spec, the .styleSheet is never null, but in our implementation it can
  // be.  See <https://bugzilla.mozilla.org/show_bug.cgi?id=1326509>.
  [SameObject] readonly attribute CSSStyleSheet? styleSheet;
  [SameObject, BinaryName="styleSheetForBindings"] readonly attribute CSSStyleSheet? styleSheet;
};
+6 −0
Original line number Diff line number Diff line
@@ -45,6 +45,12 @@ void ServoStyleRuleMap::SheetAdded(StyleSheet& aStyleSheet) {
  }
}

void ServoStyleRuleMap::SheetCloned(StyleSheet& aStyleSheet) {
  // Invalidate all data inside. We could probably track down all the individual
  // rules that changed etc, but it doesn't seem worth it.
  mTable.Clear();
}

void ServoStyleRuleMap::SheetRemoved(StyleSheet& aStyleSheet) {
  // Invalidate all data inside. This isn't strictly necessary since
  // we should always get update from document before new queries come.
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ class ServoStyleRuleMap {

  void SheetAdded(StyleSheet&);
  void SheetRemoved(StyleSheet&);
  void SheetCloned(StyleSheet&);

  void RuleAdded(StyleSheet& aStyleSheet, css::Rule&);
  void RuleRemoved(StyleSheet& aStyleSheet, css::Rule&);
Loading