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

Side by Side Diff: third_party/WebKit/Source/core/style/BasicShapes.cpp

Issue 2751653003: Replace ASSERT and ASSERT_NOT_REACHED in core/style/ (Closed)
Patch Set: Replace ASSERT and ASSERT_NOT_REACHED in core/style/ 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
« no previous file with comments | « AUTHORS ('k') | third_party/WebKit/Source/core/style/BorderEdge.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2012 Adobe Systems Incorporated. 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 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 if (m_radius.type() == BasicShapeRadius::ClosestSide) 89 if (m_radius.type() == BasicShapeRadius::ClosestSide)
90 return std::min(std::min(std::abs(center.x()), widthDelta), 90 return std::min(std::min(std::abs(center.x()), widthDelta),
91 std::min(std::abs(center.y()), heightDelta)); 91 std::min(std::abs(center.y()), heightDelta));
92 92
93 // If radius.type() == BasicShapeRadius::FarthestSide. 93 // If radius.type() == BasicShapeRadius::FarthestSide.
94 return std::max(std::max(center.x(), widthDelta), 94 return std::max(std::max(center.x(), widthDelta),
95 std::max(center.y(), heightDelta)); 95 std::max(center.y(), heightDelta));
96 } 96 }
97 97
98 void BasicShapeCircle::path(Path& path, const FloatRect& boundingBox) { 98 void BasicShapeCircle::path(Path& path, const FloatRect& boundingBox) {
99 ASSERT(path.isEmpty()); 99 DCHECK(path.isEmpty());
100 FloatPoint center = 100 FloatPoint center =
101 floatPointForCenterCoordinate(m_centerX, m_centerY, boundingBox.size()); 101 floatPointForCenterCoordinate(m_centerX, m_centerY, boundingBox.size());
102 float radius = floatValueForRadiusInBox(boundingBox.size()); 102 float radius = floatValueForRadiusInBox(boundingBox.size());
103 path.addEllipse(FloatRect(center.x() - radius + boundingBox.x(), 103 path.addEllipse(FloatRect(center.x() - radius + boundingBox.x(),
104 center.y() - radius + boundingBox.y(), radius * 2, 104 center.y() - radius + boundingBox.y(), radius * 2,
105 radius * 2)); 105 radius * 2));
106 } 106 }
107 107
108 PassRefPtr<BasicShape> BasicShapeCircle::blend(const BasicShape* other, 108 PassRefPtr<BasicShape> BasicShapeCircle::blend(const BasicShape* other,
109 double progress) const { 109 double progress) const {
110 ASSERT(type() == other->type()); 110 DCHECK_EQ(type(), other->type());
111 const BasicShapeCircle* o = toBasicShapeCircle(other); 111 const BasicShapeCircle* o = toBasicShapeCircle(other);
112 RefPtr<BasicShapeCircle> result = BasicShapeCircle::create(); 112 RefPtr<BasicShapeCircle> result = BasicShapeCircle::create();
113 113
114 result->setCenterX(m_centerX.blend(o->centerX(), progress)); 114 result->setCenterX(m_centerX.blend(o->centerX(), progress));
115 result->setCenterY(m_centerY.blend(o->centerY(), progress)); 115 result->setCenterY(m_centerY.blend(o->centerY(), progress));
116 result->setRadius(m_radius.blend(o->radius(), progress)); 116 result->setRadius(m_radius.blend(o->radius(), progress));
117 return result.release(); 117 return result.release();
118 } 118 }
119 119
120 bool BasicShapeEllipse::operator==(const BasicShape& o) const { 120 bool BasicShapeEllipse::operator==(const BasicShape& o) const {
121 if (!isSameType(o)) 121 if (!isSameType(o))
122 return false; 122 return false;
123 const BasicShapeEllipse& other = toBasicShapeEllipse(o); 123 const BasicShapeEllipse& other = toBasicShapeEllipse(o);
124 return m_centerX == other.m_centerX && m_centerY == other.m_centerY && 124 return m_centerX == other.m_centerX && m_centerY == other.m_centerY &&
125 m_radiusX == other.m_radiusX && m_radiusY == other.m_radiusY; 125 m_radiusX == other.m_radiusX && m_radiusY == other.m_radiusY;
126 } 126 }
127 127
128 float BasicShapeEllipse::floatValueForRadiusInBox( 128 float BasicShapeEllipse::floatValueForRadiusInBox(
129 const BasicShapeRadius& radius, 129 const BasicShapeRadius& radius,
130 float center, 130 float center,
131 float boxWidthOrHeight) const { 131 float boxWidthOrHeight) const {
132 if (radius.type() == BasicShapeRadius::Value) 132 if (radius.type() == BasicShapeRadius::Value)
133 return floatValueForLength(radius.value(), boxWidthOrHeight); 133 return floatValueForLength(radius.value(), boxWidthOrHeight);
134 134
135 float widthOrHeightDelta = std::abs(boxWidthOrHeight - center); 135 float widthOrHeightDelta = std::abs(boxWidthOrHeight - center);
136 if (radius.type() == BasicShapeRadius::ClosestSide) 136 if (radius.type() == BasicShapeRadius::ClosestSide)
137 return std::min(std::abs(center), widthOrHeightDelta); 137 return std::min(std::abs(center), widthOrHeightDelta);
138 138
139 ASSERT(radius.type() == BasicShapeRadius::FarthestSide); 139 DCHECK_EQ(radius.type(), BasicShapeRadius::FarthestSide);
140 return std::max(center, widthOrHeightDelta); 140 return std::max(center, widthOrHeightDelta);
141 } 141 }
142 142
143 void BasicShapeEllipse::path(Path& path, const FloatRect& boundingBox) { 143 void BasicShapeEllipse::path(Path& path, const FloatRect& boundingBox) {
144 ASSERT(path.isEmpty()); 144 DCHECK(path.isEmpty());
145 FloatPoint center = 145 FloatPoint center =
146 floatPointForCenterCoordinate(m_centerX, m_centerY, boundingBox.size()); 146 floatPointForCenterCoordinate(m_centerX, m_centerY, boundingBox.size());
147 float radiusX = 147 float radiusX =
148 floatValueForRadiusInBox(m_radiusX, center.x(), boundingBox.width()); 148 floatValueForRadiusInBox(m_radiusX, center.x(), boundingBox.width());
149 float radiusY = 149 float radiusY =
150 floatValueForRadiusInBox(m_radiusY, center.y(), boundingBox.height()); 150 floatValueForRadiusInBox(m_radiusY, center.y(), boundingBox.height());
151 path.addEllipse(FloatRect(center.x() - radiusX + boundingBox.x(), 151 path.addEllipse(FloatRect(center.x() - radiusX + boundingBox.x(),
152 center.y() - radiusY + boundingBox.y(), radiusX * 2, 152 center.y() - radiusY + boundingBox.y(), radiusX * 2,
153 radiusY * 2)); 153 radiusY * 2));
154 } 154 }
155 155
156 PassRefPtr<BasicShape> BasicShapeEllipse::blend(const BasicShape* other, 156 PassRefPtr<BasicShape> BasicShapeEllipse::blend(const BasicShape* other,
157 double progress) const { 157 double progress) const {
158 ASSERT(type() == other->type()); 158 DCHECK_EQ(type(), other->type());
159 const BasicShapeEllipse* o = toBasicShapeEllipse(other); 159 const BasicShapeEllipse* o = toBasicShapeEllipse(other);
160 RefPtr<BasicShapeEllipse> result = BasicShapeEllipse::create(); 160 RefPtr<BasicShapeEllipse> result = BasicShapeEllipse::create();
161 161
162 if (m_radiusX.type() != BasicShapeRadius::Value || 162 if (m_radiusX.type() != BasicShapeRadius::Value ||
163 o->radiusX().type() != BasicShapeRadius::Value || 163 o->radiusX().type() != BasicShapeRadius::Value ||
164 m_radiusY.type() != BasicShapeRadius::Value || 164 m_radiusY.type() != BasicShapeRadius::Value ||
165 o->radiusY().type() != BasicShapeRadius::Value) { 165 o->radiusY().type() != BasicShapeRadius::Value) {
166 result->setCenterX(o->centerX()); 166 result->setCenterX(o->centerX());
167 result->setCenterY(o->centerY()); 167 result->setCenterY(o->centerY());
168 result->setRadiusX(o->radiusX()); 168 result->setRadiusX(o->radiusX());
169 result->setRadiusY(o->radiusY()); 169 result->setRadiusY(o->radiusY());
170 return result; 170 return result;
171 } 171 }
172 172
173 result->setCenterX(m_centerX.blend(o->centerX(), progress)); 173 result->setCenterX(m_centerX.blend(o->centerX(), progress));
174 result->setCenterY(m_centerY.blend(o->centerY(), progress)); 174 result->setCenterY(m_centerY.blend(o->centerY(), progress));
175 result->setRadiusX(m_radiusX.blend(o->radiusX(), progress)); 175 result->setRadiusX(m_radiusX.blend(o->radiusX(), progress));
176 result->setRadiusY(m_radiusY.blend(o->radiusY(), progress)); 176 result->setRadiusY(m_radiusY.blend(o->radiusY(), progress));
177 return result.release(); 177 return result.release();
178 } 178 }
179 179
180 void BasicShapePolygon::path(Path& path, const FloatRect& boundingBox) { 180 void BasicShapePolygon::path(Path& path, const FloatRect& boundingBox) {
181 ASSERT(path.isEmpty()); 181 DCHECK(path.isEmpty());
182 ASSERT(!(m_values.size() % 2)); 182 DCHECK(!(m_values.size() % 2));
183 size_t length = m_values.size(); 183 size_t length = m_values.size();
184 184
185 if (!length) 185 if (!length)
186 return; 186 return;
187 187
188 path.moveTo( 188 path.moveTo(
189 FloatPoint(floatValueForLength(m_values.at(0), boundingBox.width()) + 189 FloatPoint(floatValueForLength(m_values.at(0), boundingBox.width()) +
190 boundingBox.x(), 190 boundingBox.x(),
191 floatValueForLength(m_values.at(1), boundingBox.height()) + 191 floatValueForLength(m_values.at(1), boundingBox.height()) +
192 boundingBox.y())); 192 boundingBox.y()));
193 for (size_t i = 2; i < length; i = i + 2) { 193 for (size_t i = 2; i < length; i = i + 2) {
194 path.addLineTo(FloatPoint( 194 path.addLineTo(FloatPoint(
195 floatValueForLength(m_values.at(i), boundingBox.width()) + 195 floatValueForLength(m_values.at(i), boundingBox.width()) +
196 boundingBox.x(), 196 boundingBox.x(),
197 floatValueForLength(m_values.at(i + 1), boundingBox.height()) + 197 floatValueForLength(m_values.at(i + 1), boundingBox.height()) +
198 boundingBox.y())); 198 boundingBox.y()));
199 } 199 }
200 path.closeSubpath(); 200 path.closeSubpath();
201 } 201 }
202 202
203 PassRefPtr<BasicShape> BasicShapePolygon::blend(const BasicShape* other, 203 PassRefPtr<BasicShape> BasicShapePolygon::blend(const BasicShape* other,
204 double progress) const { 204 double progress) const {
205 ASSERT(other && isSameType(*other)); 205 DCHECK(other);
206 DCHECK(isSameType(*other));
206 207
207 const BasicShapePolygon* o = toBasicShapePolygon(other); 208 const BasicShapePolygon* o = toBasicShapePolygon(other);
208 ASSERT(m_values.size() == o->values().size()); 209 DCHECK_EQ(m_values.size(), o->values().size());
209 ASSERT(!(m_values.size() % 2)); 210 DCHECK(!(m_values.size() % 2));
210 211
211 size_t length = m_values.size(); 212 size_t length = m_values.size();
212 RefPtr<BasicShapePolygon> result = BasicShapePolygon::create(); 213 RefPtr<BasicShapePolygon> result = BasicShapePolygon::create();
213 if (!length) 214 if (!length)
214 return result.release(); 215 return result.release();
215 216
216 result->setWindRule(o->getWindRule()); 217 result->setWindRule(o->getWindRule());
217 218
218 for (size_t i = 0; i < length; i = i + 2) { 219 for (size_t i = 0; i < length; i = i + 2) {
219 result->appendPoint( 220 result->appendPoint(
(...skipping 13 matching lines...) Expand all
233 } 234 }
234 235
235 static FloatSize floatSizeForLengthSize(const LengthSize& lengthSize, 236 static FloatSize floatSizeForLengthSize(const LengthSize& lengthSize,
236 const FloatRect& boundingBox) { 237 const FloatRect& boundingBox) {
237 return FloatSize( 238 return FloatSize(
238 floatValueForLength(lengthSize.width(), boundingBox.width()), 239 floatValueForLength(lengthSize.width(), boundingBox.width()),
239 floatValueForLength(lengthSize.height(), boundingBox.height())); 240 floatValueForLength(lengthSize.height(), boundingBox.height()));
240 } 241 }
241 242
242 void BasicShapeInset::path(Path& path, const FloatRect& boundingBox) { 243 void BasicShapeInset::path(Path& path, const FloatRect& boundingBox) {
243 ASSERT(path.isEmpty()); 244 DCHECK(path.isEmpty());
244 float left = floatValueForLength(m_left, boundingBox.width()); 245 float left = floatValueForLength(m_left, boundingBox.width());
245 float top = floatValueForLength(m_top, boundingBox.height()); 246 float top = floatValueForLength(m_top, boundingBox.height());
246 FloatRect rect( 247 FloatRect rect(
247 left + boundingBox.x(), top + boundingBox.y(), 248 left + boundingBox.x(), top + boundingBox.y(),
248 std::max<float>(boundingBox.width() - left - 249 std::max<float>(boundingBox.width() - left -
249 floatValueForLength(m_right, boundingBox.width()), 250 floatValueForLength(m_right, boundingBox.width()),
250 0), 251 0),
251 std::max<float>(boundingBox.height() - top - 252 std::max<float>(boundingBox.height() - top -
252 floatValueForLength(m_bottom, boundingBox.height()), 253 floatValueForLength(m_bottom, boundingBox.height()),
253 0)); 254 0));
(...skipping 11 matching lines...) Expand all
265 static inline LengthSize blendLengthSize(const LengthSize& to, 266 static inline LengthSize blendLengthSize(const LengthSize& to,
266 const LengthSize& from, 267 const LengthSize& from,
267 double progress) { 268 double progress) {
268 return LengthSize( 269 return LengthSize(
269 to.width().blend(from.width(), progress, ValueRangeNonNegative), 270 to.width().blend(from.width(), progress, ValueRangeNonNegative),
270 to.height().blend(from.height(), progress, ValueRangeNonNegative)); 271 to.height().blend(from.height(), progress, ValueRangeNonNegative));
271 } 272 }
272 273
273 PassRefPtr<BasicShape> BasicShapeInset::blend(const BasicShape* other, 274 PassRefPtr<BasicShape> BasicShapeInset::blend(const BasicShape* other,
274 double progress) const { 275 double progress) const {
275 ASSERT(other && isSameType(*other)); 276 DCHECK(other);
277 DCHECK(isSameType(*other));
276 278
277 const BasicShapeInset& otherInset = toBasicShapeInset(*other); 279 const BasicShapeInset& otherInset = toBasicShapeInset(*other);
278 RefPtr<BasicShapeInset> result = BasicShapeInset::create(); 280 RefPtr<BasicShapeInset> result = BasicShapeInset::create();
279 result->setTop(m_top.blend(otherInset.top(), progress, ValueRangeAll)); 281 result->setTop(m_top.blend(otherInset.top(), progress, ValueRangeAll));
280 result->setRight(m_right.blend(otherInset.right(), progress, ValueRangeAll)); 282 result->setRight(m_right.blend(otherInset.right(), progress, ValueRangeAll));
281 result->setBottom( 283 result->setBottom(
282 m_bottom.blend(otherInset.bottom(), progress, ValueRangeAll)); 284 m_bottom.blend(otherInset.bottom(), progress, ValueRangeAll));
283 result->setLeft(m_left.blend(otherInset.left(), progress, ValueRangeAll)); 285 result->setLeft(m_left.blend(otherInset.left(), progress, ValueRangeAll));
284 286
285 result->setTopLeftRadius( 287 result->setTopLeftRadius(
(...skipping 14 matching lines...) Expand all
300 const BasicShapeInset& other = toBasicShapeInset(o); 302 const BasicShapeInset& other = toBasicShapeInset(o);
301 return m_right == other.m_right && m_top == other.m_top && 303 return m_right == other.m_right && m_top == other.m_top &&
302 m_bottom == other.m_bottom && m_left == other.m_left && 304 m_bottom == other.m_bottom && m_left == other.m_left &&
303 m_topLeftRadius == other.m_topLeftRadius && 305 m_topLeftRadius == other.m_topLeftRadius &&
304 m_topRightRadius == other.m_topRightRadius && 306 m_topRightRadius == other.m_topRightRadius &&
305 m_bottomRightRadius == other.m_bottomRightRadius && 307 m_bottomRightRadius == other.m_bottomRightRadius &&
306 m_bottomLeftRadius == other.m_bottomLeftRadius; 308 m_bottomLeftRadius == other.m_bottomLeftRadius;
307 } 309 }
308 310
309 } // namespace blink 311 } // namespace blink
OLDNEW
« no previous file with comments | « AUTHORS ('k') | third_party/WebKit/Source/core/style/BorderEdge.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698