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

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

Issue 2516973002: [GeometryInferface] add Constructor(DOMString transformList). (Closed)
Patch Set: [GeometryInferface] add Constructor(DOMString transformList). Created 4 years, 1 month 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/DOMMatrixReadOnly.cpp
diff --git a/third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp b/third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp
index 7c7f2ede94b480e8a5869fa9af2897653f5a6e82..da4c7c9d3f5d9dc0eabd4a1a118d5ac299cc97fd 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,11 @@ DOMMatrixReadOnly* DOMMatrixReadOnly::create(ExceptionState& exceptionState) {
return new DOMMatrixReadOnly(TransformationMatrix());
}
+DOMMatrixReadOnly* DOMMatrixReadOnly::create(const String& transformList,
+ ExceptionState& exceptionState) {
+ return new DOMMatrixReadOnly(transformList, exceptionState);
+}
+
DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence,
ExceptionState& exceptionState) {
if (sequence.size() != 6 && sequence.size() != 16) {
@@ -253,6 +265,12 @@ DOMPoint* DOMMatrixReadOnly::transformPoint(const DOMPointInit& point) {
return DOMPoint::create(x, y, z, w);
}
+DOMMatrixReadOnly::DOMMatrixReadOnly(const String& inputString,
+ ExceptionState& exceptionState) {
+ m_matrix = TransformationMatrix::create();
+ setMatrixValue(inputString, exceptionState);
+}
+
DOMMatrixReadOnly::DOMMatrixReadOnly(const TransformationMatrix& matrix,
bool is2D) {
m_matrix = TransformationMatrix::create(matrix);
@@ -330,4 +348,54 @@ ScriptValue DOMMatrixReadOnly::toJSONForBinding(
return result.scriptValue();
}
+DOMMatrixReadOnly* DOMMatrixReadOnly::setMatrixValue(
+ 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 nullptr;
+ }
+
+ if (value->isIdentifierValue()) {
+ DCHECK(toCSSIdentifierValue(value)->getValueID() == CSSValueNone);
+ m_matrix->makeIdentity();
+ m_is2D = true;
+ return this;
+ }
+
+ if (TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) {
+ exceptionState.throwDOMException(SyntaxError,
+ "Relative lengths not supported.");
+ return nullptr;
+ }
+
+ const ComputedStyle& initialStyle = ComputedStyle::initialStyle();
+ TransformOperations operations = TransformBuilder::createTransformOperations(
+ *value, CSSToLengthConversionData(&initialStyle, &initialStyle,
+ LayoutViewItem(nullptr), 1.0f));
+
+ if (operations.dependsOnBoxSize()) {
+ exceptionState.throwDOMException(SyntaxError,
+ "The transformation depends on the box "
+ "size, which is not supported.");
+ return nullptr;
+ }
+
+ m_matrix->makeIdentity();
+ operations.apply(FloatSize(0, 0), *m_matrix);
+
+ m_is2D = !operations.has3DOperation();
+
+ return this;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698