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..f084a536466988ca065787eacdf492e0d530c6c9 100644 |
--- a/third_party/WebKit/Source/core/dom/DOMMatrix.cpp |
+++ b/third_party/WebKit/Source/core/dom/DOMMatrix.cpp |
@@ -4,6 +4,14 @@ |
#include "core/dom/DOMMatrix.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/layout/api/LayoutViewItem.h" |
+#include "core/style/ComputedStyle.h" |
+ |
namespace blink { |
DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) { |
@@ -211,4 +219,65 @@ DOMMatrix* DOMMatrix::invertSelf() { |
return this; |
} |
+static inline PassRefPtr<ComputedStyle> createInitialStyle() { |
Timothy Loh
2016/10/19 02:59:08
Just use ComputedStyle::initialStyle() instead of
Hwanseung Lee
2016/10/22 14:44:56
Done.
Timothy Loh
2016/10/24 04:18:30
I meant that we shouldn't need a createInitialStyl
Hwanseung Lee
2016/10/24 13:23:37
Done.
|
+ RefPtr<ComputedStyle> initialStyle = ComputedStyle::create(); |
+ initialStyle->font().update(nullptr); |
+ return initialStyle; |
+} |
+ |
+DOMMatrix* DOMMatrix::setMatrixValue(const String& string, |
+ ExceptionState& exceptionState) { |
+ DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)")); |
+ String inputString = string; |
Timothy Loh
2016/10/19 02:59:08
This naming is weird, if you have inputString and
Hwanseung Lee
2016/10/22 14:44:56
Done.
|
+ if (string.isEmpty()) |
+ inputString = identityMatrix2D; |
+ |
+ const CSSValue* value = |
+ CSSParser::parseSingleValue(CSSPropertyTransform, inputString); |
+ |
+ if (!value) { // There is something there but parsing failed. |
+ exceptionState.throwDOMException(SyntaxError, |
+ "Failed to parse '" + string + "'."); |
+ return nullptr; |
+ } |
+ |
+ if (value->isIdentifierValue() && |
+ (toCSSIdentifierValue(value))->getValueID() == CSSValueNone) { |
+ exceptionState.throwDOMException(SyntaxError, |
+ "Failed to parse '" + string + "'."); |
+ return nullptr; |
+ } |
+ |
+ DEFINE_STATIC_REF(ComputedStyle, initialStyle, createInitialStyle()); |
+ |
+ if (TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) { |
+ exceptionState.throwDOMException(SyntaxError, |
+ "Relative lengths not supported."); |
+ return nullptr; |
+ } |
+ |
+ TransformOperations operations; |
+ TransformBuilder::createTransformOperations( |
+ *value, CSSToLengthConversionData(initialStyle, initialStyle, |
+ LayoutViewItem(nullptr), 1.0f), |
+ operations); |
+ |
+ // Convert transform operations to a TransformationMatrix. This can fail |
Timothy Loh
2016/10/19 02:59:08
This comment is misplaced, the conversion is 12 li
Hwanseung Lee
2016/10/22 14:44:56
Done.
|
+ // if a param has a percentage ('%') |
+ if (operations.dependsOnBoxSize()) { |
+ exceptionState.throwDOMException(SyntaxError, |
+ "The transformation depends on the box " |
+ "size, which is not supported."); |
+ return nullptr; |
+ } |
+ |
+ if (operations.has3DOperation()) |
+ m_is2D = false; |
Timothy Loh
2016/10/19 02:59:08
Shouldn't this be
m_is2D = !operations.has3DOpera
Hwanseung Lee
2016/10/22 14:44:57
Done.
|
+ |
+ m_matrix = TransformationMatrix::create(); |
+ operations.apply(FloatSize(0, 0), *m_matrix); |
+ |
+ return this; |
+} |
+ |
} // namespace blink |