Skip to content
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

Merged
merged 1 commit into from
Dec 24, 2015
Merged

Conversation

dzbarsky
Copy link
Contributor

Review on Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label 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;")))
Copy link
Contributor

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.

@dzbarsky
Copy link
Contributor Author

Good catch. We're matching Chrome's output now.

@eefriedman
Copy link
Contributor

Review status: 0 of 2 files reviewed at latest revision, 2 unresolved discussions.


components/script/dom/htmlcanvaselement.rs, line 271 [r2] (raw file):
Please make this explicitly None, and add an explicit branch for any unhandled case. I think handling for webgl contexts is missing?


components/script/dom/htmlcanvaselement.rs, line 272 [r2] (raw file):
If I'm not mistaken, this is solid white, and the spec says "fully transparent black". At the very least, there should be a comment explicitly noting what color this is.

Also, a test for this behavior would be nice.


Comments from the review on Reviewable.io

@dzbarsky
Copy link
Contributor Author

Don't have time to write a test right now, but if you mark me delegate+ and I'll land with a test.

@eefriedman
Copy link
Contributor

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.

eefriedman added a commit to eefriedman/servo that referenced this pull request Nov 29, 2015
eefriedman added a commit to eefriedman/servo that referenced this pull request Nov 30, 2015
bors-servo pushed a commit that referenced this pull request Nov 30, 2015
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 -->
asajeffrey pushed a commit to asajeffrey/servo that referenced this pull request Dec 2, 2015
@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #8825) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Dec 18, 2015
@dzbarsky
Copy link
Contributor Author

Fixed the test @eefriedman

// Step 2.
if self.Width() == 0 || self.Height() == 0 {
return Ok(DOMString::from("data:,"));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does step 2 need to come before step 3?

Otherwise looks fine.

@bors-servo delegate+

Copy link
Contributor Author

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.

@dzbarsky dzbarsky force-pushed the no_context branch 2 times, most recently from 50d0f25 to 84ec9c4 Compare December 24, 2015 19:44
@dzbarsky
Copy link
Contributor Author

@bors-servo r+

@bors-servo
Copy link
Contributor

🔑 Insufficient privileges

@michaelwu
Copy link
Contributor

@bors-servo r=eefriedman

@bors-servo
Copy link
Contributor

📌 Commit 84ec9c4 has been approved by eefriedman

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. S-needs-rebase There are merge conflict errors. labels Dec 24, 2015
@bors-servo
Copy link
Contributor

⌛ Testing commit 84ec9c4 with merge 7db6ce4...

bors-servo pushed a commit that referenced this pull request Dec 24, 2015
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 -->
@bors-servo
Copy link
Contributor

☀️ Test successful - android, gonk, linux-dev, linux-rel, mac-dev-ref-unit, mac-rel-css, mac-rel-wpt

@bors-servo bors-servo merged commit 84ec9c4 into servo:master Dec 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants