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 {
match property {
PropertyDeclarationId::Longhand(id) => {
let context = resolved::Context {
style: self,
};
let mut s = String::new();
self.get_resolved_value(
self.computed_or_resolved_value(
id,
Some(&context),
&mut s
).unwrap();
s

View file

@ -119,12 +119,20 @@ impl ToResolvedValue for LineHeight {
fn to_resolved_value(self, context: &ResolvedContext) -> Self::ResolvedValue {
// Resolve <number> to an absolute <length> based on font size.
if matches!(self, Self::Normal | Self::MozBlockHeight) {
return self;
#[cfg(feature = "gecko")] {
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]

View file

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