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

Side by Side Diff: third_party/WebKit/Source/core/css/CSSMatrix.cpp

Issue 2688533002: Test code
Patch Set: Storing InspectorRevalidateDOMTask object whenever binding/unbinding node. Created 3 years, 9 months 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 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 15 matching lines...) Expand all
26 #include "core/css/CSSMatrix.h" 26 #include "core/css/CSSMatrix.h"
27 27
28 #include "bindings/core/v8/ExceptionState.h" 28 #include "bindings/core/v8/ExceptionState.h"
29 #include "core/CSSPropertyNames.h" 29 #include "core/CSSPropertyNames.h"
30 #include "core/CSSValueKeywords.h" 30 #include "core/CSSValueKeywords.h"
31 #include "core/css/CSSIdentifierValue.h" 31 #include "core/css/CSSIdentifierValue.h"
32 #include "core/css/CSSToLengthConversionData.h" 32 #include "core/css/CSSToLengthConversionData.h"
33 #include "core/css/StylePropertySet.h" 33 #include "core/css/StylePropertySet.h"
34 #include "core/css/parser/CSSParser.h" 34 #include "core/css/parser/CSSParser.h"
35 #include "core/css/resolver/TransformBuilder.h" 35 #include "core/css/resolver/TransformBuilder.h"
36 #include "core/dom/DOMMatrix.h"
36 #include "core/dom/ExceptionCode.h" 37 #include "core/dom/ExceptionCode.h"
37 #include "core/frame/UseCounter.h" 38 #include "core/frame/UseCounter.h"
38 #include "core/layout/api/LayoutViewItem.h" 39 #include "core/layout/api/LayoutViewItem.h"
39 #include "core/style/ComputedStyle.h" 40 #include "core/style/ComputedStyle.h"
40 #include "core/style/StyleInheritedData.h" 41 #include "core/style/StyleInheritedData.h"
41 #include "wtf/MathExtras.h" 42 #include "wtf/MathExtras.h"
42 43
43 namespace blink { 44 namespace blink {
44 45
45 CSSMatrix* CSSMatrix::create(ExecutionContext* executionContext, 46 CSSMatrix* CSSMatrix::create(ExecutionContext* executionContext,
46 const String& s, 47 const String& s,
47 ExceptionState& exceptionState) { 48 ExceptionState& exceptionState) {
48 UseCounter::count(executionContext, UseCounter::WebKitCSSMatrix); 49 UseCounter::count(executionContext, UseCounter::WebKitCSSMatrix);
49 return new CSSMatrix(s, exceptionState); 50 return new CSSMatrix(s, exceptionState);
50 } 51 }
51 52
52 CSSMatrix::CSSMatrix(const TransformationMatrix& m) 53 CSSMatrix::CSSMatrix(const TransformationMatrix& m) : DOMMatrix(m) {}
53 : m_matrix(TransformationMatrix::create(m)) {}
54 54
55 CSSMatrix::CSSMatrix(const String& s, ExceptionState& exceptionState) 55 CSSMatrix::CSSMatrix(const String& s, ExceptionState& exceptionState)
56 : m_matrix(TransformationMatrix::create()) { 56 : DOMMatrix() {
57 setMatrixValue(s, exceptionState); 57 setMatrixValue(s, exceptionState);
58 } 58 }
59 59
60 static inline PassRefPtr<ComputedStyle> createInitialStyle() {
61 RefPtr<ComputedStyle> initialStyle = ComputedStyle::create();
62 initialStyle->font().update(nullptr);
63 return initialStyle;
64 }
65
66 void CSSMatrix::setMatrixValue(const String& string, 60 void CSSMatrix::setMatrixValue(const String& string,
67 ExceptionState& exceptionState) { 61 ExceptionState& exceptionState) {
68 if (string.isEmpty()) 62 DOMMatrix::setMatrixValue(string, exceptionState);
69 return;
70
71 if (const CSSValue* value =
72 CSSParser::parseSingleValue(CSSPropertyTransform, string)) {
73 // Check for a "none" transform. In these cases we can use the default
74 // identity matrix.
75 if (value->isIdentifierValue() &&
76 (toCSSIdentifierValue(value))->getValueID() == CSSValueNone)
77 return;
78
79 DEFINE_STATIC_REF(ComputedStyle, initialStyle, createInitialStyle());
80 TransformOperations operations =
81 TransformBuilder::createTransformOperations(
82 *value, CSSToLengthConversionData(initialStyle, initialStyle,
83 LayoutViewItem(nullptr), 1.0f));
84
85 // Convert transform operations to a TransformationMatrix. This can fail
86 // if a param has a percentage ('%')
87 if (operations.dependsOnBoxSize())
88 exceptionState.throwDOMException(SyntaxError,
89 "The transformation depends on the box "
90 "size, which is not supported.");
91 m_matrix = TransformationMatrix::create();
92 operations.apply(FloatSize(0, 0), *m_matrix);
93 } else { // There is something there but parsing failed.
94 exceptionState.throwDOMException(SyntaxError,
95 "Failed to parse '" + string + "'.");
96 }
97 } 63 }
98 64
99 // Perform a concatenation of the matrices (this * secondMatrix) 65 // Perform a concatenation of the matrices (this * secondMatrix)
100 CSSMatrix* CSSMatrix::multiply(CSSMatrix* secondMatrix) const { 66 CSSMatrix* CSSMatrix::multiply(CSSMatrix* secondMatrix,
67 ExceptionState& exceptionState) {
101 if (!secondMatrix) 68 if (!secondMatrix)
102 return nullptr; 69 return nullptr;
103 70
104 return CSSMatrix::create( 71 DOMMatrixInit matrix;
105 TransformationMatrix(*m_matrix).multiply(*secondMatrix->m_matrix)); 72
73 matrix.setM11(secondMatrix->m11());
74 matrix.setM12(secondMatrix->m12());
75 matrix.setM13(secondMatrix->m13());
76 matrix.setM14(secondMatrix->m14());
77 matrix.setM21(secondMatrix->m21());
78 matrix.setM22(secondMatrix->m22());
79 matrix.setM23(secondMatrix->m23());
80 matrix.setM24(secondMatrix->m24());
81 matrix.setM31(secondMatrix->m31());
82 matrix.setM32(secondMatrix->m32());
83 matrix.setM33(secondMatrix->m33());
84 matrix.setM34(secondMatrix->m34());
85 matrix.setM41(secondMatrix->m41());
86 matrix.setM42(secondMatrix->m42());
87 matrix.setM43(secondMatrix->m43());
88 matrix.setM44(secondMatrix->m44());
89
90 return (CSSMatrix*)multiplySelf(matrix, exceptionState);
106 } 91 }
107 92
108 CSSMatrix* CSSMatrix::inverse(ExceptionState& exceptionState) const { 93 CSSMatrix* CSSMatrix::inverse(ExceptionState& exceptionState) {
109 if (!m_matrix->isInvertible()) { 94 return (CSSMatrix*)invertSelf();
110 exceptionState.throwDOMException(NotSupportedError,
111 "The matrix is not invertable.");
112 return nullptr;
113 }
114
115 return CSSMatrix::create(m_matrix->inverse());
116 } 95 }
117 96
118 CSSMatrix* CSSMatrix::translate(double x, double y, double z) const { 97 CSSMatrix* CSSMatrix::translate(double x, double y, double z) {
119 if (std::isnan(x)) 98 if (std::isnan(x))
120 x = 0; 99 x = 0;
121 if (std::isnan(y)) 100 if (std::isnan(y))
122 y = 0; 101 y = 0;
123 if (std::isnan(z)) 102 if (std::isnan(z))
124 z = 0; 103 z = 0;
125 return CSSMatrix::create( 104 return (CSSMatrix*)translateSelf(x, y, z);
126 TransformationMatrix(*m_matrix).translate3d(x, y, z));
127 } 105 }
128 106
129 CSSMatrix* CSSMatrix::scale(double scaleX, double scaleY, double scaleZ) const { 107 CSSMatrix* CSSMatrix::scale(double scaleX, double scaleY, double scaleZ) {
130 if (std::isnan(scaleX)) 108 if (std::isnan(scaleX))
131 scaleX = 1; 109 scaleX = 1;
132 if (std::isnan(scaleY)) 110 if (std::isnan(scaleY))
133 scaleY = scaleX; 111 scaleY = scaleX;
134 if (std::isnan(scaleZ)) 112 if (std::isnan(scaleZ))
135 scaleZ = 1; 113 scaleZ = 1;
136 return CSSMatrix::create( 114 return (CSSMatrix*)scaleSelf(scaleX, scaleY, scaleZ);
137 TransformationMatrix(*m_matrix).scale3d(scaleX, scaleY, scaleZ));
138 } 115 }
139 116
140 CSSMatrix* CSSMatrix::rotate(double rotX, double rotY, double rotZ) const { 117 CSSMatrix* CSSMatrix::rotate(double rotX, double rotY, double rotZ) {
141 if (std::isnan(rotX)) 118 if (std::isnan(rotX))
142 rotX = 0; 119 rotX = 0;
143 120
144 if (std::isnan(rotY) && std::isnan(rotZ)) { 121 if (std::isnan(rotY) && std::isnan(rotZ)) {
145 rotZ = rotX; 122 rotZ = rotX;
146 rotX = 0; 123 rotX = 0;
147 rotY = 0; 124 rotY = 0;
148 } 125 }
149 126
150 if (std::isnan(rotY)) 127 if (std::isnan(rotY))
151 rotY = 0; 128 rotY = 0;
152 if (std::isnan(rotZ)) 129 if (std::isnan(rotZ))
153 rotZ = 0; 130 rotZ = 0;
154 return CSSMatrix::create( 131 return (CSSMatrix*)rotateSelf(rotX, rotY, rotZ);
155 TransformationMatrix(*m_matrix).rotate3d(rotX, rotY, rotZ));
156 } 132 }
157 133
158 CSSMatrix* CSSMatrix::rotateAxisAngle(double x, 134 CSSMatrix* CSSMatrix::rotateAxisAngle(double x,
159 double y, 135 double y,
160 double z, 136 double z,
161 double angle) const { 137 double angle) {
162 if (std::isnan(x)) 138 if (std::isnan(x))
163 x = 0; 139 x = 0;
164 if (std::isnan(y)) 140 if (std::isnan(y))
165 y = 0; 141 y = 0;
166 if (std::isnan(z)) 142 if (std::isnan(z))
167 z = 0; 143 z = 0;
168 if (std::isnan(angle)) 144 if (std::isnan(angle))
169 angle = 0; 145 angle = 0;
170 if (!x && !y && !z) 146 if (!x && !y && !z)
171 z = 1; 147 z = 1;
172 return CSSMatrix::create( 148 return (CSSMatrix*)rotateAxisAngleSelf(x, y, z, angle);
173 TransformationMatrix(*m_matrix).rotate3d(x, y, z, angle));
174 } 149 }
175 150
176 CSSMatrix* CSSMatrix::skewX(double angle) const { 151 CSSMatrix* CSSMatrix::skewX(double angle) {
177 if (std::isnan(angle)) 152 if (std::isnan(angle))
178 angle = 0; 153 angle = 0;
179 return CSSMatrix::create(TransformationMatrix(*m_matrix).skewX(angle)); 154 return (CSSMatrix*)skewXSelf(angle);
180 } 155 }
181 156
182 CSSMatrix* CSSMatrix::skewY(double angle) const { 157 CSSMatrix* CSSMatrix::skewY(double angle) {
183 if (std::isnan(angle)) 158 if (std::isnan(angle))
184 angle = 0; 159 angle = 0;
185 return CSSMatrix::create(TransformationMatrix(*m_matrix).skewY(angle)); 160 return (CSSMatrix*)skewYSelf(angle);
186 } 161 }
187 162
188 String CSSMatrix::toString() const { 163 String CSSMatrix::toString() {
189 // FIXME - Need to ensure valid CSS floating point values 164 return DOMMatrix::toString();
190 // (https://bugs.webkit.org/show_bug.cgi?id=20674)
191 if (m_matrix->isAffine())
192 return String::format("matrix(%f, %f, %f, %f, %f, %f)", m_matrix->a(),
193 m_matrix->b(), m_matrix->c(), m_matrix->d(),
194 m_matrix->e(), m_matrix->f());
195 return String::format(
196 "matrix3d(%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, "
197 "%f)",
198 m_matrix->m11(), m_matrix->m12(), m_matrix->m13(), m_matrix->m14(),
199 m_matrix->m21(), m_matrix->m22(), m_matrix->m23(), m_matrix->m24(),
200 m_matrix->m31(), m_matrix->m32(), m_matrix->m33(), m_matrix->m34(),
201 m_matrix->m41(), m_matrix->m42(), m_matrix->m43(), m_matrix->m44());
202 } 165 }
203 166
204 } // namespace blink 167 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSMatrix.h ('k') | third_party/WebKit/Source/core/css/WebKitCSSMatrix.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698