@@ -8,6 +8,7 @@ namespace AngleSharp.Css.Declarations
8
8
using AngleSharp . Text ;
9
9
using System ;
10
10
using System . Collections . Generic ;
11
+ using System . Linq ;
11
12
12
13
static class ContentDeclaration
13
14
{
@@ -21,7 +22,7 @@ static class ContentDeclaration
21
22
22
23
sealed class ContentValueConverter : IValueConverter
23
24
{
24
- private static readonly Dictionary < String , IContentMode > ContentModes = new ( StringComparer . OrdinalIgnoreCase )
25
+ private static readonly Dictionary < String , ContentMode > ContentModes = new ( StringComparer . OrdinalIgnoreCase )
25
26
{
26
27
{ CssKeywords . OpenQuote , new OpenQuoteContentMode ( ) } ,
27
28
{ CssKeywords . NoOpenQuote , new NoOpenQuoteContentMode ( ) } ,
@@ -117,86 +118,86 @@ public ContentValue(ICssValue[] modes)
117
118
}
118
119
119
120
public String CssText => _modes . Length == 0 ? CssKeywords . None : _modes . Join ( " " ) ;
121
+
122
+ public ICssValue Compute ( ICssComputeContext context )
123
+ {
124
+ var modes = _modes . Select ( mode => mode . Compute ( context ) ) . ToArray ( ) ;
125
+ return new ContentValue ( modes ) ;
126
+ }
120
127
}
121
128
122
- private interface IContentMode : ICssValue
129
+ private abstract class ContentMode : ICssValue
123
130
{
124
- String Stringify ( IElement element ) ;
131
+ public String CssText => GetCssText ( ) ;
132
+
133
+ public abstract String Stringify ( IElement element ) ;
134
+
135
+ public abstract String GetCssText ( ) ;
136
+
137
+ ICssValue ICssValue . Compute ( ICssComputeContext context )
138
+ {
139
+ return this ;
140
+ }
125
141
}
126
142
127
143
/// <summary>
128
144
/// Computes to none for the :before and :after pseudo-elements.
129
145
/// </summary>
130
- private sealed class NormalContentMode : IContentMode
146
+ private sealed class NormalContentMode : ContentMode
131
147
{
132
- public String CssText => CssKeywords . Normal ;
148
+ public override String GetCssText ( ) => CssKeywords . Normal ;
133
149
134
- public String Stringify ( IElement element )
135
- {
136
- return String . Empty ;
137
- }
150
+ public override String Stringify ( IElement element ) => String . Empty ;
138
151
}
139
152
140
153
/// <summary>
141
154
/// The value is replaced by the open quote string from the quotes
142
155
/// property.
143
156
/// </summary>
144
- private sealed class OpenQuoteContentMode : IContentMode
157
+ private sealed class OpenQuoteContentMode : ContentMode
145
158
{
146
- public String CssText => CssKeywords . OpenQuote ;
159
+ public override String GetCssText ( ) => CssKeywords . OpenQuote ;
147
160
148
- public String Stringify ( IElement element )
149
- {
150
- return String . Empty ;
151
- }
161
+ public override String Stringify ( IElement element ) => String . Empty ;
152
162
}
153
163
154
164
/// <summary>
155
165
/// The value is replaced by the close string from the quotes
156
166
/// property.
157
167
/// </summary>
158
- private sealed class CloseQuoteContentMode : IContentMode
168
+ private sealed class CloseQuoteContentMode : ContentMode
159
169
{
160
- public String CssText => CssKeywords . CloseQuote ;
170
+ public override String GetCssText ( ) => CssKeywords . CloseQuote ;
161
171
162
- public String Stringify ( IElement element )
163
- {
164
- return String . Empty ;
165
- }
172
+ public override String Stringify ( IElement element ) => String . Empty ;
166
173
}
167
174
168
175
/// <summary>
169
176
/// Introduces no content, but increments the level of nesting for
170
177
/// quotes.
171
178
/// </summary>
172
- private sealed class NoOpenQuoteContentMode : IContentMode
179
+ private sealed class NoOpenQuoteContentMode : ContentMode
173
180
{
174
- public String CssText => CssKeywords . NoOpenQuote ;
181
+ public override String GetCssText ( ) => CssKeywords . NoOpenQuote ;
175
182
176
- public String Stringify ( IElement element )
177
- {
178
- return String . Empty ;
179
- }
183
+ public override String Stringify ( IElement element ) => String . Empty ;
180
184
}
181
185
182
186
/// <summary>
183
187
/// Introduces no content, but decrements the level of nesting for
184
188
/// quotes.
185
189
/// </summary>
186
- private sealed class NoCloseQuoteContentMode : IContentMode
190
+ private sealed class NoCloseQuoteContentMode : ContentMode
187
191
{
188
- public String CssText => CssKeywords . NoCloseQuote ;
192
+ public override String GetCssText ( ) => CssKeywords . NoCloseQuote ;
189
193
190
- public String Stringify ( IElement element )
191
- {
192
- return String . Empty ;
193
- }
194
+ public override String Stringify ( IElement element ) => String . Empty ;
194
195
}
195
196
196
197
/// <summary>
197
198
/// Text content.
198
199
/// </summary>
199
- private sealed class TextContentMode : IContentMode
200
+ private sealed class TextContentMode : ContentMode
200
201
{
201
202
private readonly String _text ;
202
203
@@ -205,20 +206,17 @@ public TextContentMode(String text)
205
206
_text = text ;
206
207
}
207
208
208
- public String CssText => _text . CssString ( ) ;
209
+ public override String GetCssText ( ) => _text . CssString ( ) ;
209
210
210
- public String Stringify ( IElement element )
211
- {
212
- return _text ;
213
- }
211
+ public override String Stringify ( IElement element ) => _text ;
214
212
}
215
213
216
214
/// <summary>
217
215
/// The generated text is the value of all counters with the given name
218
216
/// in scope at this pseudo-element, from outermost to innermost
219
217
/// separated by the specified string.
220
218
/// </summary>
221
- private sealed class CounterContentMode : IContentMode
219
+ private sealed class CounterContentMode : ContentMode
222
220
{
223
221
private readonly CounterDefinition _counter ;
224
222
@@ -227,19 +225,16 @@ public CounterContentMode(CounterDefinition counter)
227
225
_counter = counter ;
228
226
}
229
227
230
- public String CssText => _counter . CssText ;
228
+ public override String GetCssText ( ) => _counter . CssText ;
231
229
232
- public String Stringify ( IElement element )
233
- {
234
- return String . Empty ;
235
- }
230
+ public override String Stringify ( IElement element ) => String . Empty ;
236
231
}
237
232
238
233
/// <summary>
239
234
/// Returns the value of the element's attribute X as a string. If
240
235
/// there is no attribute X, an empty string is returned.
241
236
/// </summary>
242
- private sealed class AttributeContentMode : IContentMode
237
+ private sealed class AttributeContentMode : ContentMode
243
238
{
244
239
private readonly String _attribute ;
245
240
@@ -248,20 +243,17 @@ public AttributeContentMode(String attribute)
248
243
_attribute = attribute ;
249
244
}
250
245
251
- public String CssText => FunctionNames . Attr . CssFunction ( _attribute ) ;
246
+ public override String GetCssText ( ) => FunctionNames . Attr . CssFunction ( _attribute ) ;
252
247
253
- public String Stringify ( IElement element )
254
- {
255
- return element . GetAttribute ( _attribute ) ?? String . Empty ;
256
- }
248
+ public override String Stringify ( IElement element ) => element . GetAttribute ( _attribute ) ?? String . Empty ;
257
249
}
258
250
259
251
/// <summary>
260
252
/// The value is a URI that designates an external resource (such as an
261
253
/// image). If the resource or image can't be displayed, it is either
262
254
/// ignored or some placeholder shows up.
263
255
/// </summary>
264
- private sealed class UrlContentMode : IContentMode
256
+ private sealed class UrlContentMode : ContentMode
265
257
{
266
258
private readonly CssUrlValue _url ;
267
259
@@ -270,12 +262,9 @@ public UrlContentMode(CssUrlValue url)
270
262
_url = url ;
271
263
}
272
264
273
- public String CssText => _url . CssText ;
265
+ public override String GetCssText ( ) => _url . CssText ;
274
266
275
- public String Stringify ( IElement element )
276
- {
277
- return String . Empty ;
278
- }
267
+ public override String Stringify ( IElement element ) => String . Empty ;
279
268
}
280
269
}
281
270
}
0 commit comments