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 struct CSSNamespace {
00052 DOMString m_prefix;
00053 DOMString m_uri;
00054 CSSNamespace* m_parent;
00055
00056 CSSNamespace(const DOMString& p, const DOMString& u, CSSNamespace* parent)
00057 :m_prefix(p), m_uri(u), m_parent(parent) {}
00058 ~CSSNamespace() { delete m_parent; }
00059
00060 const DOMString& uri() { return m_uri; }
00061 const DOMString& prefix() { return m_prefix; }
00062
00063 CSSNamespace* namespaceForPrefix(const DOMString& prefix) {
00064 if (prefix == m_prefix)
00065 return this;
00066 if (m_parent)
00067 return m_parent->namespaceForPrefix(prefix);
00068 return 0;
00069 }
00070 };
00071
00072
00073 class CSSSelector
00074 {
00075 public:
00076 CSSSelector()
00077 : tagHistory(0), simpleSelector(0), attr(0), tag(anyQName), relation( Descendant ),
00078 match( None ), nonCSSHint( false ), pseudoId( 0 ), _pseudoType(PseudoNotParsed)
00079 {}
00080
00081 ~CSSSelector() {
00082 delete tagHistory;
00083 delete simpleSelector;
00084 }
00085
00089 void print();
00090
00094 DOMString selectorText() const;
00095
00096
00097 bool operator == ( const CSSSelector &other ) const;
00098
00099
00100
00101 unsigned int specificity() const;
00102
00103
00104 enum Match
00105 {
00106 None = 0,
00107 Id,
00108 Exact,
00109 Set,
00110 Class,
00111 List,
00112 Hyphen,
00113 PseudoClass,
00114 PseudoElement,
00115 Contain,
00116 Begin,
00117 End
00118 };
00119
00120 enum Relation
00121 {
00122 Descendant = 0,
00123 Child,
00124 DirectAdjacent,
00125 IndirectAdjacent,
00126 SubSelector
00127 };
00128
00129 enum PseudoType
00130 {
00131 PseudoNotParsed = 0,
00132 PseudoOther,
00133 PseudoEmpty,
00134 PseudoFirstChild,
00135 PseudoLastChild,
00136 PseudoNthChild,
00137 PseudoNthLastChild,
00138 PseudoOnlyChild,
00139 PseudoFirstOfType,
00140 PseudoLastOfType,
00141 PseudoNthOfType,
00142 PseudoNthLastOfType,
00143 PseudoOnlyOfType,
00144 PseudoLink,
00145 PseudoVisited,
00146 PseudoHover,
00147 PseudoFocus,
00148 PseudoActive,
00149 PseudoTarget,
00150 PseudoLang,
00151 PseudoNot,
00152 PseudoContains,
00153 PseudoRoot,
00154 PseudoEnabled,
00155 PseudoDisabled,
00156 PseudoChecked,
00157 PseudoIndeterminate,
00158
00159
00160 PseudoFirstLine,
00161 PseudoFirstLetter,
00162 PseudoSelection,
00163
00164 PseudoBefore,
00165 PseudoAfter,
00166 PseudoMarker,
00167 PseudoReplaced
00168 };
00169
00170 PseudoType pseudoType() const {
00171 if (_pseudoType == PseudoNotParsed)
00172 extractPseudoType();
00173 return _pseudoType;
00174 }
00175
00176 mutable DOM::DOMString value;
00177 CSSSelector *tagHistory;
00178 CSSSelector* simpleSelector;
00179 DOM::DOMString string_arg;
00180 DOM::NodeImpl::Id attr;
00181 DOM::NodeImpl::Id tag;
00182
00183 Relation relation : 3;
00184 mutable Match match : 4;
00185 bool nonCSSHint : 1;
00186 unsigned int pseudoId : 4;
00187 mutable PseudoType _pseudoType : 6;
00188
00189 private:
00190 void extractPseudoType() const;
00191 };
00192
00193
00194 class StyleBaseImpl : public khtml::TreeShared<StyleBaseImpl>
00195 {
00196 public:
00197 StyleBaseImpl() { m_parent = 0; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
00198 StyleBaseImpl(StyleBaseImpl *p) {
00199 m_parent = p; hasInlinedDecl = false;
00200 strictParsing = (m_parent ? m_parent->useStrictParsing() : true);
00201 multiLength = false;
00202 }
00203
00204 virtual ~StyleBaseImpl() {}
00205
00206
00207
00208 KURL baseURL();
00209
00210 virtual bool isStyleSheet() const { return false; }
00211 virtual bool isCSSStyleSheet() const { return false; }
00212 virtual bool isStyleSheetList() const { return false; }
00213 virtual bool isMediaList() const { return false; }
00214 virtual bool isRuleList() const { return false; }
00215 virtual bool isRule() const { return false; }
00216 virtual bool isStyleRule() const { return false; }
00217 virtual bool isCharetRule() const { return false; }
00218 virtual bool isImportRule() const { return false; }
00219 virtual bool isMediaRule() const { return false; }
00220 virtual bool isFontFaceRule() const { return false; }
00221 virtual bool isPageRule() const { return false; }
00222 virtual bool isUnknownRule() const { return false; }
00223 virtual bool isStyleDeclaration() const { return false; }
00224 virtual bool isValue() const { return false; }
00225 virtual bool isPrimitiveValue() const { return false; }
00226 virtual bool isValueList() const { return false; }
00227 virtual bool isValueCustom() const { return false; }
00228
00229 void setParent(StyleBaseImpl *parent) { m_parent = parent; }
00230
00231 static void setParsedValue(int propId, const CSSValueImpl *parsedValue,
00232 bool important, bool nonCSSHint, QPtrList<CSSProperty> *propList);
00233
00234 virtual bool parseString(const DOMString &, bool = false) { return false; }
00235
00236 virtual void checkLoaded() const;
00237
00238 void setStrictParsing( bool b ) { strictParsing = b; }
00239 bool useStrictParsing() const { return strictParsing; }
00240
00241
00242 StyleSheetImpl* stylesheet();
00243
00244 protected:
00245 bool hasInlinedDecl : 1;
00246 bool strictParsing : 1;
00247 bool multiLength : 1;
00248 };
00249
00250
00251 class StyleListImpl : public StyleBaseImpl
00252 {
00253 public:
00254 StyleListImpl() : StyleBaseImpl() { m_lstChildren = 0; }
00255 StyleListImpl(StyleBaseImpl *parent) : StyleBaseImpl(parent) { m_lstChildren = 0; }
00256 virtual ~StyleListImpl();
00257
00258 unsigned long length() const { return m_lstChildren->count(); }
00259 StyleBaseImpl *item(unsigned long num) const { return m_lstChildren->at(num); }
00260
00261 void append(StyleBaseImpl *item) { m_lstChildren->append(item); }
00262
00263 protected:
00264 QPtrList<StyleBaseImpl> *m_lstChildren;
00265 };
00266
00267 KDE_NO_EXPORT int getPropertyID(const char *tagStr, int len);
00268
00269 }
00270
00271 #endif