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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 117 } |
118 | 118 |
119 static void makePresentationAttributeCacheKey(Element& element, PresentationAttr
ibuteCacheKey& result) | 119 static void makePresentationAttributeCacheKey(Element& element, PresentationAttr
ibuteCacheKey& result) |
120 { | 120 { |
121 // FIXME: Enable for SVG. | 121 // FIXME: Enable for SVG. |
122 if (!element.isHTMLElement()) | 122 if (!element.isHTMLElement()) |
123 return; | 123 return; |
124 // Interpretation of the size attributes on <input> depends on the type attr
ibute. | 124 // Interpretation of the size attributes on <input> depends on the type attr
ibute. |
125 if (isHTMLInputElement(element)) | 125 if (isHTMLInputElement(element)) |
126 return; | 126 return; |
127 AttributeIteratorAccessor attributes = element.attributesIterator(); | 127 AttributeCollection attributes = element.attributes(); |
128 AttributeConstIterator end = attributes.end(); | 128 AttributeCollection::const_iterator end = attributes.end(); |
129 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { | 129 for (AttributeCollection::const_iterator it = attributes.begin(); it != end;
++it) { |
130 if (!element.isPresentationAttribute(it->name())) | 130 if (!element.isPresentationAttribute(it->name())) |
131 continue; | 131 continue; |
132 if (!it->namespaceURI().isNull()) | 132 if (!it->namespaceURI().isNull()) |
133 return; | 133 return; |
134 // FIXME: Background URL may depend on the base URL and can't be shared.
Disallow caching. | 134 // FIXME: Background URL may depend on the base URL and can't be shared.
Disallow caching. |
135 if (it->name() == backgroundAttr) | 135 if (it->name() == backgroundAttr) |
136 return; | 136 return; |
137 result.attributesAndValues.append(std::make_pair(it->localName().impl(),
it->value())); | 137 result.attributesAndValues.append(std::make_pair(it->localName().impl(),
it->value())); |
138 } | 138 } |
139 if (result.attributesAndValues.isEmpty()) | 139 if (result.attributesAndValues.isEmpty()) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } else { | 172 } else { |
173 cacheValue = 0; | 173 cacheValue = 0; |
174 } | 174 } |
175 | 175 |
176 RefPtr<StylePropertySet> style; | 176 RefPtr<StylePropertySet> style; |
177 if (cacheHash && cacheValue->value) { | 177 if (cacheHash && cacheValue->value) { |
178 style = cacheValue->value->value; | 178 style = cacheValue->value->value; |
179 cacheCleaner.didHitPresentationAttributeCache(); | 179 cacheCleaner.didHitPresentationAttributeCache(); |
180 } else { | 180 } else { |
181 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr
ibuteMode : HTMLAttributeMode); | 181 style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttr
ibuteMode : HTMLAttributeMode); |
182 AttributeIteratorAccessor attributes = element.attributesIterator(); | 182 AttributeCollection attributes = element.attributes(); |
183 AttributeConstIterator end = attributes.end(); | 183 AttributeCollection::const_iterator end = attributes.end(); |
184 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) | 184 for (AttributeCollection::const_iterator it = attributes.begin(); it !=
end; ++it) |
185 element.collectStyleForPresentationAttribute(it->name(), it->value()
, toMutableStylePropertySet(style)); | 185 element.collectStyleForPresentationAttribute(it->name(), it->value()
, toMutableStylePropertySet(style)); |
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 |