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