#pragma once
#include "FloatRect.h"
#include "QualifiedName.h"
#include "SVGAnimatedPropertyImpl.h"
#include "SVGNames.h"
#include "SVGPreserveAspectRatio.h"
#include "SVGPropertyOwnerRegistry.h"
#include <wtf/HashSet.h>
namespace WebCore {
class AffineTransform;
class SVGFitToViewBox {
WTF_MAKE_NONCOPYABLE(SVGFitToViewBox);
public:
static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect, const SVGPreserveAspectRatioValue&, float viewWidth, float viewHeight);
using PropertyRegistry = SVGPropertyOwnerRegistry<SVGFitToViewBox>;
const FloatRect& viewBox() const { return m_viewBox->currentValue(); }
const SVGPreserveAspectRatioValue& preserveAspectRatio() const { return m_preserveAspectRatio->currentValue(); }
SVGAnimatedRect& viewBoxAnimated() { return m_viewBox; }
SVGAnimatedPreserveAspectRatio& preserveAspectRatioAnimated() { return m_preserveAspectRatio; }
void setViewBox(const FloatRect&);
void resetViewBox();
void setPreserveAspectRatio(const SVGPreserveAspectRatioValue& preserveAspectRatio) { m_preserveAspectRatio->setBaseValInternal(preserveAspectRatio); }
void resetPreserveAspectRatio() { m_preserveAspectRatio->setBaseValInternal({ }); }
String viewBoxString() const { return SVGPropertyTraits<FloatRect>::toString(viewBox()); }
String preserveAspectRatioString() const { return preserveAspectRatio().valueAsString(); }
bool hasValidViewBox() const { return m_isViewBoxValid; }
bool hasEmptyViewBox() const { return m_isViewBoxValid && viewBox().isEmpty(); }
protected:
SVGFitToViewBox(SVGElement* contextElement, SVGPropertyAccess = SVGPropertyAccess::ReadWrite);
static bool isKnownAttribute(const QualifiedName& attributeName) { return PropertyRegistry::isKnownAttribute(attributeName); }
void reset();
bool parseAttribute(const QualifiedName&, const AtomString&);
Optional<FloatRect> parseViewBox(StringView);
Optional<FloatRect> parseViewBox(StringParsingBuffer<LChar>&, bool validate = true);
Optional<FloatRect> parseViewBox(StringParsingBuffer<UChar>&, bool validate = true);
private:
template<typename CharacterType> Optional<FloatRect> parseViewBoxGeneric(StringParsingBuffer<CharacterType>&, bool validate = true);
Ref<SVGAnimatedRect> m_viewBox;
Ref<SVGAnimatedPreserveAspectRatio> m_preserveAspectRatio;
bool m_isViewBoxValid { false };
};
}