OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 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. | 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. | 4 * Copyright (C) 2012 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 12 matching lines...) Expand all Loading... |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 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. | 24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #ifndef ScopedStyleResolver_h | 27 #ifndef ScopedStyleResolver_h |
28 #define ScopedStyleResolver_h | 28 #define ScopedStyleResolver_h |
29 | 29 |
30 #include "core/css/ElementRuleCollector.h" | 30 #include "core/css/ElementRuleCollector.h" |
31 #include "core/css/RuleSet.h" | 31 #include "core/css/RuleSet.h" |
32 #include "core/dom/ContainerNode.h" | 32 #include "core/dom/ContainerNode.h" |
| 33 #include "core/dom/shadow/ShadowRoot.h" |
33 #include "wtf/HashMap.h" | 34 #include "wtf/HashMap.h" |
34 #include "wtf/OwnPtr.h" | 35 #include "wtf/OwnPtr.h" |
35 #include "wtf/PassOwnPtr.h" | 36 #include "wtf/PassOwnPtr.h" |
36 | 37 |
37 namespace WebCore { | 38 namespace WebCore { |
38 | 39 |
39 class MediaQueryEvaluator; | 40 class MediaQueryEvaluator; |
40 class PageRuleCollector; | 41 class PageRuleCollector; |
41 class ShadowRoot; | 42 class ShadowRoot; |
42 class StyleSheetContents; | 43 class StyleSheetContents; |
43 | 44 |
44 // This class selects a RenderStyle for a given element based on a collection of
stylesheets. | 45 // This class selects a RenderStyle for a given element based on a collection of
stylesheets. |
45 class ScopedStyleResolver { | 46 class ScopedStyleResolver { |
46 WTF_MAKE_NONCOPYABLE(ScopedStyleResolver); WTF_MAKE_FAST_ALLOCATED; | 47 WTF_MAKE_NONCOPYABLE(ScopedStyleResolver); WTF_MAKE_FAST_ALLOCATED; |
47 public: | 48 public: |
48 static PassOwnPtr<ScopedStyleResolver> create(ContainerNode& scopingNode) {
return adoptPtr(new ScopedStyleResolver(scopingNode)); } | 49 static PassOwnPtr<ScopedStyleResolver> create(ContainerNode& scopingNode) {
return adoptPtr(new ScopedStyleResolver(scopingNode)); } |
49 | 50 |
50 static ContainerNode* scopingNodeFor(Document&, const CSSStyleSheet*); | 51 static ContainerNode* scopingNodeFor(Document&, const CSSStyleSheet*); |
51 | 52 |
52 const ContainerNode& scopingNode() const { return m_scopingNode; } | 53 const ContainerNode& scopingNode() const { return m_scopingNode; } |
53 const TreeScope& treeScope() const { return m_scopingNode.treeScope(); } | 54 const TreeScope& treeScope() const { return m_scopingNode.treeScope(); } |
54 void setParent(ScopedStyleResolver* newParent) { m_parent = newParent; } | 55 void setParent(ScopedStyleResolver* newParent) { m_parent = newParent; } |
55 ScopedStyleResolver* parent() { return m_parent; } | 56 ScopedStyleResolver* parent() { return m_parent; } |
| 57 bool crossingScopeBoundary(const Element*) const; |
56 | 58 |
57 public: | 59 public: |
58 bool checkRegionStyle(Element*); | 60 bool checkRegionStyle(Element*); |
59 const StyleRuleKeyframes* keyframeStylesForAnimation(const StringImpl* anima
tionName); | 61 const StyleRuleKeyframes* keyframeStylesForAnimation(const StringImpl* anima
tionName); |
60 void addKeyframeStyle(PassRefPtr<StyleRuleKeyframes>); | 62 void addKeyframeStyle(PassRefPtr<StyleRuleKeyframes>); |
61 | 63 |
62 void collectMatchingAuthorRules(ElementRuleCollector&, bool includeEmptyRule
s, bool applyAuthorStyles, CascadeScope, CascadeOrder = ignoreCascadeOrder); | 64 void collectMatchingAuthorRules(ElementRuleCollector&, bool includeEmptyRule
s, bool applyAuthorStyles, CascadeScope, CascadeOrder = ignoreCascadeOrder); |
63 void matchPageRules(PageRuleCollector&); | 65 void matchPageRules(PageRuleCollector&); |
64 void addRulesFromSheet(CSSStyleSheet*, const MediaQueryEvaluator&, StyleReso
lver*); | 66 void addRulesFromSheet(CSSStyleSheet*, const MediaQueryEvaluator&, StyleReso
lver*); |
65 void collectFeaturesTo(RuleFeatureSet&); | 67 void collectFeaturesTo(RuleFeatureSet&); |
66 void resetAuthorStyle(); | 68 void resetAuthorStyle(); |
67 void collectViewportRulesTo(StyleResolver*) const; | 69 void collectViewportRulesTo(StyleResolver*) const; |
68 | 70 |
69 private: | 71 private: |
70 explicit ScopedStyleResolver(ContainerNode& scopingNode) : m_scopingNode(sco
pingNode), m_parent(0) { } | 72 explicit ScopedStyleResolver(ContainerNode& scopingNode) : m_scopingNode(sco
pingNode), m_parent(0) { } |
71 | 73 |
72 ContainerNode& m_scopingNode; | 74 ContainerNode& m_scopingNode; |
73 ScopedStyleResolver* m_parent; | 75 ScopedStyleResolver* m_parent; |
74 | 76 |
75 Vector<CSSStyleSheet*> m_authorStyleSheets; | 77 Vector<CSSStyleSheet*> m_authorStyleSheets; |
76 | 78 |
77 typedef HashMap<const StringImpl*, RefPtr<StyleRuleKeyframes> > KeyframesRul
eMap; | 79 typedef HashMap<const StringImpl*, RefPtr<StyleRuleKeyframes> > KeyframesRul
eMap; |
78 KeyframesRuleMap m_keyframesRuleMap; | 80 KeyframesRuleMap m_keyframesRuleMap; |
79 }; | 81 }; |
80 | 82 |
| 83 inline bool ScopedStyleResolver::crossingScopeBoundary(const Element* element) c
onst |
| 84 { |
| 85 // Since this resolver is for style scoped, rules declared in the style have
higher priority |
| 86 // than rules declared in styles whose scoping node is the ancestor. So need
to ++cascadeScope. |
| 87 if (!m_scopingNode.isShadowRoot()) |
| 88 return true; |
| 89 |
| 90 // If parent is a given shadow host, this resolver is for shadow trees hoste
d by the host. |
| 91 // Since styles in shadow trees hosted by the same shadow host will apply al
l elements in |
| 92 // the shadow trees, we should treat rules in the styles as the same cascade
. |
| 93 // Should not ++cascadeScope. |
| 94 Element* host = toShadowRoot(&m_scopingNode)->host(); |
| 95 if (element == host) |
| 96 return false; |
| 97 |
| 98 // If parent is document scope or style scoped, ++cascadeScope because of CS
S cascade spec. |
| 99 if (!m_parent || !m_parent->scopingNode().isShadowRoot()) |
| 100 return true; |
| 101 |
| 102 // If parent is hosted by the same shadow host, keep the same cascadeScope. |
| 103 // Otherwise, ++cascadeScope. |
| 104 return toShadowRoot(&m_parent->scopingNode())->host() != host; |
| 105 } |
| 106 |
81 } // namespace WebCore | 107 } // namespace WebCore |
82 | 108 |
83 #endif // ScopedStyleResolver_h | 109 #endif // ScopedStyleResolver_h |
OLD | NEW |