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