Bug 1307357 part 4 - Add impl class of CSSStyleRule for stylo. r=heycam,manishearth
authorXidorn Quan <me@upsuper.org>
Wed, 23 Nov 2016 10:26:20 +1100
changeset 323893 31fdda2f930d856d0786563d5ea1a3e8a6d076b4
parent 323892 2ba29077a23e4fbbc79bbf54efb2c1a563056295
child 323894 d6a77d3e4bb8ad6466f58383cd946fb32a678d62
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersheycam, manishearth
bugs1307357
milestone53.0a1
Bug 1307357 part 4 - Add impl class of CSSStyleRule for stylo. r=heycam,manishearth MozReview-Commit-ID: CNrvA0HuuL6
layout/style/ServoBindingList.h
layout/style/ServoBindingTypes.h
layout/style/ServoBindings.cpp
layout/style/ServoCSSRuleList.cpp
layout/style/ServoStyleRule.cpp
layout/style/ServoStyleRule.h
layout/style/moz.build
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -50,16 +50,18 @@ SERVO_BINDING_FUNC(Servo_StyleSet_Remove
 SERVO_BINDING_FUNC(Servo_StyleSet_InsertStyleSheetBefore, void,
                    RawServoStyleSetBorrowed set, RawServoStyleSheetBorrowed sheet,
                    RawServoStyleSheetBorrowed reference)
 
 // CSSRuleList
 SERVO_BINDING_FUNC(Servo_CssRules_ListTypes, void,
                    ServoCssRulesBorrowed rules,
                    nsTArrayBorrowed_uintptr_t result)
+SERVO_BINDING_FUNC(Servo_CssRules_GetStyleRuleAt, RawServoStyleRuleStrong,
+                   ServoCssRulesBorrowed rules, uint32_t index)
 
 // Animations API
 SERVO_BINDING_FUNC(Servo_ParseProperty,
                    RawServoDeclarationBlockStrong,
                    const nsACString* property, const nsACString* value,
                    const nsACString* base_url, ThreadSafeURIHolder* base,
                    ThreadSafeURIHolder* referrer,
                    ThreadSafePrincipalHolder* principal)
--- a/layout/style/ServoBindingTypes.h
+++ b/layout/style/ServoBindingTypes.h
@@ -10,16 +10,17 @@
 #include "mozilla/RefPtr.h"
 #include "mozilla/UniquePtr.h"
 
 struct ServoComputedValues;
 struct ServoCssRules;
 struct RawServoStyleSheet;
 struct RawServoStyleSet;
 struct RawServoDeclarationBlock;
+struct RawServoStyleRule;
 
 namespace mozilla {
 namespace dom {
 class Element;
 class StyleChildrenIterator;
 } // namespace dom
 } // namespace mozilla
 
@@ -71,16 +72,17 @@ typedef nsIDocument RawGeckoDocument;
   typedef type_* type_##OwnedOrNull;               \
   DECL_NULLABLE_BORROWED_REF_TYPE_FOR(type_)       \
   DECL_NULLABLE_BORROWED_MUT_REF_TYPE_FOR(type_)
 
 DECL_ARC_REF_TYPE_FOR(ServoComputedValues)
 DECL_ARC_REF_TYPE_FOR(ServoCssRules)
 DECL_ARC_REF_TYPE_FOR(RawServoStyleSheet)
 DECL_ARC_REF_TYPE_FOR(RawServoDeclarationBlock)
+DECL_ARC_REF_TYPE_FOR(RawServoStyleRule)
 // This is a reference to a reference of RawServoDeclarationBlock, which
 // corresponds to Option<&Arc<RawServoDeclarationBlock>> in Servo side.
 DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawServoDeclarationBlockStrong)
 
 DECL_OWNED_REF_TYPE_FOR(RawServoStyleSet)
 DECL_NULLABLE_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
 DECL_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
 
@@ -122,16 +124,17 @@ DECL_BORROWED_MUT_REF_TYPE_FOR(nsCSSValu
     }                                                \
   };                                                 \
   }
 
 DEFINE_REFPTR_TRAITS(CssRules, ServoCssRules)
 DEFINE_REFPTR_TRAITS(StyleSheet, RawServoStyleSheet)
 DEFINE_REFPTR_TRAITS(ComputedValues, ServoComputedValues)
 DEFINE_REFPTR_TRAITS(DeclarationBlock, RawServoDeclarationBlock)
+DEFINE_REFPTR_TRAITS(StyleRule, RawServoStyleRule)
 
 #undef DEFINE_REFPTR_TRAITS
 
 extern "C" void Servo_StyleSet_Drop(RawServoStyleSetOwned ptr);
 
 namespace mozilla {
 template<>
 class DefaultDelete<RawServoStyleSet>
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -43,16 +43,17 @@ using namespace mozilla::dom;
     result.swap(mPtr);                  \
     return result.forget();             \
   }
 
 IMPL_STRONG_REF_TYPE_FOR(ServoComputedValues)
 IMPL_STRONG_REF_TYPE_FOR(ServoCssRules)
 IMPL_STRONG_REF_TYPE_FOR(RawServoStyleSheet)
 IMPL_STRONG_REF_TYPE_FOR(RawServoDeclarationBlock)
+IMPL_STRONG_REF_TYPE_FOR(RawServoStyleRule)
 
 #undef IMPL_STRONG_REF_TYPE_FOR
 
 uint32_t
 Gecko_ChildrenCount(RawGeckoNodeBorrowed aNode)
 {
   return aNode->GetChildCount();
 }
--- a/layout/style/ServoCSSRuleList.cpp
+++ b/layout/style/ServoCSSRuleList.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* representation of CSSRuleList for stylo */
 
 #include "mozilla/ServoCSSRuleList.h"
 
 #include "mozilla/ServoBindings.h"
+#include "mozilla/ServoStyleRule.h"
 
 namespace mozilla {
 
 ServoCSSRuleList::ServoCSSRuleList(ServoStyleSheet* aStyleSheet,
                                    already_AddRefed<ServoCssRules> aRawRules)
   : mStyleSheet(aStyleSheet)
   , mRawRules(aRawRules)
 {
@@ -30,17 +31,21 @@ ServoCSSRuleList::IndexedGetter(uint32_t
     aFound = false;
     return nullptr;
   }
   aFound = true;
   uintptr_t rule = mRules[aIndex];
   if (rule <= kMaxRuleType) {
     RefPtr<css::Rule> ruleObj = nullptr;
     switch (rule) {
-      case nsIDOMCSSRule::STYLE_RULE:
+      case nsIDOMCSSRule::STYLE_RULE: {
+        ruleObj = new ServoStyleRule(
+          Servo_CssRules_GetStyleRuleAt(mRawRules, aIndex).Consume());
+        break;
+      }
       case nsIDOMCSSRule::MEDIA_RULE:
       case nsIDOMCSSRule::FONT_FACE_RULE:
       case nsIDOMCSSRule::KEYFRAMES_RULE:
       case nsIDOMCSSRule::NAMESPACE_RULE:
         // XXX create corresponding rules
       default:
         MOZ_CRASH("stylo: not implemented yet");
     }
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoStyleRule.cpp
@@ -0,0 +1,114 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* representation of CSSStyleRule for stylo */
+
+#include "mozilla/ServoStyleRule.h"
+
+#include "nsDOMClassInfoID.h"
+
+namespace mozilla {
+
+// -- ServoStyleRule --------------------------------------------------
+
+// QueryInterface implementation for ServoStyleRule
+NS_INTERFACE_MAP_BEGIN(ServoStyleRule)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, css::Rule)
+  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule)
+NS_INTERFACE_MAP_END
+
+NS_IMPL_ADDREF(ServoStyleRule)
+NS_IMPL_RELEASE(ServoStyleRule)
+
+already_AddRefed<css::Rule>
+ServoStyleRule::Clone() const
+{
+  // Rule::Clone is only used when CSSStyleSheetInner is cloned in
+  // preparation of being mutated. However, ServoStyleSheet never clones
+  // anything, so this method should never be called.
+  MOZ_ASSERT_UNREACHABLE("Shouldn't be cloning ServoStyleRule");
+  return nullptr;
+}
+
+size_t
+ServoStyleRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  // TODO Implement this!
+  return aMallocSizeOf(this);
+}
+
+#ifdef DEBUG
+void
+ServoStyleRule::List(FILE* out, int32_t aIndent) const
+{
+  // TODO Implement this!
+}
+#endif
+
+/* CSSRule implementation */
+
+NS_IMETHODIMP
+ServoStyleRule::GetType(uint16_t* aType)
+{
+  *aType = nsIDOMCSSRule::STYLE_RULE;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+ServoStyleRule::GetCssText(nsAString& aCssText)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+ServoStyleRule::SetCssText(const nsAString& aCssText)
+{
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+ServoStyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
+{
+  return css::Rule::GetParentStyleSheet(aSheet);
+}
+
+NS_IMETHODIMP
+ServoStyleRule::GetParentRule(nsIDOMCSSRule** aParentRule)
+{
+  *aParentRule = nullptr;
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+css::Rule*
+ServoStyleRule::GetCSSRule()
+{
+  return this;
+}
+
+/* CSSStyleRule implementation */
+
+NS_IMETHODIMP
+ServoStyleRule::GetSelectorText(nsAString& aSelectorText)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+ServoStyleRule::SetSelectorText(const nsAString& aSelectorText)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+ServoStyleRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
+{
+  *aStyle = nullptr;
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoStyleRule.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* representation of CSSStyleRule for stylo */
+
+#ifndef mozilla_ServoStyleRule_h
+#define mozilla_ServoStyleRule_h
+
+#include "mozilla/css/Rule.h"
+#include "mozilla/ServoBindingTypes.h"
+
+#include "nsIDOMCSSStyleRule.h"
+
+namespace mozilla {
+
+class ServoStyleRule final : public css::Rule
+                           , public nsIDOMCSSStyleRule
+{
+public:
+  explicit ServoStyleRule(already_AddRefed<RawServoStyleRule> aRawRule)
+    : css::Rule(0, 0)
+    , mRawRule(aRawRule)
+  {}
+
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSIDOMCSSRULE
+  NS_DECL_NSIDOMCSSSTYLERULE
+
+  // Methods of mozilla::css::Rule
+  int32_t GetType() const final { return css::Rule::STYLE_RULE; }
+  already_AddRefed<Rule> Clone() const final;
+  nsIDOMCSSRule* GetDOMRule() final { return this; }
+  nsIDOMCSSRule* GetExistingDOMRule() final { return this; }
+  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final;
+#ifdef DEBUG
+  void List(FILE* out = stdout, int32_t aIndent = 0) const final;
+#endif
+
+private:
+  ~ServoStyleRule() {}
+
+  RefPtr<RawServoStyleRule> mRawRule;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_ServoStyleRule_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -94,16 +94,17 @@ EXPORTS.mozilla += [
     'RuleNodeCacheConditions.h',
     'RuleProcessorCache.h',
     'ServoBindingList.h',
     'ServoBindings.h',
     'ServoBindingTypes.h',
     'ServoCSSRuleList.h',
     'ServoDeclarationBlock.h',
     'ServoElementSnapshot.h',
+    'ServoStyleRule.h',
     'ServoStyleSet.h',
     'ServoStyleSheet.h',
     'ServoTypes.h',
     'ServoUtils.h',
     'SheetType.h',
     'StyleAnimationValue.h',
     'StyleBackendType.h',
     'StyleComplexColor.h',
@@ -195,16 +196,17 @@ UNIFIED_SOURCES += [
     'nsStyleUtil.cpp',
     'nsTransitionManager.cpp',
     'RuleNodeCacheConditions.cpp',
     'RuleProcessorCache.cpp',
     'ServoBindings.cpp',
     'ServoCSSRuleList.cpp',
     'ServoDeclarationBlock.cpp',
     'ServoElementSnapshot.cpp',
+    'ServoStyleRule.cpp',
     'ServoStyleSet.cpp',
     'ServoStyleSheet.cpp',
     'StyleAnimationValue.cpp',
     'StyleRule.cpp',
     'StyleSheet.cpp',
     'SVGAttrAnimationRuleProcessor.cpp',
 ]