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/CSSValueList.h" |
| 10 #include "core/css/parser/CSSParser.h" |
| 11 #include "core/css/resolver/TransformBuilder.h" |
| 12 #include "core/layout/api/LayoutViewItem.h" |
| 13 #include "core/style/ComputedStyle.h" |
| 14 |
7 namespace blink { | 15 namespace blink { |
8 | 16 |
9 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) { | 17 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) { |
10 return new DOMMatrix(TransformationMatrix()); | 18 return new DOMMatrix(TransformationMatrix()); |
11 } | 19 } |
12 | 20 |
13 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other, | 21 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other, |
14 ExceptionState& exceptionState) { | 22 ExceptionState& exceptionState) { |
15 return new DOMMatrix(other->matrix(), other->is2D()); | 23 return new DOMMatrix(other->matrix(), other->is2D()); |
16 } | 24 } |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 DOMMatrix* DOMMatrix::invertSelf() { | 246 DOMMatrix* DOMMatrix::invertSelf() { |
239 if (m_matrix->isInvertible()) { | 247 if (m_matrix->isInvertible()) { |
240 m_matrix = TransformationMatrix::create(m_matrix->inverse()); | 248 m_matrix = TransformationMatrix::create(m_matrix->inverse()); |
241 } else { | 249 } else { |
242 setNAN(); | 250 setNAN(); |
243 setIs2D(false); | 251 setIs2D(false); |
244 } | 252 } |
245 return this; | 253 return this; |
246 } | 254 } |
247 | 255 |
| 256 DOMMatrix* DOMMatrix::setMatrixValue(const String& inputString, |
| 257 ExceptionState& exceptionState) { |
| 258 DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)")); |
| 259 String string = inputString; |
| 260 if (string.isEmpty()) |
| 261 string = identityMatrix2D; |
| 262 |
| 263 const CSSValue* value = |
| 264 CSSParser::parseSingleValue(CSSPropertyTransform, string); |
| 265 |
| 266 if (!value || value->isCSSWideKeyword()) { |
| 267 exceptionState.throwDOMException(SyntaxError, |
| 268 "Failed to parse '" + inputString + "'."); |
| 269 return nullptr; |
| 270 } |
| 271 |
| 272 if (value->isIdentifierValue()) { |
| 273 DCHECK(toCSSIdentifierValue(value)->getValueID() == CSSValueNone); |
| 274 m_matrix->makeIdentity(); |
| 275 m_is2D = true; |
| 276 return this; |
| 277 } |
| 278 |
| 279 if (TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) { |
| 280 exceptionState.throwDOMException(SyntaxError, |
| 281 "Relative lengths not supported."); |
| 282 return nullptr; |
| 283 } |
| 284 |
| 285 const ComputedStyle& initialStyle = ComputedStyle::initialStyle(); |
| 286 TransformOperations operations = TransformBuilder::createTransformOperations( |
| 287 *value, CSSToLengthConversionData(&initialStyle, &initialStyle, |
| 288 LayoutViewItem(nullptr), 1.0f)); |
| 289 |
| 290 if (operations.dependsOnBoxSize()) { |
| 291 exceptionState.throwDOMException(SyntaxError, |
| 292 "The transformation depends on the box " |
| 293 "size, which is not supported."); |
| 294 return nullptr; |
| 295 } |
| 296 |
| 297 m_matrix->makeIdentity(); |
| 298 operations.apply(FloatSize(0, 0), *m_matrix); |
| 299 |
| 300 m_is2D = !operations.has3DOperation(); |
| 301 |
| 302 return this; |
| 303 } |
| 304 |
248 } // namespace blink | 305 } // namespace blink |
OLD | NEW |