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

Side by Side Diff: Source/core/css/resolver/MatchedPropertiesCache.cpp

Issue 1033943002: Rename LayoutStyle to papayawhip (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: ensureComputedStyle Created 5 years, 8 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 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 13 matching lines...) Expand all
24 * along with this library; see the file COPYING.LIB. If not, write to 24 * along with this library; see the file COPYING.LIB. If not, write to
25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 * Boston, MA 02110-1301, USA. 26 * Boston, MA 02110-1301, USA.
27 */ 27 */
28 28
29 #include "config.h" 29 #include "config.h"
30 #include "core/css/resolver/MatchedPropertiesCache.h" 30 #include "core/css/resolver/MatchedPropertiesCache.h"
31 31
32 #include "core/css/StylePropertySet.h" 32 #include "core/css/StylePropertySet.h"
33 #include "core/css/resolver/StyleResolverState.h" 33 #include "core/css/resolver/StyleResolverState.h"
34 #include "core/layout/style/LayoutStyle.h" 34 #include "core/layout/style/ComputedStyle.h"
35 35
36 namespace blink { 36 namespace blink {
37 37
38 void CachedMatchedProperties::set(const LayoutStyle& style, const LayoutStyle& p arentStyle, const MatchResult& matchResult) 38 void CachedMatchedProperties::set(const ComputedStyle& style, const ComputedStyl e& parentStyle, const MatchResult& matchResult)
39 { 39 {
40 matchedProperties.appendVector(matchResult.matchedProperties); 40 matchedProperties.appendVector(matchResult.matchedProperties);
41 ranges = matchResult.ranges; 41 ranges = matchResult.ranges;
42 42
43 // Note that we don't cache the original LayoutStyle instance. It may be fur ther modified. 43 // Note that we don't cache the original ComputedStyle instance. It may be f urther modified.
44 // The LayoutStyle in the cache is really just a holder for the substructure s and never used as-is. 44 // The ComputedStyle in the cache is really just a holder for the substructu res and never used as-is.
45 this->layoutStyle = LayoutStyle::clone(style); 45 this->computedStyle = ComputedStyle::clone(style);
46 this->parentLayoutStyle = LayoutStyle::clone(parentStyle); 46 this->parentComputedStyle = ComputedStyle::clone(parentStyle);
47 } 47 }
48 48
49 void CachedMatchedProperties::clear() 49 void CachedMatchedProperties::clear()
50 { 50 {
51 matchedProperties.clear(); 51 matchedProperties.clear();
52 layoutStyle = nullptr; 52 computedStyle = nullptr;
53 parentLayoutStyle = nullptr; 53 parentComputedStyle = nullptr;
54 } 54 }
55 55
56 MatchedPropertiesCache::MatchedPropertiesCache() 56 MatchedPropertiesCache::MatchedPropertiesCache()
57 #if !ENABLE(OILPAN) 57 #if !ENABLE(OILPAN)
58 : m_additionsSinceLastSweep(0) 58 : m_additionsSinceLastSweep(0)
59 , m_sweepTimer(this, &MatchedPropertiesCache::sweep) 59 , m_sweepTimer(this, &MatchedPropertiesCache::sweep)
60 #endif 60 #endif
61 { 61 {
62 } 62 }
63 63
64 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const StyleResolverState& styleResolverState, const MatchResult& matchResult) 64 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const StyleResolverState& styleResolverState, const MatchResult& matchResult)
65 { 65 {
66 ASSERT(hash); 66 ASSERT(hash);
67 67
68 Cache::iterator it = m_cache.find(hash); 68 Cache::iterator it = m_cache.find(hash);
69 if (it == m_cache.end()) 69 if (it == m_cache.end())
70 return 0; 70 return 0;
71 CachedMatchedProperties* cacheItem = it->value.get(); 71 CachedMatchedProperties* cacheItem = it->value.get();
72 ASSERT(cacheItem); 72 ASSERT(cacheItem);
73 73
74 size_t size = matchResult.matchedProperties.size(); 74 size_t size = matchResult.matchedProperties.size();
75 if (size != cacheItem->matchedProperties.size()) 75 if (size != cacheItem->matchedProperties.size())
76 return 0; 76 return 0;
77 if (cacheItem->layoutStyle->insideLink() != styleResolverState.style()->insi deLink()) 77 if (cacheItem->computedStyle->insideLink() != styleResolverState.style()->in sideLink())
78 return 0; 78 return 0;
79 for (size_t i = 0; i < size; ++i) { 79 for (size_t i = 0; i < size; ++i) {
80 if (matchResult.matchedProperties[i] != cacheItem->matchedProperties[i]) 80 if (matchResult.matchedProperties[i] != cacheItem->matchedProperties[i])
81 return 0; 81 return 0;
82 } 82 }
83 if (cacheItem->ranges != matchResult.ranges) 83 if (cacheItem->ranges != matchResult.ranges)
84 return 0; 84 return 0;
85 return cacheItem; 85 return cacheItem;
86 } 86 }
87 87
88 void MatchedPropertiesCache::add(const LayoutStyle& style, const LayoutStyle& pa rentStyle, unsigned hash, const MatchResult& matchResult) 88 void MatchedPropertiesCache::add(const ComputedStyle& style, const ComputedStyle & parentStyle, unsigned hash, const MatchResult& matchResult)
89 { 89 {
90 #if !ENABLE(OILPAN) 90 #if !ENABLE(OILPAN)
91 static const unsigned maxAdditionsBetweenSweeps = 100; 91 static const unsigned maxAdditionsBetweenSweeps = 100;
92 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps 92 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps
93 && !m_sweepTimer.isActive()) { 93 && !m_sweepTimer.isActive()) {
94 static const unsigned sweepTimeInSeconds = 60; 94 static const unsigned sweepTimeInSeconds = 60;
95 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE); 95 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE);
96 } 96 }
97 #endif 97 #endif
98 98
(...skipping 12 matching lines...) Expand all
111 void MatchedPropertiesCache::clear() 111 void MatchedPropertiesCache::clear()
112 { 112 {
113 m_cache.clear(); 113 m_cache.clear();
114 } 114 }
115 115
116 void MatchedPropertiesCache::clearViewportDependent() 116 void MatchedPropertiesCache::clearViewportDependent()
117 { 117 {
118 Vector<unsigned, 16> toRemove; 118 Vector<unsigned, 16> toRemove;
119 for (const auto& cacheEntry : m_cache) { 119 for (const auto& cacheEntry : m_cache) {
120 CachedMatchedProperties* cacheItem = cacheEntry.value.get(); 120 CachedMatchedProperties* cacheItem = cacheEntry.value.get();
121 if (cacheItem->layoutStyle->hasViewportUnits()) 121 if (cacheItem->computedStyle->hasViewportUnits())
122 toRemove.append(cacheEntry.key); 122 toRemove.append(cacheEntry.key);
123 } 123 }
124 m_cache.removeAll(toRemove); 124 m_cache.removeAll(toRemove);
125 } 125 }
126 126
127 #if !ENABLE(OILPAN) 127 #if !ENABLE(OILPAN)
128 void MatchedPropertiesCache::sweep(Timer<MatchedPropertiesCache>*) 128 void MatchedPropertiesCache::sweep(Timer<MatchedPropertiesCache>*)
129 { 129 {
130 // Look for cache entries containing a style declaration with a single ref a nd remove them. 130 // Look for cache entries containing a style declaration with a single ref a nd remove them.
131 // This may happen when an element attribute mutation causes it to generate a new inlineStyle() 131 // This may happen when an element attribute mutation causes it to generate a new inlineStyle()
132 // or presentationAttributeStyle(), potentially leaving this cache with the last ref on the old one. 132 // or presentationAttributeStyle(), potentially leaving this cache with the last ref on the old one.
133 Vector<unsigned, 16> toRemove; 133 Vector<unsigned, 16> toRemove;
134 for (const auto& cacheEntry : m_cache) { 134 for (const auto& cacheEntry : m_cache) {
135 CachedMatchedProperties* cacheItem = cacheEntry.value.get(); 135 CachedMatchedProperties* cacheItem = cacheEntry.value.get();
136 Vector<MatchedProperties>& matchedProperties = cacheItem->matchedPropert ies; 136 Vector<MatchedProperties>& matchedProperties = cacheItem->matchedPropert ies;
137 for (size_t i = 0; i < matchedProperties.size(); ++i) { 137 for (size_t i = 0; i < matchedProperties.size(); ++i) {
138 if (matchedProperties[i].properties->hasOneRef()) { 138 if (matchedProperties[i].properties->hasOneRef()) {
139 toRemove.append(cacheEntry.key); 139 toRemove.append(cacheEntry.key);
140 break; 140 break;
141 } 141 }
142 } 142 }
143 } 143 }
144 m_cache.removeAll(toRemove); 144 m_cache.removeAll(toRemove);
145 m_additionsSinceLastSweep = 0; 145 m_additionsSinceLastSweep = 0;
146 } 146 }
147 #endif 147 #endif
148 148
149 bool MatchedPropertiesCache::isCacheable(const Element* element, const LayoutSty le& style, const LayoutStyle& parentStyle) 149 bool MatchedPropertiesCache::isCacheable(const Element* element, const ComputedS tyle& style, const ComputedStyle& parentStyle)
150 { 150 {
151 if (style.unique() || (style.styleType() != NOPSEUDO && parentStyle.unique() )) 151 if (style.unique() || (style.styleType() != NOPSEUDO && parentStyle.unique() ))
152 return false; 152 return false;
153 if (style.hasAppearance()) 153 if (style.hasAppearance())
154 return false; 154 return false;
155 if (style.zoom() != LayoutStyle::initialZoom()) 155 if (style.zoom() != ComputedStyle::initialZoom())
156 return false; 156 return false;
157 if (style.writingMode() != LayoutStyle::initialWritingMode()) 157 if (style.writingMode() != ComputedStyle::initialWritingMode())
158 return false; 158 return false;
159 // The cache assumes static knowledge about which properties are inherited. 159 // The cache assumes static knowledge about which properties are inherited.
160 if (parentStyle.hasExplicitlyInheritedProperties()) 160 if (parentStyle.hasExplicitlyInheritedProperties())
161 return false; 161 return false;
162 return true; 162 return true;
163 } 163 }
164 164
165 DEFINE_TRACE(MatchedPropertiesCache) 165 DEFINE_TRACE(MatchedPropertiesCache)
166 { 166 {
167 #if ENABLE(OILPAN) 167 #if ENABLE(OILPAN)
168 visitor->trace(m_cache); 168 visitor->trace(m_cache);
169 #endif 169 #endif
170 } 170 }
171 171
172 } 172 }
OLDNEW
« no previous file with comments | « Source/core/css/resolver/MatchedPropertiesCache.h ('k') | Source/core/css/resolver/ScopedStyleResolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698