michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* base class for all rule types in a CSS style sheet */ michael@0: michael@0: #ifndef mozilla_css_Rule_h___ michael@0: #define mozilla_css_Rule_h___ michael@0: michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "nsIStyleRule.h" michael@0: #include "nsIDOMCSSRule.h" michael@0: #include "nsCSSStyleSheet.h" michael@0: michael@0: class nsIStyleSheet; michael@0: class nsIDocument; michael@0: struct nsRuleData; michael@0: template struct already_AddRefed; michael@0: class nsHTMLCSSStyleSheet; michael@0: michael@0: namespace mozilla { michael@0: namespace css { michael@0: class GroupRule; michael@0: michael@0: #define DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ michael@0: virtual void MapRuleInfoInto(nsRuleData* aRuleData); michael@0: michael@0: #define DECL_STYLE_RULE_INHERIT \ michael@0: DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ michael@0: virtual nsIDOMCSSRule* GetDOMRule(); \ michael@0: virtual nsIDOMCSSRule* GetExistingDOMRule(); michael@0: michael@0: class Rule : public nsIStyleRule { michael@0: protected: michael@0: Rule() michael@0: : mSheet(0), michael@0: mParentRule(nullptr) michael@0: { michael@0: } michael@0: michael@0: Rule(const Rule& aCopy) michael@0: : mSheet(aCopy.mSheet), michael@0: mParentRule(aCopy.mParentRule) michael@0: { michael@0: } michael@0: michael@0: virtual ~Rule() {} michael@0: michael@0: public: michael@0: michael@0: // The constants in this list must maintain the following invariants: michael@0: // If a rule of type N must appear before a rule of type M in stylesheets michael@0: // then N < M michael@0: // Note that nsCSSStyleSheet::RebuildChildList assumes that no other kinds of michael@0: // rules can come between two rules of type IMPORT_RULE. michael@0: enum { michael@0: UNKNOWN_RULE = 0, michael@0: CHARSET_RULE, michael@0: IMPORT_RULE, michael@0: NAMESPACE_RULE, michael@0: STYLE_RULE, michael@0: MEDIA_RULE, michael@0: FONT_FACE_RULE, michael@0: PAGE_RULE, michael@0: KEYFRAME_RULE, michael@0: KEYFRAMES_RULE, michael@0: DOCUMENT_RULE, michael@0: SUPPORTS_RULE, michael@0: FONT_FEATURE_VALUES_RULE michael@0: }; michael@0: michael@0: virtual int32_t GetType() const = 0; michael@0: michael@0: nsCSSStyleSheet* GetStyleSheet() const; michael@0: nsHTMLCSSStyleSheet* GetHTMLCSSStyleSheet() const; michael@0: michael@0: // Return the document the rule lives in, if any michael@0: nsIDocument* GetDocument() const michael@0: { michael@0: nsCSSStyleSheet* sheet = GetStyleSheet(); michael@0: return sheet ? sheet->GetDocument() : nullptr; michael@0: } michael@0: michael@0: virtual void SetStyleSheet(nsCSSStyleSheet* aSheet); michael@0: // This does not need to be virtual, because GroupRule and MediaRule are not michael@0: // used for inline style. michael@0: void SetHTMLCSSStyleSheet(nsHTMLCSSStyleSheet* aSheet); michael@0: michael@0: void SetParentRule(GroupRule* aRule) { michael@0: // We don't reference count this up reference. The group rule michael@0: // will tell us when it's going away or when we're detached from michael@0: // it. michael@0: mParentRule = aRule; michael@0: } michael@0: michael@0: /** michael@0: * Clones |this|. Never returns nullptr. michael@0: */ michael@0: virtual already_AddRefed Clone() const = 0; michael@0: michael@0: // Note that this returns null for inline style rules since they aren't michael@0: // supposed to have a DOM rule representation (and our code wouldn't work). michael@0: virtual nsIDOMCSSRule* GetDOMRule() = 0; michael@0: michael@0: // Like GetDOMRule(), but won't create one if we don't have one yet michael@0: virtual nsIDOMCSSRule* GetExistingDOMRule() = 0; michael@0: michael@0: // to implement methods on nsIDOMCSSRule michael@0: nsresult GetParentRule(nsIDOMCSSRule** aParentRule); michael@0: nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet); michael@0: michael@0: // This is pure virtual because all of Rule's data members are non-owning and michael@0: // thus measured elsewhere. michael@0: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) michael@0: const MOZ_MUST_OVERRIDE = 0; michael@0: michael@0: // This is used to measure nsCOMArrays. michael@0: static size_t SizeOfCOMArrayElementIncludingThis(css::Rule* aElement, michael@0: mozilla::MallocSizeOf aMallocSizeOf, michael@0: void* aData); michael@0: michael@0: protected: michael@0: // This is either an nsCSSStyleSheet* or a nsHTMLStyleSheet*. The former michael@0: // if the low bit is 0, the latter if the low bit is 1. michael@0: uintptr_t mSheet; michael@0: GroupRule* mParentRule; michael@0: }; michael@0: michael@0: } // namespace css michael@0: } // namespace mozilla michael@0: michael@0: #endif /* mozilla_css_Rule_h___ */