Skip to content

Commit 433051c

Browse files
noamrtabatkins
andauthored
[css-background-3] Adjust border-radius outset correction (#12896)
* [css-background-3] Adjust border-radius outset adjustment The new adjustment makes the radius reduction factor in the minimum radius percentage of the corner, making it less pronounced the closer the corner's border-radius gets to 50%. Closes #7103 Resolution: #7103 (comment) * Also apply to margin-box * Adjust variable names * Apply new algo to corner-shape as well * Update css-backgrounds-3/Overview.bs --------- Co-authored-by: Tab Atkins Jr. <jackalmage@gmail.com>
1 parent af8cd55 commit 433051c

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

css-backgrounds-3/Overview.bs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,13 +2453,30 @@ Corner Shaping</h3>
24532453

24542454
The [=margin edge=], being outside the [=border edge=],
24552455
calculates its radius by <em>adding</em> the corresponding margin thickness
2456-
to each border radius.
2457-
However, in order to create a sharper corner when the border radius is small
2458-
(and thus ensure continuity between round and sharp corners),
2459-
when the [=border radius=] is less than the margin,
2460-
the margin is multiplied by the proportion 1 + (<var>r</var>-1)<sup>3</sup>,
2461-
where <var>r</var> is the ratio of the border radius to the margin,
2462-
in calculating the corner radii of the margin box shape.
2456+
to each border radius, with the corresponding [=outset-adjusted border radius=] applied.
2457+
2458+
<div algorithm="border-radius-outset">
2459+
2460+
When expanding an [=edge=] that has a [=border radius=], e.g. for computing the [=margin edge=], 'box-shadow' spread, or 'overflow-clip-margin',
2461+
the different [=border radius=] values are adjusted so that a small rounded corner with a big outset does not appear to be disproportionally round.
2462+
2463+
This is done by computing the corresponding [=outset-adjusted border radius=].
2464+
2465+
To compute the <dfn export>outset-adjusted border radius</dfn> given the 2-dimensional [=size=]s |edge|, |radius|, and |outset|:
2466+
1. Let |coverage| be <code>2 * min(|radius|'s [=width=] / |edge|'s [=width=], |radius|'s [=height=] / |edge|'s [=height=])</code>.
2467+
1. Let |adustedRadiusWidth| be the [=adjusted radius dimension=] given |coverage|, |radius|'s [=width=], and |outset|'s [=width=].
2468+
1. Let |adustedRadiusHeight| be the [=adjusted radius dimension=] given |coverage|, |radius|'s [=height=], and |outset|'s [=height=].
2469+
1. Return (|adustedRadiusWidth|, |adustedRadiusHeight|).
2470+
2471+
To compute the <dfn>adjusted radius dimension</dfn> given numbers |coverage|, |radius|, and |outset|:
2472+
1. If |radius| is greater than |spread|, or if |coverage| is greater than 1, then return <code>|radius| + |outset|</code>.
2473+
1. Let |ratio| be <code>|radius| / |outset|</code>.
2474+
1. Return <code>|radius| + |outset| * (1 - (1 - |ratio|)<sup>3</sup> * (1 - |coverage|<sup>3</sup>))</code>.
2475+
2476+
Note: this algorithm is designed to reduce the effect of the |outset| (or spread) on the shape of the corner.
2477+
The |coverage| factor makes this reduction more pronounced for rectangular shapes (where the [=border-radius=] is close to 0),
2478+
and less pronounced for elliptical shapes (where the [=border-radius=] is close to 50%).
2479+
</div>
24632480

24642481

24652482
<h3 id="corner-clipping">
@@ -3544,19 +3561,8 @@ Shadow Shape, Spread, and Knockout</h4>
35443561
the corner radii of the shadow are also increased (decreased, for inner shadows)
35453562
from the border-box (padding-box) radii by adding (subtracting)
35463563
the [=spread distance=] (and flooring at zero).
3547-
However, in order to create a sharper corner when the border radius is small
3548-
(and thus ensure continuity between round and sharp corners),
3549-
when the [=border radius=] is less than the [=spread distance=]
3550-
(or in the case of an inner shadow,
3551-
less than the absolute value of a negative [=spread distance=]),
3552-
the [=spread distance=]
3553-
is first multiplied by the proportion 1 + (<var>r</var>-1)<sup>3</sup>,
3554-
where <var>r</var> is the ratio of the border radius to the [=spread distance=],
3555-
in calculating the corner radii of the spread shadow shape.
3556-
For example, if the border radius is 10px and the [=spread distance=] is 20px (<var>r</var> = .5),
3557-
the corner radius of the shadow shape will be 10px + 20px × (1 + (.5 - 1)<sup>3</sup>) = 27.5px
3558-
rather than 30px.
3559-
This adjustment is applied independently to the radii in each dimension.
3564+
For outer shadows, the [=border-radius=] is then [=outset-adjusted border radius|adjusted=], independently in each dimension,
3565+
to preseve the sharpness of rounded corners.
35603566

35613567
The 'border-image' does not affect the shape of the box-shadow.
35623568

css-borders-4/Overview.bs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,10 +1432,10 @@ Each shadow of [=/element=]'s 'box shadow' is shaped by the [=border contour pat
14321432

14331433
<div algorithm="adjust-border-inner-path-for-corner-shape">
14341434
To compute an [=/element=] |element|'s <dfn>border contour path</dfn> given an [=edge=] |targetEdge| and an optional number |spread| (default 0):
1435-
1. Let |outerLeft|, |outerTop|, |outerRight|, |outerBottom| be |element|'s [=unshaped edge|unshaped=] [=border edge=].
1435+
1. Let |outerLeft|, |outerTop|, |outerRight|, |outerBottom| be |element|'s [=unshaped edge|unshaped=] [=border edge=], outset by |spread|.
14361436
1. Let |topLeftHorizontalRadius|, |topLeftVericalRadius|, |topRightHorizontalRadius|, |topRightVerticalRadius|, |bottomRightHorizontalRadius|,
14371437
|bottomRightVerticalRadius|, |bottomLeftHorizontalRadius|, and |bottomLeftVerticalRadius| be |element| [=border edge=]'s radii,
1438-
scaled by |element|'s [=opposite corner scale factor=].
1438+
scaled by |element|'s [=opposite corner scale factor=] and [=outset-adjusted border radius|outset-adjusted=].
14391439
1. Let |topLeftShape|, |topRightShape|, |bottomRightShape|, and |bottomLeftShape| be |element|'s [=computed value|computed=] 'corner-*-shape' values.
14401440
1. Let |targetLeft|, |targetTop|, |targetRight|, |targetBottom| [=unshaped edge|unshaped=] |targetEdge|.
14411441
1. Let |path| be a new path [[SVG2]].
@@ -1451,11 +1451,6 @@ To compute an [=/element=] |element|'s <dfn>border contour path</dfn> given an [
14511451
1. [=Add corner to path=] given |path|,
14521452
the [=rectangle=] <code>(|outerLeft|, |outerTop|, |topLeftHorizontalRadius|, |topLeftVericalRadius|)</code>, |targetEdge|,
14531453
3, |targetLeft| - |outerLeft|, |targetTop| - |outerTop|, and |topLeftShape|.
1454-
1. If |spread| is not 0, then:
1455-
1. Scale |path| by <code>1 + (|spread| * 2) / (|targetEdge|'s [=width dimension|width=]), 1 + (|spread| * 2) / (|targetEdge|'s [=height dimension|height=])</code>.
1456-
1. Translate |path| by <code>-|spread|, -|spread|</code>.
1457-
1458-
Note: this creates an effect where the resulting path has the same shape as the original path, but scaled to fit the given spread.
14591454
1. Return |path|.
14601455

14611456
To <dfn>add corner to path</dfn> given a path |path|, a rectangle |cornerRect|, a rectangle |trimRect|,

css-shapes-1/Overview.bs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,10 +1371,7 @@ Shapes from Box Values</h2>
13711371
or margin is negative or zero,
13721372
then the margin box corner radius is
13731373
<code>max(border-radius + margin, 0)</code>.
1374-
If the ratio of <code>border-radius/margin</code> is less than 1,
1375-
and margin is positive,
1376-
then the margin box corner radius is
1377-
<code>border-radius + margin * (1 + (ratio-1)^3)</code>.
1374+
The margin box's corners are [=outset-adjusted border radius|outset-adjusted=] given the element's [=border box=], 'border-radius', and the margin.
13781375

13791376
The <dfn value for="<shape-box>, shape-outside">border-box</dfn> value defines the shape
13801377
enclosed by the outside border edge.

0 commit comments

Comments
 (0)