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  *               2002 Apple Computer, Inc.
00007  *               2004 Allan Sandfeld Jensen (kde@carewolf.com)
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Library General Public License
00020  * along with this library; see the file COPYING.LIB.  If not, write to
00021  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022  * Boston, MA 02110-1301, USA.
00023  *
00024  */
00025 #ifndef _CSS_BASE_H
00026 #define _CSS_BASE_H
00027 
00028 #include "dom/dom_string.h"
00029 #include "dom/dom_misc.h"
00030 #include "xml/dom_nodeimpl.h"
00031 #include "misc/shared.h"
00032 #include <kdemacros.h>
00033 #include <qdatetime.h>
00034 #include <qptrlist.h>
00035 
00036 namespace DOM {
00037 
00038     class StyleSheetImpl;
00039     class MediaList;
00040 
00041     class CSSSelector;
00042     class CSSProperty;
00043     class CSSValueImpl;
00044     class CSSPrimitiveValueImpl;
00045     class CSSStyleDeclarationImpl;
00046     class CSSRuleImpl;
00047     class CSSStyleRuleImpl;
00048 
00049     class DocumentImpl;
00050 
00051     struct CSSNamespace {
00052         DOMString m_prefix;
00053         DOMString m_uri;
00054         CSSNamespace* m_parent;
00055 
00056         CSSNamespace(const DOMString& p, const DOMString& u, CSSNamespace* parent)
00057             :m_prefix(p), m_uri(u), m_parent(parent) {}
00058         ~CSSNamespace() { delete m_parent; }
00059 
00060         const DOMString& uri() { return m_uri; }
00061         const DOMString& prefix() { return m_prefix; }
00062 
00063         CSSNamespace* namespaceForPrefix(const DOMString& prefix) {
00064             if (prefix == m_prefix)
00065                 return this;
00066             if (m_parent)
00067                 return m_parent->namespaceForPrefix(prefix);
00068             return 0;
00069         }
00070     };
00071 
00072 // this class represents a selector for a StyleRule
00073     class CSSSelector
00074     {
00075     public:
00076     CSSSelector()
00077         : tagHistory(0), simpleSelector(0), attr(0), tag(anyQName), relation( Descendant ),
00078           match( None ), nonCSSHint( false ), pseudoId( 0 ), _pseudoType(PseudoNotParsed)
00079         {}
00080 
00081     ~CSSSelector() {
00082         delete tagHistory;
00083             delete simpleSelector;
00084     }
00085 
00089     void print();
00090 
00094     DOMString selectorText() const;
00095 
00096     // checks if the 2 selectors (including sub selectors) agree.
00097     bool operator == ( const CSSSelector &other ) const;
00098 
00099     // tag == -1 means apply to all elements (Selector = *)
00100 
00101     unsigned int specificity() const;
00102 
00103     /* how the attribute value has to match.... Default is Exact */
00104     enum Match
00105     {
00106         None = 0,
00107         Id,
00108         Exact,
00109         Set,
00110         List,
00111         Hyphen,
00112         PseudoClass,
00113         PseudoElement,
00114         Contain,   // css3: E[foo*="bar"]
00115         Begin,     // css3: E[foo^="bar"]
00116         End        // css3: E[foo$="bar"]
00117     };
00118 
00119     enum Relation
00120     {
00121         Descendant = 0,
00122         Child,
00123         DirectAdjacent,
00124             IndirectAdjacent,
00125             SubSelector
00126     };
00127 
00128     enum PseudoType
00129     {
00130         PseudoNotParsed = 0,
00131         PseudoOther,
00132         PseudoEmpty,
00133         PseudoFirstChild,
00134             PseudoLastChild,
00135             PseudoNthChild,
00136             PseudoNthLastChild,
00137             PseudoOnlyChild,
00138             PseudoFirstOfType,
00139             PseudoLastOfType,
00140             PseudoNthOfType,
00141             PseudoNthLastOfType,
00142             PseudoOnlyOfType,
00143             PseudoFirstLine,
00144         PseudoFirstLetter,
00145         PseudoLink,
00146         PseudoVisited,
00147         PseudoHover,
00148         PseudoFocus,
00149         PseudoActive,
00150             PseudoTarget,
00151         PseudoBefore,
00152         PseudoAfter,
00153             PseudoLang,
00154             PseudoNot,
00155             PseudoContains,
00156             PseudoRoot,
00157             PseudoSelection,
00158             PseudoEnabled,
00159             PseudoDisabled,
00160             PseudoChecked,
00161             PseudoIndeterminate
00162     };
00163 
00164     PseudoType pseudoType() const {
00165             if (_pseudoType == PseudoNotParsed)
00166                 extractPseudoType();
00167             return _pseudoType;
00168         }
00169 
00170         mutable DOM::DOMString value;
00171     CSSSelector *tagHistory;
00172         CSSSelector* simpleSelector; // Used by :not
00173         DOM::DOMString string_arg; // Used by :contains, :lang and :nth-*
00174         DOM::NodeImpl::Id attr;
00175         DOM::NodeImpl::Id tag;
00176 
00177     Relation relation     : 3;
00178     mutable Match    match         : 4;
00179     bool    nonCSSHint : 1;
00180     unsigned int pseudoId : 3;
00181     mutable PseudoType _pseudoType : 5;
00182 
00183     private:
00184     void extractPseudoType() const;
00185     };
00186 
00187     // a style class which has a parent (almost all have)
00188     class StyleBaseImpl : public khtml::TreeShared<StyleBaseImpl>
00189     {
00190     public:
00191     StyleBaseImpl()  { m_parent = 0; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
00192     StyleBaseImpl(StyleBaseImpl *p) {
00193         m_parent = p; hasInlinedDecl = false;
00194         strictParsing = (m_parent ? m_parent->useStrictParsing() : true);
00195         multiLength = false;
00196     }
00197 
00198     virtual ~StyleBaseImpl() {}
00199 
00200     // returns the url of the style sheet this object belongs to
00201         // not const
00202     KURL baseURL();
00203 
00204     virtual bool isStyleSheet() const { return false; }
00205     virtual bool isCSSStyleSheet() const { return false; }
00206     virtual bool isStyleSheetList() const { return false; }
00207     virtual bool isMediaList() const { return false; }
00208     virtual bool isRuleList() const { return false; }
00209     virtual bool isRule() const { return false; }
00210     virtual bool isStyleRule() const { return false; }
00211     virtual bool isCharetRule() const { return false; }
00212     virtual bool isImportRule() const { return false; }
00213     virtual bool isMediaRule() const { return false; }
00214     virtual bool isFontFaceRule() const { return false; }
00215     virtual bool isPageRule() const { return false; }
00216     virtual bool isUnknownRule() const { return false; }
00217     virtual bool isStyleDeclaration() const { return false; }
00218     virtual bool isValue() const { return false; }
00219     virtual bool isPrimitiveValue() const { return false; }
00220     virtual bool isValueList() const { return false; }
00221     virtual bool isValueCustom() const { return false; }
00222 
00223     void setParent(StyleBaseImpl *parent) { m_parent = parent; }
00224 
00225     static void setParsedValue(int propId, const CSSValueImpl *parsedValue,
00226                    bool important, bool nonCSSHint, QPtrList<CSSProperty> *propList);
00227 
00228     virtual bool parseString(const DOMString &/*cssString*/, bool = false) { return false; }
00229 
00230     virtual void checkLoaded() const;
00231 
00232     void setStrictParsing( bool b ) { strictParsing = b; }
00233     bool useStrictParsing() const { return strictParsing; }
00234 
00235         // not const
00236     StyleSheetImpl* stylesheet();
00237 
00238     protected:
00239     bool hasInlinedDecl : 1;
00240     bool strictParsing : 1;
00241     bool multiLength : 1;
00242     };
00243 
00244     // a style class which has a list of children (StyleSheets for example)
00245     class StyleListImpl : public StyleBaseImpl
00246     {
00247     public:
00248     StyleListImpl() : StyleBaseImpl() { m_lstChildren = 0; }
00249     StyleListImpl(StyleBaseImpl *parent) : StyleBaseImpl(parent) { m_lstChildren = 0; }
00250     virtual ~StyleListImpl();
00251 
00252     unsigned long length() const { return m_lstChildren->count(); }
00253     StyleBaseImpl *item(unsigned long num) const { return m_lstChildren->at(num); }
00254 
00255     void append(StyleBaseImpl *item) { m_lstChildren->append(item); }
00256 
00257     protected:
00258     QPtrList<StyleBaseImpl> *m_lstChildren;
00259     };
00260 
00261     KDE_NO_EXPORT int getPropertyID(const char *tagStr, int len);
00262 
00263 }
00264 
00265 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys