1/* 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21#ifndef SVGPreserveAspectRatio_h 22#define SVGPreserveAspectRatio_h 23 24#include "core/svg/properties/SVGProperty.h" 25 26namespace WebCore { 27 28class AffineTransform; 29class FloatRect; 30class SVGPreserveAspectRatioTearOff; 31 32class SVGPreserveAspectRatio : public SVGPropertyBase { 33public: 34 enum SVGPreserveAspectRatioType { 35 SVG_PRESERVEASPECTRATIO_UNKNOWN = 0, 36 SVG_PRESERVEASPECTRATIO_NONE = 1, 37 SVG_PRESERVEASPECTRATIO_XMINYMIN = 2, 38 SVG_PRESERVEASPECTRATIO_XMIDYMIN = 3, 39 SVG_PRESERVEASPECTRATIO_XMAXYMIN = 4, 40 SVG_PRESERVEASPECTRATIO_XMINYMID = 5, 41 SVG_PRESERVEASPECTRATIO_XMIDYMID = 6, 42 SVG_PRESERVEASPECTRATIO_XMAXYMID = 7, 43 SVG_PRESERVEASPECTRATIO_XMINYMAX = 8, 44 SVG_PRESERVEASPECTRATIO_XMIDYMAX = 9, 45 SVG_PRESERVEASPECTRATIO_XMAXYMAX = 10 46 }; 47 48 enum SVGMeetOrSliceType { 49 SVG_MEETORSLICE_UNKNOWN = 0, 50 SVG_MEETORSLICE_MEET = 1, 51 SVG_MEETORSLICE_SLICE = 2 52 }; 53 54 typedef SVGPreserveAspectRatioTearOff TearOffType; 55 56 static PassRefPtr<SVGPreserveAspectRatio> create() 57 { 58 return adoptRef(new SVGPreserveAspectRatio()); 59 } 60 61 virtual PassRefPtr<SVGPreserveAspectRatio> clone() const; 62 virtual PassRefPtr<SVGPropertyBase> cloneForAnimation(const String&) const OVERRIDE; 63 64 bool operator==(const SVGPreserveAspectRatio&) const; 65 bool operator!=(const SVGPreserveAspectRatio& other) const { return !operator==(other); } 66 67 void setAlign(SVGPreserveAspectRatioType align) { m_align = align; } 68 SVGPreserveAspectRatioType align() const { return m_align; } 69 70 void setMeetOrSlice(SVGMeetOrSliceType meetOrSlice) { m_meetOrSlice = meetOrSlice; } 71 SVGMeetOrSliceType meetOrSlice() const { return m_meetOrSlice; } 72 73 void transformRect(FloatRect& destRect, FloatRect& srcRect); 74 75 AffineTransform getCTM(float logicX, float logicY, 76 float logicWidth, float logicHeight, 77 float physWidth, float physHeight) const; 78 79 virtual String valueAsString() const OVERRIDE; 80 virtual void setValueAsString(const String&, ExceptionState&); 81 bool parse(const UChar*& ptr, const UChar* end, bool validate); 82 bool parse(const LChar*& ptr, const LChar* end, bool validate); 83 84 virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) OVERRIDE; 85 virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBase> to, PassRefPtr<SVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement) OVERRIDE; 86 virtual float calculateDistance(PassRefPtr<SVGPropertyBase> to, SVGElement* contextElement) OVERRIDE; 87 88 static AnimatedPropertyType classType() { return AnimatedPreserveAspectRatio; } 89 90private: 91 SVGPreserveAspectRatio(); 92 93 void setDefault(); 94 template<typename CharType> 95 bool parseInternal(const CharType*& ptr, const CharType* end, bool validate); 96 97 SVGPreserveAspectRatioType m_align; 98 SVGMeetOrSliceType m_meetOrSlice; 99}; 100 101inline PassRefPtr<SVGPreserveAspectRatio> toSVGPreserveAspectRatio(PassRefPtr<SVGPropertyBase> passBase) 102{ 103 RefPtr<SVGPropertyBase> base = passBase; 104 ASSERT(base->type() == SVGPreserveAspectRatio::classType()); 105 return static_pointer_cast<SVGPreserveAspectRatio>(base.release()); 106} 107 108} // namespace WebCore 109 110#endif // SVGPreserveAspectRatio_h 111