Bug 1328319 part 2 - Add basic integration of @counter-style. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Mon, 15 May 2017 14:18:44 +1000
changeset 578526 c775d5d81219cadd8dd651c990c1bf904efdf7c6
parent 578525 c809472ebe27215dda7aba51e3ffa417aadd3768
child 578527 ee7a2656f2eaccb637da451a254a9f7d76556123
push id58946
push userxquan@mozilla.com
push dateTue, 16 May 2017 04:45:08 +0000
reviewersheycam
bugs1328319
milestone55.0a1
Bug 1328319 part 2 - Add basic integration of @counter-style. r?heycam MozReview-Commit-ID: 68CcxyWuINu
layout/style/ServoBindingList.h
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
layout/style/ServoCSSRuleList.cpp
layout/style/nsCSSRules.cpp
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -117,16 +117,18 @@ GROUP_RULE_FUNCS(Media)
 BASIC_RULE_FUNCS(Namespace)
 BASIC_RULE_FUNCS(Page)
 GROUP_RULE_FUNCS(Supports)
 GROUP_RULE_FUNCS(Document)
 #undef GROUP_RULE_FUNCS
 #undef BASIC_RULE_FUNCS
 SERVO_BINDING_FUNC(Servo_CssRules_GetFontFaceRuleAt, nsCSSFontFaceRule*,
                    ServoCssRulesBorrowed rules, uint32_t index)
+SERVO_BINDING_FUNC(Servo_CssRules_GetCounterStyleRuleAt, nsCSSCounterStyleRule*,
+                   ServoCssRulesBorrowed rules, uint32_t index)
 SERVO_BINDING_FUNC(Servo_StyleRule_GetStyle, RawServoDeclarationBlockStrong,
                    RawServoStyleRuleBorrowed rule)
 SERVO_BINDING_FUNC(Servo_StyleRule_SetStyle, void,
                    RawServoStyleRuleBorrowed rule,
                    RawServoDeclarationBlockBorrowed declarations)
 SERVO_BINDING_FUNC(Servo_StyleRule_GetSelectorText, void,
                    RawServoStyleRuleBorrowed rule, nsAString* result)
 SERVO_BINDING_FUNC(Servo_MediaRule_GetMedia, RawServoMediaListStrong,
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -6,16 +6,17 @@
 
 #include "mozilla/ServoBindings.h"
 
 #include "ChildIterator.h"
 #include "GeckoProfiler.h"
 #include "gfxFontFamilyList.h"
 #include "nsAnimationManager.h"
 #include "nsAttrValueInlines.h"
+#include "nsCSSCounterStyleRule.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsCSSProps.h"
 #include "nsCSSParser.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSRuleProcessor.h"
 #include "nsContentUtils.h"
 #include "nsDOMTokenList.h"
 #include "nsIContentInlines.h"
@@ -2111,16 +2112,33 @@ Gecko_CSSFontFaceRule_GetCssText(const n
   // and prevent accidentally calling this elsewhere
   MOZ_ASSERT(NS_IsMainThread());
 
   aRule->GetCssText(*aResult);
 }
 
 NS_IMPL_FFI_REFCOUNTING(nsCSSFontFaceRule, CSSFontFaceRule);
 
+nsCSSCounterStyleRule*
+Gecko_CSSCounterStyle_Create(nsIAtom* aName)
+{
+  RefPtr<nsCSSCounterStyleRule> rule = new nsCSSCounterStyleRule(aName, 0, 0);
+  return rule.forget().take();
+}
+
+void
+Gecko_CSSCounterStyle_GetCssText(const nsCSSCounterStyleRule* aRule,
+                                 nsAString* aResult)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  aRule->GetCssText(*aResult);
+}
+
+NS_IMPL_FFI_REFCOUNTING(nsCSSCounterStyleRule, CSSCounterStyleRule);
+
 NS_IMPL_THREADSAFE_FFI_REFCOUNTING(nsCSSValueSharedList, CSSValueSharedList);
 
 #define STYLE_STRUCT(name, checkdata_cb)                                      \
                                                                               \
 void                                                                          \
 Gecko_Construct_Default_nsStyle##name(nsStyle##name* ptr,                     \
                                       const nsPresContext* pres_context)      \
 {                                                                             \
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -45,16 +45,17 @@ namespace mozilla {
   enum class UpdateAnimationsTasks : uint8_t;
   struct LangGroupFontPrefs;
   class ServoStyleSheet;
   class ServoElementSnapshotTable;
 }
 using mozilla::FontFamilyList;
 using mozilla::FontFamilyType;
 using mozilla::ServoElementSnapshot;
+class nsCSSCounterStyleRule;
 class nsCSSFontFaceRule;
 struct nsMediaFeature;
 struct nsStyleList;
 struct nsStyleImage;
 struct nsStyleGradientStop;
 class nsStyleGradient;
 class nsStyleCoord;
 struct nsStyleDisplay;
@@ -514,16 +515,22 @@ nsCSSKeyword Gecko_LookupCSSKeyword(cons
 const char* Gecko_CSSKeywordString(nsCSSKeyword keyword, uint32_t* len);
 
 // Font face rule
 // Creates and returns a new (already-addrefed) nsCSSFontFaceRule object.
 nsCSSFontFaceRule* Gecko_CSSFontFaceRule_Create(uint32_t line, uint32_t column);
 void Gecko_CSSFontFaceRule_GetCssText(const nsCSSFontFaceRule* rule, nsAString* result);
 NS_DECL_FFI_REFCOUNTING(nsCSSFontFaceRule, CSSFontFaceRule);
 
+// Counter style rule
+// Creates and returns a new (already-addrefed) nsCSSCounterStyleRule object.
+nsCSSCounterStyleRule* Gecko_CSSCounterStyle_Create(nsIAtom* name);
+void Gecko_CSSCounterStyle_GetCssText(const nsCSSCounterStyleRule* rule, nsAString* result);
+NS_DECL_FFI_REFCOUNTING(nsCSSCounterStyleRule, CSSCounterStyleRule);
+
 RawGeckoElementBorrowedOrNull Gecko_GetBody(RawGeckoPresContextBorrowed pres_context);
 
 // We use an int32_t here instead of a LookAndFeel::ColorID
 // because forward-declaring a nested enum/struct is impossible
 nscolor Gecko_GetLookAndFeelSystemColor(int32_t color_id,
                                         RawGeckoPresContextBorrowed pres_context);
 
 bool Gecko_MatchStringArgPseudo(RawGeckoElementBorrowed element,
--- a/layout/style/ServoCSSRuleList.cpp
+++ b/layout/style/ServoCSSRuleList.cpp
@@ -10,16 +10,17 @@
 
 #include "mozilla/ServoBindings.h"
 #include "mozilla/ServoDocumentRule.h"
 #include "mozilla/ServoMediaRule.h"
 #include "mozilla/ServoNamespaceRule.h"
 #include "mozilla/ServoPageRule.h"
 #include "mozilla/ServoStyleRule.h"
 #include "mozilla/ServoSupportsRule.h"
+#include "nsCSSCounterStyleRule.h"
 #include "nsCSSFontFaceRule.h"
 
 namespace mozilla {
 
 ServoCSSRuleList::ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules)
   : mRawRules(aRawRules)
 {
   Servo_CssRules_ListTypes(mRawRules, &mRules);
@@ -41,20 +42,23 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Se
   tmp->DropAllRules();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(dom::CSSRuleList)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoCSSRuleList,
                                                   dom::CSSRuleList)
   tmp->EnumerateInstantiatedRules([&](css::Rule* aRule) {
     if (!aRule->IsCCLeaf()) {
       NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRules[i]");
       cb.NoteXPCOMChild(aRule);
-      // Note about @font-face rule again, since there is an indirect
-      // owning edge through Servo's struct that FontFaceRule in Servo
-      // owns a Gecko nsCSSFontFaceRule object.
-      if (aRule->Type() == nsIDOMCSSRule::FONT_FACE_RULE) {
+      // Note about @font-face and @counter-style rule again, since
+      // there is an indirect owning edge through Servo's struct that
+      // FontFaceRule / CounterStyleRule in Servo owns a Gecko
+      // nsCSSFontFaceRule / nsCSSCounterStyleRule object.
+      auto type = aRule->Type();
+      if (type == nsIDOMCSSRule::FONT_FACE_RULE ||
+          type == nsIDOMCSSRule::COUNTER_STYLE_RULE) {
         NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRawRules[i]");
         cb.NoteXPCOMChild(aRule);
       }
     }
   });
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 void
@@ -94,23 +98,28 @@ ServoCSSRuleList::GetRule(uint32_t aInde
       }
       CASE_RULE(STYLE, Style)
       CASE_RULE(MEDIA, Media)
       CASE_RULE(NAMESPACE, Namespace)
       CASE_RULE(PAGE, Page)
       CASE_RULE(SUPPORTS, Supports)
       CASE_RULE(DOCUMENT, Document)
 #undef CASE_RULE
+      // For @font-face and @counter-style rules, the function returns
+      // a borrowed Gecko rule object directly, so we don't need to
+      // create anything here. But we still need to have the style sheet
+      // and parent rule set properly.
       case nsIDOMCSSRule::FONT_FACE_RULE: {
-        // Returns a borrowed nsCSSFontFaceRule object directly, so we
-        // don't need to create anything here, but we still need to have
-        // the style sheet and parent rule set properly.
         ruleObj = Servo_CssRules_GetFontFaceRuleAt(mRawRules, aIndex);
         break;
       }
+      case nsIDOMCSSRule::COUNTER_STYLE_RULE: {
+        ruleObj = Servo_CssRules_GetCounterStyleRuleAt(mRawRules, aIndex);
+        break;
+      }
       case nsIDOMCSSRule::KEYFRAMES_RULE:
         // XXX create corresponding rules
       default:
         NS_WARNING("stylo: not implemented yet");
         return nullptr;
     }
     ruleObj->SetStyleSheet(mStyleSheet);
     ruleObj->SetParentRule(mParentRule);
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -2456,17 +2456,21 @@ nsCSSCounterStyleRule::SetName(const nsA
   nsCSSParser parser;
   if (nsCOMPtr<nsIAtom> name = parser.ParseCounterStyleName(aName, nullptr)) {
     nsIDocument* doc = GetDocument();
     MOZ_AUTO_DOC_UPDATE(doc, UPDATE_STYLE, true);
 
     mName = name;
 
     if (StyleSheet* sheet = GetStyleSheet()) {
-      sheet->AsGecko()->SetModifiedByChildRule();
+      if (sheet->IsGecko()) {
+        sheet->AsGecko()->SetModifiedByChildRule();
+      } else {
+        NS_ERROR("stylo: Dynamic change on @counter-style not yet supported");
+      }
       if (doc) {
         doc->StyleRuleChanged(sheet, this);
       }
     }
   }
   return NS_OK;
 }
 
@@ -2501,17 +2505,21 @@ nsCSSCounterStyleRule::SetDesc(nsCSSCoun
 
   nsIDocument* doc = GetDocument();
   MOZ_AUTO_DOC_UPDATE(doc, UPDATE_STYLE, true);
 
   mValues[aDescID] = aValue;
   mGeneration++;
 
   if (StyleSheet* sheet = GetStyleSheet()) {
-    sheet->AsGecko()->SetModifiedByChildRule();
+    if (sheet->IsGecko()) {
+      sheet->AsGecko()->SetModifiedByChildRule();
+    } else {
+      NS_ERROR("stylo: Dynamic change on @counter-style not yet supported");
+    }
     if (doc) {
       doc->StyleRuleChanged(sheet, this);
     }
   }
 }
 
 NS_IMETHODIMP
 nsCSSCounterStyleRule::GetSystem(nsAString& aSystem)