layout/style/Rule.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /* base class for all rule types in a CSS style sheet */
michael@0 7
michael@0 8 #ifndef mozilla_css_Rule_h___
michael@0 9 #define mozilla_css_Rule_h___
michael@0 10
michael@0 11 #include "mozilla/MemoryReporting.h"
michael@0 12 #include "nsIStyleRule.h"
michael@0 13 #include "nsIDOMCSSRule.h"
michael@0 14 #include "nsCSSStyleSheet.h"
michael@0 15
michael@0 16 class nsIStyleSheet;
michael@0 17 class nsIDocument;
michael@0 18 struct nsRuleData;
michael@0 19 template<class T> struct already_AddRefed;
michael@0 20 class nsHTMLCSSStyleSheet;
michael@0 21
michael@0 22 namespace mozilla {
michael@0 23 namespace css {
michael@0 24 class GroupRule;
michael@0 25
michael@0 26 #define DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
michael@0 27 virtual void MapRuleInfoInto(nsRuleData* aRuleData);
michael@0 28
michael@0 29 #define DECL_STYLE_RULE_INHERIT \
michael@0 30 DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
michael@0 31 virtual nsIDOMCSSRule* GetDOMRule(); \
michael@0 32 virtual nsIDOMCSSRule* GetExistingDOMRule();
michael@0 33
michael@0 34 class Rule : public nsIStyleRule {
michael@0 35 protected:
michael@0 36 Rule()
michael@0 37 : mSheet(0),
michael@0 38 mParentRule(nullptr)
michael@0 39 {
michael@0 40 }
michael@0 41
michael@0 42 Rule(const Rule& aCopy)
michael@0 43 : mSheet(aCopy.mSheet),
michael@0 44 mParentRule(aCopy.mParentRule)
michael@0 45 {
michael@0 46 }
michael@0 47
michael@0 48 virtual ~Rule() {}
michael@0 49
michael@0 50 public:
michael@0 51
michael@0 52 // The constants in this list must maintain the following invariants:
michael@0 53 // If a rule of type N must appear before a rule of type M in stylesheets
michael@0 54 // then N < M
michael@0 55 // Note that nsCSSStyleSheet::RebuildChildList assumes that no other kinds of
michael@0 56 // rules can come between two rules of type IMPORT_RULE.
michael@0 57 enum {
michael@0 58 UNKNOWN_RULE = 0,
michael@0 59 CHARSET_RULE,
michael@0 60 IMPORT_RULE,
michael@0 61 NAMESPACE_RULE,
michael@0 62 STYLE_RULE,
michael@0 63 MEDIA_RULE,
michael@0 64 FONT_FACE_RULE,
michael@0 65 PAGE_RULE,
michael@0 66 KEYFRAME_RULE,
michael@0 67 KEYFRAMES_RULE,
michael@0 68 DOCUMENT_RULE,
michael@0 69 SUPPORTS_RULE,
michael@0 70 FONT_FEATURE_VALUES_RULE
michael@0 71 };
michael@0 72
michael@0 73 virtual int32_t GetType() const = 0;
michael@0 74
michael@0 75 nsCSSStyleSheet* GetStyleSheet() const;
michael@0 76 nsHTMLCSSStyleSheet* GetHTMLCSSStyleSheet() const;
michael@0 77
michael@0 78 // Return the document the rule lives in, if any
michael@0 79 nsIDocument* GetDocument() const
michael@0 80 {
michael@0 81 nsCSSStyleSheet* sheet = GetStyleSheet();
michael@0 82 return sheet ? sheet->GetDocument() : nullptr;
michael@0 83 }
michael@0 84
michael@0 85 virtual void SetStyleSheet(nsCSSStyleSheet* aSheet);
michael@0 86 // This does not need to be virtual, because GroupRule and MediaRule are not
michael@0 87 // used for inline style.
michael@0 88 void SetHTMLCSSStyleSheet(nsHTMLCSSStyleSheet* aSheet);
michael@0 89
michael@0 90 void SetParentRule(GroupRule* aRule) {
michael@0 91 // We don't reference count this up reference. The group rule
michael@0 92 // will tell us when it's going away or when we're detached from
michael@0 93 // it.
michael@0 94 mParentRule = aRule;
michael@0 95 }
michael@0 96
michael@0 97 /**
michael@0 98 * Clones |this|. Never returns nullptr.
michael@0 99 */
michael@0 100 virtual already_AddRefed<Rule> Clone() const = 0;
michael@0 101
michael@0 102 // Note that this returns null for inline style rules since they aren't
michael@0 103 // supposed to have a DOM rule representation (and our code wouldn't work).
michael@0 104 virtual nsIDOMCSSRule* GetDOMRule() = 0;
michael@0 105
michael@0 106 // Like GetDOMRule(), but won't create one if we don't have one yet
michael@0 107 virtual nsIDOMCSSRule* GetExistingDOMRule() = 0;
michael@0 108
michael@0 109 // to implement methods on nsIDOMCSSRule
michael@0 110 nsresult GetParentRule(nsIDOMCSSRule** aParentRule);
michael@0 111 nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet);
michael@0 112
michael@0 113 // This is pure virtual because all of Rule's data members are non-owning and
michael@0 114 // thus measured elsewhere.
michael@0 115 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
michael@0 116 const MOZ_MUST_OVERRIDE = 0;
michael@0 117
michael@0 118 // This is used to measure nsCOMArray<Rule>s.
michael@0 119 static size_t SizeOfCOMArrayElementIncludingThis(css::Rule* aElement,
michael@0 120 mozilla::MallocSizeOf aMallocSizeOf,
michael@0 121 void* aData);
michael@0 122
michael@0 123 protected:
michael@0 124 // This is either an nsCSSStyleSheet* or a nsHTMLStyleSheet*. The former
michael@0 125 // if the low bit is 0, the latter if the low bit is 1.
michael@0 126 uintptr_t mSheet;
michael@0 127 GroupRule* mParentRule;
michael@0 128 };
michael@0 129
michael@0 130 } // namespace css
michael@0 131 } // namespace mozilla
michael@0 132
michael@0 133 #endif /* mozilla_css_Rule_h___ */

mercurial