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