Home | History | Annotate | Download | only in css
      1 /*
      2  * (C) 1999-2003 Lars Knoll (knoll (at) kde.org)
      3  * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Library General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2 of the License, or (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Library General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU Library General Public License
     16  * along with this library; see the file COPYING.LIB.  If not, write to
     17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18  * Boston, MA 02110-1301, USA.
     19  */
     20 
     21 #ifndef CSSStyleSheet_h
     22 #define CSSStyleSheet_h
     23 
     24 #include "CSSRuleList.h"
     25 #include "StyleSheet.h"
     26 
     27 namespace WebCore {
     28 
     29 struct CSSNamespace;
     30 class CSSParser;
     31 class CSSRule;
     32 class CachedResourceLoader;
     33 class Document;
     34 
     35 typedef int ExceptionCode;
     36 
     37 class CSSStyleSheet : public StyleSheet {
     38 public:
     39     static PassRefPtr<CSSStyleSheet> create()
     40     {
     41         return adoptRef(new CSSStyleSheet(static_cast<CSSStyleSheet*>(0), String(), KURL(), String()));
     42     }
     43     static PassRefPtr<CSSStyleSheet> create(Node* ownerNode)
     44     {
     45         return adoptRef(new CSSStyleSheet(ownerNode, String(), KURL(), String()));
     46     }
     47     static PassRefPtr<CSSStyleSheet> create(Node* ownerNode, const String& originalURL, const KURL& finalURL)
     48     {
     49         return adoptRef(new CSSStyleSheet(ownerNode, originalURL, finalURL, String()));
     50     }
     51     static PassRefPtr<CSSStyleSheet> create(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset)
     52     {
     53         return adoptRef(new CSSStyleSheet(ownerNode, originalURL, finalURL, charset));
     54     }
     55     static PassRefPtr<CSSStyleSheet> create(CSSRule* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset)
     56     {
     57         return adoptRef(new CSSStyleSheet(ownerRule, originalURL, finalURL, charset));
     58     }
     59     static PassRefPtr<CSSStyleSheet> createInline(Node* ownerNode, const KURL& finalURL)
     60     {
     61         return adoptRef(new CSSStyleSheet(ownerNode, finalURL.string(), finalURL, String()));
     62     }
     63 
     64     virtual ~CSSStyleSheet();
     65 
     66     CSSRule* ownerRule() const;
     67     PassRefPtr<CSSRuleList> cssRules(bool omitCharsetRules = false);
     68     unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
     69     void deleteRule(unsigned index, ExceptionCode&);
     70 
     71     // IE Extensions
     72     PassRefPtr<CSSRuleList> rules() { return cssRules(true); }
     73     int addRule(const String& selector, const String& style, int index, ExceptionCode&);
     74     int addRule(const String& selector, const String& style, ExceptionCode&);
     75     void removeRule(unsigned index, ExceptionCode& ec) { deleteRule(index, ec); }
     76 
     77     void addNamespace(CSSParser*, const AtomicString& prefix, const AtomicString& uri);
     78     const AtomicString& determineNamespace(const AtomicString& prefix);
     79 
     80     virtual void styleSheetChanged();
     81 
     82     virtual bool parseString(const String&, bool strict = true);
     83 
     84     bool parseStringAtLine(const String&, bool strict, int startLineNumber);
     85 
     86     virtual bool isLoading();
     87 
     88     virtual void checkLoaded();
     89 
     90     Document* document();
     91 
     92     const String& charset() const { return m_charset; }
     93 
     94     bool loadCompleted() const { return m_loadCompleted; }
     95 
     96     virtual KURL completeURL(const String& url) const;
     97     virtual void addSubresourceStyleURLs(ListHashSet<KURL>&);
     98 
     99     void setStrictParsing(bool b) { m_strictParsing = b; }
    100     bool useStrictParsing() const { return m_strictParsing; }
    101 
    102     void setIsUserStyleSheet(bool b) { m_isUserStyleSheet = b; }
    103     bool isUserStyleSheet() const { return m_isUserStyleSheet; }
    104     void setHasSyntacticallyValidCSSHeader(bool b) { m_hasSyntacticallyValidCSSHeader = b; }
    105     bool hasSyntacticallyValidCSSHeader() const { return m_hasSyntacticallyValidCSSHeader; }
    106 
    107 private:
    108     CSSStyleSheet(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset);
    109     CSSStyleSheet(CSSStyleSheet* parentSheet, const String& originalURL, const KURL& finalURL, const String& charset);
    110     CSSStyleSheet(CSSRule* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset);
    111 
    112     virtual bool isCSSStyleSheet() const { return true; }
    113     virtual String type() const { return "text/css"; }
    114 
    115     OwnPtr<CSSNamespace> m_namespaces;
    116     String m_charset;
    117     bool m_loadCompleted : 1;
    118     bool m_strictParsing : 1;
    119     bool m_isUserStyleSheet : 1;
    120     bool m_hasSyntacticallyValidCSSHeader : 1;
    121 };
    122 
    123 } // namespace
    124 
    125 #endif
    126