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_cssparser_h_
00025 #define _CSS_cssparser_h_
00026
00027 #include "dom/dom_string.h"
00028 #include "dom/dom_misc.h"
00029 #include "misc/shared.h"
00030 #include <qdatetime.h>
00031 #include <qptrlist.h>
00032
00033 namespace DOM {
00034
00035 class StyleSheetImpl;
00036 class MediaList;
00037
00038 class CSSSelector;
00039 class CSSProperty;
00040 class CSSValueImpl;
00041 class CSSPrimitiveValueImpl;
00042 class CSSStyleDeclarationImpl;
00043 class CSSRuleImpl;
00044 class CSSStyleRuleImpl;
00045
00046 class DocumentImpl;
00047
00048 int getPropertyID(const char *tagStr, int len);
00049
00050
00051 class CSSSelector
00052 {
00053 public:
00054 CSSSelector(void)
00055 : tagHistory(0), attr(0), tag(0), relation( Descendant ),
00056 match( None ), nonCSSHint( false ), pseudoId( 0 ) {}
00057
00058 ~CSSSelector(void) {
00059 if (tagHistory)
00060 delete tagHistory;
00061 }
00062
00066 void print(void);
00067
00071 DOMString selectorText() const;
00072
00073
00074 bool operator == ( const CSSSelector &other );
00075
00076
00077
00078 unsigned int specificity();
00079
00080
00081 enum Match
00082 {
00083 None = 0,
00084 Exact,
00085 Set,
00086 List,
00087 Hyphen,
00088 Pseudo,
00089 Contain,
00090 Begin,
00091 End
00092 };
00093
00094 enum Relation
00095 {
00096 Descendant = 0,
00097 Child,
00098 Sibling,
00099 SubSelector
00100 };
00101
00102 DOM::DOMString value;
00103 CSSSelector *tagHistory;
00104 int attr;
00105 int tag;
00106
00107 Relation relation : 2;
00108 Match match : 4;
00109 bool nonCSSHint : 1;
00110 unsigned int pseudoId : 3;
00111
00112
00113 };
00114
00115
00116 class StyleBaseImpl : public khtml::TreeShared<StyleBaseImpl>
00117 {
00118 public:
00119 StyleBaseImpl() { m_parent = 0; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
00120 StyleBaseImpl(StyleBaseImpl *p) { m_parent = p; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
00121
00122 virtual ~StyleBaseImpl() {}
00123
00124
00125 DOMString baseURL();
00126
00127 virtual bool isStyleSheet() const { return false; }
00128 virtual bool isCSSStyleSheet() const { return false; }
00129 virtual bool isStyleSheetList() const { return false; }
00130 virtual bool isMediaList() { return false; }
00131 virtual bool isRuleList() { return false; }
00132 virtual bool isRule() { return false; }
00133 virtual bool isStyleRule() { return false; }
00134 virtual bool isCharetRule() { return false; }
00135 virtual bool isImportRule() { return false; }
00136 virtual bool isMediaRule() { return false; }
00137 virtual bool isFontFaceRule() { return false; }
00138 virtual bool isPageRule() { return false; }
00139 virtual bool isUnknownRule() { return false; }
00140 virtual bool isStyleDeclaration() { return false; }
00141 virtual bool isValue() { return false; }
00142 virtual bool isPrimitiveValue() const { return false; }
00143 virtual bool isValueList() { return false; }
00144 virtual bool isValueCustom() { return false; }
00145
00146 void setParent(StyleBaseImpl *parent) { m_parent = parent; }
00147
00148 const QString preprocess(const QString &str, bool justOneRule = false);
00149 const QChar *parseSpace(const QChar *curP, const QChar *endP);
00150 const QChar *parseToChar(const QChar *curP, const QChar *endP,
00151 QChar c, bool chkws, bool endAtBlock = false);
00152
00153 CSSSelector *parseSelector2(const QChar *curP, const QChar *endP, CSSSelector::Relation relation);
00154 CSSSelector *parseSelector1(const QChar *curP, const QChar *endP);
00155 QPtrList<CSSSelector> *parseSelector(const QChar *curP, const QChar *endP);
00156
00157 void parseProperty(const QChar *curP, const QChar *endP);
00158 QPtrList<CSSProperty> *parseProperties(const QChar *curP, const QChar *endP);
00159
00160
00161 bool parseValue(const QChar *curP, const QChar *endP, int propId);
00162 bool parseValue(const QChar *curP, const QChar *endP, int propId,
00163 bool important, bool nonCSSHint, QPtrList<CSSProperty> *propList);
00164 bool parseFont(const QChar *curP, const QChar *endP);
00165 bool parse4Values(const QChar *curP, const QChar *endP, const int *properties);
00166 bool parseShortHand(const QChar *curP, const QChar *endP, const int *properties, int num);
00167 void setParsedValue(int propId, const CSSValueImpl *parsedValue);
00168 void setParsedValue(int propId, const CSSValueImpl *parsedValue,
00169 bool important, bool nonCSSHint, QPtrList<CSSProperty> *propList);
00170 QPtrList<QChar> splitShorthandProperties(const QChar *curP, const QChar *endP);
00171 bool parseBackgroundPosition(const QChar *curP, const QChar *&nextP, const QChar *endP);
00172
00173
00174 bool parse2Values(const QChar *curP, const QChar *endP, const int *properties);
00175 bool parseAuralValue(const QChar *curP, const QChar *endP, int propId);
00176
00177 CSSValueImpl* parseContent(const QChar *curP, const QChar *endP);
00178
00179
00180 enum Units
00181 {
00182 UNKNOWN = 0x0000,
00183 INTEGER = 0x0001,
00184 NUMBER = 0x0002,
00185 PERCENT = 0x0004,
00186 LENGTH = 0x0008,
00187 ANGLE = 0x0010,
00188 TIME = 0x0020,
00189 FREQUENCY = 0x0040,
00190 NONNEGATIVE = 0x0080,
00191 RELATIVE = 0x0100
00192 };
00193
00194
00195 CSSPrimitiveValueImpl *parseUnit(const QChar * curP, const QChar *endP, int allowedUnits);
00196
00197 CSSRuleImpl *parseAtRule(const QChar *&curP, const QChar *endP);
00198
00199
00200 CSSRuleImpl *parseStyleRule(const QChar *&curP, const QChar *endP);
00201 CSSRuleImpl *parseRule(const QChar *&curP, const QChar *endP);
00202
00203 virtual bool parseString(const DOMString &, bool = false) { return false; }
00204
00205 virtual void checkLoaded();
00206
00207 void setStrictParsing( bool b ) { strictParsing = b; }
00208 bool useStrictParsing() const { return strictParsing; }
00209
00210 protected:
00211 bool hasInlinedDecl : 1;
00212 bool strictParsing : 1;
00213 bool multiLength : 1;
00214 private:
00215 bool isHexadecimal( QChar &c );
00216 };
00217
00218
00219 class StyleListImpl : public StyleBaseImpl
00220 {
00221 public:
00222 StyleListImpl() : StyleBaseImpl() { m_lstChildren = 0; }
00223 StyleListImpl(StyleBaseImpl *parent) : StyleBaseImpl(parent) { m_lstChildren = 0; }
00224
00225 virtual ~StyleListImpl();
00226
00227 unsigned long length() { return m_lstChildren->count(); }
00228 StyleBaseImpl *item(unsigned long num) { return m_lstChildren->at(num); }
00229
00230 void append(StyleBaseImpl *item) { m_lstChildren->append(item); }
00231
00232 protected:
00233 QPtrList<StyleBaseImpl> *m_lstChildren;
00234 };
00235
00236 };
00237 #endif