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/CSSToLengthConversionData.h" |
| 8 #include "core/css/parser/CSSParser.h" |
| 9 #include "core/css/resolver/TransformBuilder.h" |
| 10 #include "core/layout/api/LayoutViewItem.h" |
| 11 #include "core/style/ComputedStyle.h" |
| 12 |
7 namespace blink { | 13 namespace blink { |
8 | 14 |
9 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) | 15 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) |
10 { | 16 { |
11 return new DOMMatrix(TransformationMatrix()); | 17 return new DOMMatrix(TransformationMatrix()); |
12 } | 18 } |
13 | 19 |
14 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other, ExceptionState& exception
State) | 20 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other, ExceptionState& exception
State) |
15 { | 21 { |
16 return new DOMMatrix(other->matrix(), other->is2D()); | 22 return new DOMMatrix(other->matrix(), other->is2D()); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 setM34(NAN); | 206 setM34(NAN); |
201 setM41(NAN); | 207 setM41(NAN); |
202 setM42(NAN); | 208 setM42(NAN); |
203 setM43(NAN); | 209 setM43(NAN); |
204 setM44(NAN); | 210 setM44(NAN); |
205 setIs2D(false); | 211 setIs2D(false); |
206 } | 212 } |
207 return this; | 213 return this; |
208 } | 214 } |
209 | 215 |
| 216 static inline PassRefPtr<ComputedStyle> createInitialStyle() |
| 217 { |
| 218 RefPtr<ComputedStyle> initialStyle = ComputedStyle::create(); |
| 219 initialStyle->font().update(nullptr); |
| 220 return initialStyle; |
| 221 } |
| 222 |
| 223 DOMMatrix* DOMMatrix::setMatrixValue(const String& string, ExceptionState& excep
tionState) |
| 224 { |
| 225 String inputString; |
| 226 if (string.isEmpty()) { |
| 227 inputString = "matrix(1, 0, 0, 1, 0, 0)"; |
| 228 } else { |
| 229 inputString = string; |
| 230 } |
| 231 |
| 232 if (const CSSValue* value = CSSParser::parseSingleValue(CSSPropertyTransform
, inputString)) { |
| 233 if (value->isPrimitiveValue() && (toCSSPrimitiveValue(value))->getValueI
D() == CSSValueNone) |
| 234 exceptionState.throwDOMException(SyntaxError, "Failed to parse '" +
string + "'."); |
| 235 |
| 236 DEFINE_STATIC_REF(ComputedStyle, initialStyle, createInitialStyle()); |
| 237 TransformOperations operations; |
| 238 TransformBuilder::createTransformOperations(*value, CSSToLengthConversio
nData(initialStyle, initialStyle, LayoutViewItem(nullptr), 1.0f), operations); |
| 239 |
| 240 // Convert transform operations to a TransformationMatrix. This can fail |
| 241 // if a param has a percentage ('%') |
| 242 if (operations.dependsOnBoxSize()) |
| 243 exceptionState.throwDOMException(SyntaxError, "The transformation de
pends on the box size, which is not supported."); |
| 244 |
| 245 if (operations.has3DOperation()) |
| 246 m_is2D = false; |
| 247 |
| 248 operations.apply(FloatSize(0, 0), *m_matrix); |
| 249 |
| 250 } else { // There is something there but parsing failed. |
| 251 exceptionState.throwDOMException(SyntaxError, "Failed to parse '" + stri
ng + "'."); |
| 252 } |
| 253 |
| 254 return this; |
| 255 } |
| 256 |
210 } // namespace blink | 257 } // namespace blink |
OLD | NEW |