X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fthird_party%2FWebKit%2FSource%2Fcore%2Fsvg%2FSVGFitToViewBox.h;h=3620dd43f69cc9622b0f2847dc811eaed396de6f;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=ba8ca3cf8faf8452eb94add6f4328fcd3fd2dce2;hpb=172ee7c03df346ff158858709f7f6494e695e0e4;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/third_party/WebKit/Source/core/svg/SVGFitToViewBox.h b/src/third_party/WebKit/Source/core/svg/SVGFitToViewBox.h index ba8ca3c..3620dd4 100644 --- a/src/third_party/WebKit/Source/core/svg/SVGFitToViewBox.h +++ b/src/third_party/WebKit/Source/core/svg/SVGFitToViewBox.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis + * Copyright (C) 2014 Samsung Electronics. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -22,7 +23,12 @@ #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" @@ -34,40 +40,54 @@ class Document; class SVGFitToViewBox { public: - static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect, const SVGPreserveAspectRatio&, float viewWidth, float viewHeight); + enum PropertyMapPolicy { + PropertyMapPolicyAdd, + PropertyMapPolicySkip, + }; + + static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect, PassRefPtr, float viewWidth, float viewHeight); static bool isKnownAttribute(const QualifiedName&); static void addSupportedAttributes(HashSet&); - template - static bool parseAttribute(SVGElementTarget* target, const QualifiedName& name, const AtomicString& value) + bool parseAttribute(const QualifiedName& name, const AtomicString& value, Document& document, SVGParsingError& parseError) { - ASSERT(target); if (name == SVGNames::viewBoxAttr) { - FloatRect viewBox; - bool valueIsValid = !value.isNull() && parseViewBox(&target->document(), value, viewBox); - if (valueIsValid) - target->setViewBoxBaseValue(viewBox); - else - target->setViewBoxBaseValue(SVGRect(SVGRect::InvalidSVGRectTag())); + 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) { - SVGPreserveAspectRatio preserveAspectRatio; - preserveAspectRatio.parse(value); - target->setPreserveAspectRatioBaseValue(preserveAspectRatio); + m_preserveAspectRatio->setBaseValueAsString(value, parseError); return true; } - return false; } - static bool parseViewBox(Document*, const LChar*& start, const LChar* end, FloatRect& viewBox, bool validate = true); - static bool parseViewBox(Document*, const UChar*& start, const UChar* end, FloatRect& viewBox, bool validate = true); + // SVGFitToViewBox JS API. + 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 = 0; } + void clearPreserveAspectRatio() { m_preserveAspectRatio = 0; } private: - static bool parseViewBox(Document*, const String&, FloatRect&); + RefPtr m_viewBox; + RefPtr m_preserveAspectRatio; }; } // namespace WebCore