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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/shapes/parsing/parsing-test-utils.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSBasicShapes.cpp
diff --git a/Source/core/css/CSSBasicShapes.cpp b/Source/core/css/CSSBasicShapes.cpp
index 72bfcef26d5af2c9cc68b41243562c6bc75579b9..692fff7539c0ff83bb3580700a5eece02d92197e 100644
--- a/Source/core/css/CSSBasicShapes.cpp
+++ b/Source/core/css/CSSBasicShapes.cpp
@@ -284,6 +284,23 @@ void CSSBasicShapePolygon::trace(Visitor* visitor)
CSSBasicShape::trace(visitor);
}
+static bool buildInsetRadii(Vector<String> &radii, const String& topLeftRadius, const String& topRightRadius, const String& bottomRightRadius, const String& bottomLeftRadius)
+{
+ bool showBottomLeft = topRightRadius != bottomLeftRadius;
+ bool showBottomRight = showBottomLeft || (bottomRightRadius != topLeftRadius);
+ bool showTopRight = showBottomRight || (topRightRadius != topLeftRadius);
+
+ radii.append(topLeftRadius);
+ if (showTopRight)
+ radii.append(topRightRadius);
+ if (showBottomRight)
+ radii.append(bottomRightRadius);
+ if (showBottomLeft)
+ radii.append(bottomLeftRadius);
+
+ return radii.size() == 1 && radii[0] == "0px";
+}
+
static String buildInsetString(const String& top, const String& right, const String& bottom, const String& left,
const String& topLeftRadiusWidth, const String& topLeftRadiusHeight,
const String& topRightRadiusWidth, const String& topRightRadiusHeight,
@@ -296,43 +313,47 @@ static String buildInsetString(const String& top, const String& right, const Str
StringBuilder result;
result.appendLiteral(opening);
result.append(top);
- if (!right.isNull()) {
+ bool showLeftArg = !left.isNull() && left != right;
+ bool showBottomArg = !bottom.isNull() && (bottom != top || showLeftArg);
+ bool showRightArg = !right.isNull() && (right != top || showBottomArg);
+ if (showRightArg) {
result.appendLiteral(separator);
result.append(right);
}
- if (!bottom.isNull()) {
+ if (showBottomArg) {
result.appendLiteral(separator);
result.append(bottom);
}
- if (!left.isNull()) {
+ if (showLeftArg) {
result.appendLiteral(separator);
result.append(left);
}
if (!topLeftRadiusWidth.isNull() && !topLeftRadiusHeight.isNull()) {
- result.appendLiteral(separator);
- result.appendLiteral(cornersSeparator);
- result.appendLiteral(separator);
+ Vector<String> horizontalRadii;
+ bool areDefaultCornerRadii = buildInsetRadii(horizontalRadii, topLeftRadiusWidth, topRightRadiusWidth, bottomRightRadiusWidth, bottomLeftRadiusWidth);
- result.append(topLeftRadiusWidth);
- result.appendLiteral(separator);
- result.append(topRightRadiusWidth);
- result.appendLiteral(separator);
- result.append(bottomRightRadiusWidth);
- result.appendLiteral(separator);
- result.append(bottomLeftRadiusWidth);
+ Vector<String> verticalRadii;
+ areDefaultCornerRadii &= buildInsetRadii(verticalRadii, topLeftRadiusHeight, topRightRadiusHeight, bottomRightRadiusHeight, bottomLeftRadiusHeight);
- result.appendLiteral(separator);
- result.appendLiteral("/");
- result.appendLiteral(separator);
-
- result.append(topLeftRadiusHeight);
- result.appendLiteral(separator);
- result.append(topRightRadiusHeight);
- result.appendLiteral(separator);
- result.append(bottomRightRadiusHeight);
- result.appendLiteral(separator);
- result.append(bottomLeftRadiusHeight);
+ if (!areDefaultCornerRadii) {
+ result.appendLiteral(separator);
+ result.appendLiteral(cornersSeparator);
+
+ for (size_t i = 0; i < horizontalRadii.size(); ++i) {
+ result.appendLiteral(separator);
+ result.append(horizontalRadii[i]);
+ }
+ if (horizontalRadii != verticalRadii) {
+ result.appendLiteral(separator);
+ result.appendLiteral("/");
+
+ for (size_t i = 0; i < verticalRadii.size(); ++i) {
+ result.appendLiteral(separator);
+ result.append(verticalRadii[i]);
+ }
+ }
+ }
}
result.append(')');
« 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