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

Side by Side Diff: Source/core/css/CSSBasicShapes.cpp

Issue 227793002: [CSS Shapes] inset args and radial args should serialize to the simplest form (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase and fix calc expectation Created 6 years, 8 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 | « LayoutTests/fast/shapes/parsing/parsing-test-utils.js ('k') | no next file » | 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) 2011 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2011 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 277
278 return compareCSSValueVector(m_values, rhs.m_values); 278 return compareCSSValueVector(m_values, rhs.m_values);
279 } 279 }
280 280
281 void CSSBasicShapePolygon::trace(Visitor* visitor) 281 void CSSBasicShapePolygon::trace(Visitor* visitor)
282 { 282 {
283 visitor->trace(m_values); 283 visitor->trace(m_values);
284 CSSBasicShape::trace(visitor); 284 CSSBasicShape::trace(visitor);
285 } 285 }
286 286
287 static bool buildInsetRadii(Vector<String> &radii, const String& topLeftRadius, const String& topRightRadius, const String& bottomRightRadius, const String& bot tomLeftRadius)
288 {
289 bool showBottomLeft = topRightRadius != bottomLeftRadius;
290 bool showBottomRight = showBottomLeft || (bottomRightRadius != topLeftRadius );
291 bool showTopRight = showBottomRight || (topRightRadius != topLeftRadius);
292
293 radii.append(topLeftRadius);
294 if (showTopRight)
295 radii.append(topRightRadius);
296 if (showBottomRight)
297 radii.append(bottomRightRadius);
298 if (showBottomLeft)
299 radii.append(bottomLeftRadius);
300
301 return radii.size() == 1 && radii[0] == "0px";
302 }
303
287 static String buildInsetString(const String& top, const String& right, const Str ing& bottom, const String& left, 304 static String buildInsetString(const String& top, const String& right, const Str ing& bottom, const String& left,
288 const String& topLeftRadiusWidth, const String& topLeftRadiusHeight, 305 const String& topLeftRadiusWidth, const String& topLeftRadiusHeight,
289 const String& topRightRadiusWidth, const String& topRightRadiusHeight, 306 const String& topRightRadiusWidth, const String& topRightRadiusHeight,
290 const String& bottomRightRadiusWidth, const String& bottomRightRadiusHeight, 307 const String& bottomRightRadiusWidth, const String& bottomRightRadiusHeight,
291 const String& bottomLeftRadiusWidth, const String& bottomLeftRadiusHeight) 308 const String& bottomLeftRadiusWidth, const String& bottomLeftRadiusHeight)
292 { 309 {
293 char opening[] = "inset("; 310 char opening[] = "inset(";
294 char separator[] = " "; 311 char separator[] = " ";
295 char cornersSeparator[] = "round"; 312 char cornersSeparator[] = "round";
296 StringBuilder result; 313 StringBuilder result;
297 result.appendLiteral(opening); 314 result.appendLiteral(opening);
298 result.append(top); 315 result.append(top);
299 if (!right.isNull()) { 316 bool showLeftArg = !left.isNull() && left != right;
317 bool showBottomArg = !bottom.isNull() && (bottom != top || showLeftArg);
318 bool showRightArg = !right.isNull() && (right != top || showBottomArg);
319 if (showRightArg) {
300 result.appendLiteral(separator); 320 result.appendLiteral(separator);
301 result.append(right); 321 result.append(right);
302 } 322 }
303 if (!bottom.isNull()) { 323 if (showBottomArg) {
304 result.appendLiteral(separator); 324 result.appendLiteral(separator);
305 result.append(bottom); 325 result.append(bottom);
306 } 326 }
307 if (!left.isNull()) { 327 if (showLeftArg) {
308 result.appendLiteral(separator); 328 result.appendLiteral(separator);
309 result.append(left); 329 result.append(left);
310 } 330 }
311 331
312 if (!topLeftRadiusWidth.isNull() && !topLeftRadiusHeight.isNull()) { 332 if (!topLeftRadiusWidth.isNull() && !topLeftRadiusHeight.isNull()) {
313 result.appendLiteral(separator); 333 Vector<String> horizontalRadii;
314 result.appendLiteral(cornersSeparator); 334 bool areDefaultCornerRadii = buildInsetRadii(horizontalRadii, topLeftRad iusWidth, topRightRadiusWidth, bottomRightRadiusWidth, bottomLeftRadiusWidth);
315 result.appendLiteral(separator);
316 335
317 result.append(topLeftRadiusWidth); 336 Vector<String> verticalRadii;
318 result.appendLiteral(separator); 337 areDefaultCornerRadii &= buildInsetRadii(verticalRadii, topLeftRadiusHei ght, topRightRadiusHeight, bottomRightRadiusHeight, bottomLeftRadiusHeight);
319 result.append(topRightRadiusWidth);
320 result.appendLiteral(separator);
321 result.append(bottomRightRadiusWidth);
322 result.appendLiteral(separator);
323 result.append(bottomLeftRadiusWidth);
324 338
325 result.appendLiteral(separator); 339 if (!areDefaultCornerRadii) {
326 result.appendLiteral("/"); 340 result.appendLiteral(separator);
327 result.appendLiteral(separator); 341 result.appendLiteral(cornersSeparator);
328 342
329 result.append(topLeftRadiusHeight); 343 for (size_t i = 0; i < horizontalRadii.size(); ++i) {
330 result.appendLiteral(separator); 344 result.appendLiteral(separator);
331 result.append(topRightRadiusHeight); 345 result.append(horizontalRadii[i]);
332 result.appendLiteral(separator); 346 }
333 result.append(bottomRightRadiusHeight); 347 if (horizontalRadii != verticalRadii) {
334 result.appendLiteral(separator); 348 result.appendLiteral(separator);
335 result.append(bottomLeftRadiusHeight); 349 result.appendLiteral("/");
350
351 for (size_t i = 0; i < verticalRadii.size(); ++i) {
352 result.appendLiteral(separator);
353 result.append(verticalRadii[i]);
354 }
355 }
356 }
336 } 357 }
337 result.append(')'); 358 result.append(')');
338 359
339 return result.toString(); 360 return result.toString();
340 } 361 }
341 362
342 static inline void updateCornerRadiusWidthAndHeight(CSSPrimitiveValue* corner, S tring& width, String& height) 363 static inline void updateCornerRadiusWidthAndHeight(CSSPrimitiveValue* corner, S tring& width, String& height)
343 { 364 {
344 if (!corner) 365 if (!corner)
345 return; 366 return;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 visitor->trace(m_left); 425 visitor->trace(m_left);
405 visitor->trace(m_topLeftRadius); 426 visitor->trace(m_topLeftRadius);
406 visitor->trace(m_topRightRadius); 427 visitor->trace(m_topRightRadius);
407 visitor->trace(m_bottomRightRadius); 428 visitor->trace(m_bottomRightRadius);
408 visitor->trace(m_bottomLeftRadius); 429 visitor->trace(m_bottomLeftRadius);
409 CSSBasicShape::trace(visitor); 430 CSSBasicShape::trace(visitor);
410 } 431 }
411 432
412 } // namespace WebCore 433 } // namespace WebCore
413 434
OLDNEW
« no previous file with comments | « LayoutTests/fast/shapes/parsing/parsing-test-utils.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698