Home | History | Annotate | Download | only in dom
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2001 Dirk Mueller (mueller (at) kde.org)
      5  *           (C) 2006 Alexey Proskuryakov (ap (at) webkit.org)
      6  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
      7  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
      8  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
      9  * Copyright (C) 2011 Google Inc. All rights reserved.
     10  *
     11  * This library is free software; you can redistribute it and/or
     12  * modify it under the terms of the GNU Library General Public
     13  * License as published by the Free Software Foundation; either
     14  * version 2 of the License, or (at your option) any later version.
     15  *
     16  * This library is distributed in the hope that it will be useful,
     17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     19  * Library General Public License for more details.
     20  *
     21  * You should have received a copy of the GNU Library General Public License
     22  * along with this library; see the file COPYING.LIB.  If not, write to
     23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     24  * Boston, MA 02110-1301, USA.
     25  *
     26  */
     27 
     28 #ifndef DocumentStyleSheetCollection_h
     29 #define DocumentStyleSheetCollection_h
     30 
     31 #include "core/dom/Document.h"
     32 #include "core/dom/DocumentOrderedList.h"
     33 #include "core/dom/StyleSheetCollection.h"
     34 #include "wtf/FastAllocBase.h"
     35 #include "wtf/ListHashSet.h"
     36 #include "wtf/RefPtr.h"
     37 #include "wtf/Vector.h"
     38 #include "wtf/text/WTFString.h"
     39 
     40 namespace WebCore {
     41 
     42 class CSSStyleSheet;
     43 class Node;
     44 class RuleFeatureSet;
     45 class StyleSheet;
     46 class StyleSheetContents;
     47 class StyleSheetList;
     48 
     49 class DocumentStyleSheetCollection {
     50     WTF_MAKE_FAST_ALLOCATED;
     51 public:
     52     static PassOwnPtr<DocumentStyleSheetCollection> create(Document* document) { return adoptPtr(new DocumentStyleSheetCollection(document)); }
     53 
     54     ~DocumentStyleSheetCollection();
     55 
     56     const Vector<RefPtr<StyleSheet> >& styleSheetsForStyleSheetList();
     57     const Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets() const;
     58 
     59     CSSStyleSheet* pageUserSheet();
     60     const Vector<RefPtr<CSSStyleSheet> >& documentUserStyleSheets() const { return m_userStyleSheets; }
     61     const Vector<RefPtr<CSSStyleSheet> >& documentAuthorStyleSheets() const { return m_authorStyleSheets; }
     62     const Vector<RefPtr<CSSStyleSheet> >& injectedUserStyleSheets() const;
     63     const Vector<RefPtr<CSSStyleSheet> >& injectedAuthorStyleSheets() const;
     64 
     65     void addStyleSheetCandidateNode(Node*, bool createdByParser);
     66     void removeStyleSheetCandidateNode(Node*, ContainerNode* scopingNode = 0);
     67 
     68     void clearPageUserSheet();
     69     void updatePageUserSheet();
     70     void invalidateInjectedStyleSheetCache();
     71     void updateInjectedStyleSheetCache() const;
     72 
     73     void addAuthorSheet(PassRefPtr<StyleSheetContents> authorSheet);
     74     void addUserSheet(PassRefPtr<StyleSheetContents> userSheet);
     75 
     76     bool needsUpdateActiveStylesheetsOnStyleRecalc() const { return m_needsUpdateActiveStylesheetsOnStyleRecalc; }
     77 
     78     bool updateActiveStyleSheets(StyleResolverUpdateMode);
     79 
     80     String preferredStylesheetSetName() const { return m_preferredStylesheetSetName; }
     81     String selectedStylesheetSetName() const { return m_selectedStylesheetSetName; }
     82     void setPreferredStylesheetSetName(const String& name) { m_preferredStylesheetSetName = name; }
     83     void setSelectedStylesheetSetName(const String& name) { m_selectedStylesheetSetName = name; }
     84 
     85     void addPendingSheet() { m_pendingStylesheets++; }
     86     enum RemovePendingSheetNotificationType {
     87         RemovePendingSheetNotifyImmediately,
     88         RemovePendingSheetNotifyLater
     89     };
     90     void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSheetNotifyImmediately);
     91 
     92     bool hasPendingSheets() const { return m_pendingStylesheets > 0; }
     93 
     94     bool usesSiblingRules() const { return m_usesSiblingRules || m_usesSiblingRulesOverride; }
     95     void setUsesSiblingRulesOverride(bool b) { m_usesSiblingRulesOverride = b; }
     96     bool usesFirstLineRules() const { return m_usesFirstLineRules; }
     97     bool usesFirstLetterRules() const { return m_usesFirstLetterRules; }
     98     void setUsesFirstLetterRules(bool b) { m_usesFirstLetterRules = b; }
     99     bool usesBeforeAfterRules() const { return m_usesBeforeAfterRules || m_usesBeforeAfterRulesOverride; }
    100     void setUsesBeforeAfterRulesOverride(bool b) { m_usesBeforeAfterRulesOverride = b; }
    101     bool usesRemUnits() const { return m_usesRemUnits; }
    102     void setUsesRemUnit(bool b) { m_usesRemUnits = b; }
    103     bool hasScopedStyleSheet() { return m_collectionForDocument.scopingNodesForStyleScoped(); }
    104 
    105     void combineCSSFeatureFlags(const RuleFeatureSet&);
    106     void resetCSSFeatureFlags(const RuleFeatureSet&);
    107 
    108 private:
    109     DocumentStyleSheetCollection(Document*);
    110 
    111     Document* m_document;
    112 
    113     // Track the number of currently loading top-level stylesheets needed for rendering.
    114     // Sheets loaded using the @import directive are not included in this count.
    115     // We use this count of pending sheets to detect when we can begin attaching
    116     // elements and when it is safe to execute scripts.
    117     int m_pendingStylesheets;
    118 
    119     RefPtr<CSSStyleSheet> m_pageUserSheet;
    120 
    121     mutable Vector<RefPtr<CSSStyleSheet> > m_injectedUserStyleSheets;
    122     mutable Vector<RefPtr<CSSStyleSheet> > m_injectedAuthorStyleSheets;
    123     mutable bool m_injectedStyleSheetCacheValid;
    124 
    125     Vector<RefPtr<CSSStyleSheet> > m_userStyleSheets;
    126     Vector<RefPtr<CSSStyleSheet> > m_authorStyleSheets;
    127 
    128     bool m_hadActiveLoadingStylesheet;
    129     bool m_needsUpdateActiveStylesheetsOnStyleRecalc;
    130 
    131     StyleSheetCollection m_collectionForDocument;
    132 
    133     String m_preferredStylesheetSetName;
    134     String m_selectedStylesheetSetName;
    135 
    136     bool m_usesSiblingRules;
    137     bool m_usesSiblingRulesOverride;
    138     bool m_usesFirstLineRules;
    139     bool m_usesFirstLetterRules;
    140     bool m_usesBeforeAfterRules;
    141     bool m_usesBeforeAfterRulesOverride;
    142     bool m_usesRemUnits;
    143 };
    144 
    145 }
    146 
    147 #endif
    148 
    149