Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / resolver / ScopedStyleResolver.h
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  * Copyright (C) 2012 Google Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #ifndef ScopedStyleResolver_h
28 #define ScopedStyleResolver_h
29
30 #include "core/css/ElementRuleCollector.h"
31 #include "core/css/RuleSet.h"
32 #include "core/dom/TreeScope.h"
33 #include "wtf/HashMap.h"
34 #include "wtf/HashSet.h"
35 #include "wtf/OwnPtr.h"
36 #include "wtf/PassOwnPtr.h"
37
38 namespace blink {
39
40 class MediaQueryEvaluator;
41 class PageRuleCollector;
42 class StyleResolver;
43 class StyleSheetContents;
44
45 // This class selects a RenderStyle for a given element based on a collection of stylesheets.
46 class ScopedStyleResolver FINAL : public NoBaseWillBeGarbageCollected<ScopedStyleResolver> {
47     WTF_MAKE_NONCOPYABLE(ScopedStyleResolver);
48     WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
49 public:
50     static PassOwnPtrWillBeRawPtr<ScopedStyleResolver> create(TreeScope& scope)
51     {
52         return adoptPtrWillBeNoop(new ScopedStyleResolver(scope));
53     }
54
55     static TreeScope* treeScopeFor(Document&, const CSSStyleSheet*);
56
57     const TreeScope& treeScope() const { return *m_scope; }
58     ScopedStyleResolver* parent() const;
59
60 public:
61     const StyleRuleKeyframes* keyframeStylesForAnimation(const StringImpl* animationName);
62     void addKeyframeStyle(PassRefPtrWillBeRawPtr<StyleRuleKeyframes>);
63
64     void collectMatchingAuthorRules(ElementRuleCollector&, bool includeEmptyRules, CascadeScope, CascadeOrder = ignoreCascadeOrder);
65     void matchPageRules(PageRuleCollector&);
66     void addRulesFromSheet(CSSStyleSheet*, const MediaQueryEvaluator&, StyleResolver*);
67     void collectFeaturesTo(RuleFeatureSet&, HashSet<const StyleSheetContents*>& visitedSharedStyleSheetContents) const;
68     void resetAuthorStyle();
69     void collectViewportRulesTo(StyleResolver*) const;
70
71     void trace(Visitor*);
72
73 private:
74     explicit ScopedStyleResolver(TreeScope& scope)
75         : m_scope(scope)
76     {
77     }
78
79     RawPtrWillBeMember<TreeScope> m_scope;
80
81     WillBeHeapVector<RawPtrWillBeMember<CSSStyleSheet> > m_authorStyleSheets;
82
83     typedef WillBeHeapHashMap<const StringImpl*, RefPtrWillBeMember<StyleRuleKeyframes> > KeyframesRuleMap;
84     KeyframesRuleMap m_keyframesRuleMap;
85 };
86
87 } // namespace blink
88
89 #endif // ScopedStyleResolver_h