Code

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