Bug 42211

Summary: Canvas: rect(x,y,w,h) should move to (x,y) even if w=0 and h=0
Product: WebKit Reporter: Andreas Kling <kling>
Component: WebCore Misc.Assignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal Keywords: HTML5
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Proposed patch darin: review+, kling: commit-queue-

Description Andreas Kling 2010-07-13 16:37:42 PDT
Quoth HTML5:

The rect(x, y, w, h) method must create a new subpath containing just the four points (x, y), (x+w, y), (x+w, y+h), (x, y+h), with those four points connected by straight lines, and must then mark the subpath as closed. It must then create a new subpath with the point (x, y) as the only point in the subpath.

This would fix one in-tree layout test:
- canvas/philip/tests/2d.path.rect.zero.4.html

Spec link:
http://www.whatwg.org/specs/web-apps/current-work/#dom-context-2d-rect
Comment 1 Andreas Kling 2010-07-13 16:40:45 PDT
Created attachment 61433 [details]
Proposed patch
Comment 2 Darin Adler 2010-07-13 17:18:57 PDT
Comment on attachment 61433 [details]
Proposed patch

Do we still need the validateRectForCanvas function? Can we refactor it so we can still use it?

> +    if (!isfinite(x) | !isfinite(y) | !isfinite(width) | !isfinite(height))
> +        return;

Why "|" instead of "||"?

> +    if (width < 0) {
> +        width = -width;
> +        x -= width;
> +    }
> +
> +    if (height < 0) {
> +        height = -height;
> +        y -= height;
> +    }

It’s inelegant to modify the arguments like this.

r=me
Comment 3 Andreas Kling 2010-07-13 17:45:43 PDT
Committed r63270: <http://trac.webkit.org/changeset/63270>