-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add roundRect to CanvasRenderingContext2D path #6765
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great addition to the API and I'm looking forward to a wide support.
There is just one point about how the DOMPoint input integrates in there that doesn't seem clear to me, and a small note about where the new subpath should starts.
(Also a bit sad that negative values aren't allowed and thus we'll still need to make concave corners ourselves , but since this is more about replicating CSS border-radius which doesn't support it either, I understand this choice).
Ps: cc @whatwg/canvas
I think I'm opposed to this but not Opposed. I would like to see a JS-only reference polyfill for this. |
Any particular reason to be against this? Given the number of various implementations out there in the wild, I think we can claim it's a feature that web-authors actually want.
I made a quick implementation here: https://github.com/Kaiido/roundRect |
I care a lot about enabling previously-impossible or -difficult use cases, but not so much about ones that are easy to polyfill. I think proof that implementations exist in the wild indicates that while it may be differentially more ergonomic to have as baseline in browsers, we have to ask: Are people going to stop using their own battle-tested implementations and use ours? Can they really simplify their util libraries usefully? They will still need to support browsers that don't have roundRect for quite some time, and I'm not convinced that it's onerous for them to use their own implementations. I fear adding this is more likely to cause portability problems between UAs than not having it at all. Without moving this to core, everyone always polyfills, and it works everywhere that supports canvas today. With this though, apps written and tested in UAs that do implement this will fail to work in UAs that have no support. Yes, ideally people look up the support matrix, but that doesn't always happen. As such, I think the picture for the web is better without this than with it. |
I obviously don't have the answer to that, but I guess that yes, if there is a "standard" way to do this action, why would they keep spending hours / days of search and trial to find the best implementation in the wild?
I think so yes, rather than having each library implement there own version of a roundRect primitive, they can implement only once a real polyfill, that actually follows a "standard" behavior. Currently the "various implementations out there in the wild" I talked about are NOT polyfills, they all come with different signatures and are sometimes actually wrong because like the explainer says, it's hard to get it right. They may all do something that someone could call a "rounded rectangle", but they will all do it differently, which means that if you ask three different web-authors to do three different components in the same page where such a shape should be rendered, they may come up with three different versions of the code.
Having one polyfill is not onerous, but once again, without a "standard" there is no polyfill, and having several implementations is onerous.
Same, they don't "polyfill", they reimplement, again and again.
But here they'll be able to really polyfill, with a single polyfill that everyone will agree on, and with standard tests to make it reliable, because there will finally be a "standard". I get that polluting the APIs with easy to come functions is a bad thing, but here I strongly believe this is beneficial for the eco-system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a few fixup commits since most of the things I found were really small typographical things. Feel free to look over the diff, but for future reference to refine your (already-great) HTML spec contributions, here are some themes:
-
We're currently not wrapping the Dependencies section in the same way as the rest of the spec. (Related: Consider not outputting the Dependencies section #5919 to make this less of a nightmare for contributors.)
-
We use Oxford comma
-
RangeError is not a DOMException
-
We try to use spaces around mathematical operators. (We are not consistent about this, as you can see from rect() right above.)
-
−
is nicer than-
-
Don't forget to cross-link all the instances of dictionary
x
andy
members -
Don't forget to
<var>
all the variables -
Don't put
<var>
around non-variable names, e.g. it's<var>normalizedRadii</var>[0]
, not<var>normalizedRadii[0]</var>
. -
Don't forget
<p>
inside<li>
s -
Don't forget periods at the end of sentences.
-
Check out the style for nested list indents.
I left a few inline comments that are somewhat substantial, but besides those, I think we are ready to go.
negative number, or is an <code data-x="">{ x, y }</code> object whose <code data-x="">x</code> | ||
or <code data-x="">y</code> properties are negative numbers.</p> | ||
|
||
<!-- Consider adding this useful information to all the methods which behave this way: --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented this out for now and added a comment above explaining that we should consider adding it everywhere. I think it is helpful information that would be good to have but I worry that only one method explaining when it silently does nothing would be confusing for developers.
If you're up for fixing the other methods in this PR or a followup PR, that'd be lovely :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you mean all path functions that fail silently and return if their inputs are non-finite?
I'd be happy to tackle that in a separate PR once the Canvas2D new api is launched 😃
Thanks for the feedback @domenic! I'll save this list for future reference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Can you confirm the test coverage is complete? In particular all the details we hashed out about early-returns vs. exceptions, and what type of exceptions? I didn't find any in a quick skim of the test directories you linked; I only saw success cases.
Empty array for radii throws: https://github.com/web-platform-tests/wpt/blob/master/html/canvas/element/path-objects/2d.path.roundrect.radius.none.html 5 elements for radii array throws: https://github.com/web-platform-tests/wpt/blob/master/html/canvas/element/path-objects/2d.path.roundrect.radius.toomany.html Nonfinite fails silently: https://github.com/web-platform-tests/wpt/blob/master/html/canvas/element/path-objects/2d.path.roundrect.nonfinite.html Looks like we're just missing an exception from negative radii. I'll add that now. |
All the exception tests should be updated to RangeError, not "IndexSizeError" DOMException.
Can you test the
Can you test the |
Done and done |
Oh, it looks like your implementation has a bug: it's using DOMPoint, not DOMPointInit. https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/canvas/canvas2d/canvas_path.idl;l=16?q=canvas_path.idl&ss=chromium Let's get that updated and add some test cases (again, just a sprinkling, no need to be exhaustive) that use pure (Note that since DOMPoints also satisfy the DOMPointInit contract, you can use either.) |
Yeah, and I ALSO broke backwards compatibility. It's just roundRect that should move to a RangeError, right? https://chromium-review.googlesource.com/c/chromium/src/+/3015806 |
Yeah. I mean, I'd kind of like to fix the others at some point, but it carries a likely-small-but-potentially-real compat risk, so I don't think it's a great idea to tie it into this change. |
This is what we decided on in the spec debate. whatwg/html#6765 Bug: 1193694 Change-Id: Ic24a8cf9ec61ab584318a40660c0c0e06a0b9848
This is what we decided on in the spec debate. whatwg/html#6765 Bug: 1193694 Change-Id: Ic24a8cf9ec61ab584318a40660c0c0e06a0b9848
This is what we decided on in the spec debate. whatwg/html#6765 Bug: 1193694 Change-Id: Ic24a8cf9ec61ab584318a40660c0c0e06a0b9848 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3016815 Commit-Queue: Aaron Krajeski <[email protected]> Reviewed-by: Justin Novosad <[email protected]> Cr-Commit-Position: refs/heads/master@{#899818}
This is what we decided on in the spec debate. whatwg/html#6765 Bug: 1193694 Change-Id: Ic24a8cf9ec61ab584318a40660c0c0e06a0b9848 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3016815 Commit-Queue: Aaron Krajeski <[email protected]> Reviewed-by: Justin Novosad <[email protected]> Cr-Commit-Position: refs/heads/master@{#899818}
This is what we decided on in the spec debate. whatwg/html#6765 Bug: 1193694 Change-Id: Ic24a8cf9ec61ab584318a40660c0c0e06a0b9848 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3016815 Commit-Queue: Aaron Krajeski <[email protected]> Reviewed-by: Justin Novosad <[email protected]> Cr-Commit-Position: refs/heads/master@{#899818}
Alright, the tests look pretty comprehensive to me now! I'll merge this. @mysteryDate, when you have some time, please file bugs on WebKit and Gecko and update the OP with links to them. |
data-x="DOMPointInit-x">x</code>"].</p></li> | ||
|
||
<li><p>Let <var>left</var> be <var>lowerLeft</var>["<code data-x="DOMPointInit-y">y</code>"] | ||
+ <var>lowerRight</var>["<code data-x="DOMPointInit-y">y</code>"]</p></li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spot this a bit late, sorry...
I think this should read "Let left
be upperLeft
["y"] + lowerLeft
["y"].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks for the catch. Would you or @mysteryDate be up for a quick followup PR to fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened #6871
The algorithm to fix corner overlapping has a typo. I missed it during the review of whatwg#6765 so here is a follow-up. If @mysteryDate could have a look that'd be great.
Automatic update from web-platform-tests Use DOMPointInit for roundRect This is what we decided on in the spec debate. whatwg/html#6765 Bug: 1193694 Change-Id: Ic24a8cf9ec61ab584318a40660c0c0e06a0b9848 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3016815 Commit-Queue: Aaron Krajeski <[email protected]> Reviewed-by: Justin Novosad <[email protected]> Cr-Commit-Position: refs/heads/master@{#899818} -- wpt-commits: adcec00147f8dc59daaca5793d8bcd5f8d2d519a wpt-pr: 29615
Automatic update from web-platform-tests Use DOMPointInit for roundRect This is what we decided on in the spec debate. whatwg/html#6765 Bug: 1193694 Change-Id: Ic24a8cf9ec61ab584318a40660c0c0e06a0b9848 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3016815 Commit-Queue: Aaron Krajeski <[email protected]> Reviewed-by: Justin Novosad <[email protected]> Cr-Commit-Position: refs/heads/master@{#899818} -- wpt-commits: adcec00147f8dc59daaca5793d8bcd5f8d2d519a wpt-pr: 29615
Automatic update from web-platform-tests Use DOMPointInit for roundRect This is what we decided on in the spec debate. whatwg/html#6765 Bug: 1193694 Change-Id: Ic24a8cf9ec61ab584318a40660c0c0e06a0b9848 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3016815 Commit-Queue: Aaron Krajeski <[email protected]> Reviewed-by: Justin Novosad <[email protected]> Cr-Commit-Position: refs/heads/master@{#899818} -- wpt-commits: adcec00147f8dc59daaca5793d8bcd5f8d2d519a wpt-pr: 29615
Automatic update from web-platform-tests Use DOMPointInit for roundRect This is what we decided on in the spec debate. whatwg/html#6765 Bug: 1193694 Change-Id: Ic24a8cf9ec61ab584318a40660c0c0e06a0b9848 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3016815 Commit-Queue: Aaron Krajeski <[email protected]> Reviewed-by: Justin Novosad <[email protected]> Cr-Commit-Position: refs/heads/master@{#899818} -- wpt-commits: adcec00147f8dc59daaca5793d8bcd5f8d2d519a wpt-pr: 29615
This is what we decided on in the spec debate. whatwg/html#6765 Bug: 1193694 Change-Id: Ic24a8cf9ec61ab584318a40660c0c0e06a0b9848 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3016815 Commit-Queue: Aaron Krajeski <[email protected]> Reviewed-by: Justin Novosad <[email protected]> Cr-Commit-Position: refs/heads/master@{#899818} NOKEYCHECK=True GitOrigin-RevId: 0011ce02c0881ded430eb0fd7fa03c78d7411dfe
Original proposal: https://github.com/fserb/canvas2D/blob/master/spec/roundrect.md
Closes #5619
/canvas.html ( diff )
/infrastructure.html ( diff )