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 THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_PRESERVE_ASPECT_RATIO_H_ 22 #define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_PRESERVE_ASPECT_RATIO_H_ 23 24 #include "third_party/blink/renderer/core/svg/properties/svg_property_helper.h" 25 #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" 26 27 namespace blink { 28 29 class AffineTransform; 30 class FloatRect; 31 class SVGPreserveAspectRatioTearOff; 32 33 class SVGPreserveAspectRatio final 34 : public SVGPropertyHelper<SVGPreserveAspectRatio> { 35 public: 36 enum SVGPreserveAspectRatioType { 37 kSvgPreserveaspectratioUnknown = 0, 38 kSvgPreserveaspectratioNone = 1, 39 kSvgPreserveaspectratioXminymin = 2, 40 kSvgPreserveaspectratioXmidymin = 3, 41 kSvgPreserveaspectratioXmaxymin = 4, 42 kSvgPreserveaspectratioXminymid = 5, 43 kSvgPreserveaspectratioXmidymid = 6, 44 kSvgPreserveaspectratioXmaxymid = 7, 45 kSvgPreserveaspectratioXminymax = 8, 46 kSvgPreserveaspectratioXmidymax = 9, 47 kSvgPreserveaspectratioXmaxymax = 10 48 }; 49 50 enum SVGMeetOrSliceType { 51 kSvgMeetorsliceUnknown = 0, 52 kSvgMeetorsliceMeet = 1, 53 kSvgMeetorsliceSlice = 2 54 }; 55 56 typedef SVGPreserveAspectRatioTearOff TearOffType; 57 58 SVGPreserveAspectRatio(); 59 60 virtual SVGPreserveAspectRatio* Clone() const; 61 62 bool operator==(const SVGPreserveAspectRatio&) const; 63 bool operator!=(const SVGPreserveAspectRatio& other) const { 64 return !operator==(other); 65 } 66 SetAlign(SVGPreserveAspectRatioType align)67 void SetAlign(SVGPreserveAspectRatioType align) { align_ = align; } Align()68 SVGPreserveAspectRatioType Align() const { return align_; } 69 SetMeetOrSlice(SVGMeetOrSliceType meet_or_slice)70 void SetMeetOrSlice(SVGMeetOrSliceType meet_or_slice) { 71 meet_or_slice_ = meet_or_slice; 72 } MeetOrSlice()73 SVGMeetOrSliceType MeetOrSlice() const { return meet_or_slice_; } 74 75 void TransformRect(FloatRect& dest_rect, FloatRect& src_rect) const; 76 77 AffineTransform ComputeTransform(float logical_x, 78 float logical_y, 79 float logical_width, 80 float logical_height, 81 float physical_width, 82 float physical_height) const; 83 84 String ValueAsString() const override; 85 SVGParsingError SetValueAsString(const String&); 86 bool Parse(const UChar*& ptr, const UChar* end, bool validate); 87 bool Parse(const LChar*& ptr, const LChar* end, bool validate); 88 89 void Add(SVGPropertyBase*, SVGElement*) override; 90 void CalculateAnimatedValue(const SVGAnimateElement&, 91 float percentage, 92 unsigned repeat_count, 93 SVGPropertyBase* from, 94 SVGPropertyBase* to, 95 SVGPropertyBase* to_at_end_of_duration_value, 96 SVGElement* context_element) override; 97 float CalculateDistance(SVGPropertyBase* to, 98 SVGElement* context_element) override; 99 ClassType()100 static AnimatedPropertyType ClassType() { 101 return kAnimatedPreserveAspectRatio; 102 } 103 104 void SetDefault(); 105 106 private: 107 template <typename CharType> 108 SVGParsingError ParseInternal(const CharType*& ptr, 109 const CharType* end, 110 bool validate); 111 112 SVGPreserveAspectRatioType align_; 113 SVGMeetOrSliceType meet_or_slice_; 114 }; 115 116 } // namespace blink 117 118 #endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_PRESERVE_ASPECT_RATIO_H_ 119