Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: Source/core/css/resolver/ScopedStyleResolver.h

Issue 102953007: Selectors in styles in shadowRoots should match in all of the host's shadowRoots. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed @keyframes regression Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // Always ++cascadeScope if style scoped.
dglazkov 2014/01/16 17:31:31 "++cascadeScope" lacks context here. It describes
tasak 2014/01/20 03:50:06 Done.
86 if (!m_scopingNode.isShadowRoot())
87 return true;
88
89 // If parent is a given shadow host, this resolver is for shadow trees hoste d by the host.
90 // Should not ++casscadeScope.
91 Element* host = toShadowRoot(&m_scopingNode)->host();
92 if (element == host)
93 return false;
94
95 // If parent is document scope or style scoped, ++cascadeScope.
96 if (!m_parent || !m_parent->scopingNode().isShadowRoot())
97 return true;
98
99 // If parent is hosted by the same shadow host, keep the same cascadeScope.
100 // Instead, ++cascadeScope.
101 return toShadowRoot(&m_parent->scopingNode())->host() != host;
102 }
103
81 } // namespace WebCore 104 } // namespace WebCore
82 105
83 #endif // ScopedStyleResolver_h 106 #endif // ScopedStyleResolver_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698