Skip to content

Commit

Permalink
fixup! Add unique canvas IDs to all canvas operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brody-Eastwood committed Apr 1, 2018
1 parent 7e50873 commit 57166fe
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions components/script/dom/htmlcanvaselement.rs
Expand Up @@ -105,6 +105,7 @@ pub trait LayoutHTMLCanvasElementHelpers {
fn data(&self) -> HTMLCanvasData;
fn get_width(&self) -> LengthOrPercentageOrAuto;
fn get_height(&self) -> LengthOrPercentageOrAuto;
fn get_canvas_id_for_layout(&self) -> CanvasId;
}

impl LayoutHTMLCanvasElementHelpers for LayoutDom<HTMLCanvasElement> {
Expand Down Expand Up @@ -133,7 +134,7 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<HTMLCanvasElement> {
source: source,
width: width_attr.map_or(DEFAULT_WIDTH, |val| val.as_uint()),
height: height_attr.map_or(DEFAULT_HEIGHT, |val| val.as_uint()),
canvas_id: canvas.get_canvas_id(),
canvas_id: self.get_canvas_id_for_layout(),
}
}
}
Expand All @@ -157,6 +158,18 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<HTMLCanvasElement> {
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}

#[allow(unsafe_code)]
fn get_canvas_id_for_layout(&self) -> CanvasId {
unsafe {
let canvas = &*self.unsafe_get();
if let &Some(CanvasContext::Context2d(ref context)) = canvas.context.borrow_for_layout() {
context.get_canvas_id()
} else {
CanvasId(0)
}
}
}
}


Expand Down Expand Up @@ -282,14 +295,6 @@ impl HTMLCanvasElement {

Some((data, size))
}

pub fn get_canvas_id(&self) -> CanvasId {
if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() {
context.get_canvas_id()
} else {
CanvasId(0)
}
}
}

impl HTMLCanvasElementMethods for HTMLCanvasElement {
Expand Down

0 comments on commit 57166fe

Please sign in to comment.