1e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch/*
2e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch *           (C) 2001 Dirk Mueller (mueller@kde.org)
5e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch *           (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
7e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
9e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * Copyright (C) 2011 Google Inc. All rights reserved.
10e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch *
11e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * This library is free software; you can redistribute it and/or
12e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * modify it under the terms of the GNU Library General Public
13e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * License as published by the Free Software Foundation; either
14e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * version 2 of the License, or (at your option) any later version.
15e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch *
16e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * This library is distributed in the hope that it will be useful,
17e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * but WITHOUT ANY WARRANTY; without even the implied warranty of
18e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * Library General Public License for more details.
20e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch *
21e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * You should have received a copy of the GNU Library General Public License
22e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * along with this library; see the file COPYING.LIB.  If not, write to
23e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch * Boston, MA 02110-1301, USA.
25e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch *
26e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch */
27e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
28e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#ifndef StyleSheetCollection_h
29e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#define StyleSheetCollection_h
30e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
31e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/dom/Document.h"
32e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/dom/DocumentOrderedList.h"
3302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "core/dom/StyleSheetScopingNodeList.h"
34e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/dom/TreeScope.h"
35e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/FastAllocBase.h"
3602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "wtf/HashMap.h"
37e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/ListHashSet.h"
38e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/RefPtr.h"
39e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/Vector.h"
40e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/text/WTFString.h"
41e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
42e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochnamespace WebCore {
43e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
4402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdochclass ContainerNode;
45e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochclass CSSStyleSheet;
469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)class StyleEngine;
47e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochclass Node;
48e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochclass StyleSheet;
49e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochclass StyleSheetContents;
50e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochclass StyleSheetList;
51e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
5251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)// FIXME: Should be in separate file and be renamed like:
5351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)// - StyleSheetCollectionBase -> StyleSheetCollection
5451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)// - StyleSheetCollection -> ScopeStyleSheetCollection
5551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)//
5651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class StyleSheetCollectionBase {
5751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    WTF_MAKE_NONCOPYABLE(StyleSheetCollectionBase); WTF_MAKE_FAST_ALLOCATED;
58e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochpublic:
5951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    StyleSheetCollectionBase();
6051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    ~StyleSheetCollectionBase();
61e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
62e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets() { return m_activeAuthorStyleSheets; }
63e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    Vector<RefPtr<StyleSheet> >& styleSheetsForStyleSheetList() { return m_styleSheetsForStyleSheetList; }
64e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    const Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets() const { return m_activeAuthorStyleSheets; }
65e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    const Vector<RefPtr<StyleSheet> >& styleSheetsForStyleSheetList() const { return m_styleSheetsForStyleSheetList; }
66e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
6751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void swap(StyleSheetCollectionBase&);
6851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void appendActiveStyleSheets(const Vector<RefPtr<CSSStyleSheet> >&);
6951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void appendActiveStyleSheet(CSSStyleSheet*);
7051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void appendSheetForList(StyleSheet*);
7151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
7251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)protected:
7351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    Vector<RefPtr<StyleSheet> > m_styleSheetsForStyleSheetList;
7451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    Vector<RefPtr<CSSStyleSheet> > m_activeAuthorStyleSheets;
7551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)};
7651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
7751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
7851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class StyleSheetCollection : public StyleSheetCollectionBase {
7951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)public:
8051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void addStyleSheetCandidateNode(Node*, bool createdByParser);
8151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void removeStyleSheetCandidateNode(Node*, ContainerNode* scopingNode);
8251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    bool hasStyleSheetCandidateNodes() const { return !m_styleSheetCandidateNodes.isEmpty(); }
8351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
8451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
85e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    bool usesRemUnits() const { return m_usesRemUnits; }
86e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
87e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    DocumentOrderedList& styleSheetCandidateNodes() { return m_styleSheetCandidateNodes; }
8802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch    DocumentOrderedList* scopingNodesForStyleScoped() { return m_scopingNodesForStyleScoped.scopingNodes(); }
8902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch    ListHashSet<Node*, 4>* scopingNodesRemoved() { return m_scopingNodesForStyleScoped.scopingNodesRemoved(); }
90e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
9151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void clearMediaQueryRuleSetStyleSheets();
9251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
93e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)protected:
948abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    explicit StyleSheetCollection(TreeScope&);
95e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
968abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    Document* document() { return m_treeScope.documentScope(); }
97e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
98e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    enum StyleResolverUpdateType {
99e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        Reconstruct,
100e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        Reset,
10151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Additive,
10251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        ResetStyleResolverAndFontSelector
10351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    };
10451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
10551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    struct StyleSheetChange {
10651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        StyleResolverUpdateType styleResolverUpdateType;
10751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        bool requiresFullStyleRecalc;
10851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
10951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        StyleSheetChange()
11051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)            : styleResolverUpdateType(Reconstruct)
11151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)            , requiresFullStyleRecalc(true) { }
112e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    };
11351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
11451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void analyzeStyleSheetChange(StyleResolverUpdateMode, const StyleSheetCollectionBase&, StyleSheetChange&);
115e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    void resetAllRuleSetsInTreeScope(StyleResolver*);
116e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    void updateUsesRemUnits();
117e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
118e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochprivate:
11951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    static StyleResolverUpdateType compareStyleSheets(const Vector<RefPtr<CSSStyleSheet> >& oldStyleSheets, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, Vector<StyleSheetContents*>& addedSheets);
120e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    bool activeLoadingStyleSheetLoaded(const Vector<RefPtr<CSSStyleSheet> >& newStyleSheets);
121e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
122e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)protected:
1238abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    TreeScope& m_treeScope;
124e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    bool m_hadActiveLoadingStylesheet;
125e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    bool m_usesRemUnits;
126e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
127e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    DocumentOrderedList m_styleSheetCandidateNodes;
12802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch    StyleSheetScopingNodeList m_scopingNodesForStyleScoped;
129e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch};
130e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
131e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch}
132e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
133e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#endif
134e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
135