summaryrefslogtreecommitdiff
path: root/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPODTypeWrapper.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/webkit/WebCore/bindings/js/JSSVGPODTypeWrapper.h')
-rw-r--r--src/3rdparty/webkit/WebCore/bindings/js/JSSVGPODTypeWrapper.h108
1 files changed, 54 insertions, 54 deletions
diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPODTypeWrapper.h b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPODTypeWrapper.h
index 51e4e9e64b..2efc60ea7c 100644
--- a/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPODTypeWrapper.h
+++ b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPODTypeWrapper.h
@@ -28,28 +28,31 @@
#define JSSVGPODTypeWrapper_h
#if ENABLE(SVG)
+#include "JSSVGContextCache.h"
#include "SVGElement.h"
#include <wtf/StdLibExtras.h>
namespace WebCore {
+class DOMObject;
+
template<typename PODType>
class JSSVGPODTypeWrapper : public RefCounted<JSSVGPODTypeWrapper<PODType> > {
public:
virtual ~JSSVGPODTypeWrapper() { }
virtual operator PODType() = 0;
- virtual void commitChange(PODType, SVGElement*) = 0;
+ virtual void commitChange(PODType, DOMObject*) = 0;
};
// This file contains JS wrapper objects for SVG datatypes, that are passed around by value
-// in WebCore/svg (aka. 'POD types'). For instance SVGMatrix is mapped to TransformationMatrix, and
+// in WebCore/svg (aka. 'POD types'). For instance SVGMatrix is mapped to AffineTransform, and
// passed around as const reference. SVG DOM demands these objects to be "live", changes to any
// of the writable attributes of SVGMatrix need to be reflected in the object which exposed the
-// SVGMatrix object (ie. 'someElement.transform.matrix.a = 50.0', in that case 'SVGTransform').
-// The SVGTransform class stores its "TransformationMatrix m_matrix" object on the stack. If it would
+// SVGMatrix object (i.e. 'someElement.transform.matrix.a = 50.0', in that case 'SVGTransform').
+// The SVGTransform class stores its "AffineTransform m_matrix" object on the stack. If it would
// be stored as pointer we could just build an auto-generated JSSVG* wrapper object around it
-// and all changes to that object would automatically affect the TransformationMatrix* object stored
+// and all changes to that object would automatically affect the AffineTransform* object stored
// in the SVGTransform object. For the sake of efficiency and memory we don't pass around any
// primitive values as pointers, so a custom JS wrapper object is needed for all SVG types, that
// are internally represented by POD types (SVGRect <-> FloatRect, SVGPoint <-> FloatPoint, ...).
@@ -68,13 +71,13 @@ public:
// GetterMethod and SetterMethod are each 12 bytes. We have to pack to a size
// greater than or equal to that to avoid an alignment warning (C4121). 16 is
// the next-largest size allowed for packing, so we use that.
-#pragma pack(16)
+#pragma pack(push, 16)
#endif
template<typename PODType, typename PODTypeCreator>
class JSSVGDynamicPODTypeWrapper : public JSSVGPODTypeWrapper<PODType> {
public:
typedef PODType (PODTypeCreator::*GetterMethod)() const;
- typedef void (PODTypeCreator::*SetterMethod)(PODType);
+ typedef void (PODTypeCreator::*SetterMethod)(const PODType&);
static PassRefPtr<JSSVGDynamicPODTypeWrapper> create(PassRefPtr<PODTypeCreator> creator, GetterMethod getter, SetterMethod setter)
{
@@ -86,12 +89,10 @@ public:
return (m_creator.get()->*m_getter)();
}
- virtual void commitChange(PODType type, SVGElement* context)
+ virtual void commitChange(PODType type, DOMObject* wrapper)
{
(m_creator.get()->*m_setter)(type);
-
- if (context)
- context->svgAttributeChanged(m_creator->associatedAttributeName());
+ JSSVGContextCache::propagateSVGDOMChange(wrapper, m_creator->associatedAttributeName());
}
private:
@@ -105,15 +106,20 @@ private:
ASSERT(m_setter);
}
+ virtual ~JSSVGDynamicPODTypeWrapper();
+
// Update callbacks
RefPtr<PODTypeCreator> m_creator;
GetterMethod m_getter;
SetterMethod m_setter;
};
+#if COMPILER(MSVC)
+#pragma pack(pop)
+#endif
-// Represents a JS wrapper object for SVG POD types (not for SVGAnimated* clases). Any modification to the SVG POD
+// Represents a JS wrapper object for SVG POD types (not for SVGAnimated* classes). Any modification to the SVG POD
// types don't cause any updates unlike JSSVGDynamicPODTypeWrapper. This class is used for return values (ie. getBBox())
-// and for properties where SVG specification explicitely states, that the contents of the POD type are immutable.
+// and for properties where SVG specification explicitly states, that the contents of the POD type are immutable.
template<typename PODType>
class JSSVGStaticPODTypeWrapper : public JSSVGPODTypeWrapper<PODType> {
@@ -128,7 +134,7 @@ public:
return m_podType;
}
- virtual void commitChange(PODType type, SVGElement*)
+ virtual void commitChange(PODType type, DOMObject*)
{
m_podType = type;
}
@@ -152,10 +158,10 @@ public:
return adoptRef(new JSSVGStaticPODTypeWrapperWithPODTypeParent(type, parent));
}
- virtual void commitChange(PODType type, SVGElement* context)
+ virtual void commitChange(PODType type, DOMObject* wrapper)
{
- JSSVGStaticPODTypeWrapper<PODType>::commitChange(type, context);
- m_parentType->commitChange(ParentTypeArg(type), context);
+ JSSVGStaticPODTypeWrapper<PODType>::commitChange(type, wrapper);
+ m_parentType->commitChange(ParentTypeArg(type), wrapper);
}
private:
@@ -172,7 +178,7 @@ private:
// GetterMethod and SetterMethod are each 12 bytes. We have to pack to a size
// greater than or equal to that to avoid an alignment warning (C4121). 16 is
// the next-largest size allowed for packing, so we use that.
-#pragma pack(16)
+#pragma pack(push, 16)
#endif
template<typename PODType, typename ParentType>
class JSSVGStaticPODTypeWrapperWithParent : public JSSVGPODTypeWrapper<PODType> {
@@ -190,7 +196,7 @@ public:
return (m_parent.get()->*m_getter)();
}
- virtual void commitChange(PODType type, SVGElement*)
+ virtual void commitChange(PODType type, DOMObject*)
{
(m_parent.get()->*m_setter)(type);
}
@@ -223,7 +229,7 @@ public:
typedef SVGPODListItem<PODType> PODListItemPtrType;
typedef PODType (SVGPODListItem<PODType>::*GetterMethod)() const;
- typedef void (SVGPODListItem<PODType>::*SetterMethod)(PODType);
+ typedef void (SVGPODListItem<PODType>::*SetterMethod)(const PODType&);
static PassRefPtr<JSSVGPODTypeWrapperCreatorForList> create(PassRefPtr<PODListItemPtrType> creator, const QualifiedName& attributeName)
{
@@ -235,15 +241,13 @@ public:
return (m_creator.get()->*m_getter)();
}
- virtual void commitChange(PODType type, SVGElement* context)
+ virtual void commitChange(PODType type, DOMObject* wrapper)
{
if (!m_setter)
return;
(m_creator.get()->*m_setter)(type);
-
- if (context)
- context->svgAttributeChanged(m_associatedAttributeName);
+ JSSVGContextCache::propagateSVGDOMChange(wrapper, m_associatedAttributeName);
}
private:
@@ -269,7 +273,7 @@ private:
template<typename PODType, typename PODTypeCreator>
struct PODTypeWrapperCacheInfo {
typedef PODType (PODTypeCreator::*GetterMethod)() const;
- typedef void (PODTypeCreator::*SetterMethod)(PODType);
+ typedef void (PODTypeCreator::*SetterMethod)(const PODType&);
// Empty value
PODTypeWrapperCacheInfo()
@@ -309,6 +313,9 @@ struct PODTypeWrapperCacheInfo {
GetterMethod getter;
SetterMethod setter;
};
+#if COMPILER(MSVC)
+#pragma pack(pop)
+#endif
template<typename PODType, typename PODTypeCreator>
struct PODTypeWrapperCacheInfoHash {
@@ -351,60 +358,53 @@ struct PODTypeWrapperCacheInfoTraits : WTF::GenericHashTraits<PODTypeWrapperCach
}
};
+// Used for dynamic read-write attributes
template<typename PODType, typename PODTypeCreator>
class JSSVGDynamicPODTypeWrapperCache {
public:
typedef PODType (PODTypeCreator::*GetterMethod)() const;
- typedef void (PODTypeCreator::*SetterMethod)(PODType);
+ typedef void (PODTypeCreator::*SetterMethod)(const PODType&);
typedef PODTypeWrapperCacheInfo<PODType, PODTypeCreator> CacheInfo;
typedef PODTypeWrapperCacheInfoHash<PODType, PODTypeCreator> CacheInfoHash;
typedef PODTypeWrapperCacheInfoTraits<PODType, PODTypeCreator> CacheInfoTraits;
typedef JSSVGPODTypeWrapper<PODType> WrapperBase;
- typedef JSSVGDynamicPODTypeWrapper<PODType, PODTypeCreator> DynamicWrapper;
- typedef HashMap<CacheInfo, DynamicWrapper*, CacheInfoHash, CacheInfoTraits> DynamicWrapperHashMap;
- typedef typename DynamicWrapperHashMap::const_iterator DynamicWrapperHashMapIterator;
+ typedef JSSVGDynamicPODTypeWrapper<PODType, PODTypeCreator> Wrapper;
+ typedef HashMap<CacheInfo, Wrapper*, CacheInfoHash, CacheInfoTraits> WrapperMap;
- static DynamicWrapperHashMap& dynamicWrapperHashMap()
+ static WrapperMap& wrapperMap()
{
- DEFINE_STATIC_LOCAL(DynamicWrapperHashMap, s_dynamicWrapperHashMap, ());
- return s_dynamicWrapperHashMap;
+ DEFINE_STATIC_LOCAL(WrapperMap, s_wrapperMap, ());
+ return s_wrapperMap;
}
- // Used for readwrite attributes only
static PassRefPtr<WrapperBase> lookupOrCreateWrapper(PODTypeCreator* creator, GetterMethod getter, SetterMethod setter)
{
- DynamicWrapperHashMap& map(dynamicWrapperHashMap());
CacheInfo info(creator, getter, setter);
+ pair<typename WrapperMap::iterator, bool> result = wrapperMap().add(info, 0);
+ if (!result.second) // pre-existing entry
+ return result.first->second;
- if (map.contains(info))
- return map.get(info);
-
- RefPtr<DynamicWrapper> wrapper = DynamicWrapper::create(creator, getter, setter);
- map.set(info, wrapper.get());
+ RefPtr<Wrapper> wrapper = Wrapper::create(creator, getter, setter);
+ result.first->second = wrapper.get();
return wrapper.release();
}
- static void forgetWrapper(WrapperBase* wrapper)
+ static void forgetWrapper(PODTypeCreator* creator, GetterMethod getter, SetterMethod setter)
{
- DynamicWrapperHashMap& map(dynamicWrapperHashMap());
-
- DynamicWrapperHashMapIterator it = map.begin();
- DynamicWrapperHashMapIterator end = map.end();
-
- for (; it != end; ++it) {
- if (it->second != wrapper)
- continue;
-
- // It's guaranteed that there's just one object we need to take care of.
- map.remove(it->first);
- break;
- }
+ CacheInfo info(creator, getter, setter);
+ wrapperMap().remove(info);
}
};
-};
+template<typename PODType, typename PODTypeCreator>
+JSSVGDynamicPODTypeWrapper<PODType, PODTypeCreator>::~JSSVGDynamicPODTypeWrapper()
+{
+ JSSVGDynamicPODTypeWrapperCache<PODType, PODTypeCreator>::forgetWrapper(m_creator.get(), m_getter, m_setter);
+}
+
+} // namespace WebCore
#endif // ENABLE(SVG)
#endif // JSSVGPODTypeWrapper_h