cssparser.h
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef _CSS_cssparser_h_
00024 #define _CSS_cssparser_h_
00025 
00026 #include <qstring.h>
00027 #include <dom/dom_string.h>
00028 
00029 namespace DOM {
00030     class StyleListImpl;
00031     class CSSStyleSheetImpl;
00032     class CSSRuleImpl;
00033     class CSSStyleRuleImpl;
00034     class DocumentImpl;
00035     class CSSValueImpl;
00036     class CSSValueListImpl;
00037     class CSSPrimitiveValueImpl;
00038     class CSSStyleDeclarationImpl;
00039     class CSSProperty;
00040     class CSSRuleListImpl;
00041 
00042 
00043     struct ParseString {
00044     unsigned short *string;
00045     int length;
00046     };
00047 
00048     struct Value;
00049     class ValueList;
00050 
00051     struct Function {
00052     ParseString name;
00053     ValueList *args;
00054     };
00055 
00056     struct Value {
00057     int id;
00058     union {
00059         double fValue;
00060         int iValue;
00061         ParseString string;
00062         struct Function *function;
00063     };
00064     enum {
00065         Operator = 0x100000,
00066         Function = 0x100001,
00067         Q_EMS     = 0x100002
00068     };
00069 
00070     int unit;
00071     };
00072 
00073     static inline QString qString( const ParseString &ps ) {
00074     return QString( (QChar *)ps.string, ps.length );
00075     }
00076     static inline DOMString domString( const ParseString &ps ) {
00077     return DOMString( (QChar *)ps.string, ps.length );
00078     }
00079 
00080     class ValueList {
00081     public:
00082     ValueList();
00083     ~ValueList();
00084     void addValue( const Value &val );
00085     Value *current() { return currentValue < numValues ? values + currentValue : 0; }
00086     Value *next() { ++currentValue; return current(); }
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 );
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     bool parseShape( int propId, bool important );
00121     bool parseFont(bool important);
00122     CSSValueListImpl *parseFontFamily();
00123     CSSPrimitiveValueImpl *parseColor();
00124 
00125     int yyparse( void );
00126     public:
00127     bool strict;
00128     bool important;
00129     bool nonCSSHint;
00130     unsigned int id;
00131     DOM::StyleListImpl* styleElement;
00132     DOM::CSSRuleImpl *rule;
00133     ValueList *valueList;
00134     CSSProperty **parsedProperties;
00135     int numParsedProperties;
00136     int maxParsedProperties;
00137     bool inParseShortHand;
00138     unsigned int defaultNamespace;
00139 
00140     static CSSParser *currentParser;
00141 
00142     
00143     public:
00144     int lex( void *yylval );
00145     int token() { return yyTok; }
00146     unsigned short *text( int *length);
00147     int lex();
00148     private:
00149 
00150     unsigned short *data;
00151     unsigned short *yytext;
00152     unsigned short *yy_c_buf_p;
00153     unsigned short yy_hold_char;
00154     int yy_last_accepting_state;
00155     unsigned short *yy_last_accepting_cpos;
00156     int yyleng;
00157     int yyTok;
00158     int yy_start;
00159     };
00160 
00161 } 
00162 #endif
 
This file is part of the documentation for khtml Library Version 3.2.0.