2017-10-27 17:33:53 +00: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: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2006-03-25 05:47:31 +00:00
|
|
|
|
|
|
|
/* base class for all rule types in a CSS style sheet */
|
|
|
|
|
2011-03-07 03:59:03 +00:00
|
|
|
#ifndef mozilla_css_Rule_h___
|
|
|
|
#define mozilla_css_Rule_h___
|
1999-06-10 05:32:38 +00:00
|
|
|
|
2018-01-11 08:17:56 +00:00
|
|
|
#include "mozilla/dom/CSSRuleBinding.h"
|
2018-05-11 10:57:38 +00:00
|
|
|
#include "mozilla/dom/DocumentOrShadowRoot.h"
|
2017-03-28 09:05:12 +00:00
|
|
|
#include "mozilla/StyleSheet.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2015-11-05 08:44:10 +00:00
|
|
|
#include "nsISupports.h"
|
2017-01-13 15:41:02 +00:00
|
|
|
#include "nsWrapperCache.h"
|
1999-06-10 05:32:38 +00:00
|
|
|
|
2010-08-08 05:28:33 +00:00
|
|
|
struct nsRuleData;
|
|
|
|
template <class T>
|
|
|
|
struct already_AddRefed;
|
2012-09-30 16:40:24 +00:00
|
|
|
class nsHTMLCSSStyleSheet;
|
2010-08-08 05:28:33 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
class GroupRule;
|
|
|
|
|
2018-01-11 08:17:56 +00:00
|
|
|
class Rule : public nsISupports, public nsWrapperCache {
|
2011-03-29 03:21:20 +00:00
|
|
|
protected:
|
2018-06-29 02:56:09 +00:00
|
|
|
Rule(StyleSheet* aSheet, Rule* aParentRule, uint32_t aLineNumber,
|
|
|
|
uint32_t aColumnNumber)
|
|
|
|
: mSheet(aSheet),
|
|
|
|
mParentRule(aParentRule),
|
|
|
|
mLineNumber(aLineNumber),
|
|
|
|
mColumnNumber(aColumnNumber) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Would be nice to check that this->Type() is KEYFRAME_RULE when
|
|
|
|
// mParentRule->Tye() is KEYFRAMES_RULE, but we can't call
|
|
|
|
// this->Type() here since it's virtual.
|
|
|
|
if (mParentRule) {
|
|
|
|
int16_t type = mParentRule->Type();
|
|
|
|
MOZ_ASSERT(type == dom::CSSRule_Binding::MEDIA_RULE ||
|
|
|
|
type == dom::CSSRule_Binding::DOCUMENT_RULE ||
|
|
|
|
type == dom::CSSRule_Binding::SUPPORTS_RULE ||
|
|
|
|
type == dom::CSSRule_Binding::KEYFRAMES_RULE);
|
|
|
|
}
|
|
|
|
#endif
|
2010-09-18 18:43:17 +00:00
|
|
|
}
|
1999-06-10 05:32:38 +00:00
|
|
|
|
2011-03-07 03:59:03 +00:00
|
|
|
Rule(const Rule& aCopy)
|
2010-09-18 18:43:17 +00:00
|
|
|
: mSheet(aCopy.mSheet),
|
2014-07-14 22:57:02 +00:00
|
|
|
mParentRule(aCopy.mParentRule),
|
|
|
|
mLineNumber(aCopy.mLineNumber),
|
2015-11-05 08:44:10 +00:00
|
|
|
mColumnNumber(aCopy.mColumnNumber) {}
|
1999-06-10 05:32:38 +00:00
|
|
|
|
2018-05-11 10:57:38 +00:00
|
|
|
virtual ~Rule() = default;
|
2011-03-18 05:18:08 +00:00
|
|
|
|
2011-03-29 03:21:20 +00:00
|
|
|
public:
|
2016-11-30 23:18:14 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2017-01-13 15:41:02 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(Rule)
|
2016-11-30 23:18:14 +00:00
|
|
|
// Return true if this rule is known to be a cycle collection leaf, in the
|
|
|
|
// sense that it doesn't have any outgoing owning edges.
|
|
|
|
virtual bool IsCCLeaf() const MOZ_MUST_OVERRIDE;
|
|
|
|
|
2015-11-05 08:44:10 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0;
|
|
|
|
#endif
|
|
|
|
|
2016-11-22 23:26:20 +00:00
|
|
|
StyleSheet* GetStyleSheet() const { return mSheet; }
|
2011-04-08 03:51:25 +00:00
|
|
|
|
2018-06-29 02:56:09 +00:00
|
|
|
// Clear the mSheet pointer on this rule and descendants.
|
|
|
|
virtual void DropSheetReference();
|
2011-04-08 03:51:25 +00:00
|
|
|
|
2018-06-29 02:56:09 +00:00
|
|
|
// Clear the mParentRule pointer on this rule.
|
|
|
|
void DropParentRuleReference() { mParentRule = nullptr; }
|
|
|
|
|
|
|
|
void DropReferences() {
|
|
|
|
DropSheetReference();
|
|
|
|
DropParentRuleReference();
|
2011-04-08 03:51:25 +00:00
|
|
|
}
|
1999-06-10 05:32:38 +00:00
|
|
|
|
2014-07-14 22:57:02 +00:00
|
|
|
uint32_t GetLineNumber() const { return mLineNumber; }
|
|
|
|
uint32_t GetColumnNumber() const { return mColumnNumber; }
|
|
|
|
|
2019-04-29 05:34:06 +00:00
|
|
|
// Whether this a rule in a read only style sheet.
|
|
|
|
bool IsReadOnly() const;
|
|
|
|
|
2019-11-30 12:24:24 +00:00
|
|
|
// Whether this rule is an @import rule that hasn't loaded yet (and thus
|
|
|
|
// doesn't affect the style of the page).
|
|
|
|
bool IsIncompleteImportRule() const;
|
|
|
|
|
2012-01-03 02:19:14 +00:00
|
|
|
// This is pure virtual because all of Rule's data members are non-owning and
|
|
|
|
// thus measured elsewhere.
|
2019-11-30 11:57:10 +00:00
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf) const MOZ_MUST_OVERRIDE = 0;
|
2012-01-03 02:19:14 +00:00
|
|
|
|
2018-01-11 08:17:56 +00:00
|
|
|
// WebIDL interface
|
2017-01-13 15:41:02 +00:00
|
|
|
virtual uint16_t Type() const = 0;
|
2018-01-30 21:30:08 +00:00
|
|
|
virtual void GetCssText(nsAString& aCssText) const = 0;
|
2018-01-11 08:17:56 +00:00
|
|
|
void SetCssText(const nsAString& aCssText);
|
2017-01-13 15:41:03 +00:00
|
|
|
Rule* GetParentRule() const;
|
|
|
|
StyleSheet* GetParentStyleSheet() const { return GetStyleSheet(); }
|
2018-05-11 10:57:38 +00:00
|
|
|
nsINode* GetParentObject() const {
|
|
|
|
if (!mSheet) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto* associated = mSheet->GetAssociatedDocumentOrShadowRoot();
|
|
|
|
return associated ? &associated->AsNode() : nullptr;
|
|
|
|
}
|
2017-01-13 15:41:02 +00:00
|
|
|
|
1999-06-10 05:32:38 +00:00
|
|
|
protected:
|
2016-11-30 23:18:14 +00:00
|
|
|
// True if we're known-live for cycle collection purposes.
|
|
|
|
bool IsKnownLive() const;
|
|
|
|
|
2019-07-22 18:33:29 +00:00
|
|
|
// Hook subclasses can use to properly unlink the nsWrapperCache of
|
|
|
|
// their declarations.
|
|
|
|
void UnlinkDeclarationWrapper(nsWrapperCache& aDecl);
|
|
|
|
|
2018-06-29 02:56:09 +00:00
|
|
|
// mSheet should only ever be null when we create a synthetic CSSFontFaceRule
|
|
|
|
// for an InspectorFontFace.
|
|
|
|
//
|
|
|
|
// mSheet and mParentRule will be cleared when they are detached from the
|
|
|
|
// parent object, either because the rule is removed or the parent is
|
|
|
|
// destroyed.
|
|
|
|
StyleSheet* MOZ_NON_OWNING_REF mSheet;
|
2018-03-28 01:20:41 +00:00
|
|
|
Rule* MOZ_NON_OWNING_REF mParentRule;
|
2014-07-14 22:57:02 +00:00
|
|
|
|
|
|
|
// Keep the same type so that MSVC packs them.
|
|
|
|
uint32_t mLineNumber;
|
2015-11-05 08:44:10 +00:00
|
|
|
uint32_t mColumnNumber;
|
1999-06-10 05:32:38 +00:00
|
|
|
};
|
|
|
|
|
2011-03-07 03:59:03 +00:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_css_Rule_h___ */
|