khtml Library API Documentation

css_base.h

00001 /*
00002  * This file is part of the CSS implementation for KDE.
00003  *
00004  * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
00005  *               1999 Waldo Bastian (bastian@kde.org)
00006  * Copyright (C) 2002 Apple Computer, Inc.
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  */
00024 #ifndef _CSS_BASE_H
00025 #define _CSS_BASE_H
00026 
00027 #include "dom/dom_string.h"
00028 #include "dom/dom_misc.h"
00029 #include "xml/dom_nodeimpl.h"
00030 #include "misc/shared.h"
00031 #include <kdemacros.h>
00032 #include <qdatetime.h>
00033 #include <qptrlist.h>
00034 
00035 namespace DOM {
00036 
00037     class StyleSheetImpl;
00038     class MediaList;
00039 
00040     class CSSSelector;
00041     class CSSProperty;
00042     class CSSValueImpl;
00043     class CSSPrimitiveValueImpl;
00044     class CSSStyleDeclarationImpl;
00045     class CSSRuleImpl;
00046     class CSSStyleRuleImpl;
00047 
00048     class DocumentImpl;
00049 
00050 // this class represents a selector for a StyleRule
00051     class CSSSelector
00052     {
00053     public:
00054     CSSSelector()
00055         : tagHistory(0), simpleSelector(0), attr(0), tag(0xffff), relation( Descendant ),
00056           match( None ), nonCSSHint( false ), pseudoId( 0 ), _pseudoType(PseudoNotParsed)
00057         {}
00058 
00059     ~CSSSelector() {
00060         delete tagHistory;
00061             delete simpleSelector;
00062     }
00063 
00067     void print();
00068 
00072     DOMString selectorText() const;
00073 
00074     // checks if the 2 selectors (including sub selectors) agree.
00075     bool operator == ( const CSSSelector &other ) const;
00076 
00077     // tag == -1 means apply to all elements (Selector = *)
00078 
00079     unsigned int specificity() const;
00080 
00081     /* how the attribute value has to match.... Default is Exact */
00082     enum Match
00083     {
00084         None = 0,
00085         Id,
00086         Exact,
00087         Set,
00088         List,
00089         Hyphen,
00090         Pseudo,
00091         Contain,   // css3: E[foo*="bar"]
00092         Begin,     // css3: E[foo^="bar"]
00093         End        // css3: E[foo$="bar"]
00094     };
00095 
00096     enum Relation
00097     {
00098         Descendant = 0,
00099         Child,
00100         Sibling,
00101             Cousin,
00102             SubSelector
00103     };
00104 
00105     enum PseudoType
00106     {
00107         PseudoNotParsed = 0,
00108         PseudoOther,
00109         PseudoEmpty,
00110         PseudoFirstChild,
00111             PseudoLastChild,
00112             PseudoOnlyChild,
00113         PseudoFirstLine,
00114         PseudoFirstLetter,
00115         PseudoLink,
00116         PseudoVisited,
00117         PseudoHover,
00118         PseudoFocus,
00119         PseudoActive,
00120             PseudoTarget,
00121         PseudoBefore,
00122         PseudoAfter,
00123             PseudoLang,
00124             PseudoNot,
00125             PseudoRoot,
00126             PseudoSelection
00127     };
00128 
00129     PseudoType pseudoType() const {
00130             if (_pseudoType == PseudoNotParsed)
00131                 extractPseudoType();
00132             return _pseudoType;
00133         }
00134 
00135     mutable DOM::DOMString value;
00136     CSSSelector *tagHistory;
00137         CSSSelector* simpleSelector; // Used for :not.
00138         DOM::NodeImpl::Id attr;
00139         DOM::NodeImpl::Id tag;
00140 
00141     Relation relation     : 3;
00142     Match    match         : 4;
00143     bool    nonCSSHint : 1;
00144     unsigned int pseudoId : 3;
00145     mutable PseudoType _pseudoType : 5;
00146 
00147     private:
00148     void extractPseudoType() const;
00149     };
00150 
00151     // a style class which has a parent (almost all have)
00152     class StyleBaseImpl : public khtml::TreeShared<StyleBaseImpl>
00153     {
00154     public:
00155     StyleBaseImpl()  { m_parent = 0; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
00156     StyleBaseImpl(StyleBaseImpl *p) {
00157         m_parent = p; hasInlinedDecl = false;
00158         strictParsing = (m_parent ? m_parent->useStrictParsing() : true);
00159         multiLength = false;
00160     }
00161 
00162     virtual ~StyleBaseImpl() {}
00163 
00164     // returns the url of the style sheet this object belongs to
00165         // not const
00166     KURL baseURL();
00167 
00168     virtual bool isStyleSheet() const { return false; }
00169     virtual bool isCSSStyleSheet() const { return false; }
00170     virtual bool isStyleSheetList() const { return false; }
00171     virtual bool isMediaList() const { return false; }
00172     virtual bool isRuleList() const { return false; }
00173     virtual bool isRule() const { return false; }
00174     virtual bool isStyleRule() const { return false; }
00175     virtual bool isCharetRule() const { return false; }
00176     virtual bool isImportRule() const { return false; }
00177     virtual bool isMediaRule() const { return false; }
00178     virtual bool isFontFaceRule() const { return false; }
00179     virtual bool isPageRule() const { return false; }
00180     virtual bool isUnknownRule() const { return false; }
00181     virtual bool isStyleDeclaration() const { return false; }
00182     virtual bool isValue() const { return false; }
00183     virtual bool isPrimitiveValue() const { return false; }
00184     virtual bool isValueList() const { return false; }
00185     virtual bool isValueCustom() const { return false; }
00186 
00187     void setParent(StyleBaseImpl *parent) { m_parent = parent; }
00188 
00189     static void setParsedValue(int propId, const CSSValueImpl *parsedValue,
00190                    bool important, bool nonCSSHint, QPtrList<CSSProperty> *propList);
00191 
00192     virtual bool parseString(const DOMString &/*cssString*/, bool = false) { return false; }
00193 
00194     virtual void checkLoaded() const;
00195 
00196     void setStrictParsing( bool b ) { strictParsing = b; }
00197     bool useStrictParsing() const { return strictParsing; }
00198 
00199         // not const
00200     StyleSheetImpl* stylesheet();
00201 
00202     protected:
00203     bool hasInlinedDecl : 1;
00204     bool strictParsing : 1;
00205     bool multiLength : 1;
00206     };
00207 
00208     // a style class which has a list of children (StyleSheets for example)
00209     class StyleListImpl : public StyleBaseImpl
00210     {
00211     public:
00212     StyleListImpl() : StyleBaseImpl() { m_lstChildren = 0; }
00213     StyleListImpl(StyleBaseImpl *parent) : StyleBaseImpl(parent) { m_lstChildren = 0; }
00214     virtual ~StyleListImpl();
00215 
00216     unsigned long length() const { return m_lstChildren->count(); }
00217     StyleBaseImpl *item(unsigned long num) const { return m_lstChildren->at(num); }
00218 
00219     void append(StyleBaseImpl *item) { m_lstChildren->append(item); }
00220 
00221     protected:
00222     QPtrList<StyleBaseImpl> *m_lstChildren;
00223     };
00224 
00225     KDE_NO_EXPORT int getPropertyID(const char *tagStr, int len);
00226 
00227 }
00228 
00229 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 30 10:22:16 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003