2017-03-07 07:19:03 +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/. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* internal interface representing CSS style rules that contain other
|
|
|
|
* rules, such as @media rules
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mozilla/css/GroupRule.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/CSSRuleList.h"
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2017-07-24 16:07:07 +03:00
|
|
|
GroupRule::GroupRule(already_AddRefed<ServoCssRules> aRules, StyleSheet* aSheet,
|
2018-06-29 05:56:09 +03:00
|
|
|
Rule* aParentRule, uint32_t aLineNumber,
|
|
|
|
uint32_t aColumnNumber)
|
|
|
|
: Rule(aSheet, aParentRule, aLineNumber, aColumnNumber),
|
|
|
|
mRuleList(new ServoCSSRuleList(std::move(aRules), aSheet, this)) {}
|
2017-03-09 14:02:26 +03:00
|
|
|
|
|
|
|
GroupRule::~GroupRule() {
|
|
|
|
MOZ_ASSERT(!mSheet, "SetStyleSheet should have been called");
|
2018-03-28 04:25:36 +03:00
|
|
|
if (mRuleList) {
|
2018-06-29 05:56:09 +03:00
|
|
|
mRuleList->DropReferences();
|
2018-03-28 04:25:36 +03:00
|
|
|
}
|
2017-03-09 14:02:26 +03:00
|
|
|
}
|
|
|
|
|
2017-03-07 07:19:03 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(GroupRule, Rule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(GroupRule, Rule)
|
|
|
|
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GroupRule)
|
2017-03-07 07:19:03 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(Rule)
|
|
|
|
|
|
|
|
bool GroupRule::IsCCLeaf() const {
|
|
|
|
// Let's not worry for now about sorting out whether we're a leaf or not.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(GroupRule)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(GroupRule, Rule)
|
2018-03-28 04:25:36 +03:00
|
|
|
if (tmp->mRuleList) {
|
2018-06-29 05:56:09 +03:00
|
|
|
// If tmp has a style sheet (which can happen if it gets unlinked
|
|
|
|
// earlier than its owning style sheet), then we need to null out the
|
|
|
|
// style sheet pointer on descendants now, before we clear mRuleList.
|
|
|
|
tmp->mRuleList->DropReferences();
|
2018-03-28 04:25:36 +03:00
|
|
|
tmp->mRuleList = nullptr;
|
2017-03-07 07:19:03 +03:00
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(GroupRule, Rule)
|
2018-03-28 04:25:36 +03:00
|
|
|
ImplCycleCollectionTraverse(cb, tmp->mRuleList, "mRuleList");
|
2017-03-07 07:19:03 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2018-03-28 04:25:36 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
void GroupRule::List(FILE* out, int32_t aIndent) const {
|
|
|
|
// TODO list something reasonable?
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
void GroupRule::DropSheetReference() {
|
2018-06-29 05:56:09 +03:00
|
|
|
if (mRuleList) {
|
|
|
|
mRuleList->DropSheetReference();
|
2017-03-07 07:19:03 +03:00
|
|
|
}
|
2018-06-29 05:56:09 +03:00
|
|
|
Rule::DropSheetReference();
|
2017-03-07 07:19:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GroupRule::InsertRule(const nsAString& aRule, uint32_t aIndex,
|
|
|
|
ErrorResult& aRv) {
|
2019-04-29 08:34:06 +03:00
|
|
|
if (IsReadOnly()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-07 07:19:03 +03:00
|
|
|
StyleSheet* sheet = GetStyleSheet();
|
|
|
|
if (NS_WARN_IF(!sheet)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-09 14:02:26 +03:00
|
|
|
uint32_t count = StyleRuleCount();
|
|
|
|
if (aIndex > count) {
|
2020-02-03 23:35:54 +03:00
|
|
|
aRv.ThrowIndexSizeError(nsPrintfCString(
|
|
|
|
"Can't insert rule at index %u because rule list length is %u", aIndex,
|
|
|
|
count));
|
2017-03-07 07:19:03 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-09 14:02:26 +03:00
|
|
|
NS_ASSERTION(count <= INT32_MAX, "Too many style rules!");
|
2017-03-07 07:19:03 +03:00
|
|
|
|
2017-03-08 10:04:15 +03:00
|
|
|
nsresult rv = sheet->InsertRuleIntoGroup(aRule, this, aIndex);
|
2017-03-07 07:19:03 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-03-08 09:11:42 +03:00
|
|
|
return aIndex;
|
2017-03-07 07:19:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupRule::DeleteRule(uint32_t aIndex, ErrorResult& aRv) {
|
2019-04-29 08:34:06 +03:00
|
|
|
if (IsReadOnly()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-07 07:19:03 +03:00
|
|
|
StyleSheet* sheet = GetStyleSheet();
|
|
|
|
if (NS_WARN_IF(!sheet)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-09 14:02:26 +03:00
|
|
|
uint32_t count = StyleRuleCount();
|
|
|
|
if (aIndex >= count) {
|
2020-02-03 23:35:54 +03:00
|
|
|
aRv.ThrowIndexSizeError(nsPrintfCString(
|
|
|
|
"Index %u is too large for list of length %u", aIndex, count));
|
2017-03-07 07:19:03 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-09 14:02:26 +03:00
|
|
|
NS_ASSERTION(count <= INT32_MAX, "Too many style rules!");
|
2017-03-07 07:19:03 +03:00
|
|
|
|
2017-03-08 10:04:15 +03:00
|
|
|
nsresult rv = sheet->DeleteRuleFromGroup(this, aIndex);
|
2017-03-07 07:19:03 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 04:25:36 +03:00
|
|
|
size_t GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
|
|
|
|
// TODO how to implement?
|
|
|
|
return 0;
|
|
|
|
}
|
2017-03-07 07:19:03 +03:00
|
|
|
|
|
|
|
} // namespace css
|
2017-03-09 14:02:26 +03:00
|
|
|
} // namespace mozilla
|