OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
5 * Copyright (C) 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2008 Apple Inc. All rights reserved. |
6 * Copyright (C) Research In Motion Limited 2012. All rights reserved. | 6 * Copyright (C) Research In Motion Limited 2012. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
12 * | 12 * |
13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 * Library General Public License for more details. | 16 * Library General Public License for more details. |
17 * | 17 * |
18 * You should have received a copy of the GNU Library General Public License | 18 * You should have received a copy of the GNU Library General Public License |
19 * along with this library; see the file COPYING.LIB. If not, write to | 19 * along with this library; see the file COPYING.LIB. If not, write to |
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
22 */ | 22 */ |
23 | 23 |
24 #include "core/svg/SVGTransformList.h" | 24 #include "core/svg/SVGTransformList.h" |
25 | 25 |
26 #include "core/SVGNames.h" | 26 #include "core/SVGNames.h" |
| 27 #include "core/css/CSSFunctionValue.h" |
| 28 #include "core/css/CSSIdentifierValue.h" |
| 29 #include "core/css/CSSPrimitiveValue.h" |
| 30 #include "core/css/CSSValueList.h" |
27 #include "core/svg/SVGParserUtilities.h" | 31 #include "core/svg/SVGParserUtilities.h" |
28 #include "core/svg/SVGTransformDistance.h" | 32 #include "core/svg/SVGTransformDistance.h" |
29 #include "wtf/text/ParsingUtilities.h" | 33 #include "wtf/text/ParsingUtilities.h" |
30 #include "wtf/text/StringBuilder.h" | 34 #include "wtf/text/StringBuilder.h" |
31 #include "wtf/text/WTFString.h" | 35 #include "wtf/text/WTFString.h" |
32 | 36 |
33 namespace blink { | 37 namespace blink { |
34 | 38 |
35 SVGTransformList::SVGTransformList() {} | 39 SVGTransformList::SVGTransformList() {} |
36 | 40 |
(...skipping 14 matching lines...) Expand all Loading... |
51 ConstIterator it = begin(); | 55 ConstIterator it = begin(); |
52 ConstIterator itEnd = end(); | 56 ConstIterator itEnd = end(); |
53 for (; it != itEnd; ++it) | 57 for (; it != itEnd; ++it) |
54 result *= it->matrix(); | 58 result *= it->matrix(); |
55 | 59 |
56 return true; | 60 return true; |
57 } | 61 } |
58 | 62 |
59 namespace { | 63 namespace { |
60 | 64 |
| 65 CSSValueID mapTransformFunction(const SVGTransform& transform) { |
| 66 switch (transform.transformType()) { |
| 67 case kSvgTransformMatrix: |
| 68 return CSSValueMatrix; |
| 69 case kSvgTransformTranslate: |
| 70 return CSSValueTranslate; |
| 71 case kSvgTransformScale: |
| 72 return CSSValueScale; |
| 73 case kSvgTransformRotate: |
| 74 return CSSValueRotate; |
| 75 case kSvgTransformSkewx: |
| 76 return CSSValueSkewX; |
| 77 case kSvgTransformSkewy: |
| 78 return CSSValueSkewY; |
| 79 case kSvgTransformUnknown: |
| 80 default: |
| 81 NOTREACHED(); |
| 82 } |
| 83 return CSSValueInvalid; |
| 84 } |
| 85 |
| 86 CSSValue* createTransformCSSValue(const SVGTransform& transform) { |
| 87 CSSValueID functionId = mapTransformFunction(transform); |
| 88 CSSFunctionValue* transformValue = CSSFunctionValue::create(functionId); |
| 89 switch (functionId) { |
| 90 case CSSValueRotate: { |
| 91 transformValue->append(*CSSPrimitiveValue::create( |
| 92 transform.angle(), CSSPrimitiveValue::UnitType::Degrees)); |
| 93 FloatPoint rotationOrigin = transform.rotationCenter(); |
| 94 if (!toFloatSize(rotationOrigin).isZero()) { |
| 95 transformValue->append(*CSSPrimitiveValue::create( |
| 96 rotationOrigin.x(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 97 transformValue->append(*CSSPrimitiveValue::create( |
| 98 rotationOrigin.y(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 99 } |
| 100 break; |
| 101 } |
| 102 case CSSValueSkewX: |
| 103 case CSSValueSkewY: |
| 104 transformValue->append(*CSSPrimitiveValue::create( |
| 105 transform.angle(), CSSPrimitiveValue::UnitType::Degrees)); |
| 106 break; |
| 107 case CSSValueMatrix: |
| 108 transformValue->append(*CSSPrimitiveValue::create( |
| 109 transform.matrix().a(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 110 transformValue->append(*CSSPrimitiveValue::create( |
| 111 transform.matrix().b(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 112 transformValue->append(*CSSPrimitiveValue::create( |
| 113 transform.matrix().c(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 114 transformValue->append(*CSSPrimitiveValue::create( |
| 115 transform.matrix().d(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 116 transformValue->append(*CSSPrimitiveValue::create( |
| 117 transform.matrix().e(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 118 transformValue->append(*CSSPrimitiveValue::create( |
| 119 transform.matrix().f(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 120 break; |
| 121 case CSSValueScale: |
| 122 transformValue->append(*CSSPrimitiveValue::create( |
| 123 transform.matrix().a(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 124 transformValue->append(*CSSPrimitiveValue::create( |
| 125 transform.matrix().d(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 126 break; |
| 127 case CSSValueTranslate: |
| 128 transformValue->append(*CSSPrimitiveValue::create( |
| 129 transform.matrix().e(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 130 transformValue->append(*CSSPrimitiveValue::create( |
| 131 transform.matrix().f(), CSSPrimitiveValue::UnitType::UserUnits)); |
| 132 break; |
| 133 default: |
| 134 NOTREACHED(); |
| 135 } |
| 136 return transformValue; |
| 137 } |
| 138 |
| 139 } // namespace |
| 140 |
| 141 const CSSValue* SVGTransformList::cssValue() const { |
| 142 // Build a structure of CSSValues from the list we have, mapping functions as |
| 143 // appropriate. |
| 144 // TODO(fs): Eventually we'd want to support the exact same syntax here as in |
| 145 // the property, but there are some issues (crbug.com/577219 for instance) |
| 146 // that complicates things. |
| 147 size_t length = this->length(); |
| 148 if (!length) |
| 149 return CSSIdentifierValue::create(CSSValueNone); |
| 150 CSSValueList* list = CSSValueList::createSpaceSeparated(); |
| 151 if (length == 1) { |
| 152 list->append(*createTransformCSSValue(*at(0))); |
| 153 return list; |
| 154 } |
| 155 ConstIterator it = begin(); |
| 156 ConstIterator itEnd = end(); |
| 157 for (; it != itEnd; ++it) |
| 158 list->append(*createTransformCSSValue(**it)); |
| 159 return list; |
| 160 } |
| 161 |
| 162 namespace { |
| 163 |
61 template <typename CharType> | 164 template <typename CharType> |
62 SVGTransformType parseAndSkipTransformType(const CharType*& ptr, | 165 SVGTransformType parseAndSkipTransformType(const CharType*& ptr, |
63 const CharType* end) { | 166 const CharType* end) { |
64 if (ptr >= end) | 167 if (ptr >= end) |
65 return kSvgTransformUnknown; | 168 return kSvgTransformUnknown; |
66 | 169 |
67 if (*ptr == 's') { | 170 if (*ptr == 's') { |
68 if (skipToken(ptr, end, "skewX")) | 171 if (skipToken(ptr, end, "skewX")) |
69 return kSvgTransformSkewx; | 172 return kSvgTransformSkewx; |
70 if (skipToken(ptr, end, "skewY")) | 173 if (skipToken(ptr, end, "skewY")) |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 | 525 |
423 // Spec: http://www.w3.org/TR/SVG/animate.html#complexDistances | 526 // Spec: http://www.w3.org/TR/SVG/animate.html#complexDistances |
424 // Paced animations assume a notion of distance between the various animation | 527 // Paced animations assume a notion of distance between the various animation |
425 // values defined by the 'to', 'from', 'by' and 'values' attributes. Distance | 528 // values defined by the 'to', 'from', 'by' and 'values' attributes. Distance |
426 // is defined only for scalar types (such as <length>), colors and the subset | 529 // is defined only for scalar types (such as <length>), colors and the subset |
427 // of transformation types that are supported by 'animateTransform'. | 530 // of transformation types that are supported by 'animateTransform'. |
428 return SVGTransformDistance(at(0), toList->at(0)).distance(); | 531 return SVGTransformDistance(at(0), toList->at(0)).distance(); |
429 } | 532 } |
430 | 533 |
431 } // namespace blink | 534 } // namespace blink |
OLD | NEW |