Bug 72103 - box-shadow creates incorrect shadow when border-radius is too large
Summary: box-shadow creates incorrect shadow when border-radius is too large
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 420+
Hardware: Other All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-11 01:30 PST by Daniel Kurejwowski
Modified: 2012-08-10 11:36 PDT (History)
8 users (show)

See Also:


Attachments
Demonstrate border-radius interaction with box-shadow (2.66 KB, text/html)
2011-11-11 01:30 PST, Daniel Kurejwowski
no flags Details
Reduced demonstration of border-radius interaction with box-shadow (1.86 KB, text/html)
2011-11-11 01:31 PST, Daniel Kurejwowski
no flags Details
Further reduced example (936 bytes, text/html)
2011-11-11 02:10 PST, Daniel Kurejwowski
no flags Details
Patch (15.83 KB, patch)
2012-05-20 23:04 PDT, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Patch (14.44 KB, patch)
2012-06-07 04:06 PDT, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Patch (11.58 KB, patch)
2012-06-08 00:28 PDT, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Patch (11.59 KB, patch)
2012-06-08 02:57 PDT, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Patch (11.92 KB, patch)
2012-08-02 02:17 PDT, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from gce-cr-linux-03 (607.08 KB, application/zip)
2012-08-02 04:19 PDT, WebKit Review Bot
no flags Details
Patch (11.97 KB, patch)
2012-08-02 05:53 PDT, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from gce-cr-linux-08 (497.18 KB, application/zip)
2012-08-02 07:35 PDT, WebKit Review Bot
no flags Details
Patch (17.23 KB, patch)
2012-08-03 02:18 PDT, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from gce-cr-linux-02 (435.14 KB, application/zip)
2012-08-03 03:25 PDT, WebKit Review Bot
no flags Details
Archive of layout-test-results from gce-cr-linux-05 (447.52 KB, application/zip)
2012-08-03 04:18 PDT, WebKit Review Bot
no flags Details
Archive of layout-test-results from apple-mac-3 (447.30 KB, application/zip)
2012-08-03 04:32 PDT, Build Bot
no flags Details
Patch (15.88 KB, patch)
2012-08-08 04:14 PDT, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from gce-cr-linux-02 (519.58 KB, application/zip)
2012-08-08 05:21 PDT, WebKit Review Bot
no flags Details
Patch (35.43 KB, patch)
2012-08-08 19:31 PDT, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Patch (16.30 KB, patch)
2012-08-09 01:56 PDT, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Patch (16.31 KB, patch)
2012-08-09 21:13 PDT, Takashi Sakamoto
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Kurejwowski 2011-11-11 01:30:20 PST
Created attachment 114649 [details]
Demonstrate border-radius interaction with box-shadow

When using box-shadow and border-radius on an element, the shadow is incorrectly drawn if border-radius's value is larger than the height or width of the element. This occurs in different ways depending on box-shadow's spread's sign. For negative values of box-shadow spread, the resulting shadow is rectangular. Additionally there is a section of the shadow that isn't painted (the element would occupy if it weren't for the rounded border).

If an element uses a large value for border-radius, the value is capped to a the maximum. If it is used along with box-shadow with a negative spread, then instead of the radius being capped it is ignored and a square shadow is created. The border radius' biggest value before it creates a square shadow seems to be the  width or height of the element (whichever is smaller) plus the spread.

The radius that triggers the missing shadow regions seems to be equal to the smaller of width or height and doesn't seem affected by the amount of spread.

So for example a width of 500px and height of 200px, a spread of -10px, "border-radius: 0 0 191px 0" will trigger a square shadow, while "0 0 190px 0" will not. "0 0 200px 0" will trigger both the square shadow and the missing region, "0 0 199px 0" will only trigger the square shadow.
Comment 1 Daniel Kurejwowski 2011-11-11 01:31:22 PST
Created attachment 114650 [details]
Reduced demonstration of border-radius interaction with box-shadow
Comment 2 Daniel Kurejwowski 2011-11-11 01:38:11 PST
Reproduced with 
-Safari (5.1.1 (7534.51.22)) for Windows XP
-Safari for iPad 2
-Rockmelt 0.9.68.1420 (Official Build 35c4f95) WebKit 535.1 (branches/chromium/835@96063) {note, only the square shadow is reproduceable, there is no apparent missing regions}
-Google Chrome	15.0.874.106 (Official Build 107270) WebKit 535.2 (@98043) {note, only the square shadow is reproducible, no missing regions.}
Comment 3 Daniel Kurejwowski 2011-11-11 02:10:12 PST
Created attachment 114653 [details]
Further reduced example
Comment 4 David Barr 2012-02-29 19:38:33 PST
Confirmed in WebKit Nightly, Version 5.1.2 (6534.52.7, r109280).
Comment 5 Takashi Sakamoto 2012-05-20 23:04:04 PDT
Created attachment 142947 [details]
Patch
Comment 6 Hajime Morrita 2012-05-22 19:11:04 PDT
Comment on attachment 142947 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=142947&action=review

> Source/WebCore/platform/graphics/Path.cpp:-134
> -

Is this really OK? What will happen on other platforms?
Comment 7 Takashi Sakamoto 2012-06-07 04:06:43 PDT
Created attachment 146249 [details]
Patch
Comment 8 Takashi Sakamoto 2012-06-07 04:09:01 PDT
(In reply to comment #6)
> (From update of attachment 142947 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=142947&action=review
> 
> > Source/WebCore/platform/graphics/Path.cpp:-134
> > -
> 
> Is this really OK? What will happen on other platforms?

I see. I restricted the code, i.e. removing the condition, to chromium or mac.

Best regards,
Takashi Sakamoto
Comment 9 Takashi Sakamoto 2012-06-07 04:09:57 PDT
(In reply to comment #8)
> (In reply to comment #6)
> > (From update of attachment 142947 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=142947&action=review
> > 
> > > Source/WebCore/platform/graphics/Path.cpp:-134
> > > -
> > 
> > Is this really OK? What will happen on other platforms?
> 
> I see. I restricted the code, i.e. removing the condition, to chromium or mac.

I think, I need someone's help for checking Windows or other platforms...
Comment 10 Simon Fraser (smfr) 2012-06-07 08:42:55 PDT
Comment on attachment 146249 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=146249&action=review

> Source/WebCore/platform/graphics/Path.cpp:134
> +#if !PLATFORM(CHROMIUM) && !PLATFORM(MAC)
>      if (rect.width() < topLeftRadius.width() + topRightRadius.width()

Random platform #ifdefs are never a good thing in shared platform code. It's impossible to know, by reading this, why Chromium or Mac behave differently.
Comment 11 Takashi Sakamoto 2012-06-08 00:28:03 PDT
Created attachment 146498 [details]
Patch
Comment 12 Takashi Sakamoto 2012-06-08 00:30:12 PDT
(In reply to comment #10)
> (From update of attachment 146249 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=146249&action=review
> 
> > Source/WebCore/platform/graphics/Path.cpp:134
> > +#if !PLATFORM(CHROMIUM) && !PLATFORM(MAC)
> >      if (rect.width() < topLeftRadius.width() + topRightRadius.width()
> 
> Random platform #ifdefs are never a good thing in shared platform code. It's impossible to know, by reading this, why Chromium or Mac behave differently.

I see. I completely agree with you.

So I investigated how Firefox treats border-radiuses like this and implemented the logic in my new patch.
Now there are no #ifdefs in Path.cpp.

Best regards,
Takashi Sakamoto
Comment 13 Build Bot 2012-06-08 01:29:26 PDT
Comment on attachment 146498 [details]
Patch

Attachment 146498 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/12922438
Comment 14 Takashi Sakamoto 2012-06-08 02:28:12 PDT
Comment on attachment 146498 [details]
Patch

As fmax is not available in windows, I will fix and upload a new patch again.
Comment 15 Takashi Sakamoto 2012-06-08 02:57:39 PDT
Created attachment 146526 [details]
Patch
Comment 16 Takashi Sakamoto 2012-08-02 02:17:28 PDT
Created attachment 156014 [details]
Patch
Comment 17 WebKit Review Bot 2012-08-02 04:19:49 PDT
Comment on attachment 156014 [details]
Patch

Attachment 156014 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/13426145

New failing tests:
fast/borders/border-radius-larger-than-rect.html
Comment 18 WebKit Review Bot 2012-08-02 04:19:53 PDT
Created attachment 156039 [details]
Archive of layout-test-results from gce-cr-linux-03

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: gce-cr-linux-03  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.39-gcg-201203291735-x86_64-with-Ubuntu-10.04-lucid
Comment 19 Takashi Sakamoto 2012-08-02 05:53:31 PDT
Created attachment 156055 [details]
Patch
Comment 20 WebKit Review Bot 2012-08-02 07:35:40 PDT
Comment on attachment 156055 [details]
Patch

Attachment 156055 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/13411897

New failing tests:
fast/borders/border-radius-larger-than-rect.html
Comment 21 WebKit Review Bot 2012-08-02 07:35:45 PDT
Created attachment 156079 [details]
Archive of layout-test-results from gce-cr-linux-08

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: gce-cr-linux-08  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.39-gcg-201203291735-x86_64-with-Ubuntu-10.04-lucid
Comment 22 Simon Fraser (smfr) 2012-08-02 08:40:48 PDT
Comment on attachment 156055 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=156055&action=review

> Source/WebCore/platform/graphics/Path.cpp:138
> +        float maxRadiusWidth = std::max(topLeftRadius.width() + topRightRadius.width(), bottomLeftRadius.width() + bottomRightRadius.width());
> +        float maxRadiusHeight = std::max(topLeftRadius.height() + bottomLeftRadius.height(), topRightRadius.height() + bottomRightRadius.height());

We normally put a 'using namespace std' at the top of the file, then use min() and max() without the namespace qualifier.

> Source/WebCore/platform/graphics/Path.cpp:148
> +        float scale = maxRadiusWidth > maxRadiusHeight ? rect.width() / maxRadiusWidth : rect.height() / maxRadiusHeight;
> +        FloatSize adjustedTopLeftRadius(topLeftRadius);
> +        FloatSize adjustedTopRightRadius(topRightRadius);
> +        FloatSize adjustedBottomLeftRadius(bottomLeftRadius);
> +        FloatSize adjustedBottomRightRadius(bottomRightRadius);
> +        adjustedTopLeftRadius.scale(scale);
> +        adjustedTopRightRadius.scale(scale);
> +        adjustedBottomLeftRadius.scale(scale);
> +        adjustedBottomRightRadius.scale(scale);
> +        addPathForRoundedRect(rect, adjustedTopLeftRadius, adjustedTopRightRadius, adjustedBottomLeftRadius, adjustedBottomRightRadius, strategy);

Is it appropriate to have this code here, where it affects all path drawing, rather than in rendering code? What is the impact on other uses, like SVG and canvas?

It might be better to make RoundedFloatRect, then have a utility method on it that does the radius scaling, so we can call it from anywhere.

> LayoutTests/fast/borders/border-radius-larger-than-rect.html:12
> +    background-color: red;

Please don't use red in a passing test. Also, make the divs bigger so the issue is more apparent.
Comment 23 mitz 2012-08-02 08:47:20 PDT
(In reply to comment #22)

> We normally put a 'using namespace std' at the top of the file, then use min() and max() without the namespace qualifier.

Not anymore: http://www.webkit.org/coding/coding-style.html#using-in-cpp
Comment 24 Takashi Sakamoto 2012-08-03 02:18:57 PDT
Created attachment 156296 [details]
Patch
Comment 25 Takashi Sakamoto 2012-08-03 02:23:57 PDT
Thank you for reviewing.

(In reply to comment #22)
> (From update of attachment 156055 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=156055&action=review
> 
> > Source/WebCore/platform/graphics/Path.cpp:138
> > +        float maxRadiusWidth = std::max(topLeftRadius.width() + topRightRadius.width(), bottomLeftRadius.width() + bottomRightRadius.width());
> > +        float maxRadiusHeight = std::max(topLeftRadius.height() + bottomLeftRadius.height(), topRightRadius.height() + bottomRightRadius.height());
> 
> We normally put a 'using namespace std' at the top of the file, then use min() and max() without the namespace qualifier.
> 
> > Source/WebCore/platform/graphics/Path.cpp:148
> > +        float scale = maxRadiusWidth > maxRadiusHeight ? rect.width() / maxRadiusWidth : rect.height() / maxRadiusHeight;
> > +        FloatSize adjustedTopLeftRadius(topLeftRadius);
> > +        FloatSize adjustedTopRightRadius(topRightRadius);
> > +        FloatSize adjustedBottomLeftRadius(bottomLeftRadius);
> > +        FloatSize adjustedBottomRightRadius(bottomRightRadius);
> > +        adjustedTopLeftRadius.scale(scale);
> > +        adjustedTopRightRadius.scale(scale);
> > +        adjustedBottomLeftRadius.scale(scale);
> > +        adjustedBottomRightRadius.scale(scale);
> > +        addPathForRoundedRect(rect, adjustedTopLeftRadius, adjustedTopRightRadius, adjustedBottomLeftRadius, adjustedBottomRightRadius, strategy);
> 
> Is it appropriate to have this code here, where it affects all path drawing, rather than in rendering code? What is the impact on other uses, like SVG and canvas?
> 
> It might be better to make RoundedFloatRect, then have a utility method on it that does the radius scaling, so we can call it from anywhere.

I think, the code is just for fixing border-radius only when the radius is invalid. However, I reverted these codes and modified the renderer to fix this issue.

> 
> > LayoutTests/fast/borders/border-radius-larger-than-rect.html:12
> > +    background-color: red;
> 
> Please don't use red in a passing test. Also, make the divs bigger so the issue is more apparent.

I see. However I found that this test is not good for testing this issue. I recreated a new test from attached repro html.

Best regards,
Takashi Sakamoto
Comment 26 WebKit Review Bot 2012-08-03 03:25:23 PDT
Comment on attachment 156296 [details]
Patch

Attachment 156296 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/13431268

New failing tests:
fast/borders/border-shadow-large-radius.html
Comment 27 WebKit Review Bot 2012-08-03 03:25:28 PDT
Created attachment 156307 [details]
Archive of layout-test-results from gce-cr-linux-02

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: gce-cr-linux-02  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.39-gcg-201203291735-x86_64-with-Ubuntu-10.04-lucid
Comment 28 WebKit Review Bot 2012-08-03 04:18:48 PDT
Comment on attachment 156296 [details]
Patch

Attachment 156296 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/13433029

New failing tests:
fast/borders/border-shadow-large-radius.html
Comment 29 WebKit Review Bot 2012-08-03 04:18:53 PDT
Created attachment 156322 [details]
Archive of layout-test-results from gce-cr-linux-05

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: gce-cr-linux-05  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.39-gcg-201203291735-x86_64-with-Ubuntu-10.04-lucid
Comment 30 Build Bot 2012-08-03 04:32:35 PDT
Comment on attachment 156296 [details]
Patch

Attachment 156296 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/13426572

New failing tests:
fast/borders/border-shadow-large-radius.html
Comment 31 Build Bot 2012-08-03 04:32:40 PDT
Created attachment 156325 [details]
Archive of layout-test-results from apple-mac-3

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: apple-mac-3  Port: <class 'webkitpy.common.config.ports.MacPort'>  Platform: Mac OS X 10.7.4
Comment 32 Takashi Sakamoto 2012-08-08 04:14:28 PDT
Created attachment 157176 [details]
Patch
Comment 33 WebKit Review Bot 2012-08-08 05:21:37 PDT
Comment on attachment 157176 [details]
Patch

Attachment 157176 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/13461132

New failing tests:
fast/borders/border-shadow-large-radius.html
Comment 34 WebKit Review Bot 2012-08-08 05:21:41 PDT
Created attachment 157191 [details]
Archive of layout-test-results from gce-cr-linux-02

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: gce-cr-linux-02  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.39-gcg-201203291735-x86_64-with-Ubuntu-10.04-lucid
Comment 35 Takashi Sakamoto 2012-08-08 19:31:37 PDT
Created attachment 157371 [details]
Patch
Comment 36 Simon Fraser (smfr) 2012-08-08 19:54:32 PDT
Comment on attachment 157371 [details]
Patch

Please make the text not visible in the pixel results; it will cause spurious pixel comparison failures. You can have it as an HTML comment.
Comment 37 Takashi Sakamoto 2012-08-09 01:56:48 PDT
Created attachment 157426 [details]
Patch
Comment 38 Simon Fraser (smfr) 2012-08-09 10:34:17 PDT
Comment on attachment 157426 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=157426&action=review

> Source/WebCore/ChangeLog:8
> +        Additional information of the change such as approach, rationale. Please add per-function descriptions below (OOPS!).

This is still missing.
Comment 39 Takashi Sakamoto 2012-08-09 21:13:31 PDT
Created attachment 157630 [details]
Patch
Comment 40 Takashi Sakamoto 2012-08-09 21:14:59 PDT
(In reply to comment #38)
> (From update of attachment 157426 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=157426&action=review
> 
> > Source/WebCore/ChangeLog:8
> > +        Additional information of the change such as approach, rationale. Please add per-function descriptions below (OOPS!).
> 
> This is still missing.

Thank you. I fixed this.

Best regards,
Takashi Sakamoto
Comment 41 WebKit Review Bot 2012-08-10 11:35:55 PDT
Comment on attachment 157630 [details]
Patch

Clearing flags on attachment: 157630

Committed r125304: <http://trac.webkit.org/changeset/125304>
Comment 42 WebKit Review Bot 2012-08-10 11:36:01 PDT
All reviewed patches have been landed.  Closing bug.