OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/animation/LengthListPropertyFunctions.h" | 5 #include "core/animation/LengthListPropertyFunctions.h" |
6 | 6 |
7 #include "core/style/ComputedStyle.h" | 7 #include "core/style/ComputedStyle.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 { | 80 { |
81 switch (property) { | 81 switch (property) { |
82 case CSSPropertyBackgroundPositionX: | 82 case CSSPropertyBackgroundPositionX: |
83 case CSSPropertyBackgroundPositionY: | 83 case CSSPropertyBackgroundPositionY: |
84 case CSSPropertyObjectPosition: | 84 case CSSPropertyObjectPosition: |
85 case CSSPropertyPerspectiveOrigin: | 85 case CSSPropertyPerspectiveOrigin: |
86 case CSSPropertyWebkitMaskPositionX: | 86 case CSSPropertyWebkitMaskPositionX: |
87 case CSSPropertyWebkitMaskPositionY: | 87 case CSSPropertyWebkitMaskPositionY: |
88 return ValueRangeAll; | 88 return ValueRangeAll; |
89 | 89 |
| 90 case CSSPropertyBorderBottomLeftRadius: |
| 91 case CSSPropertyBorderBottomRightRadius: |
| 92 case CSSPropertyBorderTopLeftRadius: |
| 93 case CSSPropertyBorderTopRightRadius: |
90 case CSSPropertyStrokeDasharray: | 94 case CSSPropertyStrokeDasharray: |
91 return ValueRangeNonNegative; | 95 return ValueRangeNonNegative; |
92 | 96 |
93 default: | 97 default: |
94 ASSERT_NOT_REACHED(); | 98 ASSERT_NOT_REACHED(); |
95 return ValueRangeAll; | 99 return ValueRangeAll; |
96 } | 100 } |
97 } | 101 } |
98 | 102 |
99 Vector<Length> LengthListPropertyFunctions::getInitialLengthList(CSSPropertyID p
roperty) | 103 Vector<Length> LengthListPropertyFunctions::getInitialLengthList(CSSPropertyID p
roperty) |
100 { | 104 { |
101 return getLengthList(property, *ComputedStyle::initialStyle()); | 105 return getLengthList(property, *ComputedStyle::initialStyle()); |
102 } | 106 } |
103 | 107 |
| 108 static Vector<Length> toVector(const LengthPoint& point) |
| 109 { |
| 110 Vector<Length> result(2); |
| 111 result[0] = point.x(); |
| 112 result[1] = point.y(); |
| 113 return result; |
| 114 } |
| 115 |
| 116 static Vector<Length> toVector(const LengthSize& size) |
| 117 { |
| 118 Vector<Length> result(2); |
| 119 result[0] = size.width(); |
| 120 result[1] = size.height(); |
| 121 return result; |
| 122 } |
| 123 |
104 Vector<Length> LengthListPropertyFunctions::getLengthList(CSSPropertyID property
, const ComputedStyle& style) | 124 Vector<Length> LengthListPropertyFunctions::getLengthList(CSSPropertyID property
, const ComputedStyle& style) |
105 { | 125 { |
106 Vector<Length> result; | |
107 | |
108 switch (property) { | 126 switch (property) { |
109 case CSSPropertyStrokeDasharray: | 127 case CSSPropertyStrokeDasharray: { |
110 if (style.strokeDashArray()) | 128 if (style.strokeDashArray()) |
111 result.appendVector(style.strokeDashArray()->vector()); | 129 return style.strokeDashArray()->vector(); |
112 return result; | 130 return Vector<Length>(); |
| 131 } |
113 case CSSPropertyObjectPosition: | 132 case CSSPropertyObjectPosition: |
114 result.append(style.objectPosition().x()); | 133 return toVector(style.objectPosition()); |
115 result.append(style.objectPosition().y()); | |
116 return result; | |
117 case CSSPropertyPerspectiveOrigin: | 134 case CSSPropertyPerspectiveOrigin: |
118 result.append(style.perspectiveOrigin().x()); | 135 return toVector(style.perspectiveOrigin()); |
119 result.append(style.perspectiveOrigin().y()); | 136 case CSSPropertyBorderBottomLeftRadius: |
120 return result; | 137 return toVector(style.borderBottomLeftRadius()); |
| 138 case CSSPropertyBorderBottomRightRadius: |
| 139 return toVector(style.borderBottomRightRadius()); |
| 140 case CSSPropertyBorderTopLeftRadius: |
| 141 return toVector(style.borderTopLeftRadius()); |
| 142 case CSSPropertyBorderTopRightRadius: |
| 143 return toVector(style.borderTopRightRadius()); |
121 default: | 144 default: |
122 break; | 145 break; |
123 } | 146 } |
124 | 147 |
| 148 Vector<Length> result; |
125 const FillLayer* fillLayer = getFillLayer(property, style); | 149 const FillLayer* fillLayer = getFillLayer(property, style); |
126 FillLayerMethods fillLayerMethods(property); | 150 FillLayerMethods fillLayerMethods(property); |
127 while (fillLayer && (fillLayer->*fillLayerMethods.isSet)()) { | 151 while (fillLayer && (fillLayer->*fillLayerMethods.isSet)()) { |
128 result.append((fillLayer->*fillLayerMethods.get)()); | 152 result.append((fillLayer->*fillLayerMethods.get)()); |
129 fillLayer = fillLayer->next(); | 153 fillLayer = fillLayer->next(); |
130 } | 154 } |
131 return result; | 155 return result; |
132 } | 156 } |
133 | 157 |
| 158 static LengthPoint pointFromVector(const Vector<Length>& list) |
| 159 { |
| 160 ASSERT(list.size() == 2); |
| 161 return LengthPoint(list[0], list[1]); |
| 162 } |
| 163 |
| 164 static LengthSize sizeFromVector(const Vector<Length>& list) |
| 165 { |
| 166 ASSERT(list.size() == 2); |
| 167 return LengthSize(list[0], list[1]); |
| 168 } |
| 169 |
134 void LengthListPropertyFunctions::setLengthList(CSSPropertyID property, Computed
Style& style, Vector<Length>&& lengthList) | 170 void LengthListPropertyFunctions::setLengthList(CSSPropertyID property, Computed
Style& style, Vector<Length>&& lengthList) |
135 { | 171 { |
136 switch (property) { | 172 switch (property) { |
137 case CSSPropertyStrokeDasharray: | 173 case CSSPropertyStrokeDasharray: |
138 style.setStrokeDashArray(lengthList.isEmpty() ? nullptr : RefVector<Leng
th>::create(std::move(lengthList))); | 174 style.setStrokeDashArray(lengthList.isEmpty() ? nullptr : RefVector<Leng
th>::create(std::move(lengthList))); |
139 return; | 175 return; |
140 case CSSPropertyObjectPosition: | 176 case CSSPropertyObjectPosition: |
141 style.setObjectPosition(LengthPoint(lengthList[0], lengthList[1])); | 177 style.setObjectPosition(pointFromVector(lengthList)); |
142 return; | 178 return; |
143 case CSSPropertyPerspectiveOrigin: | 179 case CSSPropertyPerspectiveOrigin: |
144 style.setPerspectiveOrigin(LengthPoint(lengthList[0], lengthList[1])); | 180 style.setPerspectiveOrigin(pointFromVector(lengthList)); |
| 181 return; |
| 182 case CSSPropertyBorderBottomLeftRadius: |
| 183 style.setBorderBottomLeftRadius(sizeFromVector(lengthList)); |
| 184 return; |
| 185 case CSSPropertyBorderBottomRightRadius: |
| 186 style.setBorderBottomRightRadius(sizeFromVector(lengthList)); |
| 187 return; |
| 188 case CSSPropertyBorderTopLeftRadius: |
| 189 style.setBorderTopLeftRadius(sizeFromVector(lengthList)); |
| 190 return; |
| 191 case CSSPropertyBorderTopRightRadius: |
| 192 style.setBorderTopRightRadius(sizeFromVector(lengthList)); |
145 return; | 193 return; |
146 default: | 194 default: |
147 break; | 195 break; |
148 } | 196 } |
149 | 197 |
150 FillLayer* fillLayer = accessFillLayer(property, style); | 198 FillLayer* fillLayer = accessFillLayer(property, style); |
151 FillLayer* prev = nullptr; | 199 FillLayer* prev = nullptr; |
152 FillLayerMethods fillLayerMethods(property); | 200 FillLayerMethods fillLayerMethods(property); |
153 for (size_t i = 0; i < lengthList.size(); i++) { | 201 for (size_t i = 0; i < lengthList.size(); i++) { |
154 if (!fillLayer) | 202 if (!fillLayer) |
155 fillLayer = prev->ensureNext(); | 203 fillLayer = prev->ensureNext(); |
156 (fillLayer->*fillLayerMethods.set)(lengthList[i]); | 204 (fillLayer->*fillLayerMethods.set)(lengthList[i]); |
157 prev = fillLayer; | 205 prev = fillLayer; |
158 fillLayer = fillLayer->next(); | 206 fillLayer = fillLayer->next(); |
159 } | 207 } |
160 while (fillLayer) { | 208 while (fillLayer) { |
161 (fillLayer->*fillLayerMethods.clear)(); | 209 (fillLayer->*fillLayerMethods.clear)(); |
162 fillLayer = fillLayer->next(); | 210 fillLayer = fillLayer->next(); |
163 } | 211 } |
164 } | 212 } |
165 | 213 |
166 } // namespace blink | 214 } // namespace blink |
OLD | NEW |