Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/DOMMatrix.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/DOMMatrix.cpp b/third_party/WebKit/Source/core/dom/DOMMatrix.cpp |
| index eed0a170ce5864c208fa5ca308ce09205b8d3bba..51aa6b805e50f66bf2ff8419239dd6bd8d3953ad 100644 |
| --- a/third_party/WebKit/Source/core/dom/DOMMatrix.cpp |
| +++ b/third_party/WebKit/Source/core/dom/DOMMatrix.cpp |
| @@ -4,6 +4,13 @@ |
| #include "core/dom/DOMMatrix.h" |
| +#include "core/css/CSSIdentifierValue.h" |
| +#include "core/css/CSSToLengthConversionData.h" |
| +#include "core/css/parser/CSSParser.h" |
| +#include "core/css/resolver/TransformBuilder.h" |
| +#include "core/layout/api/LayoutViewItem.h" |
| +#include "core/style/ComputedStyle.h" |
| + |
| namespace blink { |
| DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) { |
| @@ -211,4 +218,62 @@ DOMMatrix* DOMMatrix::invertSelf() { |
| return this; |
| } |
| +static inline PassRefPtr<ComputedStyle> createInitialStyle() { |
| + RefPtr<ComputedStyle> initialStyle = ComputedStyle::create(); |
| + initialStyle->font().update(nullptr); |
| + return initialStyle; |
| +} |
| + |
| +DOMMatrix* DOMMatrix::setMatrixValue(const String& string, |
| + ExceptionState& exceptionState) { |
| + String inputString; |
| + if (string.isEmpty()) { |
| + 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.
|
| + } else { |
| + inputString = string; |
| + } |
|
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.
|
| + |
| + if (const CSSValue* value = |
| + CSSParser::parseSingleValue(CSSPropertyTransform, inputString)) { |
| + if (value->isIdentifierValue() && |
| + (toCSSIdentifierValue(value))->getValueID() == CSSValueNone) { |
| + exceptionState.throwDOMException(SyntaxError, |
| + "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.
|
| + } |
| + |
| + DEFINE_STATIC_REF(ComputedStyle, initialStyle, createInitialStyle()); |
| + |
| + if (TransformBuilder::checkHavingRelativeLengthUnit(*value)) { |
| + exceptionState.throwDOMException(SyntaxError, |
| + "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.
|
| + } |
| + |
| + TransformOperations operations; |
| + TransformBuilder::createTransformOperations( |
| + *value, CSSToLengthConversionData(initialStyle, initialStyle, |
| + LayoutViewItem(nullptr), 1.0f), |
| + operations); |
| + |
| + // Convert transform operations to a TransformationMatrix. This can fail |
| + // if a param has a percentage ('%') |
| + if (operations.dependsOnBoxSize()) { |
| + exceptionState.throwDOMException(SyntaxError, |
| + "The transformation depends on the box " |
| + "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.
|
| + } |
| + |
| + if (operations.has3DOperation()) |
| + m_is2D = false; |
| + |
| + m_matrix = TransformationMatrix::create(); |
| + operations.apply(FloatSize(0, 0), *m_matrix); |
| + |
| + } 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.
|
| + exceptionState.throwDOMException(SyntaxError, |
| + "Failed to parse '" + string + "'."); |
| + } |
| + |
| + return this; |
| +} |
| + |
| } // namespace blink |