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