cssparser.h00001
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
00141
00142
00143 CSSValueListImpl *parseFontFamily();
00144 CSSPrimitiveValueImpl *parseColor();
00145 CSSPrimitiveValueImpl *parseColorFromValue(Value* val);
00146 CSSValueImpl* parseCounterContent(ValueList *args, bool counters);
00147
00148 static bool parseColor(const QString &name, QRgb& rgb);
00149
00150
00151 bool parseShadow(int propId, bool important);
00152
00153 bool parseBorderImage(int propId, bool important);
00154
00155 public:
00156 bool strict;
00157 bool important;
00158 bool nonCSSHint;
00159 unsigned int id;
00160 DOM::StyleListImpl* styleElement;
00161 DOM::CSSRuleImpl *rule;
00162 ValueList *valueList;
00163 CSSProperty **parsedProperties;
00164 int numParsedProperties;
00165 int maxParsedProperties;
00166
00167 int m_inParseShorthand;
00168 int m_currentShorthand;
00169 bool m_implicitShorthand;
00170
00171 static CSSParser *currentParser;
00172
00173
00174 public:
00175 int lex( void *yylval );
00176 int token() { return yyTok; }
00177 unsigned short *text( int *length);
00178 int lex();
00179 private:
00180 int yyparse();
00181 void runParser(int length);
00182
00183 bool inShorthand() const { return m_inParseShorthand; }
00184
00185 unsigned short *data;
00186 unsigned short *yytext;
00187 unsigned short *yy_c_buf_p;
00188 unsigned short yy_hold_char;
00189 int yy_last_accepting_state;
00190 unsigned short *yy_last_accepting_cpos;
00191 int block_nesting;
00192 int yyleng;
00193 int yyTok;
00194 int yy_start;
00195 };
00196
00197 }
00198 #endif
|