Introduce <LayoutDom<HTMLImageElement>>::current_request

This safe helper contains the only source of unsafety from the actual image
layout helpers methods, making them completely safe.
This commit is contained in:
Anthony Ramine 2020-03-31 22:44:47 +02:00
parent fc07a5147c
commit 1cd3d6bd4c
2 changed files with 26 additions and 43 deletions

View file

@ -1493,25 +1493,21 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
#[allow(unsafe_code)]
fn image_url(self) -> Option<ServoUrl> {
unsafe {
self.downcast::<HTMLImageElement>()
.expect("not an image!")
.image_url()
}
self.downcast::<HTMLImageElement>()
.expect("not an image!")
.image_url()
}
#[allow(unsafe_code)]
fn image_data(self) -> Option<(Option<StdArc<Image>>, Option<ImageMetadata>)> {
unsafe { self.downcast::<HTMLImageElement>().map(|e| e.image_data()) }
self.downcast::<HTMLImageElement>().map(|e| e.image_data())
}
#[allow(unsafe_code)]
fn image_density(self) -> Option<f64> {
unsafe {
self.downcast::<HTMLImageElement>()
.expect("not an image!")
.image_density()
}
self.downcast::<HTMLImageElement>()
.expect("not an image!")
.image_density()
}
fn canvas_data(self) -> Option<HTMLCanvasData> {