Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: Source/core/css/resolver/TransformBuilder.cpp

Issue 333163004: Remove explicit bounds check from CSSValueList::item (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: address comment Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/resolver/StyleBuilderCustom.cpp ('k') | Source/core/svg/SVGFontFaceElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 if (!currValue->isTransformValue()) 94 if (!currValue->isTransformValue())
95 continue; 95 continue;
96 96
97 CSSTransformValue* transformValue = toCSSTransformValue(i.value()); 97 CSSTransformValue* transformValue = toCSSTransformValue(i.value());
98 if (!transformValue->length()) 98 if (!transformValue->length())
99 continue; 99 continue;
100 100
101 bool haveNonPrimitiveValue = false; 101 bool haveNonPrimitiveValue = false;
102 for (unsigned j = 0; j < transformValue->length(); ++j) { 102 for (unsigned j = 0; j < transformValue->length(); ++j) {
103 if (!transformValue->itemWithoutBoundsCheck(j)->isPrimitiveValue()) { 103 if (!transformValue->item(j)->isPrimitiveValue()) {
104 haveNonPrimitiveValue = true; 104 haveNonPrimitiveValue = true;
105 break; 105 break;
106 } 106 }
107 } 107 }
108 if (haveNonPrimitiveValue) 108 if (haveNonPrimitiveValue)
109 continue; 109 continue;
110 110
111 CSSPrimitiveValue* firstValue = toCSSPrimitiveValue(transformValue->item WithoutBoundsCheck(0)); 111 CSSPrimitiveValue* firstValue = toCSSPrimitiveValue(transformValue->item (0));
112 112
113 switch (transformValue->operationType()) { 113 switch (transformValue->operationType()) {
114 case CSSTransformValue::ScaleTransformOperation: 114 case CSSTransformValue::ScaleTransformOperation:
115 case CSSTransformValue::ScaleXTransformOperation: 115 case CSSTransformValue::ScaleXTransformOperation:
116 case CSSTransformValue::ScaleYTransformOperation: { 116 case CSSTransformValue::ScaleYTransformOperation: {
117 double sx = 1.0; 117 double sx = 1.0;
118 double sy = 1.0; 118 double sy = 1.0;
119 if (transformValue->operationType() == CSSTransformValue::ScaleYTran sformOperation) 119 if (transformValue->operationType() == CSSTransformValue::ScaleYTran sformOperation)
120 sy = firstValue->getDoubleValue(); 120 sy = firstValue->getDoubleValue();
121 else { 121 else {
122 sx = firstValue->getDoubleValue(); 122 sx = firstValue->getDoubleValue();
123 if (transformValue->operationType() != CSSTransformValue::ScaleX TransformOperation) { 123 if (transformValue->operationType() != CSSTransformValue::ScaleX TransformOperation) {
124 if (transformValue->length() > 1) { 124 if (transformValue->length() > 1) {
125 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(tra nsformValue->itemWithoutBoundsCheck(1)); 125 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(tra nsformValue->item(1));
126 sy = secondValue->getDoubleValue(); 126 sy = secondValue->getDoubleValue();
127 } else 127 } else
128 sy = sx; 128 sy = sx;
129 } 129 }
130 } 130 }
131 operations.operations().append(ScaleTransformOperation::create(sx, s y, 1.0, getTransformOperationType(transformValue->operationType()))); 131 operations.operations().append(ScaleTransformOperation::create(sx, s y, 1.0, getTransformOperationType(transformValue->operationType())));
132 break; 132 break;
133 } 133 }
134 case CSSTransformValue::ScaleZTransformOperation: 134 case CSSTransformValue::ScaleZTransformOperation:
135 case CSSTransformValue::Scale3DTransformOperation: { 135 case CSSTransformValue::Scale3DTransformOperation: {
136 double sx = 1.0; 136 double sx = 1.0;
137 double sy = 1.0; 137 double sy = 1.0;
138 double sz = 1.0; 138 double sz = 1.0;
139 if (transformValue->operationType() == CSSTransformValue::ScaleZTran sformOperation) 139 if (transformValue->operationType() == CSSTransformValue::ScaleZTran sformOperation)
140 sz = firstValue->getDoubleValue(); 140 sz = firstValue->getDoubleValue();
141 else if (transformValue->operationType() == CSSTransformValue::Scale YTransformOperation) 141 else if (transformValue->operationType() == CSSTransformValue::Scale YTransformOperation)
142 sy = firstValue->getDoubleValue(); 142 sy = firstValue->getDoubleValue();
143 else { 143 else {
144 sx = firstValue->getDoubleValue(); 144 sx = firstValue->getDoubleValue();
145 if (transformValue->operationType() != CSSTransformValue::ScaleX TransformOperation) { 145 if (transformValue->operationType() != CSSTransformValue::ScaleX TransformOperation) {
146 if (transformValue->length() > 2) { 146 if (transformValue->length() > 2) {
147 CSSPrimitiveValue* thirdValue = toCSSPrimitiveValue(tran sformValue->itemWithoutBoundsCheck(2)); 147 CSSPrimitiveValue* thirdValue = toCSSPrimitiveValue(tran sformValue->item(2));
148 sz = thirdValue->getDoubleValue(); 148 sz = thirdValue->getDoubleValue();
149 } 149 }
150 if (transformValue->length() > 1) { 150 if (transformValue->length() > 1) {
151 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(tra nsformValue->itemWithoutBoundsCheck(1)); 151 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(tra nsformValue->item(1));
152 sy = secondValue->getDoubleValue(); 152 sy = secondValue->getDoubleValue();
153 } else 153 } else
154 sy = sx; 154 sy = sx;
155 } 155 }
156 } 156 }
157 operations.operations().append(ScaleTransformOperation::create(sx, s y, sz, getTransformOperationType(transformValue->operationType()))); 157 operations.operations().append(ScaleTransformOperation::create(sx, s y, sz, getTransformOperationType(transformValue->operationType())));
158 break; 158 break;
159 } 159 }
160 case CSSTransformValue::TranslateTransformOperation: 160 case CSSTransformValue::TranslateTransformOperation:
161 case CSSTransformValue::TranslateXTransformOperation: 161 case CSSTransformValue::TranslateXTransformOperation:
162 case CSSTransformValue::TranslateYTransformOperation: { 162 case CSSTransformValue::TranslateYTransformOperation: {
163 Length tx = Length(0, Fixed); 163 Length tx = Length(0, Fixed);
164 Length ty = Length(0, Fixed); 164 Length ty = Length(0, Fixed);
165 if (transformValue->operationType() == CSSTransformValue::TranslateY TransformOperation) 165 if (transformValue->operationType() == CSSTransformValue::TranslateY TransformOperation)
166 ty = convertToFloatLength(firstValue, conversionData); 166 ty = convertToFloatLength(firstValue, conversionData);
167 else { 167 else {
168 tx = convertToFloatLength(firstValue, conversionData); 168 tx = convertToFloatLength(firstValue, conversionData);
169 if (transformValue->operationType() != CSSTransformValue::Transl ateXTransformOperation) { 169 if (transformValue->operationType() != CSSTransformValue::Transl ateXTransformOperation) {
170 if (transformValue->length() > 1) { 170 if (transformValue->length() > 1) {
171 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(tra nsformValue->itemWithoutBoundsCheck(1)); 171 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(tra nsformValue->item(1));
172 ty = convertToFloatLength(secondValue, conversionData); 172 ty = convertToFloatLength(secondValue, conversionData);
173 } 173 }
174 } 174 }
175 } 175 }
176 176
177 operations.operations().append(TranslateTransformOperation::create(t x, ty, 0, getTransformOperationType(transformValue->operationType()))); 177 operations.operations().append(TranslateTransformOperation::create(t x, ty, 0, getTransformOperationType(transformValue->operationType())));
178 break; 178 break;
179 } 179 }
180 case CSSTransformValue::TranslateZTransformOperation: 180 case CSSTransformValue::TranslateZTransformOperation:
181 case CSSTransformValue::Translate3DTransformOperation: { 181 case CSSTransformValue::Translate3DTransformOperation: {
182 Length tx = Length(0, Fixed); 182 Length tx = Length(0, Fixed);
183 Length ty = Length(0, Fixed); 183 Length ty = Length(0, Fixed);
184 double tz = 0; 184 double tz = 0;
185 if (transformValue->operationType() == CSSTransformValue::TranslateZ TransformOperation) 185 if (transformValue->operationType() == CSSTransformValue::TranslateZ TransformOperation)
186 tz = firstValue->computeLength<double>(conversionData); 186 tz = firstValue->computeLength<double>(conversionData);
187 else if (transformValue->operationType() == CSSTransformValue::Trans lateYTransformOperation) 187 else if (transformValue->operationType() == CSSTransformValue::Trans lateYTransformOperation)
188 ty = convertToFloatLength(firstValue, conversionData); 188 ty = convertToFloatLength(firstValue, conversionData);
189 else { 189 else {
190 tx = convertToFloatLength(firstValue, conversionData); 190 tx = convertToFloatLength(firstValue, conversionData);
191 if (transformValue->operationType() != CSSTransformValue::Transl ateXTransformOperation) { 191 if (transformValue->operationType() != CSSTransformValue::Transl ateXTransformOperation) {
192 if (transformValue->length() > 2) { 192 if (transformValue->length() > 2) {
193 CSSPrimitiveValue* thirdValue = toCSSPrimitiveValue(tran sformValue->itemWithoutBoundsCheck(2)); 193 CSSPrimitiveValue* thirdValue = toCSSPrimitiveValue(tran sformValue->item(2));
194 tz = thirdValue->computeLength<double>(conversionData); 194 tz = thirdValue->computeLength<double>(conversionData);
195 } 195 }
196 if (transformValue->length() > 1) { 196 if (transformValue->length() > 1) {
197 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(tra nsformValue->itemWithoutBoundsCheck(1)); 197 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(tra nsformValue->item(1));
198 ty = convertToFloatLength(secondValue, conversionData); 198 ty = convertToFloatLength(secondValue, conversionData);
199 } 199 }
200 } 200 }
201 } 201 }
202 202
203 operations.operations().append(TranslateTransformOperation::create(t x, ty, tz, getTransformOperationType(transformValue->operationType()))); 203 operations.operations().append(TranslateTransformOperation::create(t x, ty, tz, getTransformOperationType(transformValue->operationType())));
204 break; 204 break;
205 } 205 }
206 case CSSTransformValue::RotateTransformOperation: { 206 case CSSTransformValue::RotateTransformOperation: {
207 double angle = firstValue->computeDegrees(); 207 double angle = firstValue->computeDegrees();
(...skipping 13 matching lines...) Expand all
221 else if (transformValue->operationType() == CSSTransformValue::Rotat eYTransformOperation) 221 else if (transformValue->operationType() == CSSTransformValue::Rotat eYTransformOperation)
222 y = 1; 222 y = 1;
223 else 223 else
224 z = 1; 224 z = 1;
225 operations.operations().append(RotateTransformOperation::create(x, y , z, angle, getTransformOperationType(transformValue->operationType()))); 225 operations.operations().append(RotateTransformOperation::create(x, y , z, angle, getTransformOperationType(transformValue->operationType())));
226 break; 226 break;
227 } 227 }
228 case CSSTransformValue::Rotate3DTransformOperation: { 228 case CSSTransformValue::Rotate3DTransformOperation: {
229 if (transformValue->length() < 4) 229 if (transformValue->length() < 4)
230 break; 230 break;
231 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(transformValue- >itemWithoutBoundsCheck(1)); 231 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(transformValue- >item(1));
232 CSSPrimitiveValue* thirdValue = toCSSPrimitiveValue(transformValue-> itemWithoutBoundsCheck(2)); 232 CSSPrimitiveValue* thirdValue = toCSSPrimitiveValue(transformValue-> item(2));
233 CSSPrimitiveValue* fourthValue = toCSSPrimitiveValue(transformValue- >itemWithoutBoundsCheck(3)); 233 CSSPrimitiveValue* fourthValue = toCSSPrimitiveValue(transformValue- >item(3));
234 double x = firstValue->getDoubleValue(); 234 double x = firstValue->getDoubleValue();
235 double y = secondValue->getDoubleValue(); 235 double y = secondValue->getDoubleValue();
236 double z = thirdValue->getDoubleValue(); 236 double z = thirdValue->getDoubleValue();
237 double angle = fourthValue->computeDegrees(); 237 double angle = fourthValue->computeDegrees();
238 operations.operations().append(RotateTransformOperation::create(x, y , z, angle, getTransformOperationType(transformValue->operationType()))); 238 operations.operations().append(RotateTransformOperation::create(x, y , z, angle, getTransformOperationType(transformValue->operationType())));
239 break; 239 break;
240 } 240 }
241 case CSSTransformValue::SkewTransformOperation: 241 case CSSTransformValue::SkewTransformOperation:
242 case CSSTransformValue::SkewXTransformOperation: 242 case CSSTransformValue::SkewXTransformOperation:
243 case CSSTransformValue::SkewYTransformOperation: { 243 case CSSTransformValue::SkewYTransformOperation: {
244 double angleX = 0; 244 double angleX = 0;
245 double angleY = 0; 245 double angleY = 0;
246 double angle = firstValue->computeDegrees(); 246 double angle = firstValue->computeDegrees();
247 if (transformValue->operationType() == CSSTransformValue::SkewYTrans formOperation) 247 if (transformValue->operationType() == CSSTransformValue::SkewYTrans formOperation)
248 angleY = angle; 248 angleY = angle;
249 else { 249 else {
250 angleX = angle; 250 angleX = angle;
251 if (transformValue->operationType() == CSSTransformValue::SkewTr ansformOperation) { 251 if (transformValue->operationType() == CSSTransformValue::SkewTr ansformOperation) {
252 if (transformValue->length() > 1) { 252 if (transformValue->length() > 1) {
253 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(tra nsformValue->itemWithoutBoundsCheck(1)); 253 CSSPrimitiveValue* secondValue = toCSSPrimitiveValue(tra nsformValue->item(1));
254 angleY = secondValue->computeDegrees(); 254 angleY = secondValue->computeDegrees();
255 } 255 }
256 } 256 }
257 } 257 }
258 operations.operations().append(SkewTransformOperation::create(angleX , angleY, getTransformOperationType(transformValue->operationType()))); 258 operations.operations().append(SkewTransformOperation::create(angleX , angleY, getTransformOperationType(transformValue->operationType())));
259 break; 259 break;
260 } 260 }
261 case CSSTransformValue::MatrixTransformOperation: { 261 case CSSTransformValue::MatrixTransformOperation: {
262 if (transformValue->length() < 6) 262 if (transformValue->length() < 6)
263 break; 263 break;
264 double a = firstValue->getDoubleValue(); 264 double a = firstValue->getDoubleValue();
265 double b = toCSSPrimitiveValue(transformValue->itemWithoutBoundsChec k(1))->getDoubleValue(); 265 double b = toCSSPrimitiveValue(transformValue->item(1))->getDoubleVa lue();
266 double c = toCSSPrimitiveValue(transformValue->itemWithoutBoundsChec k(2))->getDoubleValue(); 266 double c = toCSSPrimitiveValue(transformValue->item(2))->getDoubleVa lue();
267 double d = toCSSPrimitiveValue(transformValue->itemWithoutBoundsChec k(3))->getDoubleValue(); 267 double d = toCSSPrimitiveValue(transformValue->item(3))->getDoubleVa lue();
268 double e = zoomFactor * toCSSPrimitiveValue(transformValue->itemWith outBoundsCheck(4))->getDoubleValue(); 268 double e = zoomFactor * toCSSPrimitiveValue(transformValue->item(4)) ->getDoubleValue();
269 double f = zoomFactor * toCSSPrimitiveValue(transformValue->itemWith outBoundsCheck(5))->getDoubleValue(); 269 double f = zoomFactor * toCSSPrimitiveValue(transformValue->item(5)) ->getDoubleValue();
270 operations.operations().append(MatrixTransformOperation::create(a, b , c, d, e, f)); 270 operations.operations().append(MatrixTransformOperation::create(a, b , c, d, e, f));
271 break; 271 break;
272 } 272 }
273 case CSSTransformValue::Matrix3DTransformOperation: { 273 case CSSTransformValue::Matrix3DTransformOperation: {
274 if (transformValue->length() < 16) 274 if (transformValue->length() < 16)
275 break; 275 break;
276 TransformationMatrix matrix(toCSSPrimitiveValue(transformValue->item WithoutBoundsCheck(0))->getDoubleValue(), 276 TransformationMatrix matrix(toCSSPrimitiveValue(transformValue->item (0))->getDoubleValue(),
277 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(1))-> getDoubleValue(), 277 toCSSPrimitiveValue(transformValue->item(1))->getDoubleValue(),
278 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(2))-> getDoubleValue(), 278 toCSSPrimitiveValue(transformValue->item(2))->getDoubleValue(),
279 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(3))-> getDoubleValue(), 279 toCSSPrimitiveValue(transformValue->item(3))->getDoubleValue(),
280 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(4))-> getDoubleValue(), 280 toCSSPrimitiveValue(transformValue->item(4))->getDoubleValue(),
281 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(5))-> getDoubleValue(), 281 toCSSPrimitiveValue(transformValue->item(5))->getDoubleValue(),
282 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(6))-> getDoubleValue(), 282 toCSSPrimitiveValue(transformValue->item(6))->getDoubleValue(),
283 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(7))-> getDoubleValue(), 283 toCSSPrimitiveValue(transformValue->item(7))->getDoubleValue(),
284 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(8))-> getDoubleValue(), 284 toCSSPrimitiveValue(transformValue->item(8))->getDoubleValue(),
285 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(9))-> getDoubleValue(), 285 toCSSPrimitiveValue(transformValue->item(9))->getDoubleValue(),
286 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(10))- >getDoubleValue(), 286 toCSSPrimitiveValue(transformValue->item(10))->getDoubleValue(),
287 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(11))- >getDoubleValue(), 287 toCSSPrimitiveValue(transformValue->item(11))->getDoubleValue(),
288 zoomFactor * toCSSPrimitiveValue(transformValue->itemWithoutBoun dsCheck(12))->getDoubleValue(), 288 zoomFactor * toCSSPrimitiveValue(transformValue->item(12))->getD oubleValue(),
289 zoomFactor * toCSSPrimitiveValue(transformValue->itemWithoutBoun dsCheck(13))->getDoubleValue(), 289 zoomFactor * toCSSPrimitiveValue(transformValue->item(13))->getD oubleValue(),
290 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(14))- >getDoubleValue(), 290 toCSSPrimitiveValue(transformValue->item(14))->getDoubleValue(),
291 toCSSPrimitiveValue(transformValue->itemWithoutBoundsCheck(15))- >getDoubleValue()); 291 toCSSPrimitiveValue(transformValue->item(15))->getDoubleValue()) ;
292 operations.operations().append(Matrix3DTransformOperation::create(ma trix)); 292 operations.operations().append(Matrix3DTransformOperation::create(ma trix));
293 break; 293 break;
294 } 294 }
295 case CSSTransformValue::PerspectiveTransformOperation: { 295 case CSSTransformValue::PerspectiveTransformOperation: {
296 double p; 296 double p;
297 if (firstValue->isLength()) 297 if (firstValue->isLength())
298 p = firstValue->computeLength<double>(conversionData); 298 p = firstValue->computeLength<double>(conversionData);
299 else { 299 else {
300 // This is a quirk that should go away when 3d transforms are fi nalized. 300 // This is a quirk that should go away when 3d transforms are fi nalized.
301 double val = firstValue->getDoubleValue(); 301 double val = firstValue->getDoubleValue();
302 if (val < 0) 302 if (val < 0)
303 return false; 303 return false;
304 p = clampToPositiveInteger(val); 304 p = clampToPositiveInteger(val);
305 } 305 }
306 306
307 operations.operations().append(PerspectiveTransformOperation::create (p)); 307 operations.operations().append(PerspectiveTransformOperation::create (p));
308 break; 308 break;
309 } 309 }
310 case CSSTransformValue::UnknownTransformOperation: 310 case CSSTransformValue::UnknownTransformOperation:
311 ASSERT_NOT_REACHED(); 311 ASSERT_NOT_REACHED();
312 break; 312 break;
313 } 313 }
314 } 314 }
315 315
316 outOperations = operations; 316 outOperations = operations;
317 return true; 317 return true;
318 } 318 }
319 319
320 } // namespace WebCore 320 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/resolver/StyleBuilderCustom.cpp ('k') | Source/core/svg/SVGFontFaceElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698