OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 static void makePresentationAttributeCacheKey(Element& element, PresentationAttr
ibuteCacheKey& result) | 118 static void makePresentationAttributeCacheKey(Element& element, PresentationAttr
ibuteCacheKey& result) |
119 { | 119 { |
120 // FIXME: Enable for SVG. | 120 // FIXME: Enable for SVG. |
121 if (!element.isHTMLElement()) | 121 if (!element.isHTMLElement()) |
122 return; | 122 return; |
123 // Interpretation of the size attributes on <input> depends on the type attr
ibute. | 123 // Interpretation of the size attributes on <input> depends on the type attr
ibute. |
124 if (element.hasTagName(inputTag)) | 124 if (element.hasTagName(inputTag)) |
125 return; | 125 return; |
126 unsigned size = element.attributeCount(); | 126 unsigned size = element.attributeCount(); |
127 for (unsigned i = 0; i < size; ++i) { | 127 for (unsigned i = 0; i < size; ++i) { |
128 const Attribute* attribute = element.attributeItem(i); | 128 const Attribute& attribute = element.attributeItem(i); |
129 if (!element.isPresentationAttribute(attribute->name())) | 129 if (!element.isPresentationAttribute(attribute.name())) |
130 continue; | 130 continue; |
131 if (!attribute->namespaceURI().isNull()) | 131 if (!attribute.namespaceURI().isNull()) |
132 return; | 132 return; |
133 // FIXME: Background URL may depend on the base URL and can't be shared.
Disallow caching. | 133 // FIXME: Background URL may depend on the base URL and can't be shared.
Disallow caching. |
134 if (attribute->name() == backgroundAttr) | 134 if (attribute.name() == backgroundAttr) |
135 return; | 135 return; |
136 result.attributesAndValues.append(std::make_pair(attribute->localName().
impl(), attribute->value())); | 136 result.attributesAndValues.append(std::make_pair(attribute.localName().i
mpl(), attribute.value())); |
137 } | 137 } |
138 if (result.attributesAndValues.isEmpty()) | 138 if (result.attributesAndValues.isEmpty()) |
139 return; | 139 return; |
140 // Attribute order doesn't matter. Sort for easy equality comparison. | 140 // Attribute order doesn't matter. Sort for easy equality comparison. |
141 std::sort(result.attributesAndValues.begin(), result.attributesAndValues.end
(), attributeNameSort); | 141 std::sort(result.attributesAndValues.begin(), result.attributesAndValues.end
(), attributeNameSort); |
142 // The cache key is non-null when the tagName is set. | 142 // The cache key is non-null when the tagName is set. |
143 result.tagName = element.localName().impl(); | 143 result.tagName = element.localName().impl(); |
144 } | 144 } |
145 | 145 |
146 static unsigned computePresentationAttributeCacheHash(const PresentationAttribut
eCacheKey& key) | 146 static unsigned computePresentationAttributeCacheHash(const PresentationAttribut
eCacheKey& key) |
(...skipping 26 matching lines...) Expand all Loading... |
173 } | 173 } |
174 | 174 |
175 RefPtr<StylePropertySet> style; | 175 RefPtr<StylePropertySet> style; |
176 if (cacheHash && cacheValue->value) { | 176 if (cacheHash && cacheValue->value) { |
177 style = cacheValue->value->value; | 177 style = cacheValue->value->value; |
178 cacheCleaner.didHitPresentationAttributeCache(); | 178 cacheCleaner.didHitPresentationAttributeCache(); |
179 } else { | 179 } else { |
180 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr
ibuteMode : HTMLAttributeMode); | 180 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr
ibuteMode : HTMLAttributeMode); |
181 unsigned size = element.attributeCount(); | 181 unsigned size = element.attributeCount(); |
182 for (unsigned i = 0; i < size; ++i) { | 182 for (unsigned i = 0; i < size; ++i) { |
183 const Attribute* attribute = element.attributeItem(i); | 183 const Attribute& attribute = element.attributeItem(i); |
184 element.collectStyleForPresentationAttribute(attribute->name(), attr
ibute->value(), toMutableStylePropertySet(style)); | 184 element.collectStyleForPresentationAttribute(attribute.name(), attri
bute.value(), toMutableStylePropertySet(style)); |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 if (!cacheHash || cacheValue->value) | 188 if (!cacheHash || cacheValue->value) |
189 return style.release(); | 189 return style.release(); |
190 | 190 |
191 OwnPtr<PresentationAttributeCacheEntry> newEntry = adoptPtr(new Presentation
AttributeCacheEntry); | 191 OwnPtr<PresentationAttributeCacheEntry> newEntry = adoptPtr(new Presentation
AttributeCacheEntry); |
192 newEntry->key = cacheKey; | 192 newEntry->key = cacheKey; |
193 newEntry->value = style; | 193 newEntry->value = style; |
194 | 194 |
195 static const unsigned presentationAttributeCacheMaximumSize = 4096; | 195 static const unsigned presentationAttributeCacheMaximumSize = 4096; |
196 if (presentationAttributeCache().size() > presentationAttributeCacheMaximumS
ize) { | 196 if (presentationAttributeCache().size() > presentationAttributeCacheMaximumS
ize) { |
197 // FIXME: Discarding the entire cache when it gets too big is probably b
ad | 197 // FIXME: Discarding the entire cache when it gets too big is probably b
ad |
198 // since it creates a perf "cliff". Perhaps we should use an LRU? | 198 // since it creates a perf "cliff". Perhaps we should use an LRU? |
199 presentationAttributeCache().clear(); | 199 presentationAttributeCache().clear(); |
200 presentationAttributeCache().set(cacheHash, newEntry.release()); | 200 presentationAttributeCache().set(cacheHash, newEntry.release()); |
201 } else { | 201 } else { |
202 cacheValue->value = newEntry.release(); | 202 cacheValue->value = newEntry.release(); |
203 } | 203 } |
204 | 204 |
205 return style.release(); | 205 return style.release(); |
206 } | 206 } |
207 | 207 |
208 } // namespace WebCore | 208 } // namespace WebCore |
OLD | NEW |