Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upHandle toDataURL with no context #8725
Conversation
| @@ -279,7 +279,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement { | |||
| let encoded = encoded.to_base64(STANDARD); | |||
| Ok(DOMString::from(format!("data:{};base64,{}", mime_type, encoded))) | |||
| } else { | |||
| Err(Error::NotSupported) | |||
| Ok(DOMString::from(format!("data:image/png;"))) | |||
This comment has been minimized.
This comment has been minimized.
eefriedman
Nov 29, 2015
Contributor
"When its canvas context mode is none, a canvas element has no rendering context, and its bitmap must be fully transparent black with an intrinsic width equal to the numeric value of the element's width attribute and an intrinsic height equal to the numeric value of the element's height attribute, those values being interpreted in CSS pixels, and being updated as the attributes are set, changed, or removed." (https://html.spec.whatwg.org/multipage/scripting.html#the-canvas-element).
In other words, a canvas always has content, so we must always return a valid image with the specified width and height.
|
Good catch. We're matching Chrome's output now. |
|
Review status: 0 of 2 files reviewed at latest revision, 2 unresolved discussions. components/script/dom/htmlcanvaselement.rs, line 271 [r2] (raw file): components/script/dom/htmlcanvaselement.rs, line 272 [r2] (raw file): Also, a test for this behavior would be nice. Comments from the review on Reviewable.io |
|
Don't have time to write a test right now, but if you mark me delegate+ and I'll land with a test. |
|
I'd like to review the test to double-check that it make sense. Also, this doesn't build as-is; looks like a bug in the lint. I'll look into it. |
Encountered in servo#8725.
Encountered in servo#8725.
Fix false positive in unrooted_must_root lint. Encountered in #8725. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8731) <!-- Reviewable:end -->
Encountered in servo#8725.
|
|
|
Fixed the test @eefriedman |
| // Step 2. | ||
| if self.Width() == 0 || self.Height() == 0 { | ||
| return Ok(DOMString::from("data:,")); | ||
| } |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dzbarsky
Dec 24, 2015
Author
Member
Not sure if GetImageData can actually throw here, but I rearranged the steps just to be safe.
50d0f25
to
84ec9c4
|
@bors-servo r+ |
|
|
|
@bors-servo r=eefriedman |
|
|
Handle toDataURL with no context <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8725) <!-- Reviewable:end -->
|
|
dzbarsky commentedNov 29, 2015