Line data Source code
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 : /* representation of CSSMediaRule for stylo */
8 :
9 : #include "mozilla/ServoMediaRule.h"
10 :
11 : #include "mozilla/ServoBindings.h"
12 : #include "mozilla/ServoMediaList.h"
13 :
14 : using namespace mozilla::dom;
15 :
16 : namespace mozilla {
17 :
18 0 : ServoMediaRule::ServoMediaRule(RefPtr<RawServoMediaRule> aRawRule,
19 0 : uint32_t aLine, uint32_t aColumn)
20 0 : : CSSMediaRule(Servo_MediaRule_GetRules(aRawRule).Consume())
21 0 : , mRawRule(Move(aRawRule))
22 : {
23 0 : }
24 :
25 0 : ServoMediaRule::~ServoMediaRule()
26 : {
27 0 : }
28 :
29 0 : NS_IMPL_ADDREF_INHERITED(ServoMediaRule, CSSMediaRule)
30 0 : NS_IMPL_RELEASE_INHERITED(ServoMediaRule, CSSMediaRule)
31 :
32 : // QueryInterface implementation for MediaRule
33 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ServoMediaRule)
34 0 : NS_INTERFACE_MAP_END_INHERITING(CSSMediaRule)
35 :
36 0 : NS_IMPL_CYCLE_COLLECTION_INHERITED(ServoMediaRule, CSSMediaRule,
37 : mMediaList)
38 :
39 : /* virtual */ already_AddRefed<css::Rule>
40 0 : ServoMediaRule::Clone() const
41 : {
42 : // Rule::Clone is only used when CSSStyleSheetInner is cloned in
43 : // preparation of being mutated. However, ServoStyleSheet never clones
44 : // anything, so this method should never be called.
45 0 : MOZ_ASSERT_UNREACHABLE("Shouldn't be cloning ServoMediaRule");
46 : return nullptr;
47 : }
48 :
49 : /* virtual */ bool
50 0 : ServoMediaRule::UseForPresentation(nsPresContext* aPresContext,
51 : nsMediaQueryResultCacheKey& aKey)
52 : {
53 : // GroupRule::UseForPresentation is only used in nsCSSRuleProcessor,
54 : // so this should never be called.
55 0 : MOZ_ASSERT_UNREACHABLE("Shouldn't be calling UseForPresentation");
56 : return false;
57 : }
58 :
59 : /* virtual */ void
60 0 : ServoMediaRule::SetStyleSheet(StyleSheet* aSheet)
61 : {
62 0 : if (mMediaList) {
63 0 : mMediaList->SetStyleSheet(aSheet);
64 : }
65 0 : CSSMediaRule::SetStyleSheet(aSheet);
66 0 : }
67 :
68 : #ifdef DEBUG
69 : /* virtual */ void
70 0 : ServoMediaRule::List(FILE* out, int32_t aIndent) const
71 : {
72 0 : nsAutoCString str;
73 0 : for (int32_t i = 0; i < aIndent; i++) {
74 0 : str.AppendLiteral(" ");
75 : }
76 0 : Servo_MediaRule_Debug(mRawRule, &str);
77 0 : fprintf_stderr(out, "%s\n", str.get());
78 0 : }
79 : #endif
80 :
81 : // nsIDOMCSSConditionRule methods
82 :
83 : NS_IMETHODIMP
84 0 : ServoMediaRule::GetConditionText(nsAString& aConditionText)
85 : {
86 0 : return Media()->GetMediaText(aConditionText);
87 : }
88 :
89 : NS_IMETHODIMP
90 0 : ServoMediaRule::SetConditionText(const nsAString& aConditionText)
91 : {
92 0 : return Media()->SetMediaText(aConditionText);
93 : }
94 :
95 : /* virtual */ void
96 0 : ServoMediaRule::GetCssTextImpl(nsAString& aCssText) const
97 : {
98 0 : Servo_MediaRule_GetCssText(mRawRule, &aCssText);
99 0 : }
100 :
101 : /* virtual */ dom::MediaList*
102 0 : ServoMediaRule::Media()
103 : {
104 0 : if (!mMediaList) {
105 : mMediaList =
106 0 : new ServoMediaList(Servo_MediaRule_GetMedia(mRawRule).Consume());
107 0 : mMediaList->SetStyleSheet(GetStyleSheet());
108 : }
109 0 : return mMediaList;
110 : }
111 :
112 : /* virtual */ size_t
113 0 : ServoMediaRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
114 : {
115 : // TODO Implement this!
116 0 : return aMallocSizeOf(this);
117 : }
118 :
119 : } // namespace mozilla
|