2016-02-24 10:01:11 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/ServoStyleSheet.h"
|
2016-12-01 21:40:04 +03:00
|
|
|
|
|
|
|
#include "mozilla/css/Rule.h"
|
2016-03-02 01:38:13 +03:00
|
|
|
#include "mozilla/StyleBackendType.h"
|
2016-11-23 02:26:20 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2017-06-19 08:45:43 +03:00
|
|
|
#include "mozilla/ServoImportRule.h"
|
2017-04-11 17:13:16 +03:00
|
|
|
#include "mozilla/ServoMediaList.h"
|
2016-11-23 02:26:20 +03:00
|
|
|
#include "mozilla/ServoCSSRuleList.h"
|
2017-03-08 10:27:53 +03:00
|
|
|
#include "mozilla/css/GroupRule.h"
|
2016-11-23 02:26:20 +03:00
|
|
|
#include "mozilla/dom/CSSRuleList.h"
|
2017-04-11 17:13:16 +03:00
|
|
|
#include "mozilla/dom/MediaList.h"
|
2017-05-26 11:01:40 +03:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
2017-05-26 10:59:01 +03:00
|
|
|
#include "Loader.h"
|
2016-02-24 10:01:11 +03:00
|
|
|
|
2017-05-19 02:36:44 +03:00
|
|
|
|
2016-11-29 14:59:55 +03:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2017-05-19 02:36:44 +03:00
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
2016-11-29 14:59:55 +03:00
|
|
|
|
2016-12-01 21:37:44 +03:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2016-02-24 10:01:11 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2017-02-14 23:05:12 +03:00
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet Inner Data Container
|
|
|
|
//
|
|
|
|
|
|
|
|
ServoStyleSheetInner::ServoStyleSheetInner(CORSMode aCORSMode,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
const SRIMetadata& aIntegrity)
|
|
|
|
: StyleSheetInfo(aCORSMode, aReferrerPolicy, aIntegrity)
|
|
|
|
{
|
2017-05-16 02:19:17 +03:00
|
|
|
MOZ_COUNT_CTOR(ServoStyleSheetInner);
|
|
|
|
}
|
|
|
|
|
|
|
|
ServoStyleSheetInner::ServoStyleSheetInner(ServoStyleSheetInner& aCopy,
|
|
|
|
ServoStyleSheet* aPrimarySheet)
|
|
|
|
: StyleSheetInfo(aCopy, aPrimarySheet)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ServoStyleSheetInner);
|
|
|
|
|
|
|
|
// Actually clone aCopy's mSheet and use that as our mSheet.
|
|
|
|
mSheet = Servo_StyleSheet_Clone(aCopy.mSheet).Consume();
|
|
|
|
|
|
|
|
mURLData = aCopy.mURLData;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServoStyleSheetInner::~ServoStyleSheetInner()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ServoStyleSheetInner);
|
|
|
|
}
|
|
|
|
|
|
|
|
StyleSheetInfo*
|
|
|
|
ServoStyleSheetInner::CloneFor(StyleSheet* aPrimarySheet)
|
|
|
|
{
|
|
|
|
return new ServoStyleSheetInner(*this,
|
|
|
|
static_cast<ServoStyleSheet*>(aPrimarySheet));
|
2017-02-14 23:05:12 +03:00
|
|
|
}
|
|
|
|
|
2017-05-30 04:03:51 +03:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(ServoStyleSheetMallocSizeOf)
|
|
|
|
|
2017-04-06 05:22:36 +03:00
|
|
|
size_t
|
|
|
|
ServoStyleSheetInner::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
2017-06-27 20:09:07 +03:00
|
|
|
// mSheet will be null if the parsing has not completed.
|
|
|
|
if (mSheet) {
|
|
|
|
n += Servo_StyleSheet_SizeOfIncludingThis(ServoStyleSheetMallocSizeOf,
|
|
|
|
mSheet);
|
|
|
|
}
|
2017-04-06 05:22:36 +03:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2016-08-02 23:12:27 +03:00
|
|
|
ServoStyleSheet::ServoStyleSheet(css::SheetParsingMode aParsingMode,
|
|
|
|
CORSMode aCORSMode,
|
2016-02-26 04:51:01 +03:00
|
|
|
net::ReferrerPolicy aReferrerPolicy,
|
|
|
|
const dom::SRIMetadata& aIntegrity)
|
2016-08-02 23:12:27 +03:00
|
|
|
: StyleSheet(StyleBackendType::Servo, aParsingMode)
|
2016-02-24 10:01:11 +03:00
|
|
|
{
|
2017-02-14 23:05:12 +03:00
|
|
|
mInner = new ServoStyleSheetInner(aCORSMode, aReferrerPolicy, aIntegrity);
|
2017-02-18 02:48:35 +03:00
|
|
|
mInner->AddSheet(this);
|
2016-02-24 10:01:11 +03:00
|
|
|
}
|
|
|
|
|
2017-02-16 00:33:17 +03:00
|
|
|
ServoStyleSheet::ServoStyleSheet(const ServoStyleSheet& aCopy,
|
|
|
|
ServoStyleSheet* aParentToUse,
|
2017-05-30 04:10:25 +03:00
|
|
|
dom::CSSImportRule* aOwnerRuleToUse,
|
2017-02-16 00:33:17 +03:00
|
|
|
nsIDocument* aDocumentToUse,
|
|
|
|
nsINode* aOwningNodeToUse)
|
2017-05-31 14:12:33 +03:00
|
|
|
: StyleSheet(aCopy,
|
|
|
|
aParentToUse,
|
|
|
|
aOwnerRuleToUse,
|
|
|
|
aDocumentToUse,
|
|
|
|
aOwningNodeToUse)
|
2017-02-16 00:33:17 +03:00
|
|
|
{
|
2017-05-31 13:27:56 +03:00
|
|
|
if (mDirty) { // CSSOM's been there, force full copy now
|
2017-05-31 14:12:33 +03:00
|
|
|
NS_ASSERTION(mInner->mComplete,
|
|
|
|
"Why have rules been accessed on an incomplete sheet?");
|
2017-05-31 13:27:56 +03:00
|
|
|
// FIXME: handle failure?
|
|
|
|
//
|
|
|
|
// NOTE: It's important to call this from the subclass, since this could
|
|
|
|
// access uninitialized members otherwise.
|
|
|
|
EnsureUniqueInner();
|
|
|
|
}
|
2017-02-16 00:33:17 +03:00
|
|
|
}
|
|
|
|
|
2016-02-26 04:51:01 +03:00
|
|
|
ServoStyleSheet::~ServoStyleSheet()
|
2016-02-24 10:01:11 +03:00
|
|
|
{
|
2017-06-19 03:15:49 +03:00
|
|
|
}
|
2017-01-24 03:37:59 +03:00
|
|
|
|
2017-06-19 03:15:49 +03:00
|
|
|
void
|
|
|
|
ServoStyleSheet::LastRelease()
|
|
|
|
{
|
2017-02-18 02:48:35 +03:00
|
|
|
DropRuleList();
|
2016-02-24 10:01:11 +03:00
|
|
|
}
|
|
|
|
|
2017-01-06 07:14:28 +03:00
|
|
|
// QueryInterface implementation for ServoStyleSheet
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ServoStyleSheet)
|
2017-05-19 02:36:44 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSStyleSheet)
|
|
|
|
if (aIID.Equals(NS_GET_IID(ServoStyleSheet)))
|
|
|
|
foundInterface = reinterpret_cast<nsISupports*>(this);
|
|
|
|
else
|
2017-01-06 07:14:28 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(StyleSheet)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(ServoStyleSheet, StyleSheet)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(ServoStyleSheet, StyleSheet)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(ServoStyleSheet)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ServoStyleSheet)
|
|
|
|
tmp->DropRuleList();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(StyleSheet)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoStyleSheet, StyleSheet)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRuleList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2016-02-24 10:01:11 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSheet::HasRules() const
|
|
|
|
{
|
2017-02-14 23:05:12 +03:00
|
|
|
return Inner()->mSheet && Servo_StyleSheet_HasRules(Inner()->mSheet);
|
2016-02-24 10:01:11 +03:00
|
|
|
}
|
|
|
|
|
2016-08-31 13:10:10 +03:00
|
|
|
nsresult
|
2016-12-17 12:58:56 +03:00
|
|
|
ServoStyleSheet::ParseSheet(css::Loader* aLoader,
|
|
|
|
const nsAString& aInput,
|
2016-02-24 10:01:11 +03:00
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2017-05-14 18:11:18 +03:00
|
|
|
uint32_t aLineNumber,
|
2017-05-26 10:59:01 +03:00
|
|
|
nsCompatibility aCompatMode,
|
|
|
|
css::LoaderReusableStyleSheets* aReusableSheets)
|
2016-02-24 10:01:11 +03:00
|
|
|
{
|
2017-06-07 08:27:17 +03:00
|
|
|
MOZ_ASSERT(!mMedia || mMedia->IsServo());
|
2017-04-04 03:04:13 +03:00
|
|
|
RefPtr<URLExtraData> extraData =
|
|
|
|
new URLExtraData(aBaseURI, aSheetURI, aSheetPrincipal);
|
2016-05-21 03:02:54 +03:00
|
|
|
|
2016-02-26 04:51:01 +03:00
|
|
|
NS_ConvertUTF16toUTF8 input(aInput);
|
2017-02-14 23:05:12 +03:00
|
|
|
if (!Inner()->mSheet) {
|
2017-04-11 17:13:16 +03:00
|
|
|
auto* mediaList = static_cast<ServoMediaList*>(mMedia.get());
|
|
|
|
RawServoMediaList* media = mediaList ? &mediaList->RawList() : nullptr;
|
|
|
|
|
2017-02-14 23:05:12 +03:00
|
|
|
Inner()->mSheet =
|
2017-04-11 17:13:16 +03:00
|
|
|
Servo_StyleSheet_FromUTF8Bytes(
|
2017-05-14 18:11:18 +03:00
|
|
|
aLoader, this, &input, mParsingMode, media, extraData,
|
|
|
|
aLineNumber, aCompatMode
|
2017-04-25 22:01:45 +03:00
|
|
|
).Consume();
|
2016-12-17 12:58:56 +03:00
|
|
|
} else {
|
2017-04-11 17:13:16 +03:00
|
|
|
// TODO(emilio): Once we have proper inner cloning (which we don't right
|
|
|
|
// now) we should update the mediaList here too, though it's slightly
|
|
|
|
// tricky.
|
2017-03-30 10:54:48 +03:00
|
|
|
Servo_StyleSheet_ClearAndUpdate(Inner()->mSheet, aLoader,
|
2017-05-26 10:59:01 +03:00
|
|
|
this, &input, extraData, aLineNumber,
|
|
|
|
aReusableSheets);
|
2016-12-17 12:58:56 +03:00
|
|
|
}
|
2016-08-31 13:10:10 +03:00
|
|
|
|
2017-04-04 06:41:44 +03:00
|
|
|
Inner()->mURLData = extraData.forget();
|
2016-08-31 13:10:10 +03:00
|
|
|
return NS_OK;
|
2016-02-26 04:51:01 +03:00
|
|
|
}
|
|
|
|
|
2016-10-25 20:15:38 +03:00
|
|
|
void
|
|
|
|
ServoStyleSheet::LoadFailed()
|
|
|
|
{
|
2017-06-09 03:52:35 +03:00
|
|
|
if (!Inner()->mSheet) {
|
|
|
|
// Only create empty stylesheet if this is a top level stylesheet.
|
|
|
|
// The raw sheet for stylesheet of @import rule is already set in
|
|
|
|
// loader, and we should not touch it.
|
|
|
|
Inner()->mSheet = Servo_StyleSheet_Empty(mParsingMode).Consume();
|
|
|
|
}
|
2017-04-04 06:41:44 +03:00
|
|
|
Inner()->mURLData = URLExtraData::Dummy();
|
2016-10-25 20:15:38 +03:00
|
|
|
}
|
|
|
|
|
2017-05-26 11:01:40 +03:00
|
|
|
nsresult
|
|
|
|
ServoStyleSheet::ReparseSheet(const nsAString& aInput)
|
|
|
|
{
|
|
|
|
if (!mInner->mComplete) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
|
|
|
|
2017-06-20 03:49:27 +03:00
|
|
|
// Hold strong ref to the CSSLoader in case the document update
|
|
|
|
// kills the document
|
2017-05-26 11:01:40 +03:00
|
|
|
RefPtr<css::Loader> loader;
|
|
|
|
if (mDocument) {
|
|
|
|
loader = mDocument->CSSLoader();
|
|
|
|
NS_ASSERTION(loader, "Document with no CSS loader!");
|
|
|
|
} else {
|
|
|
|
loader = new css::Loader(StyleBackendType::Servo, nullptr);
|
|
|
|
}
|
|
|
|
|
2017-06-20 03:49:27 +03:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
|
|
|
|
|
|
|
|
WillDirty();
|
|
|
|
|
2017-05-26 11:01:40 +03:00
|
|
|
// cache child sheets to reuse
|
|
|
|
css::LoaderReusableStyleSheets reusableSheets;
|
|
|
|
for (StyleSheet* child = GetFirstChild(); child; child = child->mNext) {
|
|
|
|
if (child->GetOriginalURI()) {
|
|
|
|
reusableSheets.AddReusableSheet(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// clean up child sheets list
|
|
|
|
for (StyleSheet* child = GetFirstChild(); child; ) {
|
|
|
|
StyleSheet* next = child->mNext;
|
|
|
|
child->mParent = nullptr;
|
|
|
|
child->SetAssociatedDocument(nullptr, NotOwnedByDocument);
|
|
|
|
child->mNext = nullptr;
|
|
|
|
child = next;
|
|
|
|
}
|
|
|
|
Inner()->mFirstChild = nullptr;
|
|
|
|
|
|
|
|
uint32_t lineNumber = 1;
|
|
|
|
if (mOwningNode) {
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> link = do_QueryInterface(mOwningNode);
|
|
|
|
if (link) {
|
|
|
|
lineNumber = link->GetLineNumber();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-20 03:49:27 +03:00
|
|
|
// Notify mDocument that all our rules are removed.
|
|
|
|
if (mDocument) {
|
|
|
|
// Get the rule list.
|
|
|
|
ServoCSSRuleList* ruleList = GetCssRulesInternal();
|
|
|
|
MOZ_ASSERT(ruleList);
|
|
|
|
|
|
|
|
uint32_t ruleCount = ruleList->Length();
|
|
|
|
for (uint32_t i = 0; i < ruleCount; ++i) {
|
|
|
|
css::Rule* rule = ruleList->GetRule(i);
|
|
|
|
MOZ_ASSERT(rule);
|
|
|
|
if (rule->GetType() == css::Rule::IMPORT_RULE &&
|
|
|
|
RuleHasPendingChildSheet(rule)) {
|
|
|
|
continue; // notify when loaded (see StyleSheetLoaded)
|
|
|
|
}
|
|
|
|
mDocument->StyleRuleRemoved(this, rule);
|
|
|
|
|
|
|
|
// Document observers could possibly detach document from this sheet.
|
|
|
|
if (!mDocument) {
|
|
|
|
// If detached, don't process any more rules.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DropRuleList();
|
|
|
|
|
2017-05-26 11:01:40 +03:00
|
|
|
nsresult rv = ParseSheet(loader, aInput, mInner->mSheetURI, mInner->mBaseURI,
|
|
|
|
mInner->mPrincipal, lineNumber,
|
|
|
|
eCompatibility_FullStandards, &reusableSheets);
|
2017-06-20 03:49:27 +03:00
|
|
|
DidDirty();
|
2017-05-26 11:01:40 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-06-20 03:49:27 +03:00
|
|
|
|
|
|
|
// Notify mDocument that all our new rules are added.
|
|
|
|
if (mDocument) {
|
|
|
|
// Get the rule list (which will need to be regenerated after ParseSheet).
|
|
|
|
ServoCSSRuleList* ruleList = GetCssRulesInternal();
|
|
|
|
MOZ_ASSERT(ruleList);
|
|
|
|
|
|
|
|
uint32_t ruleCount = ruleList->Length();
|
|
|
|
for (uint32_t i = 0; i < ruleCount; ++i) {
|
|
|
|
css::Rule* rule = ruleList->GetRule(i);
|
|
|
|
MOZ_ASSERT(rule);
|
|
|
|
if (rule->GetType() == css::Rule::IMPORT_RULE &&
|
|
|
|
RuleHasPendingChildSheet(rule)) {
|
|
|
|
continue; // notify when loaded (see StyleSheetLoaded)
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocument->StyleRuleAdded(this, rule);
|
|
|
|
|
|
|
|
// Document observers could possibly detach document from this sheet.
|
|
|
|
if (!mDocument) {
|
|
|
|
// If detached, don't process any more rules.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 11:01:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-04-03 12:55:06 +03:00
|
|
|
// nsICSSLoaderObserver implementation
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ServoStyleSheet::StyleSheetLoaded(StyleSheet* aSheet,
|
|
|
|
bool aWasAlternate,
|
|
|
|
nsresult aStatus)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aSheet->IsServo(),
|
|
|
|
"why we were called back with a CSSStyleSheet?");
|
|
|
|
|
|
|
|
ServoStyleSheet* sheet = aSheet->AsServo();
|
|
|
|
if (sheet->GetParentSheet() == nullptr) {
|
|
|
|
return NS_OK; // ignore if sheet has been detached already
|
|
|
|
}
|
|
|
|
NS_ASSERTION(this == sheet->GetParentSheet(),
|
|
|
|
"We are being notified of a sheet load for a sheet that is not our child!");
|
|
|
|
|
|
|
|
if (mDocument && NS_SUCCEEDED(aStatus)) {
|
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
|
2017-06-19 08:45:43 +03:00
|
|
|
mDocument->StyleRuleAdded(this, sheet->GetOwnerRule());
|
2017-04-03 12:55:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-01-06 07:14:28 +03:00
|
|
|
void
|
|
|
|
ServoStyleSheet::DropRuleList()
|
|
|
|
{
|
|
|
|
if (mRuleList) {
|
|
|
|
mRuleList->DropReference();
|
|
|
|
mRuleList = nullptr;
|
|
|
|
}
|
2016-02-24 10:01:11 +03:00
|
|
|
}
|
|
|
|
|
2017-02-16 00:33:17 +03:00
|
|
|
already_AddRefed<StyleSheet>
|
|
|
|
ServoStyleSheet::Clone(StyleSheet* aCloneParent,
|
2017-05-30 04:10:25 +03:00
|
|
|
dom::CSSImportRule* aCloneOwnerRule,
|
2017-02-16 00:33:17 +03:00
|
|
|
nsIDocument* aCloneDocument,
|
|
|
|
nsINode* aCloneOwningNode) const
|
|
|
|
{
|
|
|
|
RefPtr<StyleSheet> clone = new ServoStyleSheet(*this,
|
|
|
|
static_cast<ServoStyleSheet*>(aCloneParent),
|
|
|
|
aCloneOwnerRule,
|
|
|
|
aCloneDocument,
|
|
|
|
aCloneOwningNode);
|
|
|
|
return clone.forget();
|
|
|
|
}
|
|
|
|
|
2017-06-19 08:45:43 +03:00
|
|
|
ServoCSSRuleList*
|
2017-06-19 08:45:43 +03:00
|
|
|
ServoStyleSheet::GetCssRulesInternal()
|
2016-10-14 14:25:38 +03:00
|
|
|
{
|
2016-11-23 02:26:20 +03:00
|
|
|
if (!mRuleList) {
|
2017-05-19 01:48:48 +03:00
|
|
|
EnsureUniqueInner();
|
|
|
|
|
2017-02-14 23:05:12 +03:00
|
|
|
RefPtr<ServoCssRules> rawRules =
|
|
|
|
Servo_StyleSheet_GetRules(Inner()->mSheet).Consume();
|
2017-05-19 01:48:48 +03:00
|
|
|
MOZ_ASSERT(rawRules);
|
2017-05-30 04:10:25 +03:00
|
|
|
mRuleList = new ServoCSSRuleList(rawRules.forget(), this);
|
2016-11-23 02:26:20 +03:00
|
|
|
}
|
|
|
|
return mRuleList;
|
2016-10-14 14:25:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
ServoStyleSheet::InsertRuleInternal(const nsAString& aRule,
|
|
|
|
uint32_t aIndex, ErrorResult& aRv)
|
|
|
|
{
|
2016-11-29 14:59:55 +03:00
|
|
|
// Ensure mRuleList is constructed.
|
2017-06-19 08:45:43 +03:00
|
|
|
GetCssRulesInternal();
|
2016-11-29 14:59:55 +03:00
|
|
|
|
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
|
|
|
|
aRv = mRuleList->InsertRule(aRule, aIndex);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (mDocument) {
|
2017-05-30 04:10:25 +03:00
|
|
|
if (mRuleList->GetRuleType(aIndex) != css::Rule::IMPORT_RULE ||
|
|
|
|
!RuleHasPendingChildSheet(mRuleList->GetRule(aIndex))) {
|
|
|
|
// XXX We may not want to get the rule when stylesheet change event
|
|
|
|
// is not enabled.
|
|
|
|
mDocument->StyleRuleAdded(this, mRuleList->GetRule(aIndex));
|
|
|
|
}
|
2016-11-29 14:59:55 +03:00
|
|
|
}
|
|
|
|
return aIndex;
|
2016-10-14 14:25:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoStyleSheet::DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv)
|
|
|
|
{
|
2016-11-29 14:59:55 +03:00
|
|
|
// Ensure mRuleList is constructed.
|
2017-06-19 08:45:43 +03:00
|
|
|
GetCssRulesInternal();
|
2016-11-29 14:59:55 +03:00
|
|
|
if (aIndex > mRuleList->Length()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
|
|
|
|
// Hold a strong ref to the rule so it doesn't die when we remove it
|
|
|
|
// from the list. XXX We may not want to hold it if stylesheet change
|
|
|
|
// event is not enabled.
|
|
|
|
RefPtr<css::Rule> rule = mRuleList->GetRule(aIndex);
|
|
|
|
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);
|
|
|
|
}
|
2016-10-14 14:25:38 +03:00
|
|
|
}
|
|
|
|
|
2017-03-08 10:27:53 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-04-06 05:22:36 +03:00
|
|
|
size_t
|
|
|
|
ServoStyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = StyleSheet::SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
const ServoStyleSheet* s = this;
|
|
|
|
while (s) {
|
|
|
|
// See the comment in CSSStyleSheet::SizeOfIncludingThis() for an
|
|
|
|
// explanation of this.
|
|
|
|
if (s->Inner()->mSheets.LastElement() == s) {
|
|
|
|
n += s->Inner()->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it
|
|
|
|
// is worthwhile:
|
|
|
|
// - s->mRuleList
|
|
|
|
|
|
|
|
s = s->mNext ? s->mNext->AsServo() : nullptr;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:11 +03:00
|
|
|
} // namespace mozilla
|