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

Unified Diff: Source/platform/geometry/FloatRoundedRect.h

Issue 195793009: [CSS Shapes] inset does not properly clamp large corner radii (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Oops, add tests Created 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/platform/geometry/FloatRoundedRect.h
diff --git a/Source/platform/geometry/FloatRoundedRect.h b/Source/platform/geometry/FloatRoundedRect.h
index 4bdc8e2446b59baf1c445890706ca8be81fab830..7130e9d0fa8cf65c06f04d8a828ff461b8ad0488 100644
--- a/Source/platform/geometry/FloatRoundedRect.h
+++ b/Source/platform/geometry/FloatRoundedRect.h
@@ -132,6 +132,38 @@ inline bool operator==(const FloatRoundedRect& a, const FloatRoundedRect& b)
return a.rect() == b.rect() && a.radii() == b.radii();
}
+inline float calcBorderRadiiConstraintScaleFor(const FloatRect& rect, const FloatRoundedRect::Radii& radii)
+{
+ // Constrain corner radii using CSS3 rules:
+ // http://www.w3.org/TR/css3-background/#the-border-radius
+
+ float factor = 1;
+ float radiiSum;
+
+ // top
+ radiiSum = radii.topLeft().width() + radii.topRight().width(); // Casts to avoid integer overflow.
+ if (radiiSum > rect.width())
+ factor = std::min(rect.width() / radiiSum, factor);
+
+ // bottom
+ radiiSum = radii.bottomLeft().width() + radii.bottomRight().width();
+ if (radiiSum > rect.width())
+ factor = std::min(rect.width() / radiiSum, factor);
+
+ // left
+ radiiSum = radii.topLeft().height() + radii.bottomLeft().height();
+ if (radiiSum > rect.height())
+ factor = std::min(rect.height() / radiiSum, factor);
+
+ // right
+ radiiSum = radii.topRight().height() + radii.bottomRight().height();
+ if (radiiSum > rect.height())
+ factor = std::min(rect.height() / radiiSum, factor);
+
+ ASSERT(factor <= 1);
+ return factor;
+}
+
} // namespace WebCore
#endif // FloatRoundedRect_h

Powered by Google App Engine
This is Rietveld 408576698