00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _CSS_cssparser_h_
00023 #define _CSS_cssparser_h_
00024
00025 #include <qstring.h>
00026 #include <qcolor.h>
00027 #include <qvaluevector.h>
00028 #include <dom/dom_string.h>
00029
00030 namespace DOM {
00031 class StyleListImpl;
00032 class CSSStyleSheetImpl;
00033 class CSSRuleImpl;
00034 class CSSStyleRuleImpl;
00035 class DocumentImpl;
00036 class CSSValueImpl;
00037 class CSSValueListImpl;
00038 class CSSPrimitiveValueImpl;
00039 class CSSStyleDeclarationImpl;
00040 class CSSProperty;
00041 class CSSRuleListImpl;
00042
00043
00044 struct ParseString {
00045 unsigned short *string;
00046 int length;
00047 };
00048
00049 struct Value;
00050 class ValueList;
00051
00052 struct Function {
00053 ParseString name;
00054 ValueList *args;
00055 };
00056
00057 struct Value {
00058 int id;
00059 bool isInt;
00060 union {
00061 double fValue;
00062 int iValue;
00063 ParseString string;
00064 struct Function *function;
00065 };
00066 enum {
00067 Operator = 0x100000,
00068 Function = 0x100001,
00069 Q_EMS = 0x100002
00070 };
00071
00072 int unit;
00073 };
00074
00075 static inline QString qString( const ParseString &ps ) {
00076 return QString( (QChar *)ps.string, ps.length );
00077 }
00078 static inline DOMString domString( const ParseString &ps ) {
00079 return DOMString( (QChar *)ps.string, ps.length );
00080 }
00081
00082 class ValueList {
00083 public:
00084 ValueList() : m_current(0) { }
00085 ~ValueList();
00086 void addValue(const Value& v) { m_values.append(v); }
00087 unsigned int size() const { return m_values.size(); }
00088 Value* current() { return m_current < m_values.size() ? &m_values[m_current] : 0; }
00089 Value* next() { ++m_current; return current(); }
00090 private:
00091 QValueVector<Value> m_values;
00092 unsigned int m_current;
00093 };
00094
00095 class CSSParser
00096 {
00097 public:
00098 CSSParser( bool strictParsing = true );
00099 ~CSSParser();
00100
00101 void parseSheet( DOM::CSSStyleSheetImpl *sheet, const DOM::DOMString &string );
00102 DOM::CSSRuleImpl *parseRule( DOM::CSSStyleSheetImpl *sheet, const DOM::DOMString &string );
00103 bool parseValue( DOM::CSSStyleDeclarationImpl *decls, int id, const DOM::DOMString &string,
00104 bool _important, bool _nonCSSHint );
00105 bool parseDeclaration( DOM::CSSStyleDeclarationImpl *decls, const DOM::DOMString &string,
00106 bool _nonCSSHint );
00107
00108 static CSSParser *current() { return currentParser; }
00109
00110
00111 DOM::DocumentImpl *document() const;
00112
00113 unsigned int defaultNamespace();
00114
00115 void addProperty( int propId, CSSValueImpl *value, bool important );
00116 bool hasProperties() const { return numParsedProperties > 0; }
00117 CSSStyleDeclarationImpl *createStyleDeclaration( CSSStyleRuleImpl *rule );
00118 void clearProperties();
00119
00120 bool parseValue( int propId, bool important );
00121 bool parseShortHand( int propId, const int *properties, int numProperties, bool important );
00122 bool parse4Values( int propId, const int *properties, bool important );
00123 bool parseContent( int propId, bool important );
00124
00125 CSSValueImpl* parseBackgroundColor();
00126 CSSValueImpl* parseBackgroundImage();
00127 CSSValueImpl* parseBackgroundPositionXY(bool& xFound, bool& yFound);
00128 void parseBackgroundPosition(CSSValueImpl*& value1, CSSValueImpl*& value2);
00129 CSSValueImpl* parseBackgroundSize();
00130
00131 bool parseBackgroundProperty(int propId, int& propId1, int& propId2, CSSValueImpl*& retValue1, CSSValueImpl*& retValue2);
00132 bool parseBackgroundShorthand(bool important);
00133
00134 void addBackgroundValue(CSSValueImpl*& lval, CSSValueImpl* rval);
00135
00136 bool parseShape( int propId, bool important );
00137 bool parseFont(bool important);
00138 bool parseCounter(int propId, bool increment, bool important);
00139
00140 bool parseColorParameters(Value*, int* colorValues, bool parseAlpha);
00141 bool parseHSLParameters(Value*, double* colorValues, bool parseAlpha);
00142
00143
00144
00145
00146 CSSValueListImpl *parseFontFamily();
00147 CSSPrimitiveValueImpl *parseColor();
00148 CSSPrimitiveValueImpl *parseColorFromValue(Value* val);
00149 CSSValueImpl* parseCounterContent(ValueList *args, bool counters);
00150
00151 static bool parseColor(const QString &name, QRgb& rgb);
00152
00153
00154 bool parseShadow(int propId, bool important);
00155
00156 bool parseBorderImage(int propId, bool important);
00157
00158 public:
00159 bool strict;
00160 bool important;
00161 bool nonCSSHint;
00162 unsigned int id;
00163 DOM::StyleListImpl* styleElement;
00164 DOM::CSSRuleImpl *rule;
00165 ValueList *valueList;
00166 CSSProperty **parsedProperties;
00167 int numParsedProperties;
00168 int maxParsedProperties;
00169
00170 int m_inParseShorthand;
00171 int m_currentShorthand;
00172 bool m_implicitShorthand;
00173
00174 static CSSParser *currentParser;
00175
00176
00177 public:
00178 int lex( void *yylval );
00179 int token() { return yyTok; }
00180 unsigned short *text( int *length);
00181 int lex();
00182 private:
00183 int yyparse();
00184 void runParser(int length);
00185
00186 bool inShorthand() const { return m_inParseShorthand; }
00187
00188 unsigned short *data;
00189 unsigned short *yytext;
00190 unsigned short *yy_c_buf_p;
00191 unsigned short yy_hold_char;
00192 int yy_last_accepting_state;
00193 unsigned short *yy_last_accepting_cpos;
00194 int block_nesting;
00195 int yyleng;
00196 int yyTok;
00197 int yy_start;
00198 };
00199
00200 }
00201 #endif