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 <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 bool parseShape( int propId, bool important ); 00121 bool parseFont(bool important); 00122 bool parseCounter(int propId, bool increment, bool important); 00123 00124 // returns the found property 00125 // 0 if nothing found (or ok == false) 00126 // @param forward if true, it parses the next in the list 00127 CSSPrimitiveValueImpl *parseBackgroundPositionXY( int propId, bool forward, bool &ok ); 00128 CSSValueListImpl *parseFontFamily(); 00129 CSSPrimitiveValueImpl *parseColor(); 00130 CSSPrimitiveValueImpl *parseColorFromValue(Value* val); 00131 CSSValueImpl* parseCounterContent(ValueList *args, bool counters); 00132 00133 static bool parseColor(const QString &name, QRgb& rgb); 00134 00135 // CSS3 Parsing Routines (for properties specific to CSS3) 00136 bool parseShadow(int propId, bool important); 00137 00138 public: 00139 bool strict; 00140 bool important; 00141 bool nonCSSHint; 00142 unsigned int id; 00143 DOM::StyleListImpl* styleElement; 00144 DOM::CSSRuleImpl *rule; 00145 ValueList *valueList; 00146 CSSProperty **parsedProperties; 00147 int numParsedProperties; 00148 int maxParsedProperties; 00149 bool inParseShortHand; 00150 unsigned int defaultNamespace; 00151 static CSSParser *currentParser; 00152 00153 // tokenizer methods and data 00154 public: 00155 int lex( void *yylval ); 00156 int token() { return yyTok; } 00157 unsigned short *text( int *length); 00158 int lex(); 00159 private: 00160 int yyparse(); 00161 void runParser(int length); 00162 00163 unsigned short *data; 00164 unsigned short *yytext; 00165 unsigned short *yy_c_buf_p; 00166 unsigned short yy_hold_char; 00167 int yy_last_accepting_state; 00168 unsigned short *yy_last_accepting_cpos; 00169 int block_nesting; 00170 int yyleng; 00171 int yyTok; 00172 int yy_start; 00173 }; 00174 00175 } // namespace 00176 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 14 00:38:26 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003