Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Unified Diff: third_party/WebKit/Source/core/dom/DOMMatrix.cpp

Issue 2380713004: [GeometryInterface] Add setMatrixValue(transfromList) function. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 89f117301bd3dc3aafabe0953cf3c968049dcc9a..4da0cd4ee612c29eb3f4932ef68072d287628a3b 100644
--- a/third_party/WebKit/Source/core/dom/DOMMatrix.cpp
+++ b/third_party/WebKit/Source/core/dom/DOMMatrix.cpp
@@ -4,6 +4,12 @@
#include "core/dom/DOMMatrix.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)
@@ -207,4 +213,45 @@ 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)";
+ } else {
+ inputString = string;
+ }
+
+ if (const CSSValue* value = CSSParser::parseSingleValue(CSSPropertyTransform, inputString)) {
+ if (value->isPrimitiveValue() && (toCSSPrimitiveValue(value))->getValueID() == CSSValueNone)
+ exceptionState.throwDOMException(SyntaxError, "Failed to parse '" + string + "'.");
+
+ DEFINE_STATIC_REF(ComputedStyle, initialStyle, createInitialStyle());
+ 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.");
+
+ if (operations.has3DOperation())
+ m_is2D = false;
+
+ operations.apply(FloatSize(0, 0), *m_matrix);
+
+ } else { // There is something there but parsing failed.
+ exceptionState.throwDOMException(SyntaxError, "Failed to parse '" + string + "'.");
+ }
+
+ return this;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698