Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/style/CSSKeyframeRule.cpp
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
#include "mozilla/dom/CSSKeyframeRule.h"
8
9
#include "mozilla/DeclarationBlock.h"
10
#include "mozilla/dom/CSSKeyframeRuleBinding.h"
11
#include "nsDOMCSSDeclaration.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
// -------------------------------------------
17
// CSSKeyframeDeclaration
18
//
19
20
class CSSKeyframeDeclaration : public nsDOMCSSDeclaration
21
{
22
public:
23
  explicit CSSKeyframeDeclaration(CSSKeyframeRule* aRule)
24
    : mRule(aRule)
25
0
  {
26
0
    mDecls = new DeclarationBlock(
27
0
      Servo_Keyframe_GetStyle(aRule->Raw()).Consume());
28
0
  }
29
30
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
31
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
32
    CSSKeyframeDeclaration, nsICSSDeclaration)
33
34
0
  css::Rule* GetParentRule() final { return mRule; }
35
36
0
  void DropReference() {
37
0
    mRule = nullptr;
38
0
    mDecls->SetOwningRule(nullptr);
39
0
  }
40
41
  DeclarationBlock* GetOrCreateCSSDeclaration(
42
    Operation aOperation, DeclarationBlock** aCreated) final
43
0
  {
44
0
    return mDecls;
45
0
  }
46
  nsresult SetCSSDeclaration(DeclarationBlock* aDecls,
47
                             MutationClosureData* aClosureData) final
48
0
  {
49
0
    if (!mRule) {
50
0
      return NS_OK;
51
0
    }
52
0
    mRule->UpdateRule([this, aDecls]() {
53
0
      if (mDecls != aDecls) {
54
0
        mDecls->SetOwningRule(nullptr);
55
0
        mDecls = aDecls;
56
0
        mDecls->SetOwningRule(mRule);
57
0
        Servo_Keyframe_SetStyle(mRule->Raw(), mDecls->Raw());
58
0
      }
59
0
    });
60
0
    return NS_OK;
61
0
  }
62
  ParsingEnvironment GetParsingEnvironment(
63
      nsIPrincipal* aSubjectPrincipal) const final
64
0
  {
65
0
    return GetParsingEnvironmentForRule(mRule);
66
0
  }
67
0
  nsIDocument* DocToUpdate() final { return nullptr; }
68
69
  nsINode* GetParentObject() final
70
0
  {
71
0
    return mRule ? mRule->GetParentObject() : nullptr;
72
0
  }
73
74
  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
75
0
  {
76
0
    size_t n = aMallocSizeOf(this);
77
0
    // TODO we may want to add size of mDecls as well
78
0
    return n;
79
0
  }
80
81
private:
82
0
  virtual ~CSSKeyframeDeclaration() {
83
0
    MOZ_ASSERT(!mRule, "Backpointer should have been cleared");
84
0
  }
85
86
  CSSKeyframeRule* mRule;
87
  RefPtr<DeclarationBlock> mDecls;
88
};
89
90
NS_IMPL_CYCLE_COLLECTING_ADDREF(CSSKeyframeDeclaration)
91
NS_IMPL_CYCLE_COLLECTING_RELEASE(CSSKeyframeDeclaration)
92
93
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(CSSKeyframeDeclaration)
94
95
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSKeyframeDeclaration)
96
0
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
97
0
NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
98
99
// -------------------------------------------
100
// CSSKeyframeRule
101
//
102
103
CSSKeyframeRule::CSSKeyframeRule(already_AddRefed<RawServoKeyframe> aRaw,
104
                                 StyleSheet* aSheet,
105
                                 css::Rule* aParentRule,
106
                                 uint32_t aLine,
107
                                 uint32_t aColumn)
108
  : css::Rule(aSheet, aParentRule, aLine, aColumn)
109
  , mRaw(aRaw)
110
0
{
111
0
}
112
113
CSSKeyframeRule::~CSSKeyframeRule()
114
0
{
115
0
  if (mDeclaration) {
116
0
    mDeclaration->DropReference();
117
0
  }
118
0
}
119
120
NS_IMPL_ADDREF_INHERITED(CSSKeyframeRule, css::Rule)
121
NS_IMPL_RELEASE_INHERITED(CSSKeyframeRule, css::Rule)
122
123
// QueryInterface implementation for nsCSSKeyframeRule
124
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSKeyframeRule)
125
0
NS_INTERFACE_MAP_END_INHERITING(css::Rule)
126
127
NS_IMPL_CYCLE_COLLECTION_CLASS(CSSKeyframeRule)
128
129
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CSSKeyframeRule,
130
0
                                                css::Rule)
131
0
  if (tmp->mDeclaration) {
132
0
    tmp->mDeclaration->DropReference();
133
0
    tmp->mDeclaration = nullptr;
134
0
  }
135
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
136
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSKeyframeRule,
137
0
                                                  css::Rule)
138
0
  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeclaration)
139
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
140
141
bool
142
CSSKeyframeRule::IsCCLeaf() const
143
0
{
144
0
  return Rule::IsCCLeaf() && !mDeclaration;
145
0
}
146
147
#ifdef DEBUG
148
/* virtual */ void
149
CSSKeyframeRule::List(FILE* out, int32_t aIndent) const
150
{
151
  nsAutoCString str;
152
  for (int32_t i = 0; i < aIndent; i++) {
153
    str.AppendLiteral("  ");
154
  }
155
  Servo_Keyframe_Debug(mRaw, &str);
156
  fprintf_stderr(out, "%s\n", str.get());
157
}
158
#endif
159
160
template<typename Func>
161
void
162
CSSKeyframeRule::UpdateRule(Func aCallback)
163
0
{
164
0
  aCallback();
165
0
166
0
  if (StyleSheet* sheet = GetStyleSheet()) {
167
0
    sheet->RuleChanged(this);
168
0
  }
169
0
}
Unexecuted instantiation: void mozilla::dom::CSSKeyframeRule::UpdateRule<mozilla::dom::CSSKeyframeDeclaration::SetCSSDeclaration(mozilla::DeclarationBlock*, mozilla::MutationClosureData*)::{lambda()#1}>(mozilla::dom::CSSKeyframeDeclaration::SetCSSDeclaration(mozilla::DeclarationBlock*, mozilla::MutationClosureData*)::{lambda()#1})
Unexecuted instantiation: Unified_cpp_layout_style0.cpp:void mozilla::dom::CSSKeyframeRule::UpdateRule<mozilla::dom::CSSKeyframeRule::SetKeyText(nsTSubstring<char16_t> const&)::$_0>(mozilla::dom::CSSKeyframeRule::SetKeyText(nsTSubstring<char16_t> const&)::$_0)
170
171
void
172
CSSKeyframeRule::GetKeyText(nsAString& aKeyText)
173
0
{
174
0
  Servo_Keyframe_GetKeyText(mRaw, &aKeyText);
175
0
}
176
177
void
178
CSSKeyframeRule::SetKeyText(const nsAString& aKeyText)
179
0
{
180
0
  NS_ConvertUTF16toUTF8 keyText(aKeyText);
181
0
  UpdateRule([this, &keyText]() {
182
0
    Servo_Keyframe_SetKeyText(mRaw, &keyText);
183
0
  });
184
0
}
185
186
void
187
CSSKeyframeRule::GetCssText(nsAString& aCssText) const
188
0
{
189
0
  Servo_Keyframe_GetCssText(mRaw, &aCssText);
190
0
}
191
192
nsICSSDeclaration*
193
CSSKeyframeRule::Style()
194
0
{
195
0
  if (!mDeclaration) {
196
0
    mDeclaration = new CSSKeyframeDeclaration(this);
197
0
  }
198
0
  return mDeclaration;
199
0
}
200
201
size_t
202
CSSKeyframeRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
203
0
{
204
0
  size_t n = aMallocSizeOf(this);
205
0
  if (mDeclaration) {
206
0
    n += mDeclaration->SizeOfIncludingThis(aMallocSizeOf);
207
0
  }
208
0
  return n;
209
0
}
210
211
/* virtual */ JSObject*
212
CSSKeyframeRule::WrapObject(JSContext* aCx,
213
                            JS::Handle<JSObject*> aGivenProto)
214
0
{
215
0
  return CSSKeyframeRule_Binding::Wrap(aCx, this, aGivenProto);
216
0
}
217
218
} // namespace dom
219
} // namespace mozilla