aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlimageelement.rs
diff options
context:
space:
mode:
authorAnthony Ramine <nox@nox.paris>2020-03-31 22:44:47 +0200
committerAnthony Ramine <nox@nox.paris>2020-04-01 11:40:55 +0200
commit1cd3d6bd4cd0071c8c35d1f891b9f1edaaf20ac7 (patch)
tree068880298f0b1b8a7a16415d165edf774d5dd2db /components/script/dom/htmlimageelement.rs
parentfc07a5147cd26fa3d8778b3366358f8ae5bcee36 (diff)
downloadservo-1cd3d6bd4cd0071c8c35d1f891b9f1edaaf20ac7.tar.gz
servo-1cd3d6bd4cd0071c8c35d1f891b9f1edaaf20ac7.zip
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.
Diffstat (limited to 'components/script/dom/htmlimageelement.rs')
-rw-r--r--components/script/dom/htmlimageelement.rs51
1 files changed, 19 insertions, 32 deletions
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index cd32e6c95de..b5f20784c8e 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -1366,53 +1366,40 @@ impl MicrotaskRunnable for ImageElementMicrotask {
}
pub trait LayoutHTMLImageElementHelpers {
- #[allow(unsafe_code)]
- unsafe fn image(self) -> Option<Arc<Image>>;
- #[allow(unsafe_code)]
- unsafe fn image_url(self) -> Option<ServoUrl>;
- #[allow(unsafe_code)]
- unsafe fn image_density(self) -> Option<f64>;
- #[allow(unsafe_code)]
- unsafe fn image_data(self) -> (Option<Arc<Image>>, Option<ImageMetadata>);
+ fn image(self) -> Option<Arc<Image>>;
+ fn image_url(self) -> Option<ServoUrl>;
+ fn image_density(self) -> Option<f64>;
+ fn image_data(self) -> (Option<Arc<Image>>, Option<ImageMetadata>);
fn get_width(self) -> LengthOrPercentageOrAuto;
fn get_height(self) -> LengthOrPercentageOrAuto;
}
-impl LayoutHTMLImageElementHelpers for LayoutDom<'_, HTMLImageElement> {
+impl<'dom> LayoutDom<'dom, HTMLImageElement> {
#[allow(unsafe_code)]
- unsafe fn image(self) -> Option<Arc<Image>> {
- (*self.unsafe_get())
- .current_request
- .borrow_for_layout()
- .image
- .clone()
+ fn current_request(self) -> &'dom ImageRequest {
+ unsafe { self.unsafe_get().current_request.borrow_for_layout() }
+ }
+}
+
+impl LayoutHTMLImageElementHelpers for LayoutDom<'_, HTMLImageElement> {
+ fn image(self) -> Option<Arc<Image>> {
+ self.current_request().image.clone()
}
- #[allow(unsafe_code)]
- unsafe fn image_url(self) -> Option<ServoUrl> {
- (*self.unsafe_get())
- .current_request
- .borrow_for_layout()
- .parsed_url
- .clone()
+ fn image_url(self) -> Option<ServoUrl> {
+ self.current_request().parsed_url.clone()
}
- #[allow(unsafe_code)]
- unsafe fn image_data(self) -> (Option<Arc<Image>>, Option<ImageMetadata>) {
- let current_request = (*self.unsafe_get()).current_request.borrow_for_layout();
+ fn image_data(self) -> (Option<Arc<Image>>, Option<ImageMetadata>) {
+ let current_request = self.current_request();
(
current_request.image.clone(),
current_request.metadata.clone(),
)
}
- #[allow(unsafe_code)]
- unsafe fn image_density(self) -> Option<f64> {
- (*self.unsafe_get())
- .current_request
- .borrow_for_layout()
- .current_pixel_density
- .clone()
+ fn image_density(self) -> Option<f64> {
+ self.current_request().current_pixel_density.clone()
}
fn get_width(self) -> LengthOrPercentageOrAuto {