From d4b0049e467c0edcef67c8bbc401297ce78c76cf Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Thu, 25 Feb 2016 18:57:42 -0800 Subject: [PATCH] Bug 1251496 - Forward stylesheet management to RawServoStyleSet. r=heycam --- layout/style/ServoBindings.cpp | 25 +++++++++++++++++++++++++ layout/style/ServoBindings.h | 4 ++++ layout/style/ServoStyleSet.cpp | 21 +++++++++++++++++++-- layout/style/ServoStyleSheet.cpp | 2 +- layout/style/ServoStyleSheet.h | 2 ++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/layout/style/ServoBindings.cpp b/layout/style/ServoBindings.cpp index cceb53fbed5..8a5924c4ab6 100644 --- a/layout/style/ServoBindings.cpp +++ b/layout/style/ServoBindings.cpp @@ -170,6 +170,31 @@ Servo_ReleaseStylesheet(RawServoStyleSheet* sheet) "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() { diff --git a/layout/style/ServoBindings.h b/layout/style/ServoBindings.h index 3c5a3d4a3b5..2a5ebdb49d5 100644 --- a/layout/style/ServoBindings.h +++ b/layout/style/ServoBindings.h @@ -82,6 +82,10 @@ void Servo_DropNodeData(ServoNodeData* data); // 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); diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index 9b752935051..9cf0cf0027d 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -123,6 +123,9 @@ ServoStyleSet::AppendStyleSheet(SheetType 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; } @@ -137,6 +140,9 @@ ServoStyleSet::PrependStyleSheet(SheetType 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; } @@ -144,7 +150,16 @@ 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 @@ -187,7 +202,9 @@ 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 diff --git a/layout/style/ServoStyleSheet.cpp b/layout/style/ServoStyleSheet.cpp index 2682908e4b3..9a287098474 100644 --- a/layout/style/ServoStyleSheet.cpp +++ b/layout/style/ServoStyleSheet.cpp @@ -40,7 +40,7 @@ ServoStyleSheet::SetComplete() bool ServoStyleSheet::HasRules() const { - MOZ_CRASH("stylo: not implemented"); + return Servo_StyleSheetHasRules(RawSheet()); } nsIDocument* diff --git a/layout/style/ServoStyleSheet.h b/layout/style/ServoStyleSheet.h index c1dee577f31..dd2eb28bd30 100644 --- a/layout/style/ServoStyleSheet.h +++ b/layout/style/ServoStyleSheet.h @@ -53,6 +53,8 @@ public: void List(FILE* aOut = stdout, int32_t aIndex = 0) const; #endif + RawServoStyleSheet* RawSheet() const { return mSheet; } + protected: ~ServoStyleSheet();