Auto merge of #10651 - craftytrickster:10601/current-color, r=Ms2ger

Setting current color to black if canvas is not rendered in document

Fixes #10601

The change seems deceptively easy, I hope I am not missing anything...

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10651)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-22 09:26:51 -07:00
commit 4da6855e23
2 changed files with 19 additions and 7 deletions

View file

@ -486,11 +486,29 @@ impl CanvasRenderingContext2D {
match color {
Ok(CSSColor::RGBA(rgba)) => Ok(rgba),
Ok(CSSColor::CurrentColor) => {
// TODO: https://github.com/whatwg/html/issues/1099
// Reconsider how to calculate currentColor in a display:none canvas
// TODO: will need to check that the context bitmap mode is fixed
// once we implement CanvasProxy
let window = window_from_node(&*self.canvas);
let style = window.GetComputedStyle(&*self.canvas.upcast(), None);
self.parse_color(&style.GetPropertyValue(DOMString::from("color")))
let element_not_rendered =
!self.canvas.upcast::<Node>().is_in_doc() ||
style.GetPropertyValue(DOMString::from("display")) == "none";
if element_not_rendered {
Ok(RGBA {
red: 0.0,
green: 0.0,
blue: 0.0,
alpha: 1.0,
})
} else {
self.parse_color(&style.GetPropertyValue(DOMString::from("color")))
}
},
_ => Err(())
}