Auto merge of #8728 - dzbarsky:reset_bitmpa, r=dzbarsky

Reset canvas state when changing bitmap dimensions

Ran http://mxr.mozilla.org/servo/source/tests/wpt/web-platform-tests/html/semantics/embedded-content/the-canvas-element/initial.reset.2dstate.html?force=1#88 to confirm that this code is being executed, but the test still fails because the font isn't implemented and the expando doesn't get reset.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8728)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-12-04 11:57:55 +05:30
commit 2bb34feb3e
4 changed files with 103 additions and 2 deletions

View file

@ -143,12 +143,20 @@ impl CanvasRenderingContext2D {
CanvasRenderingContext2DBinding::Wrap)
}
pub fn recreate(&self, size: Size2D<i32>) {
// https://html.spec.whatwg.org/multipage/#concept-canvas-set-bitmap-dimensions
pub fn set_bitmap_dimensions(&self, size: Size2D<i32>) {
self.reset_to_initial_state();
self.ipc_renderer
.send(CanvasMsg::Common(CanvasCommonMsg::Recreate(size)))
.unwrap();
}
// https://html.spec.whatwg.org/multipage/#reset-the-rendering-context-to-its-default-state
fn reset_to_initial_state(&self) {
self.saved_states.borrow_mut().clear();
*self.state.borrow_mut() = CanvasContextState::new();
}
pub fn ipc_renderer(&self) -> IpcSender<CanvasMsg> {
self.ipc_renderer.clone()
}

View file

@ -81,7 +81,7 @@ impl HTMLCanvasElement {
let size = self.get_size();
if let Some(ref context) = *self.context.borrow() {
match *context {
CanvasContext::Context2d(ref context) => context.recreate(size),
CanvasContext::Context2d(ref context) => context.set_bitmap_dimensions(size),
CanvasContext::WebGL(ref context) => context.recreate(size),
}
}