Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/style/CSSImportRule.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/CSSImportRule.h"
8
9
#include "mozilla/dom/CSSImportRuleBinding.h"
10
#include "mozilla/dom/MediaList.h"
11
#include "mozilla/ServoBindings.h"
12
#include "mozilla/StyleSheet.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
CSSImportRule::CSSImportRule(RefPtr<RawServoImportRule> aRawRule,
18
                             StyleSheet* aSheet,
19
                             css::Rule* aParentRule,
20
                             uint32_t aLine,
21
                             uint32_t aColumn)
22
  : css::Rule(aSheet, aParentRule, aLine, aColumn)
23
  , mRawRule(std::move(aRawRule))
24
0
{
25
0
  const auto* sheet = Servo_ImportRule_GetSheet(mRawRule.get());
26
0
  MOZ_ASSERT(sheet);
27
0
  mChildSheet = const_cast<StyleSheet*>(sheet);
28
0
  mChildSheet->SetOwnerRule(this);
29
0
}
30
31
CSSImportRule::~CSSImportRule()
32
0
{
33
0
  if (mChildSheet) {
34
0
    mChildSheet->SetOwnerRule(nullptr);
35
0
  }
36
0
}
37
38
// QueryInterface implementation for CSSImportRule
39
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSImportRule)
40
0
NS_INTERFACE_MAP_END_INHERITING(css::Rule)
41
42
NS_IMPL_CYCLE_COLLECTION_CLASS(CSSImportRule)
43
44
NS_IMPL_ADDREF_INHERITED(CSSImportRule, css::Rule)
45
NS_IMPL_RELEASE_INHERITED(CSSImportRule, css::Rule)
46
47
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSImportRule,
48
0
                                                  css::Rule)
49
0
  // Note the child sheet twice, since the Servo rule also holds a strong
50
0
  // reference to it.
51
0
  NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mChildSheet");
52
0
  cb.NoteXPCOMChild(tmp->mChildSheet);
53
0
  MOZ_ASSERT_IF(tmp->mRawRule,
54
0
                Servo_ImportRule_GetSheet(tmp->mRawRule) == tmp->mChildSheet);
55
0
  cb.NoteXPCOMChild(tmp->mChildSheet);
56
0
  NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRawRule.stylesheet");
57
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
58
59
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CSSImportRule)
60
0
  if (tmp->mChildSheet) {
61
0
    tmp->mChildSheet->SetOwnerRule(nullptr);
62
0
    tmp->mChildSheet = nullptr;
63
0
  }
64
0
  tmp->mRawRule = nullptr;
65
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(css::Rule)
66
67
#ifdef DEBUG
68
/* virtual */ void
69
CSSImportRule::List(FILE* out, int32_t aIndent) const
70
{
71
  nsAutoCString str;
72
  for (int32_t i = 0; i < aIndent; i++) {
73
    str.AppendLiteral("  ");
74
  }
75
  Servo_ImportRule_Debug(mRawRule, &str);
76
  fprintf_stderr(out, "%s\n", str.get());
77
}
78
#endif
79
80
dom::MediaList*
81
CSSImportRule::GetMedia() const
82
0
{
83
0
  // When Bug 1326509 is fixed, we can assert mChildSheet instead.
84
0
  return mChildSheet ? mChildSheet->Media() : nullptr;
85
0
}
86
87
void
88
CSSImportRule::GetHref(nsAString& aHref) const
89
0
{
90
0
  Servo_ImportRule_GetHref(mRawRule, &aHref);
91
0
}
92
93
/* virtual */ void
94
CSSImportRule::GetCssText(nsAString& aCssText) const
95
0
{
96
0
  Servo_ImportRule_GetCssText(mRawRule, &aCssText);
97
0
}
98
99
/* virtual */ size_t
100
CSSImportRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
101
0
{
102
0
  // TODO Implement this!
103
0
  return aMallocSizeOf(this);
104
0
}
105
106
bool
107
CSSImportRule::IsCCLeaf() const
108
0
{
109
0
  // We're not a leaf.
110
0
  return false;
111
0
}
112
113
/* virtual */ JSObject*
114
CSSImportRule::WrapObject(JSContext* aCx,
115
                          JS::Handle<JSObject*> aGivenProto)
116
0
{
117
0
  return CSSImportRule_Binding::Wrap(aCx, this, aGivenProto);
118
0
}
119
120
} // namespace dom
121
} // namespace mozilla