/src/mozilla-central/layout/style/MediaList.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 | | /* base class for representation of media lists */ |
8 | | |
9 | | #include "mozilla/dom/MediaList.h" |
10 | | |
11 | | #include "mozAutoDocUpdate.h" |
12 | | #include "mozilla/dom/MediaListBinding.h" |
13 | | #include "mozilla/ServoBindings.h" |
14 | | #include "mozilla/ServoStyleSet.h" |
15 | | #include "mozilla/StyleSheetInlines.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace dom { |
19 | | |
20 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaList) |
21 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
22 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
23 | 0 | NS_INTERFACE_MAP_END |
24 | | |
25 | | NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaList) |
26 | | NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaList) |
27 | | |
28 | | NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(MediaList) |
29 | | |
30 | | JSObject* |
31 | | MediaList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
32 | 0 | { |
33 | 0 | return MediaList_Binding::Wrap(aCx, this, aGivenProto); |
34 | 0 | } |
35 | | |
36 | | void |
37 | | MediaList::SetStyleSheet(StyleSheet* aSheet) |
38 | 0 | { |
39 | 0 | MOZ_ASSERT(aSheet == mStyleSheet || !aSheet || !mStyleSheet, |
40 | 0 | "Multiple style sheets competing for one media list"); |
41 | 0 | mStyleSheet = aSheet; |
42 | 0 | } |
43 | | |
44 | | template<typename Func> |
45 | | nsresult |
46 | | MediaList::DoMediaChange(Func aCallback) |
47 | 0 | { |
48 | 0 | if (mStyleSheet) { |
49 | 0 | mStyleSheet->WillDirty(); |
50 | 0 | } |
51 | 0 |
|
52 | 0 | nsresult rv = aCallback(); |
53 | 0 | if (NS_FAILED(rv)) { |
54 | 0 | return rv; |
55 | 0 | } |
56 | 0 | |
57 | 0 | if (mStyleSheet) { |
58 | 0 | // FIXME(emilio): We should discern between "owned by a rule" (as in @media) |
59 | 0 | // and "owned by a sheet" (as in <style media>), and then pass something |
60 | 0 | // meaningful here. |
61 | 0 | mStyleSheet->RuleChanged(nullptr); |
62 | 0 | } |
63 | 0 |
|
64 | 0 | return rv; |
65 | 0 | } Unexecuted instantiation: Unified_cpp_layout_style1.cpp:nsresult mozilla::dom::MediaList::DoMediaChange<mozilla::dom::MediaList::SetMediaText(nsTSubstring<char16_t> const&)::$_14>(mozilla::dom::MediaList::SetMediaText(nsTSubstring<char16_t> const&)::$_14) Unexecuted instantiation: Unified_cpp_layout_style1.cpp:nsresult mozilla::dom::MediaList::DoMediaChange<mozilla::dom::MediaList::DeleteMedium(nsTSubstring<char16_t> const&, mozilla::ErrorResult&)::$_15>(mozilla::dom::MediaList::DeleteMedium(nsTSubstring<char16_t> const&, mozilla::ErrorResult&)::$_15) Unexecuted instantiation: Unified_cpp_layout_style1.cpp:nsresult mozilla::dom::MediaList::DoMediaChange<mozilla::dom::MediaList::AppendMedium(nsTSubstring<char16_t> const&, mozilla::ErrorResult&)::$_16>(mozilla::dom::MediaList::AppendMedium(nsTSubstring<char16_t> const&, mozilla::ErrorResult&)::$_16) |
66 | | |
67 | | already_AddRefed<MediaList> |
68 | | MediaList::Clone() |
69 | 0 | { |
70 | 0 | RefPtr<MediaList> clone = |
71 | 0 | new MediaList(Servo_MediaList_DeepClone(mRawList).Consume()); |
72 | 0 | return clone.forget(); |
73 | 0 | } |
74 | | |
75 | | MediaList::MediaList() |
76 | | : mRawList(Servo_MediaList_Create().Consume()) |
77 | 0 | { |
78 | 0 | } |
79 | | |
80 | | MediaList::MediaList(const nsAString& aMedia, CallerType aCallerType) |
81 | | : MediaList() |
82 | 0 | { |
83 | 0 | SetTextInternal(aMedia, aCallerType); |
84 | 0 | } |
85 | | |
86 | | void |
87 | | MediaList::GetText(nsAString& aMediaText) |
88 | 0 | { |
89 | 0 | Servo_MediaList_GetText(mRawList, &aMediaText); |
90 | 0 | } |
91 | | |
92 | | /* static */ already_AddRefed<MediaList> |
93 | | MediaList::Create(const nsAString& aMedia, CallerType aCallerType) |
94 | 0 | { |
95 | 0 | RefPtr<MediaList> mediaList = new MediaList(aMedia, aCallerType); |
96 | 0 | return mediaList.forget(); |
97 | 0 | } |
98 | | |
99 | | void |
100 | | MediaList::SetText(const nsAString& aMediaText) |
101 | 0 | { |
102 | 0 | SetTextInternal(aMediaText, CallerType::NonSystem); |
103 | 0 | } |
104 | | |
105 | | void |
106 | | MediaList::GetMediaText(nsAString& aMediaText) |
107 | 0 | { |
108 | 0 | GetText(aMediaText); |
109 | 0 | } |
110 | | |
111 | | void |
112 | | MediaList::SetTextInternal(const nsAString& aMediaText, CallerType aCallerType) |
113 | 0 | { |
114 | 0 | NS_ConvertUTF16toUTF8 mediaText(aMediaText); |
115 | 0 | Servo_MediaList_SetText(mRawList, &mediaText, aCallerType); |
116 | 0 | } |
117 | | |
118 | | uint32_t |
119 | | MediaList::Length() |
120 | 0 | { |
121 | 0 | return Servo_MediaList_GetLength(mRawList); |
122 | 0 | } |
123 | | |
124 | | void |
125 | | MediaList::IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aReturn) |
126 | 0 | { |
127 | 0 | aFound = Servo_MediaList_GetMediumAt(mRawList, aIndex, &aReturn); |
128 | 0 | if (!aFound) { |
129 | 0 | SetDOMStringToNull(aReturn); |
130 | 0 | } |
131 | 0 | } |
132 | | |
133 | | nsresult |
134 | | MediaList::Delete(const nsAString& aOldMedium) |
135 | 0 | { |
136 | 0 | NS_ConvertUTF16toUTF8 oldMedium(aOldMedium); |
137 | 0 | if (Servo_MediaList_DeleteMedium(mRawList, &oldMedium)) { |
138 | 0 | return NS_OK; |
139 | 0 | } |
140 | 0 | return NS_ERROR_DOM_NOT_FOUND_ERR; |
141 | 0 | } |
142 | | |
143 | | bool |
144 | | MediaList::Matches(nsPresContext* aPresContext) const |
145 | 0 | { |
146 | 0 | const RawServoStyleSet* rawSet = |
147 | 0 | aPresContext->StyleSet()->RawSet(); |
148 | 0 | MOZ_ASSERT(rawSet, "The RawServoStyleSet should be valid!"); |
149 | 0 | return Servo_MediaList_Matches(mRawList, rawSet); |
150 | 0 | } |
151 | | |
152 | | nsresult |
153 | | MediaList::Append(const nsAString& aNewMedium) |
154 | 0 | { |
155 | 0 | if (aNewMedium.IsEmpty()) { |
156 | 0 | return NS_ERROR_DOM_NOT_FOUND_ERR; |
157 | 0 | } |
158 | 0 | NS_ConvertUTF16toUTF8 newMedium(aNewMedium); |
159 | 0 | Servo_MediaList_AppendMedium(mRawList, &newMedium); |
160 | 0 | return NS_OK; |
161 | 0 | } |
162 | | |
163 | | void |
164 | | MediaList::SetMediaText(const nsAString& aMediaText) |
165 | 0 | { |
166 | 0 | DoMediaChange([&]() { |
167 | 0 | SetText(aMediaText); |
168 | 0 | return NS_OK; |
169 | 0 | }); |
170 | 0 | } |
171 | | |
172 | | void |
173 | | MediaList::Item(uint32_t aIndex, nsAString& aReturn) |
174 | 0 | { |
175 | 0 | bool dummy; |
176 | 0 | IndexedGetter(aIndex, dummy, aReturn); |
177 | 0 | } |
178 | | |
179 | | void |
180 | | MediaList::DeleteMedium(const nsAString& aOldMedium, ErrorResult& aRv) |
181 | 0 | { |
182 | 0 | aRv = DoMediaChange([&]() { return Delete(aOldMedium); }); |
183 | 0 | } |
184 | | |
185 | | void |
186 | | MediaList::AppendMedium(const nsAString& aNewMedium, ErrorResult& aRv) |
187 | 0 | { |
188 | 0 | aRv = DoMediaChange([&]() { return Append(aNewMedium); }); |
189 | 0 | } |
190 | | |
191 | | MOZ_DEFINE_MALLOC_SIZE_OF(ServoMediaListMallocSizeOf) |
192 | | MOZ_DEFINE_MALLOC_ENCLOSING_SIZE_OF(ServoMediaListMallocEnclosingSizeOf) |
193 | | |
194 | | size_t |
195 | | MediaList::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const |
196 | 0 | { |
197 | 0 | size_t n = 0; |
198 | 0 | n += Servo_MediaList_SizeOfIncludingThis(ServoMediaListMallocSizeOf, |
199 | 0 | ServoMediaListMallocEnclosingSizeOf, |
200 | 0 | mRawList); |
201 | 0 | return n; |
202 | 0 | } |
203 | | |
204 | | } // namespace dom |
205 | | } // namespace mozilla |