Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/dom/DOMMatrix.h" | 5 #include "core/dom/DOMMatrix.h" |
| 6 | 6 |
| 7 #include "core/css/CSSIdentifierValue.h" | |
| 8 #include "core/css/CSSToLengthConversionData.h" | |
| 9 #include "core/css/parser/CSSParser.h" | |
| 10 #include "core/css/resolver/TransformBuilder.h" | |
| 11 #include "core/layout/api/LayoutViewItem.h" | |
| 12 #include "core/style/ComputedStyle.h" | |
| 13 | |
| 7 namespace blink { | 14 namespace blink { |
| 8 | 15 |
| 9 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) { | 16 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) { |
| 10 return new DOMMatrix(TransformationMatrix()); | 17 return new DOMMatrix(TransformationMatrix()); |
| 11 } | 18 } |
| 12 | 19 |
| 13 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other, | 20 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other, |
| 14 ExceptionState& exceptionState) { | 21 ExceptionState& exceptionState) { |
| 15 return new DOMMatrix(other->matrix(), other->is2D()); | 22 return new DOMMatrix(other->matrix(), other->is2D()); |
| 16 } | 23 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 setM34(NAN); | 211 setM34(NAN); |
| 205 setM41(NAN); | 212 setM41(NAN); |
| 206 setM42(NAN); | 213 setM42(NAN); |
| 207 setM43(NAN); | 214 setM43(NAN); |
| 208 setM44(NAN); | 215 setM44(NAN); |
| 209 setIs2D(false); | 216 setIs2D(false); |
| 210 } | 217 } |
| 211 return this; | 218 return this; |
| 212 } | 219 } |
| 213 | 220 |
| 221 static inline PassRefPtr<ComputedStyle> createInitialStyle() { | |
| 222 RefPtr<ComputedStyle> initialStyle = ComputedStyle::create(); | |
| 223 initialStyle->font().update(nullptr); | |
| 224 return initialStyle; | |
| 225 } | |
| 226 | |
| 227 DOMMatrix* DOMMatrix::setMatrixValue(const String& string, | |
| 228 ExceptionState& exceptionState) { | |
| 229 String inputString; | |
| 230 if (string.isEmpty()) { | |
| 231 inputString = "matrix(1, 0, 0, 1, 0, 0)"; | |
|
meade_UTC10
2016/10/17 03:22:28
You can use DEFINE_STATIC_LOCAL to avoid allocatin
Hwanseung Lee
2016/10/18 16:37:53
Done.
| |
| 232 } else { | |
| 233 inputString = string; | |
| 234 } | |
|
meade_UTC10
2016/10/17 03:22:28
This can be shortened to just 3 lines.
String inp
Hwanseung Lee
2016/10/18 16:37:53
Done.
| |
| 235 | |
| 236 if (const CSSValue* value = | |
| 237 CSSParser::parseSingleValue(CSSPropertyTransform, inputString)) { | |
| 238 if (value->isIdentifierValue() && | |
| 239 (toCSSIdentifierValue(value))->getValueID() == CSSValueNone) { | |
| 240 exceptionState.throwDOMException(SyntaxError, | |
| 241 "Failed to parse '" + string + "'."); | |
|
meade_UTC10
2016/10/17 03:22:28
This shouldn't continue after throwing the excepti
Hwanseung Lee
2016/10/18 16:37:53
Done.
| |
| 242 } | |
| 243 | |
| 244 DEFINE_STATIC_REF(ComputedStyle, initialStyle, createInitialStyle()); | |
| 245 | |
| 246 if (TransformBuilder::checkHavingRelativeLengthUnit(*value)) { | |
| 247 exceptionState.throwDOMException(SyntaxError, | |
| 248 "relative length unit can't support."); | |
|
meade_UTC10
2016/10/17 03:22:28
Nit: Incorrect English grammar. Should be somethin
Hwanseung Lee
2016/10/18 16:37:52
Done.
| |
| 249 } | |
| 250 | |
| 251 TransformOperations operations; | |
| 252 TransformBuilder::createTransformOperations( | |
| 253 *value, CSSToLengthConversionData(initialStyle, initialStyle, | |
| 254 LayoutViewItem(nullptr), 1.0f), | |
| 255 operations); | |
| 256 | |
| 257 // Convert transform operations to a TransformationMatrix. This can fail | |
| 258 // if a param has a percentage ('%') | |
| 259 if (operations.dependsOnBoxSize()) { | |
| 260 exceptionState.throwDOMException(SyntaxError, | |
| 261 "The transformation depends on the box " | |
| 262 "size, which is not supported."); | |
|
meade_UTC10
2016/10/17 03:22:28
Same comment about returning nullptr after throwin
Hwanseung Lee
2016/10/18 16:37:52
Done.
| |
| 263 } | |
| 264 | |
| 265 if (operations.has3DOperation()) | |
| 266 m_is2D = false; | |
| 267 | |
| 268 m_matrix = TransformationMatrix::create(); | |
| 269 operations.apply(FloatSize(0, 0), *m_matrix); | |
| 270 | |
| 271 } else { // There is something there but parsing failed. | |
|
meade_UTC10
2016/10/17 03:22:28
This structure would be easier to read (exit early
Hwanseung Lee
2016/10/18 16:37:53
Done.
| |
| 272 exceptionState.throwDOMException(SyntaxError, | |
| 273 "Failed to parse '" + string + "'."); | |
| 274 } | |
| 275 | |
| 276 return this; | |
| 277 } | |
| 278 | |
| 214 } // namespace blink | 279 } // namespace blink |
| OLD | NEW |