# khtml Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# cssparser.h

    00001 /*
    00002  * This file is part of the CSS implementation for KDE.
    00003  *
    00004  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    00005  *               1999 Waldo Bastian (bastian@kde.org)
    00006  *
    00007  * This library is free software; you can redistribute it and/or
    00008  * modify it under the terms of the GNU Library General Public
    00009  * License as published by the Free Software Foundation; either
    00010  * version 2 of the License, or (at your option) any later version.
    00011  *
    00012  * This library is distributed in the hope that it will be useful,
    00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015  * Library General Public License for more details.
    00016  *
    00017  * You should have received a copy of the GNU Library General Public License
    00018  * along with this library; see the file COPYING.LIB.  If not, write to
    00019  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00020  * Boston, MA 02111-1307, USA.
    00021  *
    00022  * $Id: cssparser.h,v 1.60.2.1 2003/05/18 12:34:36 mueller Exp $
    00023  */
    00024 #ifndef _CSS_cssparser_h_
    00025 #define _CSS_cssparser_h_
    00026
    00027 #include "dom/dom_string.h"
    00028 #include "dom/dom_misc.h"
    00029 #include "misc/shared.h"
    00030 #include <qdatetime.h>
    00031 #include <qptrlist.h>
    00032
    00033 namespace DOM {
    00034
    00035     class StyleSheetImpl;
    00036     class MediaList;
    00037
    00038     class CSSSelector;
    00039     class CSSProperty;
    00040     class CSSValueImpl;
    00041     class CSSPrimitiveValueImpl;
    00042     class CSSStyleDeclarationImpl;
    00043     class CSSRuleImpl;
    00044     class CSSStyleRuleImpl;
    00045
    00046     class DocumentImpl;
    00047
    00048     int getPropertyID(const char *tagStr, int len);
    00049
    00050 // this class represents a selector for a StyleRule
    00051 class CSSSelector
    00052 {
    00053 public:
    00054     CSSSelector(void)
    00055         : tagHistory(0), attr(0), tag(0), relation( Descendant ),
    00056     match( None ), nonCSSHint( false ), pseudoId( 0 ) {}
    00057
    00058     ~CSSSelector(void) {
    00059         if (tagHistory)
    00060             delete tagHistory;
    00061     }
    00062
    00066     void print(void);
    00067
    00071     DOMString selectorText() const;
    00072
    00073     // checks if the 2 selectors (including sub selectors) agree.
    00074     bool operator == ( const CSSSelector &other );
    00075
    00076     // tag == -1 means apply to all elements (Selector = *)
    00077
    00078     unsigned int specificity();
    00079
    00080     /* how the attribute value has to match.... Default is Exact */
    00081     enum Match
    00082     {
    00083         None = 0,
    00084         Exact,
    00085         Set,
    00086         List,
    00087         Hyphen,
    00088         Pseudo,
    00089         Contain,   // css3: E[foo*="bar"]
    00090         Begin,     // css3: E[foo^="bar"]
    00091         End        // css3: E[foo$="bar"]
    00092     };
    00093
    00094     enum Relation
    00095     {
    00096         Descendant = 0,
    00097         Child,
    00098         Sibling,
    00099         SubSelector
    00100     };
    00101
    00102     DOM::DOMString value;
    00103     CSSSelector *tagHistory;
    00104     int          attr;
    00105     int          tag;
    00106
    00107     Relation relation     : 2;
    00108     Match        match         : 4;
    00109     bool        nonCSSHint : 1;
    00110     unsigned int pseudoId : 3;
    00111
    00112
    00113 };
    00114
    00115     // a style class which has a parent (almost all have)
    00116     class StyleBaseImpl : public khtml::TreeShared<StyleBaseImpl>
    00117     {
    00118     public:
    00119         StyleBaseImpl()  { m_parent = 0; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
    00120         StyleBaseImpl(StyleBaseImpl *p) { m_parent = p; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
    00121
    00122         virtual ~StyleBaseImpl() {}
    00123
    00124         // returns the url of the style sheet this object belongs to
    00125         DOMString baseURL();
    00126
    00127         virtual bool isStyleSheet() const { return false; }
    00128         virtual bool isCSSStyleSheet() const { return false; }
    00129         virtual bool isStyleSheetList() const { return false; }
    00130         virtual bool isMediaList() { return false; }
    00131         virtual bool isRuleList() { return false; }
    00132         virtual bool isRule() { return false; }
    00133         virtual bool isStyleRule() { return false; }
    00134         virtual bool isCharetRule() { return false; }
    00135         virtual bool isImportRule() { return false; }
    00136         virtual bool isMediaRule() { return false; }
    00137         virtual bool isFontFaceRule() { return false; }
    00138         virtual bool isPageRule() { return false; }
    00139         virtual bool isUnknownRule() { return false; }
    00140         virtual bool isStyleDeclaration() { return false; }
    00141         virtual bool isValue() { return false; }
    00142         virtual bool isPrimitiveValue() const { return false; }
    00143         virtual bool isValueList() { return false; }
    00144         virtual bool isValueCustom() { return false; }
    00145
    00146         void setParent(StyleBaseImpl *parent) { m_parent = parent; }
    00147
    00148         const QString preprocess(const QString &str, bool justOneRule = false);
    00149         const QChar *parseSpace(const QChar *curP, const QChar *endP);
    00150         const QChar *parseToChar(const QChar *curP, const QChar *endP,
    00151                                  QChar c, bool chkws, bool endAtBlock = false);
    00152
    00153         CSSSelector *parseSelector2(const QChar *curP, const QChar *endP, CSSSelector::Relation relation);
    00154         CSSSelector *parseSelector1(const QChar *curP, const QChar *endP);
    00155         QPtrList<CSSSelector> *parseSelector(const QChar *curP, const QChar *endP);
    00156
    00157         void parseProperty(const QChar *curP, const QChar *endP);
    00158         QPtrList<CSSProperty> *parseProperties(const QChar *curP, const QChar *endP);
    00159
    00160         /* parses generic CSSValues, return true, if it found a valid value */
    00161         bool parseValue(const QChar *curP, const QChar *endP, int propId);
    00162         bool parseValue(const QChar *curP, const QChar *endP, int propId,
    00163                         bool important, bool nonCSSHint, QPtrList<CSSProperty> *propList);
    00164         bool parseFont(const QChar *curP, const QChar *endP);
    00165         bool parse4Values(const QChar *curP, const QChar *endP, const int *properties);
    00166         bool parseShortHand(const QChar *curP, const QChar *endP, const int *properties, int num);
    00167         void setParsedValue(int propId, const CSSValueImpl *parsedValue);
    00168         void setParsedValue(int propId, const CSSValueImpl *parsedValue,
    00169                             bool important, bool nonCSSHint, QPtrList<CSSProperty> *propList);
    00170         QPtrList<QChar> splitShorthandProperties(const QChar *curP, const QChar *endP);
    00171         bool parseBackgroundPosition(const QChar *curP, const QChar *&nextP, const QChar *endP);
    00172
    00173         /* define CSS_AURAL in cssparser.cpp if you want to parse CSS2 Aural properties */
    00174         bool parse2Values(const QChar *curP, const QChar *endP, const int *properties);
    00175         bool parseAuralValue(const QChar *curP, const QChar *endP, int propId);
    00176
    00177         CSSValueImpl* parseContent(const QChar *curP, const QChar *endP);
    00178
    00179         // defines units allowed for a certain property, used in parseUnit
    00180         enum Units
    00181         {
    00182             UNKNOWN   = 0x0000,
    00183             INTEGER   = 0x0001,
    00184             NUMBER    = 0x0002,  // real numbers
    00185             PERCENT   = 0x0004,
    00186             LENGTH    = 0x0008,
    00187             ANGLE     = 0x0010,
    00188             TIME      = 0x0020,
    00189             FREQUENCY = 0x0040,
    00190             NONNEGATIVE = 0x0080,
    00191             RELATIVE  = 0x0100
    00192         };
    00193
    00194         /* called by parseValue, parses numbers+units */
    00195         CSSPrimitiveValueImpl *parseUnit(const QChar * curP, const QChar *endP, int allowedUnits);
    00196
    00197         CSSRuleImpl *parseAtRule(const QChar *&curP, const QChar *endP);
    00198
    00199         // the caller is responible for deleting the returned lists in the next to methods
    00200         CSSRuleImpl *parseStyleRule(const QChar *&curP, const QChar *endP);
    00201         CSSRuleImpl *parseRule(const QChar *&curP, const QChar *endP);
    00202
    00203         virtual bool parseString(const DOMString &/*cssString*/, bool = false) { return false; }
    00204
    00205         virtual void checkLoaded();
    00206
    00207         void setStrictParsing( bool b ) { strictParsing = b; }
    00208         bool useStrictParsing() const { return strictParsing; }
    00209
    00210     protected:
    00211         bool hasInlinedDecl : 1;
    00212         bool strictParsing : 1;
    00213         bool multiLength : 1;
    00214     private:
    00215         bool isHexadecimal( QChar &c );
    00216     };
    00217
    00218     // a style class which has a list of children (StyleSheets for example)
    00219     class StyleListImpl : public StyleBaseImpl
    00220     {
    00221     public:
    00222         StyleListImpl() : StyleBaseImpl() { m_lstChildren = 0; }
    00223         StyleListImpl(StyleBaseImpl *parent) : StyleBaseImpl(parent) { m_lstChildren = 0; }
    00224
    00225         virtual ~StyleListImpl();
    00226
    00227         unsigned long length() { return m_lstChildren->count(); }
    00228         StyleBaseImpl *item(unsigned long num) { return m_lstChildren->at(num); }
    00229
    00230         void append(StyleBaseImpl *item) { m_lstChildren->append(item); }
    00231
    00232     protected:
    00233         QPtrList<StyleBaseImpl> *m_lstChildren;
    00234     };
    00235
    00236 } // namespace
    00237 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:33:34 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001