Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/css/Rule.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
/* base class for all rule types in a CSS style sheet */
8
9
#ifndef mozilla_css_Rule_h___
10
#define mozilla_css_Rule_h___
11
12
#include "mozilla/dom/CSSRuleBinding.h"
13
#include "mozilla/dom/DocumentOrShadowRoot.h"
14
#include "mozilla/StyleSheet.h"
15
#include "mozilla/MemoryReporting.h"
16
#include "nsISupports.h"
17
#include "nsWrapperCache.h"
18
19
class nsIDocument;
20
struct nsRuleData;
21
template<class T> struct already_AddRefed;
22
class nsHTMLCSSStyleSheet;
23
24
namespace mozilla {
25
namespace css {
26
class GroupRule;
27
28
class Rule : public nsISupports
29
           , public nsWrapperCache
30
{
31
protected:
32
  Rule(StyleSheet* aSheet,
33
       Rule* aParentRule,
34
       uint32_t aLineNumber,
35
       uint32_t aColumnNumber)
36
    : mSheet(aSheet)
37
    , mParentRule(aParentRule)
38
    , mLineNumber(aLineNumber)
39
    , mColumnNumber(aColumnNumber)
40
0
  {
41
#ifdef DEBUG
42
    // Would be nice to check that this->Type() is KEYFRAME_RULE when
43
    // mParentRule->Tye() is KEYFRAMES_RULE, but we can't call
44
    // this->Type() here since it's virtual.
45
    if (mParentRule) {
46
      int16_t type = mParentRule->Type();
47
      MOZ_ASSERT(type == dom::CSSRule_Binding::MEDIA_RULE ||
48
                 type == dom::CSSRule_Binding::DOCUMENT_RULE ||
49
                 type == dom::CSSRule_Binding::SUPPORTS_RULE ||
50
                 type == dom::CSSRule_Binding::KEYFRAMES_RULE);
51
    }
52
#endif
53
  }
54
55
  Rule(const Rule& aCopy)
56
    : mSheet(aCopy.mSheet),
57
      mParentRule(aCopy.mParentRule),
58
      mLineNumber(aCopy.mLineNumber),
59
      mColumnNumber(aCopy.mColumnNumber)
60
0
  {
61
0
  }
62
63
0
  virtual ~Rule() = default;
64
65
public:
66
67
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
68
  NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(Rule)
69
  // Return true if this rule is known to be a cycle collection leaf, in the
70
  // sense that it doesn't have any outgoing owning edges.
71
  virtual bool IsCCLeaf() const MOZ_MUST_OVERRIDE;
72
73
#ifdef DEBUG
74
  virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0;
75
#endif
76
77
0
  StyleSheet* GetStyleSheet() const { return mSheet; }
78
79
  // Return the document the rule applies to, if any.
80
  //
81
  // Suitable for style updates, and that's about it.
82
  nsIDocument* GetComposedDoc() const
83
0
  {
84
0
    return mSheet ? mSheet->GetComposedDoc() : nullptr;
85
0
  }
86
87
  // Clear the mSheet pointer on this rule and descendants.
88
  virtual void DropSheetReference();
89
90
  // Clear the mParentRule pointer on this rule.
91
  void DropParentRuleReference()
92
0
  {
93
0
    mParentRule = nullptr;
94
0
  }
95
96
  void DropReferences()
97
0
  {
98
0
    DropSheetReference();
99
0
    DropParentRuleReference();
100
0
  }
101
102
0
  uint32_t GetLineNumber() const { return mLineNumber; }
103
0
  uint32_t GetColumnNumber() const { return mColumnNumber; }
104
105
  // This is pure virtual because all of Rule's data members are non-owning and
106
  // thus measured elsewhere.
107
  virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
108
    const MOZ_MUST_OVERRIDE = 0;
109
110
  // WebIDL interface
111
  virtual uint16_t Type() const = 0;
112
  virtual void GetCssText(nsAString& aCssText) const = 0;
113
  void SetCssText(const nsAString& aCssText);
114
  Rule* GetParentRule() const;
115
0
  StyleSheet* GetParentStyleSheet() const { return GetStyleSheet(); }
116
  nsINode* GetParentObject() const
117
0
  {
118
0
    if (!mSheet) {
119
0
      return nullptr;
120
0
    }
121
0
    auto* associated = mSheet->GetAssociatedDocumentOrShadowRoot();
122
0
    return associated ? &associated->AsNode() : nullptr;
123
0
  }
124
125
protected:
126
  // True if we're known-live for cycle collection purposes.
127
  bool IsKnownLive() const;
128
129
  // mSheet should only ever be null when we create a synthetic CSSFontFaceRule
130
  // for an InspectorFontFace.
131
  //
132
  // mSheet and mParentRule will be cleared when they are detached from the
133
  // parent object, either because the rule is removed or the parent is
134
  // destroyed.
135
  StyleSheet* MOZ_NON_OWNING_REF mSheet;
136
  Rule* MOZ_NON_OWNING_REF mParentRule;
137
138
  // Keep the same type so that MSVC packs them.
139
  uint32_t          mLineNumber;
140
  uint32_t          mColumnNumber;
141
};
142
143
} // namespace css
144
} // namespace mozilla
145
146
#endif /* mozilla_css_Rule_h___ */