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         Class,
00111         List,
00112         Hyphen,
00113         PseudoClass,
00114         PseudoElement,
00115         Contain,   // css3: E[foo*="bar"]
00116         Begin,     // css3: E[foo^="bar"]
00117         End        // css3: E[foo$="bar"]
00118     };
00119 
00120     enum Relation
00121     {
00122         Descendant = 0,
00123         Child,
00124         DirectAdjacent,
00125             IndirectAdjacent,
00126             SubSelector
00127     };
00128 
00129     enum PseudoType
00130     {
00131         PseudoNotParsed = 0,
00132         PseudoOther,
00133         PseudoEmpty,
00134         PseudoFirstChild,
00135             PseudoLastChild,
00136             PseudoNthChild,
00137             PseudoNthLastChild,
00138             PseudoOnlyChild,
00139             PseudoFirstOfType,
00140             PseudoLastOfType,
00141             PseudoNthOfType,
00142             PseudoNthLastOfType,
00143             PseudoOnlyOfType,
00144             PseudoFirstLine,
00145         PseudoFirstLetter,
00146         PseudoLink,
00147         PseudoVisited,
00148         PseudoHover,
00149         PseudoFocus,
00150         PseudoActive,
00151             PseudoTarget,
00152         PseudoBefore,
00153         PseudoAfter,
00154             PseudoLang,
00155             PseudoNot,
00156             PseudoContains,
00157             PseudoRoot,
00158             PseudoSelection,
00159             PseudoEnabled,
00160             PseudoDisabled,
00161             PseudoChecked,
00162             PseudoIndeterminate
00163     };
00164 
00165     PseudoType pseudoType() const {
00166             if (_pseudoType == PseudoNotParsed)
00167                 extractPseudoType();
00168             return _pseudoType;
00169         }
00170 
00171         mutable DOM::DOMString value;
00172     CSSSelector *tagHistory;
00173         CSSSelector* simpleSelector; // Used by :not
00174         DOM::DOMString string_arg; // Used by :contains, :lang and :nth-*
00175         DOM::NodeImpl::Id attr;
00176         DOM::NodeImpl::Id tag;
00177 
00178     Relation relation     : 3;
00179     mutable Match    match         : 4;
00180     bool    nonCSSHint : 1;
00181     unsigned int pseudoId : 3;
00182     mutable PseudoType _pseudoType : 5;
00183 
00184     private:
00185     void extractPseudoType() const;
00186     };
00187 
00188     // a style class which has a parent (almost all have)
00189     class StyleBaseImpl : public khtml::TreeShared<StyleBaseImpl>
00190     {
00191     public:
00192     StyleBaseImpl()  { m_parent = 0; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
00193     StyleBaseImpl(StyleBaseImpl *p) {
00194         m_parent = p; hasInlinedDecl = false;
00195         strictParsing = (m_parent ? m_parent->useStrictParsing() : true);
00196         multiLength = false;
00197     }
00198 
00199     virtual ~StyleBaseImpl() {}
00200 
00201     // returns the url of the style sheet this object belongs to
00202         // not const
00203     KURL baseURL();
00204 
00205     virtual bool isStyleSheet() const { return false; }
00206     virtual bool isCSSStyleSheet() const { return false; }
00207     virtual bool isStyleSheetList() const { return false; }
00208     virtual bool isMediaList() const { return false; }
00209     virtual bool isRuleList() const { return false; }
00210     virtual bool isRule() const { return false; }
00211     virtual bool isStyleRule() const { return false; }
00212     virtual bool isCharetRule() const { return false; }
00213     virtual bool isImportRule() const { return false; }
00214     virtual bool isMediaRule() const { return false; }
00215     virtual bool isFontFaceRule() const { return false; }
00216     virtual bool isPageRule() const { return false; }
00217     virtual bool isUnknownRule() const { return false; }
00218     virtual bool isStyleDeclaration() const { return false; }
00219     virtual bool isValue() const { return false; }
00220     virtual bool isPrimitiveValue() const { return false; }
00221     virtual bool isValueList() const { return false; }
00222     virtual bool isValueCustom() const { return false; }
00223 
00224     void setParent(StyleBaseImpl *parent) { m_parent = parent; }
00225 
00226     static void setParsedValue(int propId, const CSSValueImpl *parsedValue,
00227                    bool important, bool nonCSSHint, QPtrList<CSSProperty> *propList);
00228 
00229     virtual bool parseString(const DOMString &/*cssString*/, bool = false) { return false; }
00230 
00231     virtual void checkLoaded() const;
00232 
00233     void setStrictParsing( bool b ) { strictParsing = b; }
00234     bool useStrictParsing() const { return strictParsing; }
00235 
00236         // not const
00237     StyleSheetImpl* stylesheet();
00238 
00239     protected:
00240     bool hasInlinedDecl : 1;
00241     bool strictParsing : 1;
00242     bool multiLength : 1;
00243     };
00244 
00245     // a style class which has a list of children (StyleSheets for example)
00246     class StyleListImpl : public StyleBaseImpl
00247     {
00248     public:
00249     StyleListImpl() : StyleBaseImpl() { m_lstChildren = 0; }
00250     StyleListImpl(StyleBaseImpl *parent) : StyleBaseImpl(parent) { m_lstChildren = 0; }
00251     virtual ~StyleListImpl();
00252 
00253     unsigned long length() const { return m_lstChildren->count(); }
00254     StyleBaseImpl *item(unsigned long num) const { return m_lstChildren->at(num); }
00255 
00256     void append(StyleBaseImpl *item) { m_lstChildren->append(item); }
00257 
00258     protected:
00259     QPtrList<StyleBaseImpl> *m_lstChildren;
00260     };
00261 
00262     KDE_NO_EXPORT int getPropertyID(const char *tagStr, int len);
00263 
00264 }
00265 
00266 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys