Bug 1415940 Part 2: Give StyleSheet a new dirty flag for indicating a rule was added. draft
authorBrad Werth <bwerth@mozilla.com>
Fri, 01 Dec 2017 16:11:32 -0800
changeset 712036 6b4d5a4f7d20387eea473e3e3ef0e55e3342f162
parent 712035 974107e1e7aaab7b5e47e86559fb45bb2e33639c
child 712037 18a2c50672a1e5db71614310da5155b83665f827
push id93228
push userbwerth@mozilla.com
push dateFri, 15 Dec 2017 14:42:37 +0000
bugs1415940
milestone59.0a1
Bug 1415940 Part 2: Give StyleSheet a new dirty flag for indicating a rule was added. MozReview-Commit-ID: Fidvalnzp0v
layout/style/CSSStyleSheet.cpp
layout/style/ServoStyleSheet.cpp
layout/style/StyleSheet.cpp
layout/style/StyleSheet.h
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -359,17 +359,17 @@ CSSStyleSheet::CSSStyleSheet(const CSSSt
                aParentToUse,
                aOwnerRuleToUse,
                aDocumentToUse,
                aOwningNodeToUse)
   , mInRuleProcessorCache(false)
   , mScopeElement(nullptr)
   , mRuleProcessors(nullptr)
 {
-  if (IsDirty()) { // CSSOM's been there, force full copy now
+  if (IsModified()) { // CSSOM's been there, force full copy now
     NS_ASSERTION(mInner->mComplete,
                  "Why have rules been accessed on an incomplete sheet?");
     // FIXME: handle failure?
     //
     // NOTE: It's important to call this from the subclass, since it could
     // access uninitialized members otherwise.
     EnsureUniqueInner();
   }
@@ -617,17 +617,17 @@ CSSStyleSheet::ClearRuleCascades()
   if (mParent) {
     static_cast<CSSStyleSheet*>(mParent)->ClearRuleCascades();
   }
 }
 
 void
 CSSStyleSheet::DidDirty()
 {
-  MOZ_ASSERT(!mInner->mComplete || mDirty,
+  MOZ_ASSERT(!mInner->mComplete || IsModified(),
              "caller must have called WillDirty()");
   ClearRuleCascades();
 }
 
 nsresult
 CSSStyleSheet::RegisterNamespaceRule(css::Rule* aRule)
 {
   if (!Inner()->mNameSpaceMap) {
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -145,17 +145,17 @@ ServoStyleSheet::ServoStyleSheet(const S
                                  nsIDocument* aDocumentToUse,
                                  nsINode* aOwningNodeToUse)
   : StyleSheet(aCopy,
                aParentToUse,
                aOwnerRuleToUse,
                aDocumentToUse,
                aOwningNodeToUse)
 {
-  if (mDirty) { // CSSOM's been there, force full copy now
+  if (IsModified()) { // CSSOM's been there, force full copy now
     NS_ASSERTION(mInner->mComplete,
                  "Why have rules been accessed on an incomplete sheet?");
     // FIXME: handle failure?
     //
     // NOTE: It's important to call this from the subclass, since this could
     // access uninitialized members otherwise.
     EnsureUniqueInner();
   }
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -192,17 +192,17 @@ bool
 StyleSheet::IsComplete() const
 {
   return SheetInfo().mComplete;
 }
 
 void
 StyleSheet::SetComplete()
 {
-  NS_ASSERTION(!IsDirty(), "Can't set a dirty sheet complete!");
+  NS_ASSERTION(!IsModified(), "Can't set a dirty sheet complete!");
   SheetInfo().mComplete = true;
   if (mDocument && !mDisabled) {
     // Let the document know
     mDocument->BeginUpdate(UPDATE_STYLE);
     mDocument->SetStyleSheetApplicableState(this, true);
     mDocument->EndUpdate(UPDATE_STYLE);
   }
 
@@ -622,16 +622,17 @@ StyleSheet::DeleteRuleFromGroup(css::Gro
     current = current->mParent;                           \
   } while (current);                                      \
 } while (0)
 
 void
 StyleSheet::RuleAdded(css::Rule& aRule)
 {
   DidDirty();
+  mDirtyFlags &= RULE_ADDED;
   NOTIFY_STYLE_SETS(RuleAdded, (*this, aRule));
 
   if (mDocument) {
     mDocument->StyleRuleAdded(this, &aRule);
   }
 }
 
 void
@@ -651,16 +652,22 @@ StyleSheet::RuleChanged(css::Rule* aRule
   DidDirty();
   NOTIFY_STYLE_SETS(RuleChanged, (*this, aRule));
 
   if (mDocument) {
     mDocument->StyleRuleChanged(this, aRule);
   }
 }
 
+bool
+StyleSheet::HasRulesFromCSSOM() const
+{
+  return mDirtyFlags & RULE_ADDED;
+}
+
 nsresult
 StyleSheet::InsertRuleIntoGroup(const nsAString& aRule,
                                 css::GroupRule* aGroup,
                                 uint32_t aIndex)
 {
   NS_ASSERTION(IsComplete(), "No inserting into an incomplete sheet!");
   // check that the group actually belongs to this sheet!
   if (this != aGroup->GetStyleSheet()) {
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -261,16 +261,17 @@ public:
   void WillDirty();
   virtual void DidDirty() {}
 
   // Called when a rule changes from CSSOM.
   //
   // FIXME(emilio): This shouldn't allow null, but MediaList doesn't know about
   // it's owning media rule, plus it's used for the stylesheet media itself.
   void RuleChanged(css::Rule*);
+  bool HasRulesFromCSSOM() const;
 
   void AddStyleSet(const StyleSetHandle& aStyleSet);
   void DropStyleSet(const StyleSetHandle& aStyleSet);
 
   nsresult DeleteRuleFromGroup(css::GroupRule* aGroup, uint32_t aIndex);
   nsresult InsertRuleIntoGroup(const nsAString& aRule,
                                css::GroupRule* aGroup, uint32_t aIndex);
 
@@ -355,16 +356,17 @@ protected:
   // and/or useful in user sheets.
   css::SheetParsingMode mParsingMode;
 
   const StyleBackendType mType;
   bool                  mDisabled;
 
   enum dirtyFlagAttributes {
     INNER_MODIFIED = 0x1,
+    RULE_ADDED = 0x2,
   };
   uint8_t mDirtyFlags; // has been modified
 
   // mDocumentAssociationMode determines whether mDocument directly owns us (in
   // the sense that if it's known-live then we're known-live).  Always
   // NotOwnedByDocument when mDocument is null.
   DocumentAssociationMode mDocumentAssociationMode;