Commit 510cae01 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 7bc16951
Loading
Loading
Loading
Loading
+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&);
+26 −15
Original line number Diff line number Diff line
@@ -31,6 +31,11 @@ uint16_t CSSCounterStyleRule::Type() const {
  return CSSRule_Binding::COUNTER_STYLE_RULE;
}

void CSSCounterStyleRule::SetRawAfterClone(
    RefPtr<RawServoCounterStyleRule> aRaw) {
  mRawRule = std::move(aRaw);
}

void CSSCounterStyleRule::GetCssText(nsACString& aCssText) const {
  Servo_CounterStyleRule_GetCssText(mRawRule, &aCssText);
}
@@ -42,16 +47,27 @@ void CSSCounterStyleRule::GetName(nsAString& aName) {
  nsStyleUtil::AppendEscapedCSSIdent(nameStr, aName);
}

void CSSCounterStyleRule::SetName(const nsAString& aName) {
template <typename Func>
void CSSCounterStyleRule::ModifyRule(Func aCallback) {
  if (IsReadOnly()) {
    return;
  }
  NS_ConvertUTF16toUTF8 name(aName);
  if (Servo_CounterStyleRule_SetName(mRawRule, &name)) {
    if (StyleSheet* sheet = GetStyleSheet()) {

  StyleSheet* sheet = GetStyleSheet();
  if (sheet) {
    sheet->WillDirty();
  }

  if (aCallback() && sheet) {
    sheet->RuleChanged(this, StyleRuleChangeKind::Generic);
  }
}

void CSSCounterStyleRule::SetName(const nsAString& aName) {
  ModifyRule([&] {
    NS_ConvertUTF16toUTF8 name(aName);
    return Servo_CounterStyleRule_SetName(mRawRule, &name);
  });
}

#define CSS_COUNTER_DESC(name_, method_)                             \
@@ -61,15 +77,10 @@ void CSSCounterStyleRule::SetName(const nsAString& aName) {
        mRawRule, eCSSCounterDesc_##method_, &aValue);               \
  }                                                                  \
  void CSSCounterStyleRule::Set##method_(const nsACString& aValue) { \
    if (IsReadOnly()) {                                              \
      return;                                                        \
    }                                                                \
    if (Servo_CounterStyleRule_SetDescriptor(                        \
            mRawRule, eCSSCounterDesc_##method_, &aValue)) {         \
      if (StyleSheet* sheet = GetStyleSheet()) {                     \
        sheet->RuleChanged(this, StyleRuleChangeKind::Generic);      \
      }                                                              \
    }                                                                \
    ModifyRule([&] {                                                 \
      return Servo_CounterStyleRule_SetDescriptor(                   \
          mRawRule, eCSSCounterDesc_##method_, &aValue);             \
    });                                                              \
  }
#include "nsCSSCounterDescList.h"
#undef CSS_COUNTER_DESC
+4 −0
Original line number Diff line number Diff line
@@ -27,10 +27,14 @@ class CSSCounterStyleRule final : public css::Rule {
  CSSCounterStyleRule(const CSSCounterStyleRule& aCopy) = delete;
  ~CSSCounterStyleRule() = default;

  template <typename Func>
  void ModifyRule(Func);

 public:
  bool IsCCLeaf() const final;

  const RawServoCounterStyleRule* Raw() const { return mRawRule.get(); }
  void SetRawAfterClone(RefPtr<RawServoCounterStyleRule>);

#ifdef DEBUG
  void List(FILE* out = stdout, int32_t aIndent = 0) const final;
Loading