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
|
|
|
|
2012-08-06 02:14:52 +00:00
|
|
|
class nsIDocument;
|
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
|
2017-01-13 15:41:02 +00:00
|
|
|
, public nsWrapperCache
|
|
|
|
{
|
2011-03-29 03:21:20 +00:00
|
|
|
protected:
|
2014-07-14 22:57:54 +00:00
|
|
|
Rule(uint32_t aLineNumber, uint32_t aColumnNumber)
|
2015-11-09 07:57:16 +00:00
|
|
|
: mSheet(nullptr),
|
2014-07-14 22:57:02 +00:00
|
|
|
mParentRule(nullptr),
|
|
|
|
mLineNumber(aLineNumber),
|
2015-11-05 08:44:10 +00:00
|
|
|
mColumnNumber(aColumnNumber)
|
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)
|
2010-09-18 18:43:17 +00:00
|
|
|
{
|
|
|
|
}
|
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:
|
1999-06-10 05:32:38 +00:00
|
|
|
|
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-05-11 10:57:38 +00:00
|
|
|
// Return the document the rule applies to, if any.
|
|
|
|
//
|
|
|
|
// Suitable for style updates, and that's about it.
|
|
|
|
nsIDocument* GetComposedDoc() const
|
2012-08-06 02:14:52 +00:00
|
|
|
{
|
2018-05-11 10:57:38 +00:00
|
|
|
return mSheet ? mSheet->GetComposedDoc() : nullptr;
|
2012-08-06 02:14:52 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 23:26:20 +00:00
|
|
|
virtual void SetStyleSheet(StyleSheet* aSheet);
|
2011-04-08 03:51:25 +00:00
|
|
|
|
2018-03-28 01:20:41 +00:00
|
|
|
// We don't reference count this up reference. The rule will tell us
|
|
|
|
// when it's going away or when we're detached from it.
|
|
|
|
void SetParentRule(Rule* aRule) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (aRule) {
|
|
|
|
int16_t type = aRule->Type();
|
|
|
|
MOZ_ASSERT(type == dom::CSSRuleBinding::MEDIA_RULE ||
|
|
|
|
type == dom::CSSRuleBinding::DOCUMENT_RULE ||
|
|
|
|
type == dom::CSSRuleBinding::SUPPORTS_RULE ||
|
|
|
|
(type == dom::CSSRuleBinding::KEYFRAMES_RULE &&
|
|
|
|
Type() == dom::CSSRuleBinding::KEYFRAME_RULE));
|
|
|
|
}
|
|
|
|
#endif
|
2011-04-08 03:51:25 +00:00
|
|
|
mParentRule = aRule;
|
|
|
|
}
|
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; }
|
|
|
|
|
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.
|
2013-06-23 12:03:39 +00:00
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2013-03-24 02:14:43 +00:00
|
|
|
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;
|
|
|
|
|
2015-11-09 07:57:16 +00:00
|
|
|
// This is sometimes null (e.g., for style attributes).
|
2016-11-22 23:26:20 +00:00
|
|
|
StyleSheet* mSheet;
|
2015-05-22 05:00:00 +00:00
|
|
|
// When the parent GroupRule is destroyed, it will call SetParentRule(nullptr)
|
|
|
|
// on this object. (Through SetParentRuleReference);
|
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___ */
|