summaryrefslogtreecommitdiffstats
path: root/layout/style/Rule.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /layout/style/Rule.cpp
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/style/Rule.cpp')
-rw-r--r--layout/style/Rule.cpp113
1 files changed, 113 insertions, 0 deletions
diff --git a/layout/style/Rule.cpp b/layout/style/Rule.cpp
new file mode 100644
index 0000000000..bb34b7d14d
--- /dev/null
+++ b/layout/style/Rule.cpp
@@ -0,0 +1,113 @@
+/* -*- 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/. */
+
+/* base class for all rule types in a CSS style sheet */
+
+#include "Rule.h"
+
+#include "mozilla/css/GroupRule.h"
+#include "mozilla/dom/CSSImportRule.h"
+#include "mozilla/dom/DocumentOrShadowRoot.h"
+#include "nsCCUncollectableMarker.h"
+#include "mozilla/dom/Document.h"
+#include "mozilla/HoldDropJSObjects.h"
+#include "nsWrapperCacheInlines.h"
+
+using namespace mozilla;
+using namespace mozilla::dom;
+
+namespace mozilla {
+namespace css {
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(Rule)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(Rule)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Rule)
+ NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
+ NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Rule)
+
+bool Rule::IsCCLeaf() const { return !PreservingWrapper(); }
+
+bool Rule::IsKnownLive() const {
+ if (HasKnownLiveWrapper()) {
+ return true;
+ }
+
+ StyleSheet* sheet = GetStyleSheet();
+ if (!sheet) {
+ return false;
+ }
+
+ Document* doc = sheet->GetKeptAliveByDocument();
+ return doc &&
+ nsCCUncollectableMarker::InGeneration(doc->GetMarkedCCGeneration());
+}
+
+void Rule::UnlinkDeclarationWrapper(nsWrapperCache& aDecl) {
+ // We have to be a bit careful here. We have two separate nsWrapperCache
+ // instances, aDecl and this, that both correspond to the same CC participant:
+ // this. If we just used ReleaseWrapper() on one of them, that would
+ // unpreserve that one wrapper, then trace us with a tracer that clears JS
+ // things, and we would clear the wrapper on the cache that has not
+ // unpreserved the wrapper yet. That would violate the invariant that the
+ // cache keeps caching the wrapper until the wrapper dies.
+ //
+ // So we reimplement a modified version of nsWrapperCache::ReleaseWrapper here
+ // that unpreserves both wrappers before doing any clearing.
+ bool needDrop = PreservingWrapper() || aDecl.PreservingWrapper();
+ SetPreservingWrapper(false);
+ aDecl.SetPreservingWrapper(false);
+ if (needDrop) {
+ DropJSObjects(this);
+ }
+}
+
+NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(Rule)
+ return tmp->IsCCLeaf() || tmp->IsKnownLive();
+NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
+
+NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(Rule)
+ // Please see documentation for nsCycleCollectionParticipant::CanSkip* for why
+ // we need to check HasNothingToTrace here but not in the other two CanSkip
+ // methods.
+ return tmp->IsCCLeaf() || (tmp->IsKnownLive() && tmp->HasNothingToTrace(tmp));
+NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
+
+NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(Rule)
+ return tmp->IsCCLeaf() || tmp->IsKnownLive();
+NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
+
+/* virtual */
+void Rule::DropSheetReference() { mSheet = nullptr; }
+
+void Rule::SetCssText(const nsACString& aCssText) {
+ // We used to throw for some rule types, but not all. Specifically, we did
+ // not throw for StyleRule. Let's just always not throw.
+}
+
+Rule* Rule::GetParentRule() const { return mParentRule; }
+
+bool Rule::IsReadOnly() const {
+ MOZ_ASSERT(!mSheet || !mParentRule ||
+ mSheet->IsReadOnly() == mParentRule->IsReadOnly(),
+ "a parent rule should be read only iff the owning sheet is "
+ "read only");
+ return mSheet && mSheet->IsReadOnly();
+}
+
+bool Rule::IsIncompleteImportRule() const {
+ if (Type() != CSSRule_Binding::IMPORT_RULE) {
+ return false;
+ }
+ auto* sheet = static_cast<const dom::CSSImportRule*>(this)->GetStyleSheet();
+ return !sheet || !sheet->IsComplete();
+}
+
+} // namespace css
+} // namespace mozilla