#include "config.h"
#include "core/dom/PresentationAttributeStyle.h"
-#include "HTMLNames.h"
#include "core/css/StylePropertySet.h"
#include "core/dom/Attribute.h"
#include "core/dom/Element.h"
+#include "core/html/HTMLInputElement.h"
+#include "platform/Timer.h"
#include "wtf/HashFunctions.h"
#include "wtf/HashMap.h"
#include "wtf/text/CString.h"
-namespace WebCore {
+namespace blink {
using namespace HTMLNames;
return a.attributesAndValues != b.attributesAndValues;
}
-struct PresentationAttributeCacheEntry {
- WTF_MAKE_FAST_ALLOCATED;
+struct PresentationAttributeCacheEntry FINAL : public NoBaseWillBeGarbageCollectedFinalized<PresentationAttributeCacheEntry> {
+ WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
public:
+ void trace(Visitor* visitor) { visitor->trace(value); }
+
PresentationAttributeCacheKey key;
- RefPtr<StylePropertySet> value;
+ RefPtrWillBeMember<StylePropertySet> value;
};
-typedef HashMap<unsigned, OwnPtr<PresentationAttributeCacheEntry>, AlreadyHashed> PresentationAttributeCache;
+typedef WillBeHeapHashMap<unsigned, OwnPtrWillBeMember<PresentationAttributeCacheEntry>, AlreadyHashed> PresentationAttributeCache;
static PresentationAttributeCache& presentationAttributeCache()
{
- DEFINE_STATIC_LOCAL(PresentationAttributeCache, cache, ());
- return cache;
+ DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<PresentationAttributeCache>, cache, (adoptPtrWillBeNoop(new PresentationAttributeCache())));
+ return *cache;
}
class PresentationAttributeCacheCleaner {
m_hitCount++;
if (!m_cleanTimer.isActive())
- m_cleanTimer.startOneShot(presentationAttributeCacheCleanTimeInSeconds);
+ m_cleanTimer.startOneShot(presentationAttributeCacheCleanTimeInSeconds, FROM_HERE);
}
private:
if (!element.isHTMLElement())
return;
// Interpretation of the size attributes on <input> depends on the type attribute.
- if (element.hasTagName(inputTag))
+ if (isHTMLInputElement(element))
return;
- unsigned size = element.attributeCount();
- for (unsigned i = 0; i < size; ++i) {
- const Attribute* attribute = element.attributeItem(i);
- if (!element.isPresentationAttribute(attribute->name()))
+ AttributeCollection attributes = element.attributesWithoutUpdate();
+ AttributeCollection::iterator end = attributes.end();
+ for (AttributeCollection::iterator it = attributes.begin(); it != end; ++it) {
+ if (!element.isPresentationAttribute(it->name()))
continue;
- if (!attribute->namespaceURI().isNull())
+ if (!it->namespaceURI().isNull())
return;
// FIXME: Background URL may depend on the base URL and can't be shared. Disallow caching.
- if (attribute->name() == backgroundAttr)
+ if (it->name() == backgroundAttr)
return;
- result.attributesAndValues.append(std::make_pair(attribute->localName().impl(), attribute->value()));
+ result.attributesAndValues.append(std::make_pair(it->localName().impl(), it->value()));
}
if (result.attributesAndValues.isEmpty())
return;
return WTF::pairIntHash(key.tagName->existingHash(), attributeHash);
}
-PassRefPtr<StylePropertySet> computePresentationAttributeStyle(Element& element)
+PassRefPtrWillBeRawPtr<StylePropertySet> computePresentationAttributeStyle(Element& element)
{
DEFINE_STATIC_LOCAL(PresentationAttributeCacheCleaner, cacheCleaner, ());
cacheValue = 0;
}
- RefPtr<StylePropertySet> style;
+ RefPtrWillBeRawPtr<StylePropertySet> style = nullptr;
if (cacheHash && cacheValue->value) {
style = cacheValue->value->value;
cacheCleaner.didHitPresentationAttributeCache();
} else {
style = MutableStylePropertySet::create(element.isSVGElement() ? SVGAttributeMode : HTMLAttributeMode);
- unsigned size = element.attributeCount();
- for (unsigned i = 0; i < size; ++i) {
- const Attribute* attribute = element.attributeItem(i);
- element.collectStyleForPresentationAttribute(attribute->name(), attribute->value(), toMutableStylePropertySet(style));
- }
+ AttributeCollection attributes = element.attributesWithoutUpdate();
+ AttributeCollection::iterator end = attributes.end();
+ for (AttributeCollection::iterator it = attributes.begin(); it != end; ++it)
+ element.collectStyleForPresentationAttribute(it->name(), it->value(), toMutableStylePropertySet(style));
}
if (!cacheHash || cacheValue->value)
return style.release();
- OwnPtr<PresentationAttributeCacheEntry> newEntry = adoptPtr(new PresentationAttributeCacheEntry);
+ OwnPtrWillBeRawPtr<PresentationAttributeCacheEntry> newEntry = adoptPtrWillBeNoop(new PresentationAttributeCacheEntry);
newEntry->key = cacheKey;
newEntry->value = style;
return style.release();
}
-} // namespace WebCore
+} // namespace blink