Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp b/third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp |
| index a3cc1da8182c721b93b902f67c7778c802ccabcd..e391cea0aded42d9bdd3ca1a5fb1e84c14fbcf39 100644 |
| --- a/third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp |
| +++ b/third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp |
| @@ -5,10 +5,17 @@ |
| #include "core/dom/DOMMatrixReadOnly.h" |
| #include "bindings/core/v8/V8ObjectBuilder.h" |
| +#include "core/css/CSSIdentifierValue.h" |
| +#include "core/css/CSSToLengthConversionData.h" |
| +#include "core/css/CSSValueList.h" |
| +#include "core/css/parser/CSSParser.h" |
| +#include "core/css/resolver/TransformBuilder.h" |
| #include "core/dom/DOMMatrix.h" |
| #include "core/dom/DOMMatrixInit.h" |
| #include "core/dom/DOMPoint.h" |
| #include "core/dom/DOMPointInit.h" |
| +#include "core/layout/api/LayoutViewItem.h" |
| +#include "core/style/ComputedStyle.h" |
| namespace blink { |
| namespace { |
| @@ -89,6 +96,13 @@ DOMMatrixReadOnly* DOMMatrixReadOnly::create(ExceptionState& exceptionState) { |
| return new DOMMatrixReadOnly(TransformationMatrix()); |
| } |
| +DOMMatrixReadOnly* DOMMatrixReadOnly::create(const String& transformList, |
| + ExceptionState& exceptionState) { |
| + DOMMatrixReadOnly* matrix = new DOMMatrixReadOnly(TransformationMatrix()); |
| + matrix->setMatrixValueFromString(transformList, exceptionState); |
| + return matrix; |
| +} |
| + |
| DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence, |
| ExceptionState& exceptionState) { |
| if (sequence.size() != 6 && sequence.size() != 16) { |
| @@ -332,4 +346,55 @@ ScriptValue DOMMatrixReadOnly::toJSONForBinding( |
| return result.scriptValue(); |
| } |
| +void DOMMatrixReadOnly::setMatrixValueFromString( |
| + const String& inputString, |
| + ExceptionState& exceptionState) { |
| + DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)")); |
| + String string = inputString; |
| + if (string.isEmpty()) |
| + string = identityMatrix2D; |
| + |
| + const CSSValue* value = |
| + CSSParser::parseSingleValue(CSSPropertyTransform, string); |
| + |
| + if (!value || value->isCSSWideKeyword()) { |
| + exceptionState.throwDOMException(SyntaxError, |
| + "Failed to parse '" + inputString + "'."); |
| + return; |
| + } |
| + |
| + if (value->isIdentifierValue()) { |
| + DCHECK(toCSSIdentifierValue(value)->getValueID() == CSSValueNone); |
| + m_matrix->makeIdentity(); |
| + m_is2D = true; |
| + return; |
| + } |
| + |
| + if (TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) { |
| + exceptionState.throwDOMException( |
| + SyntaxError, |
| + "Must have an absolute lengths. It contains a relative lenghts"); |
|
dominicc (has gone to gerrit)
2016/12/06 08:44:24
Spelling--lengths
Grammar--"a relative" is signul
Hwanseung Lee
2016/12/07 13:56:59
Done.
|
| + return; |
| + } |
| + |
| + const ComputedStyle& initialStyle = ComputedStyle::initialStyle(); |
| + TransformOperations operations = TransformBuilder::createTransformOperations( |
| + *value, CSSToLengthConversionData(&initialStyle, &initialStyle, |
| + LayoutViewItem(nullptr), 1.0f)); |
| + |
| + if (operations.dependsOnBoxSize()) { |
| + exceptionState.throwDOMException(SyntaxError, |
| + "Must have an absolute lengths. The " |
|
dominicc (has gone to gerrit)
2016/12/06 08:44:24
Maybe "Lengths must be absolute, not depend on the
Hwanseung Lee
2016/12/07 13:56:59
Done.
|
| + "transformation depends on the box size"); |
| + return; |
| + } |
| + |
| + m_matrix->makeIdentity(); |
| + operations.apply(FloatSize(0, 0), *m_matrix); |
| + |
| + m_is2D = !operations.has3DOperation(); |
| + |
| + return; |
| +} |
| + |
| } // namespace blink |