mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
style: Expose line-height resolution to style, and use it from ToResolvedValue
For ToResolvedValue implementation purposes we wouldn't need to split out the vertical / font / line-height arguments and we could just pass around the ComputedStyle, but the lh unit would need that distinction, (because computing lh on font properties should use the parent style). Differential Revision: https://phabricator.services.mozilla.com/D168705
This commit is contained in:
parent
aa810f77ec
commit
8997888c6f
4 changed files with 62 additions and 28 deletions
|
@ -14,7 +14,7 @@ use crate::media_queries::MediaType;
|
|||
use crate::properties::ComputedValues;
|
||||
use crate::string_cache::Atom;
|
||||
use crate::values::computed::font::GenericFontFamily;
|
||||
use crate::values::computed::{ColorScheme, Length};
|
||||
use crate::values::computed::{ColorScheme, Length, NonNegativeLength};
|
||||
use crate::values::specified::color::SystemColor;
|
||||
use crate::values::specified::font::FONT_MEDIUM_PX;
|
||||
use crate::values::specified::ViewportVariant;
|
||||
|
@ -115,6 +115,30 @@ impl Device {
|
|||
&self.environment
|
||||
}
|
||||
|
||||
/// Returns the computed line-height for the font in a given computed values instance.
|
||||
///
|
||||
/// If you pass down an element, then the used line-height is returned.
|
||||
pub fn calc_line_height(
|
||||
&self,
|
||||
line_height: &crate::values::computed::LineHeight,
|
||||
vertical: bool,
|
||||
font: &crate::properties::style_structs::Font,
|
||||
element: Option<super::wrapper::GeckoElement>,
|
||||
) -> NonNegativeLength {
|
||||
let pres_context = self.pres_context();
|
||||
let au = Au(unsafe {
|
||||
bindings::Gecko_CalcLineHeight(
|
||||
line_height,
|
||||
pres_context.map_or(std::ptr::null(), |pc| pc),
|
||||
vertical,
|
||||
font.gecko(),
|
||||
element.map_or(std::ptr::null(), |e| e.0)
|
||||
)
|
||||
});
|
||||
NonNegativeLength::new(au.to_f32_px())
|
||||
}
|
||||
|
||||
|
||||
/// Tells the device that a new viewport rule has been found, and stores the
|
||||
/// relevant viewport constraints.
|
||||
pub fn account_for_viewport_rule(&mut self, _constraints: &ViewportConstraints) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue