css_stylesheetimpl.h

00001 /*
00002  * This file is part of the DOM implementation for KDE.
00003  *
00004  * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
00005  *           (C) 2004 Apple Computer, Inc.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public License
00018  * along with this library; see the file COPYING.LIB.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021  *
00022  */
00023 #ifndef _CSS_css_stylesheetimpl_h_
00024 #define _CSS_css_stylesheetimpl_h_
00025 
00026 #include <qvaluelist.h>
00027 #include <qptrlist.h>
00028 
00029 #include "dom/dom_string.h"
00030 #include "css/css_base.h"
00031 #include "misc/loader_client.h"
00032 #include "xml/dom_docimpl.h"
00033 
00034 namespace khtml {
00035     class CachedCSSStyleSheet;
00036     class DocLoader;
00037 }
00038 
00039 namespace DOM {
00040 
00041 class StyleSheet;
00042 class CSSStyleSheet;
00043 class CSSParser;
00044 class MediaListImpl;
00045 class CSSRuleImpl;
00046 class CSSRuleList;
00047 class CSSStyleRuleImpl;
00048 class CSSValueImpl;
00049 class NodeImpl;
00050 class DocumentImpl;
00051 
00052 class StyleSheetImpl : public StyleListImpl
00053 {
00054 public:
00055     StyleSheetImpl(DOM::NodeImpl *ownerNode, DOM::DOMString href = DOMString());
00056     StyleSheetImpl(StyleSheetImpl *parentSheet, DOM::DOMString href = DOMString());
00057     StyleSheetImpl(StyleBaseImpl *owner, DOM::DOMString href  = DOMString());
00058     StyleSheetImpl(khtml::CachedCSSStyleSheet *cached, DOM::DOMString href  = DOMString());
00059     virtual ~StyleSheetImpl();
00060 
00061     virtual bool isStyleSheet() const { return true; }
00062 
00063     virtual DOM::DOMString type() const { return DOMString(); }
00064 
00065     bool disabled() const { return m_disabled; }
00066     void setDisabled( bool disabled );
00067     DOM::NodeImpl *ownerNode() const { return m_parentNode; }
00068     StyleSheetImpl *parentStyleSheet() const;
00069     DOM::DOMString href() const { return m_strHref; }
00070     DOM::DOMString title() const { return m_strTitle; }
00071     MediaListImpl *media() const { return m_media; }
00072     void setMedia( MediaListImpl *media );
00073 
00074 protected:
00075     DOM::NodeImpl *m_parentNode;
00076     DOM::DOMString m_strHref;
00077     DOM::DOMString m_strTitle;
00078     MediaListImpl *m_media;
00079     bool m_disabled;
00080 };
00081 
00082 class CSSStyleSheetImpl : public StyleSheetImpl
00083 {
00084 public:
00085     CSSStyleSheetImpl(DOM::NodeImpl *parentNode, DOM::DOMString href = DOMString(), bool _implicit = false);
00086     CSSStyleSheetImpl(CSSStyleSheetImpl *parentSheet, DOM::DOMString href = DOMString());
00087     CSSStyleSheetImpl(CSSRuleImpl *ownerRule, DOM::DOMString href = DOMString());
00088     // clone from a cached version of the sheet
00089     CSSStyleSheetImpl(DOM::NodeImpl *parentNode, CSSStyleSheetImpl *orig);
00090     CSSStyleSheetImpl(CSSRuleImpl *ownerRule, CSSStyleSheetImpl *orig);
00091 
00092     ~CSSStyleSheetImpl() { delete m_namespaces; }
00093 
00094     virtual bool isCSSStyleSheet() const { return true; }
00095 
00096     virtual DOM::DOMString type() const { return "text/css"; }
00097 
00098     CSSRuleImpl *ownerRule() const;
00099     CSSRuleList cssRules();
00100     unsigned long insertRule ( const DOM::DOMString &rule, unsigned long index, int &exceptioncode );
00101     void deleteRule ( unsigned long index, int &exceptioncode );
00102 
00103     void addNamespace(CSSParser* p, const DOM::DOMString& prefix, const DOM::DOMString& uri);
00104     void determineNamespace(Q_UINT32& id, const DOM::DOMString& prefix);
00105 
00106     virtual bool parseString( const DOMString &string, bool strict = true );
00107 
00108     bool isLoading() const;
00109     void setNonCSSHints();
00110 
00111     virtual void checkLoaded() const;
00112 
00113     // ### remove? (clients should use sheet->doc()->docLoader())
00114     khtml::DocLoader *docLoader() const
00115     { return m_doc ? m_doc->docLoader() : 0; }
00116 
00117     DocumentImpl *doc() const { return m_doc; }
00118     bool implicit() const { return m_implicit; }
00119 protected:
00120     DocumentImpl *m_doc;
00121     bool m_implicit;
00122     CSSNamespace* m_namespaces;
00123 };
00124 
00125 // ----------------------------------------------------------------------------
00126 
00127 class StyleSheetListImpl : public khtml::Shared<StyleSheetListImpl>
00128 {
00129 public:
00130     StyleSheetListImpl() {}
00131     ~StyleSheetListImpl();
00132 
00133     // the following two ignore implicit stylesheets
00134     unsigned long length() const;
00135     StyleSheetImpl *item ( unsigned long index );
00136 
00137     void add(StyleSheetImpl* s);
00138     void remove(StyleSheetImpl* s);
00139 
00140     QPtrList<StyleSheetImpl> styleSheets;
00141 };
00142 
00143 // ----------------------------------------------------------------------------
00144 
00145 class MediaListImpl : public StyleBaseImpl
00146 {
00147 public:
00148     MediaListImpl()
00149     : StyleBaseImpl( 0 ) {}
00150     MediaListImpl( CSSStyleSheetImpl *parentSheet )
00151         : StyleBaseImpl(parentSheet) {}
00152     MediaListImpl( CSSStyleSheetImpl *parentSheet,
00153                    const DOM::DOMString &media );
00154     MediaListImpl( CSSRuleImpl *parentRule, const DOM::DOMString &media );
00155 
00156     virtual bool isMediaList() const { return true; }
00157 
00158     CSSStyleSheetImpl *parentStyleSheet() const;
00159     CSSRuleImpl *parentRule() const;
00160     unsigned long length() const { return m_lstMedia.count(); }
00161     DOM::DOMString item ( unsigned long index ) const { return m_lstMedia[index]; }
00162     void deleteMedium ( const DOM::DOMString &oldMedium );
00163     void appendMedium ( const DOM::DOMString &newMedium ) { m_lstMedia.append(newMedium); }
00164 
00165     DOM::DOMString mediaText() const;
00166     void setMediaText(const DOM::DOMString &value);
00167 
00176     bool contains( const DOM::DOMString &medium ) const;
00177 
00178 protected:
00179     QValueList<DOM::DOMString> m_lstMedia;
00180 };
00181 
00182 
00183 } // namespace
00184 
00185 #endif
00186 
KDE Home | KDE Accessibility Home | Description of Access Keys