Further changes required by Servo

This commit is contained in:
Oriol Brufau 2023-11-02 20:42:58 +01:00 committed by Martin Robinson
parent 8997888c6f
commit 53cddb1886
3 changed files with 22 additions and 7 deletions

View file

@ -3302,9 +3302,13 @@ impl ComputedValues {
pub fn computed_value_to_string(&self, property: PropertyDeclarationId) -> String { pub fn computed_value_to_string(&self, property: PropertyDeclarationId) -> String {
match property { match property {
PropertyDeclarationId::Longhand(id) => { PropertyDeclarationId::Longhand(id) => {
let context = resolved::Context {
style: self,
};
let mut s = String::new(); let mut s = String::new();
self.get_resolved_value( self.computed_or_resolved_value(
id, id,
Some(&context),
&mut s &mut s
).unwrap(); ).unwrap();
s s

View file

@ -119,12 +119,20 @@ impl ToResolvedValue for LineHeight {
fn to_resolved_value(self, context: &ResolvedContext) -> Self::ResolvedValue { fn to_resolved_value(self, context: &ResolvedContext) -> Self::ResolvedValue {
// Resolve <number> to an absolute <length> based on font size. // Resolve <number> to an absolute <length> based on font size.
if matches!(self, Self::Normal | Self::MozBlockHeight) { #[cfg(feature = "gecko")] {
return self; if matches!(self, Self::Normal | Self::MozBlockHeight) {
return self;
}
let wm = context.style.writing_mode;
let vertical = wm.is_vertical() && !wm.is_sideways();
return Self::Length(context.device.calc_line_height(&self, vertical, context.style.get_font(), Some(context.element_info.element)));
}
if let LineHeight::Number(num) = &self {
let size = context.style.get_font().clone_font_size().computed_size();
LineHeight::Length(NonNegativeLength::new(size.px() * num.0))
} else {
self
} }
let wm = context.style.writing_mode;
let vertical = wm.is_vertical() && !wm.is_sideways();
Self::Length(context.device.calc_line_height(&self, vertical, context.style.get_font(), Some(context.element_info.element)))
} }
#[inline] #[inline]

View file

@ -5,6 +5,7 @@
//! Resolved values. These are almost always computed values, but in some cases //! Resolved values. These are almost always computed values, but in some cases
//! there are used values. //! there are used values.
#[cfg(feature = "gecko")]
use crate::media_queries::Device; use crate::media_queries::Device;
use crate::properties::ComputedValues; use crate::properties::ComputedValues;
use crate::ArcSlice; use crate::ArcSlice;
@ -18,9 +19,9 @@ mod counters;
use crate::values::computed; use crate::values::computed;
/// Element-specific information needed to resolve property values. /// Element-specific information needed to resolve property values.
#[cfg(feature = "gecko")]
pub struct ResolvedElementInfo<'a> { pub struct ResolvedElementInfo<'a> {
/// Element we're resolving line-height against. /// Element we're resolving line-height against.
#[cfg(feature = "gecko")]
pub element: crate::gecko::wrapper::GeckoElement<'a>, pub element: crate::gecko::wrapper::GeckoElement<'a>,
} }
@ -30,8 +31,10 @@ pub struct Context<'a> {
pub style: &'a ComputedValues, pub style: &'a ComputedValues,
/// The device / document we're resolving style for. Useful to do font metrics stuff needed for /// The device / document we're resolving style for. Useful to do font metrics stuff needed for
/// line-height. /// line-height.
#[cfg(feature = "gecko")]
pub device: &'a Device, pub device: &'a Device,
/// The element-specific information to resolve the value. /// The element-specific information to resolve the value.
#[cfg(feature = "gecko")]
pub element_info: ResolvedElementInfo<'a>, pub element_info: ResolvedElementInfo<'a>,
} }