summaryrefslogtreecommitdiff
path: root/Source/WebCore/svg/SVGViewSpec.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/svg/SVGViewSpec.cpp')
-rw-r--r--Source/WebCore/svg/SVGViewSpec.cpp108
1 files changed, 45 insertions, 63 deletions
diff --git a/Source/WebCore/svg/SVGViewSpec.cpp b/Source/WebCore/svg/SVGViewSpec.cpp
index ee2510c10..2b467db22 100644
--- a/Source/WebCore/svg/SVGViewSpec.cpp
+++ b/Source/WebCore/svg/SVGViewSpec.cpp
@@ -18,16 +18,15 @@
*/
#include "config.h"
-
-#if ENABLE(SVG)
#include "SVGViewSpec.h"
#include "Document.h"
#include "SVGAnimatedTransformList.h"
+#include "SVGElement.h"
#include "SVGFitToViewBox.h"
#include "SVGNames.h"
#include "SVGParserUtilities.h"
-#include "SVGSVGElement.h"
+#include "SVGTransformList.h"
#include "SVGTransformable.h"
namespace WebCore {
@@ -35,7 +34,7 @@ namespace WebCore {
// Define custom animated property 'viewBox'.
const SVGPropertyInfo* SVGViewSpec::viewBoxPropertyInfo()
{
- static const SVGPropertyInfo* s_propertyInfo = 0;
+ static const SVGPropertyInfo* s_propertyInfo = nullptr;
if (!s_propertyInfo) {
s_propertyInfo = new SVGPropertyInfo(AnimatedRect,
PropertyIsReadOnly,
@@ -50,7 +49,7 @@ const SVGPropertyInfo* SVGViewSpec::viewBoxPropertyInfo()
// Define custom animated property 'preserveAspectRatio'.
const SVGPropertyInfo* SVGViewSpec::preserveAspectRatioPropertyInfo()
{
- static const SVGPropertyInfo* s_propertyInfo = 0;
+ static const SVGPropertyInfo* s_propertyInfo = nullptr;
if (!s_propertyInfo) {
s_propertyInfo = new SVGPropertyInfo(AnimatedPreserveAspectRatio,
PropertyIsReadOnly,
@@ -66,7 +65,7 @@ const SVGPropertyInfo* SVGViewSpec::preserveAspectRatioPropertyInfo()
// Define custom non-animated property 'transform'.
const SVGPropertyInfo* SVGViewSpec::transformPropertyInfo()
{
- static const SVGPropertyInfo* s_propertyInfo = 0;
+ static const SVGPropertyInfo* s_propertyInfo = nullptr;
if (!s_propertyInfo) {
s_propertyInfo = new SVGPropertyInfo(AnimatedTransformList,
PropertyIsReadOnly,
@@ -78,125 +77,109 @@ const SVGPropertyInfo* SVGViewSpec::transformPropertyInfo()
return s_propertyInfo;
}
-SVGViewSpec::SVGViewSpec(SVGElement* contextElement)
- : m_contextElement(contextElement)
- , m_zoomAndPan(SVGZoomAndPanMagnify)
+SVGViewSpec::SVGViewSpec(SVGElement& contextElement)
+ : m_contextElement(&contextElement)
{
- ASSERT(m_contextElement);
}
const AtomicString& SVGViewSpec::viewBoxIdentifier()
{
- DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecViewBoxAttribute", AtomicString::ConstructFromLiteral));
+ static NeverDestroyed<AtomicString> s_identifier("SVGViewSpecViewBoxAttribute", AtomicString::ConstructFromLiteral);
return s_identifier;
}
const AtomicString& SVGViewSpec::preserveAspectRatioIdentifier()
{
- DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecPreserveAspectRatioAttribute", AtomicString::ConstructFromLiteral));
+ static NeverDestroyed<AtomicString> s_identifier("SVGViewSpecPreserveAspectRatioAttribute", AtomicString::ConstructFromLiteral);
return s_identifier;
}
const AtomicString& SVGViewSpec::transformIdentifier()
{
- DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecTransformAttribute", AtomicString::ConstructFromLiteral));
+ static NeverDestroyed<AtomicString> s_identifier("SVGViewSpecTransformAttribute", AtomicString::ConstructFromLiteral);
return s_identifier;
}
-void SVGViewSpec::setZoomAndPan(unsigned short, ExceptionCode& ec)
+ExceptionOr<void> SVGViewSpec::setZoomAndPan(unsigned short)
{
// SVGViewSpec and all of its content is read-only.
- ec = NO_MODIFICATION_ALLOWED_ERR;
-}
-
-void SVGViewSpec::setTransformString(const String& transform)
-{
- if (!m_contextElement)
- return;
-
- SVGTransformList newList;
- newList.parse(transform);
-
- if (SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGElement, SVGAnimatedTransformList>(m_contextElement, transformPropertyInfo()))
- static_cast<SVGAnimatedTransformList*>(wrapper)->detachListWrappers(newList.size());
-
- m_transform = newList;
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
}
String SVGViewSpec::transformString() const
{
- return SVGPropertyTraits<SVGTransformList>::toString(m_transform);
+ return SVGPropertyTraits<SVGTransformListValues>::toString(m_transform);
}
String SVGViewSpec::viewBoxString() const
{
- return SVGPropertyTraits<FloatRect>::toString(viewBoxBaseValue());
+ return SVGPropertyTraits<FloatRect>::toString(m_viewBox);
}
String SVGViewSpec::preserveAspectRatioString() const
{
- return SVGPropertyTraits<SVGPreserveAspectRatio>::toString(preserveAspectRatioBaseValue());
+ return SVGPropertyTraits<SVGPreserveAspectRatioValue>::toString(m_preserveAspectRatio);
}
SVGElement* SVGViewSpec::viewTarget() const
{
if (!m_contextElement)
- return 0;
- Element* element = m_contextElement->treeScope().getElementById(m_viewTargetString);
- if (!element || !element->isSVGElement())
- return 0;
- return toSVGElement(element);
+ return nullptr;
+ auto* element = m_contextElement->treeScope().getElementById(m_viewTargetString);
+ if (!is<SVGElement>(element))
+ return nullptr;
+ return downcast<SVGElement>(element);
}
-SVGTransformListPropertyTearOff* SVGViewSpec::transform()
+RefPtr<SVGTransformList> SVGViewSpec::transform()
{
if (!m_contextElement)
- return 0;
+ return nullptr;
// Return the animVal here, as its readonly by default - which is exactly what we want here.
- return static_cast<SVGTransformListPropertyTearOff*>(static_pointer_cast<SVGAnimatedTransformList>(lookupOrCreateTransformWrapper(this))->animVal());
+ return static_reference_cast<SVGAnimatedTransformList>(lookupOrCreateTransformWrapper(this))->animVal();
}
-PassRefPtr<SVGAnimatedRect> SVGViewSpec::viewBoxAnimated()
+RefPtr<SVGAnimatedRect> SVGViewSpec::viewBoxAnimated()
{
if (!m_contextElement)
- return 0;
- return static_pointer_cast<SVGAnimatedRect>(lookupOrCreateViewBoxWrapper(this));
+ return nullptr;
+ return static_reference_cast<SVGAnimatedRect>(lookupOrCreateViewBoxWrapper(this));
}
-PassRefPtr<SVGAnimatedPreserveAspectRatio> SVGViewSpec::preserveAspectRatioAnimated()
+RefPtr<SVGAnimatedPreserveAspectRatio> SVGViewSpec::preserveAspectRatioAnimated()
{
if (!m_contextElement)
- return 0;
- return static_pointer_cast<SVGAnimatedPreserveAspectRatio>(lookupOrCreatePreserveAspectRatioWrapper(this));
+ return nullptr;
+ return static_reference_cast<SVGAnimatedPreserveAspectRatio>(lookupOrCreatePreserveAspectRatioWrapper(this));
}
-PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreateViewBoxWrapper(SVGViewSpec* ownerType)
+Ref<SVGAnimatedProperty> SVGViewSpec::lookupOrCreateViewBoxWrapper(SVGViewSpec* ownerType)
{
ASSERT(ownerType);
- ASSERT(ownerType->contextElement());
- return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedRect, FloatRect>(ownerType->contextElement(), viewBoxPropertyInfo(), ownerType->m_viewBox);
+ ASSERT(ownerType->m_contextElement);
+ return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedRect, FloatRect>(ownerType->m_contextElement, viewBoxPropertyInfo(), ownerType->m_viewBox);
}
-PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreatePreserveAspectRatioWrapper(SVGViewSpec* ownerType)
+Ref<SVGAnimatedProperty> SVGViewSpec::lookupOrCreatePreserveAspectRatioWrapper(SVGViewSpec* ownerType)
{
ASSERT(ownerType);
- ASSERT(ownerType->contextElement());
- return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedPreserveAspectRatio, SVGPreserveAspectRatio>(ownerType->contextElement(), preserveAspectRatioPropertyInfo(), ownerType->m_preserveAspectRatio);
+ ASSERT(ownerType->m_contextElement);
+ return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedPreserveAspectRatio, SVGPreserveAspectRatioValue>(ownerType->m_contextElement, preserveAspectRatioPropertyInfo(), ownerType->m_preserveAspectRatio);
}
-PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreateTransformWrapper(SVGViewSpec* ownerType)
+Ref<SVGAnimatedProperty> SVGViewSpec::lookupOrCreateTransformWrapper(SVGViewSpec* ownerType)
{
ASSERT(ownerType);
- ASSERT(ownerType->contextElement());
- return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedTransformList, SVGTransformList>(ownerType->contextElement(), transformPropertyInfo(), ownerType->m_transform);
+ ASSERT(ownerType->m_contextElement);
+ return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedTransformList, SVGTransformListValues>(ownerType->m_contextElement, transformPropertyInfo(), ownerType->m_transform);
}
void SVGViewSpec::reset()
{
m_zoomAndPan = SVGZoomAndPanMagnify;
m_transform.clear();
- m_viewBox = FloatRect();
- m_preserveAspectRatio = SVGPreserveAspectRatio();
+ m_viewBox = { };
+ m_preserveAspectRatio = { };
m_viewTargetString = emptyString();
}
@@ -209,7 +192,8 @@ static const UChar viewTargetSpec[] = {'v', 'i', 'e', 'w', 'T', 'a', 'r', 'g',
bool SVGViewSpec::parseViewSpec(const String& viewSpec)
{
- const UChar* currViewSpec = viewSpec.deprecatedCharacters();
+ auto upconvertedCharacters = StringView(viewSpec).upconvertedCharacters();
+ const UChar* currViewSpec = upconvertedCharacters;
const UChar* end = currViewSpec + viewSpec.length();
if (currViewSpec >= end || !m_contextElement)
@@ -243,7 +227,7 @@ bool SVGViewSpec::parseViewSpec(const String& viewSpec)
currViewSpec++;
if (currViewSpec >= end)
return false;
- setViewTargetString(String(viewTargetStart, currViewSpec - viewTargetStart));
+ m_viewTargetString = String(viewTargetStart, currViewSpec - viewTargetStart);
currViewSpec++;
} else
return false;
@@ -253,7 +237,7 @@ bool SVGViewSpec::parseViewSpec(const String& viewSpec)
if (currViewSpec >= end || *currViewSpec != '(')
return false;
currViewSpec++;
- if (!parseZoomAndPan(currViewSpec, end, m_zoomAndPan))
+ if (!parse(currViewSpec, end, m_zoomAndPan))
return false;
if (currViewSpec >= end || *currViewSpec != ')')
return false;
@@ -264,7 +248,7 @@ bool SVGViewSpec::parseViewSpec(const String& viewSpec)
if (currViewSpec >= end || *currViewSpec != '(')
return false;
currViewSpec++;
- SVGPreserveAspectRatio preserveAspectRatio;
+ SVGPreserveAspectRatioValue preserveAspectRatio;
if (!preserveAspectRatio.parse(currViewSpec, end, false))
return false;
setPreserveAspectRatioBaseValue(preserveAspectRatio);
@@ -295,5 +279,3 @@ bool SVGViewSpec::parseViewSpec(const String& viewSpec)
}
}
-
-#endif // ENABLE(SVG)