1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
|
#ifndef __STYLESHEETS_H__
#define __STYLESHEETS_H__
/**
* Phoebe DOM Implementation.
*
* This is a C++ approximation of the W3C DOM model, which follows
* fairly closely the specifications in the various .idl files, copies of
* which are provided for reference. Most important is this one:
*
* http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
*
* Authors:
* Bob Jamison
*
* Copyright (C) 2005-2008 Bob Jamison
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* =========================================================================
* NOTES
*
* Views, Stylesheets and CSS are DOM Level 2 for the purposes of supporting
* SVG. Be prepared in the future when they make Level 3 and SVG is likewise
* updated. The API here and many of the comments come from this document:
* http://www.w3.org/TR/DOM-Level-2-Style/stylesheets.html
*/
#include "dom.h"
#include <vector>
namespace org
{
namespace w3c
{
namespace dom
{
namespace stylesheets
{
//Make local definitions
typedef dom::DOMString DOMString;
typedef dom::Node Node;
/*#########################################################################
## MediaList
#########################################################################*/
/**
* The MediaList interface provides the abstraction of an ordered collection of
* media, without defining or constraining how this collection is implemented. An
* empty list is the same as a list that contains the medium "all".
*
* The items in the MediaList are accessible via an integral index, starting from
* 0.
*/
class MediaList
{
public:
/**
* The parsable textual representation of the media list. This is a
* comma-separated list of media.
*/
virtual DOMString getMediaText()
{
return mediaText;
}
/**
* The parsable textual representation of the media list. This is a
* comma-separated list of media.
*/
virtual void setMediaText(const DOMString &val) throw (dom::DOMException)
{
mediaText = val;
}
/**
* The number of media in the list. The range of valid media is 0 to
* length-1 inclusive.
*/
virtual unsigned long getLength()
{
return items.size();
}
/**
* Returns the indexth in the list. If index is greater than or equal to
* the number of media in the list, this returns null.
*/
virtual DOMString item(unsigned long index)
{
if (index >= items.size())
return "";
return items[index];
}
/**
* Deletes the medium indicated by oldMedium from the list.
*/
virtual void deleteMedium(const DOMString& oldMedium)
throw (dom::DOMException)
{
std::vector<DOMString>::iterator iter;
for (iter=items.begin() ; iter!=items.end() ; iter++)
{
if (*iter == oldMedium)
items.erase(iter);
}
}
/**
* Adds the medium newMedium to the end of the list. If the newMedium
* is already used, it is first removed.
*/
virtual void appendMedium(const DOMString& newMedium)
throw (dom::DOMException)
{
items.push_back(newMedium);
}
//##################
//# Non-API methods
//##################
/**
*
*/
MediaList() {}
/**
*
*/
MediaList(const MediaList &other)
{
assign(other);
}
/**
*
*/
MediaList &operator=(const MediaList &other)
{
assign(other);
return *this;
}
/**
*
*/
void assign(const MediaList &other)
{
mediaText = other.mediaText;
items = other.items;
}
/**
*
*/
virtual ~MediaList() {}
protected:
DOMString mediaText;
std::vector<DOMString>items;
};
/*#########################################################################
## StyleSheet
#########################################################################*/
/**
* The StyleSheet interface is the abstract base interface for any type of style
* sheet. It represents a single style sheet associated with a structured
* document. In HTML, the StyleSheet interface represents either an external
* style sheet, included via the HTML LINK element, or an inline STYLE element.
* In XML, this interface represents an external style sheet, included via a
* style sheet processing instruction.
*/
class StyleSheet
{
public:
/**
* This specifies the style sheet language for this style sheet. The style sheet
* language is specified as a content type (e.g. "text/css"). The content type is
* often specified in the ownerNode. Also see the type attribute definition for
* the LINK element in HTML 4.0, and the type pseudo-attribute for the XML style
* sheet processing instruction.
*/
virtual DOMString getType()
{
return type;
}
/**
* false if the style sheet is applied to the document. true if it is not.
* Modifying this attribute may cause a new resolution of style for the document.
* A stylesheet only applies if both an appropriate medium definition is present
* and the disabled attribute is false. So, if the media doesn't apply to the
* current user agent, the disabled attribute is ignored.
*/
virtual bool getDisabled()
{
return disabled;
}
/**
* Sets the value above.
*/
virtual void setDisabled(bool val)
{
disabled = val;
}
/**
* The node that associates this style sheet with the document. For HTML, this
* may be the corresponding LINK or STYLE element. For XML, it may be the linking
* processing instruction. For style sheets that are included by other style
* sheets, the value of this attribute is null.
*/
virtual NodePtr getOwnerNode()
{
return ownerNode;
}
/**
* For style sheet languages that support the concept of style sheet inclusion,
* this attribute represents the including style sheet, if one exists. If the
* style sheet is a top-level style sheet, or the style sheet language does not
* support inclusion, the value of this attribute is null.
*/
virtual StyleSheet *getParentStyleSheet()
{
return parentStylesheet;
}
/**
* If the style sheet is a linked style sheet, the value of its attribute is its
* location. For inline style sheets, the value of this attribute is null. See
* the href attribute definition for the LINK element in HTML 4.0, and the href
* pseudo-attribute for the XML style sheet processing instruction.
*/
virtual DOMString getHref()
{
return href;
}
/**
* The advisory title. The title is often specified in the ownerNode. See the
* title attribute definition for the LINK element in HTML 4.0, and the title
* pseudo-attribute for the XML style sheet processing instruction.
*/
virtual DOMString getTitle()
{
return title;
}
/**
* The intended destination media for style information. The media is often
* specified in the ownerNode. If no media has been specified, the MediaList will
* be empty. See the media attribute definition for the LINK element in HTML 4.0,
* and the media pseudo-attribute for the XML style sheet processing
* instruction . Modifying the media list may cause a change to the attribute
* disabled.
*/
virtual MediaList &getMedia()
{
MediaList &mediaListRef = mediaList;
return mediaListRef;
}
//##################
//# Non-API methods
//##################
/**
*
*/
StyleSheet()
{
type = "";
disabled = false;
ownerNode = NULL;
parentStylesheet = NULL;
href = "";
title = "";
}
/**
*
*/
StyleSheet(const StyleSheet &other)
{
assign(other);
}
/**
*
*/
StyleSheet &operator=(const StyleSheet &other)
{
assign(other);
return *this;
}
/**
*
*/
void assign(const StyleSheet &other)
{
type = other.type;
disabled = other.disabled;
ownerNode = other.ownerNode;
parentStylesheet = other.parentStylesheet;
href = other.href;
title = other.title;
mediaList = other.mediaList;
}
/**
*
*/
virtual ~StyleSheet() {}
protected:
DOMString type;
bool disabled;
NodePtr ownerNode;
StyleSheet *parentStylesheet;
DOMString href;
DOMString title;
MediaList mediaList;
};
/*#########################################################################
## StyleSheetList
#########################################################################*/
/**
* The StyleSheetList interface provides the abstraction of an ordered collection
* of style sheets.
*
* The items in the StyleSheetList are accessible via an integral index, starting
* from 0.
*/
class StyleSheetList
{
public:
/**
* The number of StyleSheets in the list. The range of valid child stylesheet
* indices is 0 to length-1 inclusive.
*/
virtual unsigned long getLength()
{
return sheets.size();
}
/**
* Used to retrieve a style sheet by ordinal index. If index is greater than or
* equal to the number of style sheets in the list, this returns null.
*/
virtual StyleSheet *item(unsigned long index)
{
if (index >= sheets.size())
return NULL;
return sheets[index];
}
//##################
//# Non-API methods
//##################
/**
*
*/
StyleSheetList() {}
/**
*
*/
StyleSheetList(const StyleSheetList &other)
{
sheets = other.sheets;
}
/**
*
*/
StyleSheetList &operator=(const StyleSheetList &other)
{
sheets = other.sheets;
return *this;
}
/**
*
*/
virtual ~StyleSheetList() {}
protected:
std::vector<StyleSheet *>sheets;
};
/*#########################################################################
## LinkStyle
#########################################################################*/
/**
* The LinkStyle interface provides a mechanism by which a style sheet can be
* retrieved from the node responsible for linking it into a document. An
* instance of the LinkStyle interface can be obtained using binding-specific
* casting methods on an instance of a linking node (HTMLLinkElement,
* HTMLStyleElement or ProcessingInstruction in DOM Level 2).
*/
class LinkStyle
{
public:
/**
* The style sheet.
*/
virtual StyleSheet &getSheet()
{
StyleSheet &sheetRef = sheet;
return sheetRef;
}
//##################
//# Non-API methods
//##################
/**
*
*/
LinkStyle()
{
}
/**
*
*/
LinkStyle(const LinkStyle &other)
{
sheet = other.sheet;
}
/**
*
*/
LinkStyle &operator=(const LinkStyle &other)
{
sheet = other.sheet;
return *this;
}
/**
*
*/
virtual ~LinkStyle() {}
protected:
StyleSheet sheet;
};
/*#########################################################################
## DocumentStyle
#########################################################################*/
/**
* The DocumentStyle interface provides a mechanism by which the style sheets
* embedded in a document can be retrieved. The expectation is that an instance
* of the DocumentStyle interface can be obtained by using binding-specific
* casting methods on an instance of the Document interface.
*/
class DocumentStyle
{
public:
/**
* A list containing all the style sheets explicitly linked into or embedded in a
* document. For HTML documents, this includes external style sheets, included
* via the HTML LINK element, and inline STYLE elements. In XML, this includes
* external style sheets, included via style sheet processing instructions (see
* [XML-StyleSheet]).
*/
virtual StyleSheetList &getStyleSheets()
{
StyleSheetList &listRef = styleSheets;
return listRef;
}
//##################
//# Non-API methods
//##################
/**
*
*/
DocumentStyle() {}
/**
*
*/
DocumentStyle(const DocumentStyle &other)
{
styleSheets = other.styleSheets;
}
/**
*
*/
DocumentStyle &operator=(const DocumentStyle &other)
{
styleSheets = other.styleSheets;
return *this;
}
/**
*
*/
virtual ~DocumentStyle() {}
protected:
StyleSheetList styleSheets;
};
} //namespace stylesheets
} //namespace dom
} //namespace w3c
} //namespace org
#endif /* __STYLESHEETS_H__ */
/*#########################################################################
## E N D O F F I L E
#########################################################################*/
|