-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Handle toDataURL with no context #8725
Conversation
dzbarsky
commented
Nov 29, 2015
@@ -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;"))) |
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.
"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.
☔ The latest upstream changes (presumably #8825) made this pull request unmergeable. Please resolve the merge conflicts. |
Fixed the test @eefriedman |
// Step 2. | ||
if self.Width() == 0 || self.Height() == 0 { | ||
return Ok(DOMString::from("data:,")); | ||
} |
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.
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.
Not sure if GetImageData can actually throw here, but I rearranged the steps just to be safe.
50d0f25
to
84ec9c4
Compare
@bors-servo r+ |
🔑 Insufficient privileges |
@bors-servo r=eefriedman |
📌 Commit 84ec9c4 has been approved by |
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 -->
☀️ Test successful - android, gonk, linux-dev, linux-rel, mac-dev-ref-unit, mac-rel-css, mac-rel-wpt |