Bug 1315601 part 14 - Add InsertRuleIntoGroup support to ServoStyleSheet. r=heycam
MozReview-Commit-ID: GUHtvjQXECW
--- a/layout/style/ServoCSSRuleList.h
+++ b/layout/style/ServoCSSRuleList.h
@@ -19,16 +19,17 @@ namespace css {
class GroupRule;
class Rule;
} // namespace css
class ServoCSSRuleList final : public dom::CSSRuleList
{
public:
explicit ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules);
+ css::GroupRule* GetParentRule() const { return mParentRule; }
void SetParentRule(css::GroupRule* aParentRule);
void SetStyleSheet(StyleSheet* aSheet);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServoCSSRuleList, dom::CSSRuleList)
ServoStyleSheet* GetParentObject() final { return mStyleSheet; }
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -5,16 +5,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ServoStyleSheet.h"
#include "mozilla/css/Rule.h"
#include "mozilla/StyleBackendType.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/ServoCSSRuleList.h"
+#include "mozilla/css/GroupRule.h"
#include "mozilla/dom/CSSRuleList.h"
#include "mozAutoDocUpdate.h"
using namespace mozilla::dom;
namespace mozilla {
@@ -197,9 +198,19 @@ ServoStyleSheet::DeleteRuleInternal(uint
aRv = mRuleList->DeleteRule(aIndex);
MOZ_ASSERT(!aRv.ErrorCodeIs(NS_ERROR_DOM_INDEX_SIZE_ERR),
"IndexSizeError should have been handled earlier");
if (!aRv.Failed() && mDocument) {
mDocument->StyleRuleRemoved(this, rule);
}
}
+nsresult
+ServoStyleSheet::InsertRuleIntoGroupInternal(const nsAString& aRule,
+ css::GroupRule* aGroup,
+ uint32_t aIndex)
+{
+ auto rules = static_cast<ServoCSSRuleList*>(aGroup->CssRules());
+ MOZ_ASSERT(rules->GetParentRule() == aGroup);
+ return rules->InsertRule(aRule, aIndex);
+}
+
} // namespace mozilla
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -98,16 +98,19 @@ protected:
return static_cast<ServoStyleSheetInner*>(mInner);
}
// 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);
+ nsresult InsertRuleIntoGroupInternal(const nsAString& aRule,
+ css::GroupRule* aGroup,
+ uint32_t aIndex);
void EnabledStateChangedInternal() {}
private:
ServoStyleSheet(const ServoStyleSheet& aCopy,
ServoStyleSheet* aParentToUse,
css::ImportRule* aOwnerRuleToUse,
nsIDocument* aDocumentToUse,
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -468,18 +468,17 @@ StyleSheet::InsertRuleIntoGroup(const ns
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
WillDirty();
nsresult result;
if (IsGecko()) {
result = AsGecko()->InsertRuleIntoGroupInternal(aRule, aGroup, aIndex);
} else {
- // TODO
- result = NS_ERROR_NOT_IMPLEMENTED;
+ result = AsServo()->InsertRuleIntoGroupInternal(aRule, aGroup, aIndex);
}
NS_ENSURE_SUCCESS(result, result);
DidDirty();
if (mDocument) {
mDocument->StyleRuleAdded(this, aGroup->GetStyleRuleAt(aIndex));
}