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

Side by Side Diff: third_party/WebKit/Source/core/dom/DOMMatrix.cpp

Issue 2380713004: [GeometryInterface] Add setMatrixValue(transfromList) function. (Closed)
Patch Set: [GeometryInterface] Add setMatrixValue(transfromList) function. 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 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/DOMMatrix.h" 5 #include "core/dom/DOMMatrix.h"
6 6
7 #include "core/css/CSSIdentifierValue.h"
8 #include "core/css/CSSToLengthConversionData.h"
9 #include "core/css/CSSValueList.h"
10 #include "core/css/parser/CSSParser.h"
11 #include "core/css/resolver/TransformBuilder.h"
12 #include "core/layout/api/LayoutViewItem.h"
13 #include "core/style/ComputedStyle.h"
14
7 namespace blink { 15 namespace blink {
8 16
9 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) { 17 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) {
10 return new DOMMatrix(TransformationMatrix()); 18 return new DOMMatrix(TransformationMatrix());
11 } 19 }
12 20
13 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other, 21 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other,
14 ExceptionState& exceptionState) { 22 ExceptionState& exceptionState) {
15 return new DOMMatrix(other->matrix(), other->is2D()); 23 return new DOMMatrix(other->matrix(), other->is2D());
16 } 24 }
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 DOMMatrix* DOMMatrix::invertSelf() { 246 DOMMatrix* DOMMatrix::invertSelf() {
239 if (m_matrix->isInvertible()) { 247 if (m_matrix->isInvertible()) {
240 m_matrix = TransformationMatrix::create(m_matrix->inverse()); 248 m_matrix = TransformationMatrix::create(m_matrix->inverse());
241 } else { 249 } else {
242 setNAN(); 250 setNAN();
243 setIs2D(false); 251 setIs2D(false);
244 } 252 }
245 return this; 253 return this;
246 } 254 }
247 255
256 DOMMatrix* DOMMatrix::setMatrixValue(const String& inputString,
257 ExceptionState& exceptionState) {
258 DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)"));
259 String string = inputString;
260 if (string.isEmpty())
261 string = identityMatrix2D;
262
263 const CSSValue* value =
264 CSSParser::parseSingleValue(CSSPropertyTransform, string);
265
266 if (!value) {
267 exceptionState.throwDOMException(SyntaxError,
268 "Failed to parse '" + inputString + "'.");
269 return nullptr;
270 }
271
272 if (value->isIdentifierValue()) {
273 if ((toCSSIdentifierValue(value))->getValueID() == CSSValueNone) {
274 m_matrix->makeIdentity();
275 m_is2D = true;
276 return this;
277 }
278 } else {
279 if (!value->isValueList()) {
280 exceptionState.throwDOMException(
Timothy Loh 2016/10/27 02:38:42 Does this exception ever get thrown? From what I c
Hwanseung Lee 2016/10/27 16:24:48 when we don't check value->isValueList(), it will
Timothy Loh 2016/10/28 02:50:04 My point here is that in the code we should make i
Hwanseung Lee 2016/10/28 12:17:58 Done.
281 SyntaxError, "Failed to parse '" + inputString + "'.");
282 return nullptr;
283 }
284 }
285
286 if (value->isValueList() &&
287 TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) {
288 exceptionState.throwDOMException(SyntaxError,
289 "Relative lengths not supported.");
290 return nullptr;
291 }
292
293 const ComputedStyle& initialStyle = ComputedStyle::initialStyle();
294 TransformOperations operations = TransformBuilder::createTransformOperations(
295 *value, CSSToLengthConversionData(&initialStyle, &initialStyle,
296 LayoutViewItem(nullptr), 1.0f));
297
298 if (operations.dependsOnBoxSize()) {
299 exceptionState.throwDOMException(SyntaxError,
300 "The transformation depends on the box "
301 "size, which is not supported.");
302 return nullptr;
303 }
304
305 m_matrix->makeIdentity();
306 operations.apply(FloatSize(0, 0), *m_matrix);
307
308 m_is2D = !operations.has3DOperation();
309
310 return this;
311 }
312
248 } // namespace blink 313 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/DOMMatrix.h ('k') | third_party/WebKit/Source/core/dom/DOMMatrix.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698