00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _CSS_BASE_H
00025 #define _CSS_BASE_H
00026
00027 #include "dom/dom_string.h"
00028 #include "dom/dom_misc.h"
00029 #include "xml/dom_nodeimpl.h"
00030 #include "misc/shared.h"
00031 #include <kdemacros.h>
00032 #include <qdatetime.h>
00033 #include <qptrlist.h>
00034
00035 namespace DOM {
00036
00037 class StyleSheetImpl;
00038 class MediaList;
00039
00040 class CSSSelector;
00041 class CSSProperty;
00042 class CSSValueImpl;
00043 class CSSPrimitiveValueImpl;
00044 class CSSStyleDeclarationImpl;
00045 class CSSRuleImpl;
00046 class CSSStyleRuleImpl;
00047
00048 class DocumentImpl;
00049
00050
00051 class CSSSelector
00052 {
00053 public:
00054 CSSSelector()
00055 : tagHistory(0), simpleSelector(0), attr(0), tag(0xffff), relation( Descendant ),
00056 match( None ), nonCSSHint( false ), pseudoId( 0 ), _pseudoType(PseudoNotParsed)
00057 {}
00058
00059 ~CSSSelector() {
00060 delete tagHistory;
00061 delete simpleSelector;
00062 }
00063
00067 void print();
00068
00072 DOMString selectorText() const;
00073
00074
00075 bool operator == ( const CSSSelector &other ) const;
00076
00077
00078
00079 unsigned int specificity() const;
00080
00081
00082 enum Match
00083 {
00084 None = 0,
00085 Id,
00086 Exact,
00087 Set,
00088 List,
00089 Hyphen,
00090 Pseudo,
00091 Contain,
00092 Begin,
00093 End
00094 };
00095
00096 enum Relation
00097 {
00098 Descendant = 0,
00099 Child,
00100 Sibling,
00101 Cousin,
00102 SubSelector
00103 };
00104
00105 enum PseudoType
00106 {
00107 PseudoNotParsed = 0,
00108 PseudoOther,
00109 PseudoEmpty,
00110 PseudoFirstChild,
00111 PseudoLastChild,
00112 PseudoOnlyChild,
00113 PseudoFirstLine,
00114 PseudoFirstLetter,
00115 PseudoLink,
00116 PseudoVisited,
00117 PseudoHover,
00118 PseudoFocus,
00119 PseudoActive,
00120 PseudoTarget,
00121 PseudoBefore,
00122 PseudoAfter,
00123 PseudoLang,
00124 PseudoNot,
00125 PseudoRoot,
00126 PseudoSelection
00127 };
00128
00129 PseudoType pseudoType() const {
00130 if (_pseudoType == PseudoNotParsed)
00131 extractPseudoType();
00132 return _pseudoType;
00133 }
00134
00135 mutable DOM::DOMString value;
00136 CSSSelector *tagHistory;
00137 CSSSelector* simpleSelector;
00138 DOM::NodeImpl::Id attr;
00139 DOM::NodeImpl::Id tag;
00140
00141 Relation relation : 3;
00142 Match match : 4;
00143 bool nonCSSHint : 1;
00144 unsigned int pseudoId : 3;
00145 mutable PseudoType _pseudoType : 5;
00146
00147 private:
00148 void extractPseudoType() const;
00149 };
00150
00151
00152 class StyleBaseImpl : public khtml::TreeShared<StyleBaseImpl>
00153 {
00154 public:
00155 StyleBaseImpl() { m_parent = 0; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
00156 StyleBaseImpl(StyleBaseImpl *p) {
00157 m_parent = p; hasInlinedDecl = false;
00158 strictParsing = (m_parent ? m_parent->useStrictParsing() : true);
00159 multiLength = false;
00160 }
00161
00162 virtual ~StyleBaseImpl() {}
00163
00164
00165
00166 KURL baseURL();
00167
00168 virtual bool isStyleSheet() const { return false; }
00169 virtual bool isCSSStyleSheet() const { return false; }
00170 virtual bool isStyleSheetList() const { return false; }
00171 virtual bool isMediaList() const { return false; }
00172 virtual bool isRuleList() const { return false; }
00173 virtual bool isRule() const { return false; }
00174 virtual bool isStyleRule() const { return false; }
00175 virtual bool isCharetRule() const { return false; }
00176 virtual bool isImportRule() const { return false; }
00177 virtual bool isMediaRule() const { return false; }
00178 virtual bool isFontFaceRule() const { return false; }
00179 virtual bool isPageRule() const { return false; }
00180 virtual bool isUnknownRule() const { return false; }
00181 virtual bool isStyleDeclaration() const { return false; }
00182 virtual bool isValue() const { return false; }
00183 virtual bool isPrimitiveValue() const { return false; }
00184 virtual bool isValueList() const { return false; }
00185 virtual bool isValueCustom() const { return false; }
00186
00187 void setParent(StyleBaseImpl *parent) { m_parent = parent; }
00188
00189 static void setParsedValue(int propId, const CSSValueImpl *parsedValue,
00190 bool important, bool nonCSSHint, QPtrList<CSSProperty> *propList);
00191
00192 virtual bool parseString(const DOMString &, bool = false) { return false; }
00193
00194 virtual void checkLoaded() const;
00195
00196 void setStrictParsing( bool b ) { strictParsing = b; }
00197 bool useStrictParsing() const { return strictParsing; }
00198
00199
00200 StyleSheetImpl* stylesheet();
00201
00202 protected:
00203 bool hasInlinedDecl : 1;
00204 bool strictParsing : 1;
00205 bool multiLength : 1;
00206 };
00207
00208
00209 class StyleListImpl : public StyleBaseImpl
00210 {
00211 public:
00212 StyleListImpl() : StyleBaseImpl() { m_lstChildren = 0; }
00213 StyleListImpl(StyleBaseImpl *parent) : StyleBaseImpl(parent) { m_lstChildren = 0; }
00214 virtual ~StyleListImpl();
00215
00216 unsigned long length() const { return m_lstChildren->count(); }
00217 StyleBaseImpl *item(unsigned long num) const { return m_lstChildren->at(num); }
00218
00219 void append(StyleBaseImpl *item) { m_lstChildren->append(item); }
00220
00221 protected:
00222 QPtrList<StyleBaseImpl> *m_lstChildren;
00223 };
00224
00225 KDE_NO_EXPORT int getPropertyID(const char *tagStr, int len);
00226
00227 }
00228
00229 #endif