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

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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 DOMMatrix* DOMMatrix::invertSelf() { 216 DOMMatrix* DOMMatrix::invertSelf() {
209 if (m_matrix->isInvertible()) { 217 if (m_matrix->isInvertible()) {
210 m_matrix = TransformationMatrix::create(m_matrix->inverse()); 218 m_matrix = TransformationMatrix::create(m_matrix->inverse());
211 } else { 219 } else {
212 setNAN(); 220 setNAN();
213 setIs2D(false); 221 setIs2D(false);
214 } 222 }
215 return this; 223 return this;
216 } 224 }
217 225
226 static inline PassRefPtr<ComputedStyle> createInitialStyle() {
227 RefPtr<ComputedStyle> initialStyle =
228 ComputedStyle::clone(ComputedStyle::initialStyle());
229 initialStyle->font().update(nullptr);
230 return initialStyle;
231 }
232
233 DOMMatrix* DOMMatrix::setMatrixValue(const String& inputString,
234 ExceptionState& exceptionState) {
235 DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)"));
236 String string = inputString;
237 if (string.isEmpty())
238 string = identityMatrix2D;
239
240 const CSSValue* value =
241 CSSParser::parseSingleValue(CSSPropertyTransform, string);
242
243 if (!value) {
244 exceptionState.throwDOMException(SyntaxError,
245 "Failed to parse '" + inputString + "'.");
246 return nullptr;
247 }
248
249 if (value->isIdentifierValue()) {
250 if ((toCSSIdentifierValue(value))->getValueID() == CSSValueNone) {
251 return this;
252 }
253 } else {
254 if (!value->isValueList()) {
255 exceptionState.throwDOMException(
256 SyntaxError, "Failed to parse '" + inputString + "'.");
257 return nullptr;
258 }
259 }
260
261 DEFINE_STATIC_REF(ComputedStyle, initialStyle, createInitialStyle());
262 if (value->isValueList() &&
263 TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) {
264 exceptionState.throwDOMException(SyntaxError,
265 "Relative lengths not supported.");
266 return nullptr;
267 }
268
269 TransformOperations operations;
270 TransformBuilder::createTransformOperations(
271 *value, CSSToLengthConversionData(initialStyle, initialStyle,
272 LayoutViewItem(nullptr), 1.0f),
273 operations);
274
275 if (operations.dependsOnBoxSize()) {
276 exceptionState.throwDOMException(SyntaxError,
277 "The transformation depends on the box "
278 "size, which is not supported.");
279 return nullptr;
280 }
281
282 m_is2D = !operations.has3DOperation();
283
284 m_matrix = TransformationMatrix::create();
285 operations.apply(FloatSize(0, 0), *m_matrix);
286
287 return this;
288 }
289
218 } // namespace blink 290 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698