OLD | NEW |
---|---|
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 Loading... | |
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 DOMMatrix* DOMMatrix::setMatrixValue(const String& inputString, | |
227 ExceptionState& exceptionState) { | |
228 DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)")); | |
229 String string = inputString; | |
230 if (string.isEmpty()) | |
231 string = identityMatrix2D; | |
232 | |
233 const CSSValue* value = | |
234 CSSParser::parseSingleValue(CSSPropertyTransform, string); | |
235 | |
236 if (!value) { | |
237 exceptionState.throwDOMException(SyntaxError, | |
238 "Failed to parse '" + inputString + "'."); | |
239 return nullptr; | |
240 } | |
241 | |
242 if (value->isIdentifierValue()) { | |
243 if ((toCSSIdentifierValue(value))->getValueID() == CSSValueNone) { | |
244 return this; | |
245 } | |
246 } else { | |
247 if (!value->isValueList()) { | |
248 exceptionState.throwDOMException( | |
249 SyntaxError, "Failed to parse '" + inputString + "'."); | |
250 return nullptr; | |
251 } | |
252 } | |
253 | |
254 DEFINE_STATIC_REF(ComputedStyle, initialStyle, | |
255 ComputedStyle::clone(ComputedStyle::initialStyle())); | |
Timothy Loh
2016/10/25 04:48:01
We don't need to clone this at all, just use Compu
Hwanseung Lee
2016/10/27 16:24:48
Done.
| |
256 if (value->isValueList() && | |
257 TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) { | |
258 exceptionState.throwDOMException(SyntaxError, | |
259 "Relative lengths not supported."); | |
260 return nullptr; | |
261 } | |
262 | |
263 TransformOperations operations; | |
264 TransformBuilder::createTransformOperations( | |
265 *value, CSSToLengthConversionData(initialStyle, initialStyle, | |
266 LayoutViewItem(nullptr), 1.0f), | |
267 operations); | |
268 | |
269 if (operations.dependsOnBoxSize()) { | |
270 exceptionState.throwDOMException(SyntaxError, | |
271 "The transformation depends on the box " | |
272 "size, which is not supported."); | |
273 return nullptr; | |
274 } | |
275 | |
276 m_is2D = !operations.has3DOperation(); | |
277 | |
278 m_matrix = TransformationMatrix::create(); | |
Timothy Loh
2016/10/25 04:48:01
It's probably better to just call makeIdentity() i
Hwanseung Lee
2016/10/26 14:51:43
Done.
| |
279 operations.apply(FloatSize(0, 0), *m_matrix); | |
280 | |
281 return this; | |
282 } | |
283 | |
218 } // namespace blink | 284 } // namespace blink |
OLD | NEW |