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 StyleSheetCollection_h
     29 #define StyleSheetCollection_h
     30 
     31 #include "core/dom/Document.h"
     32 #include "core/dom/DocumentOrderedList.h"
     33 #include "core/dom/StyleSheetScopingNodeList.h"
     34 #include "core/dom/TreeScope.h"
     35 #include "wtf/FastAllocBase.h"
     36 #include "wtf/HashMap.h"
     37 #include "wtf/ListHashSet.h"
     38 #include "wtf/RefPtr.h"
     39 #include "wtf/Vector.h"
     40 #include "wtf/text/WTFString.h"
     41 
     42 namespace WebCore {
     43 
     44 class ContainerNode;
     45 class CSSStyleSheet;
     46 class StyleEngine;
     47 class Node;
     48 class StyleSheet;
     49 class StyleSheetContents;
     50 class StyleSheetList;
     51 
     52 // FIXME: Should be in separate file and be renamed like:
     53 // - StyleSheetCollectionBase -> StyleSheetCollection
     54 // - StyleSheetCollection -> ScopeStyleSheetCollection
     55 //
     56 class StyleSheetCollectionBase {
     57     WTF_MAKE_NONCOPYABLE(StyleSheetCollectionBase); WTF_MAKE_FAST_ALLOCATED;
     58 public:
     59     StyleSheetCollectionBase();
     60     ~StyleSheetCollectionBase();
     61 
     62     Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets() { return m_activeAuthorStyleSheets; }
     63     Vector<RefPtr<StyleSheet> >& styleSheetsForStyleSheetList() { return m_styleSheetsForStyleSheetList; }
     64     const Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets() const { return m_activeAuthorStyleSheets; }
     65     const Vector<RefPtr<StyleSheet> >& styleSheetsForStyleSheetList() const { return m_styleSheetsForStyleSheetList; }
     66 
     67     void swap(StyleSheetCollectionBase&);
     68     void appendActiveStyleSheets(const Vector<RefPtr<CSSStyleSheet> >&);
     69     void appendActiveStyleSheet(CSSStyleSheet*);
     70     void appendSheetForList(StyleSheet*);
     71 
     72 protected:
     73     Vector<RefPtr<StyleSheet> > m_styleSheetsForStyleSheetList;
     74     Vector<RefPtr<CSSStyleSheet> > m_activeAuthorStyleSheets;
     75 };
     76 
     77 
     78 class StyleSheetCollection : public StyleSheetCollectionBase {
     79 public:
     80     void addStyleSheetCandidateNode(Node*, bool createdByParser);
     81     void removeStyleSheetCandidateNode(Node*, ContainerNode* scopingNode);
     82     bool hasStyleSheetCandidateNodes() const { return !m_styleSheetCandidateNodes.isEmpty(); }
     83 
     84 
     85     bool usesRemUnits() const { return m_usesRemUnits; }
     86 
     87     DocumentOrderedList& styleSheetCandidateNodes() { return m_styleSheetCandidateNodes; }
     88     DocumentOrderedList* scopingNodesForStyleScoped() { return m_scopingNodesForStyleScoped.scopingNodes(); }
     89     ListHashSet<Node*, 4>* scopingNodesRemoved() { return m_scopingNodesForStyleScoped.scopingNodesRemoved(); }
     90 
     91     void clearMediaQueryRuleSetStyleSheets();
     92 
     93 protected:
     94     explicit StyleSheetCollection(TreeScope&);
     95 
     96     Document* document() { return m_treeScope.documentScope(); }
     97 
     98     enum StyleResolverUpdateType {
     99         Reconstruct,
    100         Reset,
    101         Additive,
    102         ResetStyleResolverAndFontSelector
    103     };
    104 
    105     struct StyleSheetChange {
    106         StyleResolverUpdateType styleResolverUpdateType;
    107         bool requiresFullStyleRecalc;
    108 
    109         StyleSheetChange()
    110             : styleResolverUpdateType(Reconstruct)
    111             , requiresFullStyleRecalc(true) { }
    112     };
    113 
    114     void analyzeStyleSheetChange(StyleResolverUpdateMode, const StyleSheetCollectionBase&, StyleSheetChange&);
    115     void resetAllRuleSetsInTreeScope(StyleResolver*);
    116     void updateUsesRemUnits();
    117 
    118 private:
    119     static StyleResolverUpdateType compareStyleSheets(const Vector<RefPtr<CSSStyleSheet> >& oldStyleSheets, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, Vector<StyleSheetContents*>& addedSheets);
    120     bool activeLoadingStyleSheetLoaded(const Vector<RefPtr<CSSStyleSheet> >& newStyleSheets);
    121 
    122 protected:
    123     TreeScope& m_treeScope;
    124     bool m_hadActiveLoadingStylesheet;
    125     bool m_usesRemUnits;
    126 
    127     DocumentOrderedList m_styleSheetCandidateNodes;
    128     StyleSheetScopingNodeList m_scopingNodesForStyleScoped;
    129 };
    130 
    131 }
    132 
    133 #endif
    134 
    135