mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Use app units in replaced elements (#30825)
* use app_units in replaced elements * fmt * remove from_f32_px * fix typo
This commit is contained in:
parent
589f291523
commit
a315bec4ed
2 changed files with 18 additions and 13 deletions
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use app_units::Au;
|
||||||
use euclid::{Size2D, Vector2D};
|
use euclid::{Size2D, Vector2D};
|
||||||
use style::computed_values::background_clip::single_value::T as Clip;
|
use style::computed_values::background_clip::single_value::T as Clip;
|
||||||
use style::computed_values::background_origin::single_value::T as Origin;
|
use style::computed_values::background_origin::single_value::T as Origin;
|
||||||
|
@ -130,8 +131,8 @@ pub(super) fn layout_layer(
|
||||||
if width.is_none() && height.is_none() {
|
if width.is_none() && height.is_none() {
|
||||||
// Both computed values are 'auto':
|
// Both computed values are 'auto':
|
||||||
// use intrinsic sizes, treating missing width or height as 'auto'
|
// use intrinsic sizes, treating missing width or height as 'auto'
|
||||||
width = intrinsic.width;
|
width = intrinsic.width.map(|v| v.into());
|
||||||
height = intrinsic.height;
|
height = intrinsic.height.map(|v| v.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
match (width, height) {
|
match (width, height) {
|
||||||
|
@ -140,10 +141,10 @@ pub(super) fn layout_layer(
|
||||||
let h = if let Some(intrinsic_ratio) = intrinsic.ratio {
|
let h = if let Some(intrinsic_ratio) = intrinsic.ratio {
|
||||||
w / intrinsic_ratio
|
w / intrinsic_ratio
|
||||||
} else if let Some(intrinsic_height) = intrinsic.height {
|
} else if let Some(intrinsic_height) = intrinsic.height {
|
||||||
intrinsic_height
|
intrinsic_height.into()
|
||||||
} else {
|
} else {
|
||||||
// Treated as 100%
|
// Treated as 100%
|
||||||
Length::new(positioning_area.size.height)
|
Au::from_f32_px(positioning_area.size.height).into()
|
||||||
};
|
};
|
||||||
units::LayoutSize::new(w.px(), h.px())
|
units::LayoutSize::new(w.px(), h.px())
|
||||||
},
|
},
|
||||||
|
@ -151,10 +152,10 @@ pub(super) fn layout_layer(
|
||||||
let w = if let Some(intrinsic_ratio) = intrinsic.ratio {
|
let w = if let Some(intrinsic_ratio) = intrinsic.ratio {
|
||||||
h * intrinsic_ratio
|
h * intrinsic_ratio
|
||||||
} else if let Some(intrinsic_width) = intrinsic.width {
|
} else if let Some(intrinsic_width) = intrinsic.width {
|
||||||
intrinsic_width
|
intrinsic_width.into()
|
||||||
} else {
|
} else {
|
||||||
// Treated as 100%
|
// Treated as 100%
|
||||||
Length::new(positioning_area.size.width)
|
Au::from_f32_px(positioning_area.size.width).into()
|
||||||
};
|
};
|
||||||
units::LayoutSize::new(w.px(), h.px())
|
units::LayoutSize::new(w.px(), h.px())
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use app_units::Au;
|
||||||
use canvas_traits::canvas::{CanvasId, CanvasMsg, FromLayoutMsg};
|
use canvas_traits::canvas::{CanvasId, CanvasMsg, FromLayoutMsg};
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
use msg::constellation_msg::{BrowsingContextId, PipelineId};
|
use msg::constellation_msg::{BrowsingContextId, PipelineId};
|
||||||
|
@ -51,8 +52,8 @@ pub(crate) struct ReplacedContent {
|
||||||
/// to https://drafts.csswg.org/css-images/#intrinsic-dimensions.
|
/// to https://drafts.csswg.org/css-images/#intrinsic-dimensions.
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub(crate) struct IntrinsicSizes {
|
pub(crate) struct IntrinsicSizes {
|
||||||
pub width: Option<Length>,
|
pub width: Option<Au>,
|
||||||
pub height: Option<Length>,
|
pub height: Option<Au>,
|
||||||
pub ratio: Option<CSSFloat>,
|
pub ratio: Option<CSSFloat>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +69,8 @@ impl IntrinsicSizes {
|
||||||
};
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
width: Some(Length::new(width)),
|
width: Some(Length::new(width).into()),
|
||||||
height: Some(Length::new(height)),
|
height: Some(Length::new(height).into()),
|
||||||
ratio,
|
ratio,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,7 +212,10 @@ impl ReplacedContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flow_relative_intrinsic_size(&self, style: &ComputedValues) -> LogicalVec2<Option<Length>> {
|
fn flow_relative_intrinsic_size(&self, style: &ComputedValues) -> LogicalVec2<Option<Length>> {
|
||||||
let intrinsic_size = PhysicalSize::new(self.intrinsic.width, self.intrinsic.height);
|
let intrinsic_size = PhysicalSize::new(
|
||||||
|
self.intrinsic.width.map(|v| v.into()),
|
||||||
|
self.intrinsic.height.map(|v| v.into()),
|
||||||
|
);
|
||||||
LogicalVec2::from_physical_size(&intrinsic_size, style.writing_mode)
|
LogicalVec2::from_physical_size(&intrinsic_size, style.writing_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,8 +281,8 @@ impl ReplacedContent {
|
||||||
})]
|
})]
|
||||||
},
|
},
|
||||||
ReplacedContentKind::Canvas(canvas_info) => {
|
ReplacedContentKind::Canvas(canvas_info) => {
|
||||||
if self.intrinsic.width == Some(Length::zero()) ||
|
if self.intrinsic.width == Some(Au::zero()) ||
|
||||||
self.intrinsic.height == Some(Length::zero())
|
self.intrinsic.height == Some(Au::zero())
|
||||||
{
|
{
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue