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  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  */
00021 #ifndef _CSS_cssparser_h_
00022 #define _CSS_cssparser_h_
00023 
00024 #include <qstring.h>
00025 #include <dom/dom_string.h>
00026 
00027 namespace DOM {
00028     class StyleListImpl;
00029     class CSSStyleSheetImpl;
00030     class CSSRuleImpl;
00031     class CSSStyleRuleImpl;
00032     class DocumentImpl;
00033     class CSSValueImpl;
00034     class CSSValueListImpl;
00035     class CSSPrimitiveValueImpl;
00036     class CSSStyleDeclarationImpl;
00037     class CSSProperty;
00038     class CSSRuleListImpl;
00039 
00040 
00041     struct ParseString {
00042     unsigned short *string;
00043     int length;
00044     };
00045 
00046     struct Value;
00047     class ValueList;
00048 
00049     struct Function {
00050     ParseString name;
00051     ValueList *args;
00052     };
00053 
00054     struct Value {
00055     int id;
00056     union {
00057         double fValue;
00058         int iValue;
00059         ParseString string;
00060         struct Function *function;
00061     };
00062     enum {
00063         Operator = 0x100000,
00064         Function = 0x100001,
00065         Q_EMS     = 0x100002
00066     };
00067 
00068     int unit;
00069     };
00070 
00071     static inline QString qString( const ParseString &ps ) {
00072     return QString( (QChar *)ps.string, ps.length );
00073     }
00074     static inline DOMString domString( const ParseString &ps ) {
00075     return DOMString( (QChar *)ps.string, ps.length );
00076     }
00077 
00078     class ValueList {
00079     public:
00080     ValueList();
00081     ~ValueList();
00082     void addValue( const Value &val );
00083     Value *current() { return currentValue < numValues ? values + currentValue : 0; }
00084     Value *next() { ++currentValue; return current(); }
00085         bool isLast() const { return currentValue+1 >= numValues; }
00086     Value *values;
00087     int numValues;
00088     int maxValues;
00089     int currentValue;
00090     };
00091 
00092     class CSSParser
00093     {
00094     public:
00095     CSSParser( bool strictParsing = true );
00096     ~CSSParser();
00097 
00098     void parseSheet( DOM::CSSStyleSheetImpl *sheet, const DOM::DOMString &string );
00099     DOM::CSSRuleImpl *parseRule( DOM::CSSStyleSheetImpl *sheet, const DOM::DOMString &string );
00100     bool parseValue( DOM::CSSStyleDeclarationImpl *decls, int id, const DOM::DOMString &string,
00101              bool _important, bool _nonCSSHint );
00102     bool parseDeclaration( DOM::CSSStyleDeclarationImpl *decls, const DOM::DOMString &string,
00103                    bool _nonCSSHint );
00104 
00105     static CSSParser *current() { return currentParser; }
00106 
00107 
00108     DOM::DocumentImpl *document() const;
00109 
00110     void addProperty( int propId, CSSValueImpl *value, bool important );
00111     bool hasProperties() const { return numParsedProperties > 0; }
00112     CSSStyleDeclarationImpl *createStyleDeclaration( CSSStyleRuleImpl *rule );
00113     void clearProperties();
00114 
00115     bool parseValue( int propId, bool important, int expected=1 );
00116     bool parseShortHand( const int *properties, int numProperties, bool important );
00117     bool parse4Values( const int *properties, bool important );
00118     bool parseContent( int propId, bool important );
00119     bool parseShape( int propId, bool important );
00120     bool parseFont(bool important);
00121 
00122         // returns the found property
00123         // 0 if nothing found (or ok == false)
00124         // @param forward if true, it parses the next in the list
00125         CSSPrimitiveValueImpl *parseBackgroundPositionXY( int propId, bool forward, bool &ok );
00126     CSSValueListImpl *parseFontFamily();
00127     CSSPrimitiveValueImpl *parseColor();
00128 
00129     public:
00130     bool strict;
00131     bool important;
00132     bool nonCSSHint;
00133     unsigned int id;
00134     DOM::StyleListImpl* styleElement;
00135     DOM::CSSRuleImpl *rule;
00136     ValueList *valueList;
00137     CSSProperty **parsedProperties;
00138     int numParsedProperties;
00139     int maxParsedProperties;
00140     bool inParseShortHand;
00141     unsigned int defaultNamespace;
00142     static CSSParser *currentParser;
00143 
00144     // tokenizer methods and data
00145     public:
00146     int lex( void *yylval );
00147     int token() { return yyTok; }
00148     unsigned short *text( int *length);
00149     int lex();
00150     private:
00151     int yyparse();
00152         void runParser(int length);
00153 
00154     unsigned short *data;
00155     unsigned short *yytext;
00156     unsigned short *yy_c_buf_p;
00157     unsigned short yy_hold_char;
00158     int yy_last_accepting_state;
00159     unsigned short *yy_last_accepting_cpos;
00160         int block_nesting;
00161     int yyleng;
00162     int yyTok;
00163     int yy_start;
00164     };
00165 
00166 } // namespace
00167 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Jan 15 13:34:36 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003