Bug 1251496 - Forward stylesheet management to RawServoStyleSet. r=heycam
authorBobby Holley <bobbyholley@gmail.com>
Thu, 25 Feb 2016 18:57:42 -0800
changeset 322301 621f1087e51a5e7ebe66edcfab6a407424ea97f9
parent 322300 49904442faec1c1f4ca91cbbea0e8ebcfb2a5b6a
child 322302 cbc8aa59e92914297dcda968745e03c847498515
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1251496
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1251496 - Forward stylesheet management to RawServoStyleSet. r=heycam
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSheet.cpp
layout/style/ServoStyleSheet.h
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -165,16 +165,41 @@ Servo_StylesheetFromUTF8Bytes(const uint
 
 void
 Servo_ReleaseStylesheet(RawServoStyleSheet* sheet)
 {
   MOZ_CRASH("stylo: shouldn't be calling Servo_ReleaseStylesheet in a "
             "non-MOZ_STYLO build");
 }
 
+void
+Servo_AppendStyleSheet(RawServoStyleSheet* sheet, RawServoStyleSet* set)
+{
+  MOZ_CRASH("stylo: shouldn't be calling Servo_AppendStyleSheet in a "
+            "non-MOZ_STYLO build");
+}
+
+void Servo_PrependStyleSheet(RawServoStyleSheet* sheet, RawServoStyleSet* set)
+{
+  MOZ_CRASH("stylo: shouldn't be calling Servo_PrependStyleSheet in a "
+            "non-MOZ_STYLO build");
+}
+
+void Servo_RemoveStyleSheet(RawServoStyleSheet* sheet, RawServoStyleSet* set)
+{
+  MOZ_CRASH("stylo: shouldn't be calling Servo_RemoveStyleSheet in a "
+            "non-MOZ_STYLO build");
+}
+
+int Servo_StyleSheetHasRules(RawServoStyleSheet* sheet)
+{
+  MOZ_CRASH("stylo: shouldn't be calling Servo_StyleSheetHasRules in a "
+            "non-MOZ_STYLO build");
+}
+
 RawServoStyleSet*
 Servo_InitStyleSet()
 {
   MOZ_CRASH("stylo: shouldn't be calling Servo_InitStyleSet in a "
             "non-MOZ_STYLO build");
 }
 
 void
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -77,16 +77,20 @@ void Gecko_SetNodeData(RawGeckoNode* nod
 void Servo_DropNodeData(ServoNodeData* data);
 
 // Styleset and Stylesheet management.
 //
 // TODO: Make these return already_AddRefed and UniquePtr when the binding
 // generator is smart enough to handle them.
 RawServoStyleSheet* Servo_StylesheetFromUTF8Bytes(const uint8_t* bytes, uint32_t length);
 void Servo_ReleaseStylesheet(RawServoStyleSheet* sheet);
+void Servo_AppendStyleSheet(RawServoStyleSheet* sheet, RawServoStyleSet* set);
+void Servo_PrependStyleSheet(RawServoStyleSheet* sheet, RawServoStyleSet* set);
+void Servo_RemoveStyleSheet(RawServoStyleSheet* sheet, RawServoStyleSet* set);
+int Servo_StyleSheetHasRules(RawServoStyleSheet* sheet);
 RawServoStyleSet* Servo_InitStyleSet();
 void Servo_DropStyleSet(RawServoStyleSet* set);
 
 // Servo API.
 void Servo_RestyleDocument(RawGeckoDocument* doc, RawServoStyleSet* set);
 
 #ifdef __cplusplus
 } // extern "C"
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -118,38 +118,53 @@ ServoStyleSet::AppendStyleSheet(SheetTyp
 {
   MOZ_ASSERT(aSheet);
   MOZ_ASSERT(aSheet->IsApplicable());
   MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
 
   mSheets[aType].RemoveElement(aSheet);
   mSheets[aType].AppendElement(aSheet);
 
+  // Maintain a mirrored list of sheets on the servo side.
+  Servo_AppendStyleSheet(aSheet->RawSheet(), mRawSet.get());
+
   return NS_OK;
 }
 
 nsresult
 ServoStyleSet::PrependStyleSheet(SheetType aType,
                                  ServoStyleSheet* aSheet)
 {
   MOZ_ASSERT(aSheet);
   MOZ_ASSERT(aSheet->IsApplicable());
   MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
 
   mSheets[aType].RemoveElement(aSheet);
   mSheets[aType].InsertElementAt(0, aSheet);
 
+  // Maintain a mirrored list of sheets on the servo side.
+  Servo_PrependStyleSheet(aSheet->RawSheet(), mRawSet.get());
+
   return NS_OK;
 }
 
 nsresult
 ServoStyleSet::RemoveStyleSheet(SheetType aType,
                                 ServoStyleSheet* aSheet)
 {
-  MOZ_CRASH("stylo: not implemented");
+  MOZ_ASSERT(aSheet);
+  MOZ_ASSERT(aSheet->IsApplicable());
+  MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
+
+  mSheets[aType].RemoveElement(aSheet);
+
+  // Maintain a mirrored list of sheets on the servo side.
+  Servo_RemoveStyleSheet(aSheet->RawSheet(), mRawSet.get());
+
+  return NS_OK;
 }
 
 nsresult
 ServoStyleSet::ReplaceSheets(SheetType aType,
                              const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets)
 {
   MOZ_CRASH("stylo: not implemented");
 }
@@ -182,17 +197,19 @@ ServoStyleSet::RemoveDocStyleSheet(Servo
 {
   MOZ_CRASH("stylo: not implemented");
 }
 
 nsresult
 ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet,
                                 nsIDocument* aDocument)
 {
-  MOZ_CRASH("stylo: not implemented");
+  // XXXbholley: Implement this.
+  NS_ERROR("stylo: no support for adding doc stylesheets to ServoStyleSet");
+  return NS_OK;
 }
 
 already_AddRefed<nsStyleContext>
 ServoStyleSet::ProbePseudoElementStyle(Element* aParentElement,
                                        CSSPseudoElementType aType,
                                        nsStyleContext* aParentContext)
 {
   MOZ_CRASH("stylo: not implemented");
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -35,17 +35,17 @@ ServoStyleSheet::SetComplete()
 
   NS_ERROR("stylo: ServoStyleSheet::SetComplete should do the things "
            "CSSStyleSheet::SetComplete does");
 }
 
 bool
 ServoStyleSheet::HasRules() const
 {
-  MOZ_CRASH("stylo: not implemented");
+  return Servo_StyleSheetHasRules(RawSheet());
 }
 
 nsIDocument*
 ServoStyleSheet::GetOwningDocument() const
 {
   NS_ERROR("stylo: GetOwningDocument not implemented, returning null");
 
   return nullptr;
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -48,16 +48,18 @@ public:
                   css::SheetParsingMode aParsingMode);
 
   size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
 
 #ifdef DEBUG
   void List(FILE* aOut = stdout, int32_t aIndex = 0) const;
 #endif
 
+  RawServoStyleSheet* RawSheet() const { return mSheet; }
+
 protected:
   ~ServoStyleSheet();
 
 private:
   void DropSheet();
 
   RefPtr<RawServoStyleSheet> mSheet;
 };