| 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 17 matching lines...) Expand all Loading... |
| 28 #define ScopedStyleTree_h | 28 #define ScopedStyleTree_h |
| 29 | 29 |
| 30 #include "core/css/resolver/ScopedStyleResolver.h" | 30 #include "core/css/resolver/ScopedStyleResolver.h" |
| 31 #include "wtf/HashMap.h" | 31 #include "wtf/HashMap.h" |
| 32 #include "wtf/OwnPtr.h" | 32 #include "wtf/OwnPtr.h" |
| 33 #include "wtf/Vector.h" | 33 #include "wtf/Vector.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 class ScopedStyleTree { | 37 class ScopedStyleTree { |
| 38 WTF_MAKE_NONCOPYABLE(ScopedStyleTree); WTF_MAKE_FAST_ALLOCATED; | 38 WTF_MAKE_NONCOPYABLE(ScopedStyleTree); |
| 39 DISALLOW_ALLOCATION(); |
| 39 public: | 40 public: |
| 40 ScopedStyleTree(); | 41 ScopedStyleTree(); |
| 41 ~ScopedStyleTree(); | 42 ~ScopedStyleTree(); |
| 42 | 43 |
| 43 ScopedStyleResolver* ensureScopedStyleResolver(ContainerNode& scopingNode); | 44 ScopedStyleResolver* ensureScopedStyleResolver(ContainerNode& scopingNode); |
| 44 | 45 |
| 45 ScopedStyleResolver* scopedStyleResolverFor(const ContainerNode& scopingNode
); | 46 ScopedStyleResolver* scopedStyleResolverFor(const ContainerNode& scopingNode
); |
| 46 | 47 |
| 47 // for fast-path. | 48 // for fast-path. |
| 48 bool hasOnlyScopedResolverForDocument() const { return m_authorStyles.size()
== 1; } | 49 bool hasOnlyScopedResolverForDocument() const { return m_authorStyles.size()
== 1; } |
| 49 | 50 |
| 50 void resolveScopedStyles(const Element*, Vector<ScopedStyleResolver*, 8>&); | 51 void resolveScopedStyles(const Element*, WillBeHeapVector<RawPtrWillBeMember
<ScopedStyleResolver>, 8>&); |
| 51 void collectScopedResolversForHostedShadowTrees(const Element*, Vector<Scope
dStyleResolver*, 8>&); | 52 void collectScopedResolversForHostedShadowTrees(const Element*, WillBeHeapVe
ctor<RawPtrWillBeMember<ScopedStyleResolver>, 8>&); |
| 52 void resolveScopedKeyframesRules(const Element*, Vector<ScopedStyleResolver*
, 8>&); | 53 void resolveScopedKeyframesRules(const Element*, WillBeHeapVector<RawPtrWill
BeMember<ScopedStyleResolver>, 8>&); |
| 53 ScopedStyleResolver* scopedResolverFor(const Element*); | 54 ScopedStyleResolver* scopedResolverFor(const Element*); |
| 54 | 55 |
| 55 void remove(const ContainerNode* scopingNode); | 56 void remove(const ContainerNode* scopingNode); |
| 56 | 57 |
| 57 void pushStyleCache(const ContainerNode& scopingNode, const ContainerNode* p
arent); | 58 void pushStyleCache(const ContainerNode& scopingNode, const ContainerNode* p
arent); |
| 58 void popStyleCache(const ContainerNode& scopingNode); | 59 void popStyleCache(const ContainerNode& scopingNode); |
| 59 | 60 |
| 60 void collectFeaturesTo(RuleFeatureSet& features); | 61 void collectFeaturesTo(RuleFeatureSet& features); |
| 61 | 62 |
| 63 void trace(Visitor*); |
| 64 |
| 62 private: | 65 private: |
| 63 bool cacheIsValid(const ContainerNode* parent) const { return parent && pare
nt == m_cache.nodeForScopedStyles; } | 66 bool cacheIsValid(const ContainerNode* parent) const { return parent && pare
nt == m_cache.nodeForScopedStyles; } |
| 64 void resolveStyleCache(const ContainerNode* scopingNode); | 67 void resolveStyleCache(const ContainerNode* scopingNode); |
| 65 ScopedStyleResolver* enclosingScopedStyleResolverFor(const ContainerNode* sc
opingNode); | 68 ScopedStyleResolver* enclosingScopedStyleResolverFor(const ContainerNode* sc
opingNode); |
| 66 | 69 |
| 67 private: | 70 WillBeHeapHashMap<RawPtrWillBeMember<const ContainerNode>, RawPtrWillBeMembe
r<ScopedStyleResolver> > m_authorStyles; |
| 68 HashMap<const ContainerNode*, ScopedStyleResolver*> m_authorStyles; | |
| 69 | 71 |
| 70 struct ScopedStyleCache { | 72 class ScopedStyleCache { |
| 71 ScopedStyleResolver* scopedResolver; | 73 DISALLOW_ALLOCATION(); |
| 72 const ContainerNode* nodeForScopedStyles; | 74 public: |
| 75 RawPtrWillBeMember<ScopedStyleResolver> scopedResolver; |
| 76 RawPtrWillBeMember<const ContainerNode> nodeForScopedStyles; |
| 73 | 77 |
| 74 ScopedStyleCache() | 78 ScopedStyleCache() |
| 75 : scopedResolver(0) | 79 : scopedResolver(nullptr) |
| 76 , nodeForScopedStyles(0) | 80 , nodeForScopedStyles(nullptr) |
| 77 { | 81 { |
| 78 } | 82 } |
| 79 | 83 |
| 80 void clear() | 84 void clear() |
| 81 { | 85 { |
| 82 scopedResolver = 0; | 86 scopedResolver = nullptr; |
| 83 nodeForScopedStyles = 0; | 87 nodeForScopedStyles = nullptr; |
| 88 } |
| 89 |
| 90 void trace(Visitor* visitor) |
| 91 { |
| 92 visitor->trace(scopedResolver); |
| 93 visitor->trace(nodeForScopedStyles); |
| 84 } | 94 } |
| 85 }; | 95 }; |
| 86 ScopedStyleCache m_cache; | 96 ScopedStyleCache m_cache; |
| 87 }; | 97 }; |
| 88 | 98 |
| 89 inline ScopedStyleResolver* ScopedStyleTree::scopedResolverFor(const Element* el
ement) | 99 inline ScopedStyleResolver* ScopedStyleTree::scopedResolverFor(const Element* el
ement) |
| 90 { | 100 { |
| 91 if (!cacheIsValid(element)) | 101 if (!cacheIsValid(element)) |
| 92 resolveStyleCache(element); | 102 resolveStyleCache(element); |
| 93 | 103 |
| 94 return m_cache.scopedResolver; | 104 return m_cache.scopedResolver; |
| 95 } | 105 } |
| 96 | 106 |
| 97 } // namespace blink | 107 } // namespace blink |
| 98 | 108 |
| 99 #endif // ScopedStyleTree_h | 109 #endif // ScopedStyleTree_h |
| OLD | NEW |