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     Q_UINT32 defaultNamespace() { return m_defaultNamespace; };
00106 
00107     virtual bool parseString( const DOMString &string, bool strict = true );
00108 
00109     bool isLoading() const;
00110     void setNonCSSHints();
00111 
00112     virtual void checkLoaded() const;
00113 
00114     // ### remove? (clients should use sheet->doc()->docLoader())
00115     khtml::DocLoader *docLoader() const
00116     { return m_doc ? m_doc->docLoader() : 0; }
00117 
00118     DocumentImpl *doc() const { return m_doc; }
00119     bool implicit() const { return m_implicit; }
00120 protected:
00121     DocumentImpl *m_doc;
00122     bool m_implicit;
00123     Q_UINT32 m_defaultNamespace;
00124     CSSNamespace* m_namespaces;
00125 };
00126 
00127 // ----------------------------------------------------------------------------
00128 
00129 class StyleSheetListImpl : public khtml::Shared<StyleSheetListImpl>
00130 {
00131 public:
00132     StyleSheetListImpl() {}
00133     ~StyleSheetListImpl();
00134 
00135     // the following two ignore implicit stylesheets
00136     unsigned long length() const;
00137     StyleSheetImpl *item ( unsigned long index );
00138 
00139     void add(StyleSheetImpl* s);
00140     void remove(StyleSheetImpl* s);
00141 
00142     QPtrList<StyleSheetImpl> styleSheets;
00143 };
00144 
00145 // ----------------------------------------------------------------------------
00146 
00147 class MediaListImpl : public StyleBaseImpl
00148 {
00149 public:
00150     MediaListImpl()
00151     : StyleBaseImpl( 0 ) {}
00152     MediaListImpl( CSSStyleSheetImpl *parentSheet )
00153         : StyleBaseImpl(parentSheet) {}
00154     MediaListImpl( CSSStyleSheetImpl *parentSheet,
00155                    const DOM::DOMString &media );
00156     MediaListImpl( CSSRuleImpl *parentRule, const DOM::DOMString &media );
00157 
00158     virtual bool isMediaList() const { return true; }
00159 
00160     CSSStyleSheetImpl *parentStyleSheet() const;
00161     CSSRuleImpl *parentRule() const;
00162     unsigned long length() const { return m_lstMedia.count(); }
00163     DOM::DOMString item ( unsigned long index ) const { return m_lstMedia[index]; }
00164     void deleteMedium ( const DOM::DOMString &oldMedium );
00165     void appendMedium ( const DOM::DOMString &newMedium ) { m_lstMedia.append(newMedium); }
00166 
00167     DOM::DOMString mediaText() const;
00168     void setMediaText(const DOM::DOMString &value);
00169 
00178     bool contains( const DOM::DOMString &medium ) const;
00179 
00180 protected:
00181     QValueList<DOM::DOMString> m_lstMedia;
00182 };
00183 
00184 
00185 } // namespace
00186 
00187 #endif
00188 
KDE Home | KDE Accessibility Home | Description of Access Keys