1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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
22#ifndef PageRuleCollector_h
23#define PageRuleCollector_h
24
25#include "DocumentRuleSets.h"
26#include "StyleResolver.h"
27#include <wtf/RefPtr.h>
28#include <wtf/Vector.h>
29
30namespace WebCore {
31
32class StyleRulePage;
33
34class PageRuleCollector {
35public:
36    PageRuleCollector(StyleResolver::State& state, DocumentRuleSets& ruleSets)
37        : m_state(state)
38        , m_ruleSets(ruleSets) { }
39
40    void matchAllPageRules(int pageIndex);
41    StyleResolver::MatchResult& matchedResult() { return m_result; }
42
43private:
44    bool isLeftPage(int pageIndex) const;
45    bool isRightPage(int pageIndex) const { return !isLeftPage(pageIndex); }
46    bool isFirstPage(int pageIndex) const;
47    String pageName(int pageIndex) const;
48
49    void matchPageRules(RuleSet* rules, bool isLeftPage, bool isFirstPage, const String& pageName);
50    void matchPageRulesForList(Vector<StyleRulePage*>& matchedRules, const Vector<StyleRulePage*>& rules, bool isLeftPage, bool isFirstPage, const String& pageName);
51
52    const StyleResolver::State& m_state;
53    DocumentRuleSets& m_ruleSets;
54
55    StyleResolver::MatchResult m_result;
56};
57
58} // namespace WebCore
59
60#endif // PageRuleCollector_h
61