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

Handle toDataURL with no context #8725

merged 1 commit into from Dec 24, 2015

Conversation

@dzbarsky
Copy link
Member

dzbarsky commented Nov 29, 2015

Review on Reviewable

@@ -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.

@eefriedman

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.

@eefriedman eefriedman self-assigned this Nov 29, 2015
@dzbarsky dzbarsky force-pushed the dzbarsky:no_context branch from ab3d527 to 73956ac Nov 29, 2015
@dzbarsky
Copy link
Member Author

dzbarsky commented Nov 29, 2015

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

@eefriedman
Copy link
Contributor

eefriedman commented Nov 29, 2015

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 dzbarsky force-pushed the dzbarsky:no_context branch from 73956ac to a6e875b Nov 29, 2015
@dzbarsky
Copy link
Member Author

dzbarsky commented Nov 29, 2015

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

eefriedman commented Nov 29, 2015

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

bors-servo commented Dec 18, 2015

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

@dzbarsky dzbarsky force-pushed the dzbarsky:no_context branch from a6e875b to f5386a6 Dec 23, 2015
@dzbarsky
Copy link
Member Author

dzbarsky commented Dec 23, 2015

Fixed the test @eefriedman

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

This comment has been minimized.

@eefriedman

eefriedman Dec 24, 2015

Contributor

Does step 2 need to come before step 3?

Otherwise looks fine.

@bors-servo delegate+

This comment has been minimized.

@dzbarsky

dzbarsky Dec 24, 2015

Author Member

Not sure if GetImageData can actually throw here, but I rearranged the steps just to be safe.

@dzbarsky dzbarsky force-pushed the dzbarsky:no_context branch 2 times, most recently from 50d0f25 to 84ec9c4 Dec 24, 2015
@dzbarsky
Copy link
Member Author

dzbarsky commented Dec 24, 2015

@bors-servo
Copy link
Contributor

bors-servo commented Dec 24, 2015

🔑 Insufficient privileges

@michaelwu
Copy link
Contributor

michaelwu commented Dec 24, 2015

@bors-servo r=eefriedman

@bors-servo
Copy link
Contributor

bors-servo commented Dec 24, 2015

📌 Commit 84ec9c4 has been approved by eefriedman

@bors-servo
Copy link
Contributor

bors-servo commented Dec 24, 2015

Testing commit 84ec9c4 with merge 7db6ce4...

bors-servo added 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

bors-servo commented Dec 24, 2015

@bors-servo bors-servo merged commit 84ec9c4 into servo:master Dec 24, 2015
2 of 3 checks passed
2 of 3 checks passed
code-review/reviewable Review in progress: 0 of 3 files reviewed, 1 unresolved discussion
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.