Bug 1290218 Part 8: Implement ServoStyleSheet Clone. draft
authorBrad Werth <bwerth@mozilla.com>
Wed, 08 Feb 2017 12:39:13 -0800
changeset 480747 4a8862b9fb6e9d759d01fe91ac8cd4aef69d70af
parent 480746 1e9791e27c1f7837c548689954f8ee09c53df123
child 480748 5a87ed9514c88855a55c864c0fda669440c1d31d
push id44647
push userbwerth@mozilla.com
push dateWed, 08 Feb 2017 21:49:09 +0000
bugs1290218
milestone54.0a1
Bug 1290218 Part 8: Implement ServoStyleSheet Clone. MozReview-Commit-ID: Y2KcoMjhbn
layout/style/Loader.cpp
layout/style/ServoStyleSheet.cpp
layout/style/ServoStyleSheet.h
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -1203,17 +1203,17 @@ Loader::CreateSheet(nsIURI* aURI,
       }
       NS_ASSERTION(!sheet->AsGecko()->IsModified() ||
                    !sheet->AsGecko()->IsComplete(),
                    "Unexpected modified complete sheet");
       NS_ASSERTION(sheet->AsGecko()->IsComplete() ||
                    aSheetState != eSheetComplete,
                    "Sheet thinks it's not complete while we think it is");
 
-      RefPtr<CSSStyleSheet> clonedSheet =
+      RefPtr<StyleSheet> clonedSheet =
         sheet->AsGecko()->Clone(nullptr, nullptr, nullptr, nullptr);
       *aSheet = Move(clonedSheet);
       if (*aSheet && fromCompleteSheets &&
           !sheet->AsGecko()->GetOwnerNode() &&
           !sheet->AsGecko()->GetParentSheet()) {
         // The sheet we're cloning isn't actually referenced by
         // anyone.  Replace it in the cache, so that if our CSSOM is
         // later modified we don't end up with two copies of our inner
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -35,16 +35,26 @@ ServoStyleSheet::ServoStyleSheet(css::Sh
                                  net::ReferrerPolicy aReferrerPolicy,
                                  const dom::SRIMetadata& aIntegrity)
   : StyleSheet(StyleBackendType::Servo, aParsingMode)
 {
   mInner = new ServoStyleSheetInner(aCORSMode, aReferrerPolicy, aIntegrity);
   mInner->AddSheet(this);
 }
 
+ServoStyleSheet::ServoStyleSheet(const ServoStyleSheet& aCopy,
+                                 ServoStyleSheet* aParentToUse,
+                                 css::ImportRule* aOwnerRuleToUse,
+                                 nsIDocument* aDocumentToUse,
+                                 nsINode* aOwningNodeToUse)
+  : StyleSheet(aCopy, aDocumentToUse, aOwningNodeToUse)
+{
+  mParent = aParentToUse;
+}
+
 ServoStyleSheet::~ServoStyleSheet()
 {
   UnparentChildren();
 
   DropSheet();
 }
 
 // QueryInterface implementation for ServoStyleSheet
@@ -128,16 +138,30 @@ ServoStyleSheet::DropRuleList()
 
 css::Rule*
 ServoStyleSheet::GetDOMOwnerRule() const
 {
   NS_ERROR("stylo: Don't know how to get DOM owner rule for ServoStyleSheet");
   return nullptr;
 }
 
+already_AddRefed<ServoStyleSheet>
+ServoStyleSheet::Clone(ServoStyleSheet* aCloneParent,
+                       css::ImportRule* aCloneOwnerRule,
+                       nsIDocument* aCloneDocument,
+                       nsINode* aCloneOwningNode) const
+{
+  RefPtr<ServoStyleSheet> clone = new ServoStyleSheet(*this,
+                                                      aCloneParent,
+                                                      aCloneOwnerRule,
+                                                      aCloneDocument,
+                                                      aCloneOwningNode);
+  return clone.forget();
+}
+
 CSSRuleList*
 ServoStyleSheet::GetCssRulesInternal(ErrorResult& aRv)
 {
   if (!mRuleList) {
     ServoStyleSheetInner* inner = static_cast<ServoStyleSheetInner*>(mInner);
     RefPtr<ServoCssRules> rawRules =
       Servo_StyleSheet_GetRules(inner->mSheet).Consume();
     mRuleList = new ServoCSSRuleList(this, rawRules.forget());
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -83,28 +83,39 @@ public:
   // version.
   css::Rule* GetDOMOwnerRule() const final;
 
   void WillDirty() {}
   void DidDirty() {}
 
   bool IsModified() const final override { return false; }
 
+  already_AddRefed<ServoStyleSheet> Clone(ServoStyleSheet* aCloneParent,
+                                          css::ImportRule* aCloneOwnerRule,
+                                          nsIDocument* aCloneDocument,
+                                          nsINode* aCloneOwningNode) const;
+
 protected:
   virtual ~ServoStyleSheet();
 
   // Internal methods which do not have security check and completeness check.
   dom::CSSRuleList* GetCssRulesInternal(ErrorResult& aRv);
   uint32_t InsertRuleInternal(const nsAString& aRule,
                               uint32_t aIndex, ErrorResult& aRv);
   void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv);
 
   void EnabledStateChangedInternal() {}
 
 private:
+  ServoStyleSheet(const ServoStyleSheet& aCopy,
+                  ServoStyleSheet* aParentToUse,
+                  css::ImportRule* aOwnerRuleToUse,
+                  nsIDocument* aDocumentToUse,
+                  nsINode* aOwningNodeToUse);
+
   void DropSheet();
   void DropRuleList();
 
   RefPtr<ServoCSSRuleList> mRuleList;
 
   friend class StyleSheet;
 };