#ifndef SVGFitToViewBox_h
#define SVGFitToViewBox_h
#include "SVGNames.h"
#include "core/dom/Document.h"
#include "core/dom/QualifiedName.h"
#include "core/svg/SVGAnimatedPreserveAspectRatio.h"
#include "core/svg/SVGAnimatedRect.h"
#include "core/svg/SVGDocumentExtensions.h"
#include "core/svg/SVGParsingError.h"
#include "core/svg/SVGPreserveAspectRatio.h"
#include "core/svg/SVGRect.h"
#include "wtf/HashSet.h"
namespace WebCore {
class AffineTransform;
class Document;
class SVGFitToViewBox {
public:
enum PropertyMapPolicy {
PropertyMapPolicyAdd,
PropertyMapPolicySkip,
};
static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect, PassRefPtr<SVGPreserveAspectRatio>, float viewWidth, float viewHeight);
static bool isKnownAttribute(const QualifiedName&);
static void addSupportedAttributes(HashSet<QualifiedName>&);
bool parseAttribute(const QualifiedName& name, const AtomicString& value, Document& document, SVGParsingError& parseError)
{
if (name == SVGNames::viewBoxAttr) {
m_viewBox->setBaseValueAsString(value, parseError);
if (m_viewBox->baseValue()->width() < 0.0f) {
document.accessSVGExtensions().reportError("A negative value for ViewBox width is not allowed");
m_viewBox->baseValue()->setInvalid();
}
if (m_viewBox->baseValue()->height() < 0.0f) {
document.accessSVGExtensions().reportError("A negative value for ViewBox height is not allowed");
m_viewBox->baseValue()->setInvalid();
}
return true;
}
if (name == SVGNames::preserveAspectRatioAttr) {
m_preserveAspectRatio->setBaseValueAsString(value, parseError);
return true;
}
return false;
}
static SVGAnimatedRect* viewBox(SVGFitToViewBox& object) { return object.viewBox(); }
static SVGAnimatedPreserveAspectRatio* preserveAspectRatio(SVGFitToViewBox& object) { return object.preserveAspectRatio(); }
SVGAnimatedRect* viewBox() const { return m_viewBox.get(); }
bool hasEmptyViewBox() const { return m_viewBox->currentValue()->isValid() && m_viewBox->currentValue()->value().isEmpty(); }
SVGAnimatedPreserveAspectRatio* preserveAspectRatio() const { return m_preserveAspectRatio.get(); }
protected:
explicit SVGFitToViewBox(SVGElement*, PropertyMapPolicy = PropertyMapPolicyAdd);
void updateViewBox(const FloatRect&);
void clearViewBox() { m_viewBox = nullptr; }
void clearPreserveAspectRatio() { m_preserveAspectRatio = nullptr; }
private:
RefPtr<SVGAnimatedRect> m_viewBox;
RefPtr<SVGAnimatedPreserveAspectRatio> m_preserveAspectRatio;
};
}
#endif