khtml Library API Documentation

cssparser.h

00001 /*
00002  * This file is part of the DOM implementation for KDE.
00003  *
00004  * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
00005  *
00006  * $Id: cssparser.h,v 1.74.2.2 2004/02/29 15:27:45 mueller Exp $
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Library General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Library General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Library General Public License
00019  * along with this library; see the file COPYING.LIB.  If not, write to
00020  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021  * Boston, MA 02111-1307, USA.
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     public:
00126     bool strict;
00127     bool important;
00128     bool nonCSSHint;
00129     unsigned int id;
00130     DOM::StyleListImpl* styleElement;
00131     DOM::CSSRuleImpl *rule;
00132     ValueList *valueList;
00133     CSSProperty **parsedProperties;
00134     int numParsedProperties;
00135     int maxParsedProperties;
00136     bool inParseShortHand;
00137     unsigned int defaultNamespace;
00138     static CSSParser *currentParser;
00139 
00140     // tokenizer methods and data
00141     public:
00142     int lex( void *yylval );
00143     int token() { return yyTok; }
00144     unsigned short *text( int *length);
00145     int lex();
00146     private:
00147     int yyparse();
00148         void runParser(int length);
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 block_nesting;
00157     int yyleng;
00158     int yyTok;
00159     int yy_start;
00160     };
00161 
00162 } // namespace
00163 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Aug 4 05:28:52 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2003