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

Side by Side 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 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/DOMMatrixReadOnly.h" 5 #include "core/dom/DOMMatrixReadOnly.h"
6 6
7 #include "bindings/core/v8/V8ObjectBuilder.h" 7 #include "bindings/core/v8/V8ObjectBuilder.h"
8 #include "core/css/CSSIdentifierValue.h"
9 #include "core/css/CSSToLengthConversionData.h"
10 #include "core/css/CSSValueList.h"
11 #include "core/css/parser/CSSParser.h"
12 #include "core/css/resolver/TransformBuilder.h"
8 #include "core/dom/DOMMatrix.h" 13 #include "core/dom/DOMMatrix.h"
9 #include "core/dom/DOMMatrixInit.h" 14 #include "core/dom/DOMMatrixInit.h"
10 #include "core/dom/DOMPoint.h" 15 #include "core/dom/DOMPoint.h"
11 #include "core/dom/DOMPointInit.h" 16 #include "core/dom/DOMPointInit.h"
17 #include "core/layout/api/LayoutViewItem.h"
18 #include "core/style/ComputedStyle.h"
12 19
13 namespace blink { 20 namespace blink {
14 namespace { 21 namespace {
15 22
16 void setDictionaryMembers(DOMMatrixInit& other) { 23 void setDictionaryMembers(DOMMatrixInit& other) {
17 if (!other.hasM11()) 24 if (!other.hasM11())
18 other.setM11(other.hasA() ? other.a() : 1); 25 other.setM11(other.hasA() ? other.a() : 1);
19 26
20 if (!other.hasM12()) 27 if (!other.hasM12())
21 other.setM12(other.hasB() ? other.b() : 0); 28 other.setM12(other.hasB() ? other.b() : 0);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 other.m33() != 1 || other.m44() != 1); 89 other.m33() != 1 || other.m44() != 1);
83 other.setIs2D(is2D); 90 other.setIs2D(is2D);
84 } 91 }
85 return true; 92 return true;
86 } 93 }
87 94
88 DOMMatrixReadOnly* DOMMatrixReadOnly::create(ExceptionState& exceptionState) { 95 DOMMatrixReadOnly* DOMMatrixReadOnly::create(ExceptionState& exceptionState) {
89 return new DOMMatrixReadOnly(TransformationMatrix()); 96 return new DOMMatrixReadOnly(TransformationMatrix());
90 } 97 }
91 98
99 DOMMatrixReadOnly* DOMMatrixReadOnly::create(const String& transformList,
100 ExceptionState& exceptionState) {
101 return new DOMMatrixReadOnly(transformList, exceptionState);
102 }
103
92 DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence, 104 DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence,
93 ExceptionState& exceptionState) { 105 ExceptionState& exceptionState) {
94 if (sequence.size() != 6 && sequence.size() != 16) { 106 if (sequence.size() != 6 && sequence.size() != 16) {
95 exceptionState.throwTypeError( 107 exceptionState.throwTypeError(
96 "The sequence must contain 6 elements for a 2D matrix or 16 elements " 108 "The sequence must contain 6 elements for a 2D matrix or 16 elements "
97 "for a 3D matrix."); 109 "for a 3D matrix.");
98 return nullptr; 110 return nullptr;
99 } 111 }
100 return new DOMMatrixReadOnly(sequence, sequence.size()); 112 return new DOMMatrixReadOnly(sequence, sequence.size());
101 } 113 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 point.w() * m41(); 258 point.w() * m41();
247 double y = point.x() * m12() + point.y() * m22() + point.z() * m32() + 259 double y = point.x() * m12() + point.y() * m22() + point.z() * m32() +
248 point.w() * m42(); 260 point.w() * m42();
249 double z = point.x() * m13() + point.y() * m23() + point.z() * m33() + 261 double z = point.x() * m13() + point.y() * m23() + point.z() * m33() +
250 point.w() * m43(); 262 point.w() * m43();
251 double w = point.x() * m14() + point.y() * m24() + point.z() * m34() + 263 double w = point.x() * m14() + point.y() * m24() + point.z() * m34() +
252 point.w() * m44(); 264 point.w() * m44();
253 return DOMPoint::create(x, y, z, w); 265 return DOMPoint::create(x, y, z, w);
254 } 266 }
255 267
268 DOMMatrixReadOnly::DOMMatrixReadOnly(const String& inputString,
269 ExceptionState& exceptionState) {
270 m_matrix = TransformationMatrix::create();
271 setMatrixValue(inputString, exceptionState);
272 }
273
256 DOMMatrixReadOnly::DOMMatrixReadOnly(const TransformationMatrix& matrix, 274 DOMMatrixReadOnly::DOMMatrixReadOnly(const TransformationMatrix& matrix,
257 bool is2D) { 275 bool is2D) {
258 m_matrix = TransformationMatrix::create(matrix); 276 m_matrix = TransformationMatrix::create(matrix);
259 m_is2D = is2D; 277 m_is2D = is2D;
260 } 278 }
261 279
262 DOMFloat32Array* DOMMatrixReadOnly::toFloat32Array() const { 280 DOMFloat32Array* DOMMatrixReadOnly::toFloat32Array() const {
263 float array[] = { 281 float array[] = {
264 static_cast<float>(m_matrix->m11()), static_cast<float>(m_matrix->m12()), 282 static_cast<float>(m_matrix->m11()), static_cast<float>(m_matrix->m12()),
265 static_cast<float>(m_matrix->m13()), static_cast<float>(m_matrix->m14()), 283 static_cast<float>(m_matrix->m13()), static_cast<float>(m_matrix->m14()),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 result.addNumber("m34", m34()); 341 result.addNumber("m34", m34());
324 result.addNumber("m41", m41()); 342 result.addNumber("m41", m41());
325 result.addNumber("m42", m42()); 343 result.addNumber("m42", m42());
326 result.addNumber("m43", m43()); 344 result.addNumber("m43", m43());
327 result.addNumber("m44", m44()); 345 result.addNumber("m44", m44());
328 result.addBoolean("is2D", is2D()); 346 result.addBoolean("is2D", is2D());
329 result.addBoolean("isIdentity", isIdentity()); 347 result.addBoolean("isIdentity", isIdentity());
330 return result.scriptValue(); 348 return result.scriptValue();
331 } 349 }
332 350
351 DOMMatrixReadOnly* DOMMatrixReadOnly::setMatrixValue(
352 const String& inputString,
353 ExceptionState& exceptionState) {
354 DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)"));
355 String string = inputString;
356 if (string.isEmpty())
357 string = identityMatrix2D;
358
359 const CSSValue* value =
360 CSSParser::parseSingleValue(CSSPropertyTransform, string);
361
362 if (!value || value->isCSSWideKeyword()) {
363 exceptionState.throwDOMException(SyntaxError,
364 "Failed to parse '" + inputString + "'.");
365 return nullptr;
366 }
367
368 if (value->isIdentifierValue()) {
369 DCHECK(toCSSIdentifierValue(value)->getValueID() == CSSValueNone);
370 m_matrix->makeIdentity();
371 m_is2D = true;
372 return this;
373 }
374
375 if (TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) {
376 exceptionState.throwDOMException(SyntaxError,
377 "Relative lengths not supported.");
378 return nullptr;
379 }
380
381 const ComputedStyle& initialStyle = ComputedStyle::initialStyle();
382 TransformOperations operations = TransformBuilder::createTransformOperations(
383 *value, CSSToLengthConversionData(&initialStyle, &initialStyle,
384 LayoutViewItem(nullptr), 1.0f));
385
386 if (operations.dependsOnBoxSize()) {
387 exceptionState.throwDOMException(SyntaxError,
388 "The transformation depends on the box "
389 "size, which is not supported.");
390 return nullptr;
391 }
392
393 m_matrix->makeIdentity();
394 operations.apply(FloatSize(0, 0), *m_matrix);
395
396 m_is2D = !operations.has3DOperation();
397
398 return this;
399 }
400
333 } // namespace blink 401 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698