2017-11-24 13:01:47 +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/. */
|
|
|
|
|
|
|
|
/* base class for all rule types in a CSS style sheet */
|
|
|
|
|
|
|
|
#include "Rule.h"
|
|
|
|
|
|
|
|
#include "mozilla/css/GroupRule.h"
|
2019-11-30 15:24:24 +03:00
|
|
|
#include "mozilla/dom/CSSImportRule.h"
|
2018-05-11 13:57:38 +03:00
|
|
|
#include "mozilla/dom/DocumentOrShadowRoot.h"
|
2017-11-24 13:01:47 +03:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
Bug 1590639 part 4: Fix non-unified build issues in layout/style. r=emilio
This patch:
- Gives layout/generic/AnonymousContentKey.h an include for `<stdint.h>` to
provide the uint8_t type, and TypedEnumBits.h to provide the
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS macro. (This is a change in another
directory, but it's needed in order for layout/style/ServoStyleSet.cpp to
build successfully.)
- Adds a missing "nsINode" forward-decl to dom/base/IdentifierMapEntry.h,
because it uses that type in function declarations. (This change is needed
in order for layout/style/CachedInheritingStyles.cpp to build successfully.)
- Gives CSSStyleRule.cpp an include for PseudoStyleType.h,
nsCSSPseudoElements.h, and CSSEnabledState.h because it uses those types.
- Gives GeckoBindings.cpp an include for gfxTextRun.h, to provide the definition
of type gfxFontGroup (so GeckoBindings can call GetFirstValidFont() on an
object of that type).
- Gives Loader.h an include for nsIContentInlines.h, to provide the inline
function IsInUAWidget().
- Gives Rule.cpp an include for HoldDropJSObjects.h, to provide DropJSObjects().
- Gives nsImageLoader.cpp an include for DocumentInlines.h (and Document.h for
good measure), to provide the inline function GetPresContext().
- Gives nsStyleStruct.cpp an include for DocumentInlines.h, to provide inline
function Document::GetPresContext().
- Gives nsStyleTransformMatrix.h an include for Units.h (instead of gfxPoint.h,
which isn't useful) to provide the CSSPoint type.
- Gives nsStyleTransformMatrix.h an include for ServoStyleConsts.h, to provide
LengthPercentage and the various StyleRotate/StyleScale/StyleTransform/etc
types. (These can't be easily forward-declared, because some of them are
legitimate types whereas others are type aliases. We could theoretically
forward-declare all of the underlying types and then repeat the type aliases,
but that'd be verbose and unmaintainable.)
Depends on D50165
Differential Revision: https://phabricator.services.mozilla.com/D50166
--HG--
extra : moz-landing-system : lando
2019-10-23 11:14:54 +03:00
|
|
|
#include "mozilla/HoldDropJSObjects.h"
|
2017-11-24 13:01:47 +03:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2020-04-18 00:12:11 +03:00
|
|
|
Document* doc = sheet->GetKeptAliveByDocument();
|
|
|
|
return doc &&
|
|
|
|
nsCCUncollectableMarker::InGeneration(doc->GetMarkedCCGeneration());
|
2017-11-24 13:01:47 +03:00
|
|
|
}
|
|
|
|
|
2019-07-22 21:33:29 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-24 13:01:47 +03:00
|
|
|
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
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
void Rule::DropSheetReference() { mSheet = nullptr; }
|
2017-11-24 13:01:47 +03:00
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
void Rule::SetCssText(const nsACString& aCssText) {
|
2017-11-24 13:01:47 +03:00
|
|
|
// 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; }
|
|
|
|
|
2019-04-29 08:34:06 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-11-30 15:24:24 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2017-11-24 13:01:47 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|