mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Make style system support mozmm unit and compute it correctly.
MozReview-Commit-ID: hCUs8xuNd1
This commit is contained in:
parent
fc1e4e95ed
commit
507c90d40b
3 changed files with 63 additions and 3 deletions
|
@ -29,7 +29,10 @@ impl ToComputedValue for specified::NoCalcLength {
|
|||
specified::NoCalcLength::ViewportPercentage(length) =>
|
||||
length.to_computed_value(context.viewport_size()),
|
||||
specified::NoCalcLength::ServoCharacterWidth(length) =>
|
||||
length.to_computed_value(context.style().get_font().clone_font_size())
|
||||
length.to_computed_value(context.style().get_font().clone_font_size()),
|
||||
#[cfg(feature = "gecko")]
|
||||
specified::NoCalcLength::Physical(length) =>
|
||||
length.to_computed_value(context),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -333,6 +333,51 @@ impl Mul<CSSFloat> for AbsoluteLength {
|
|||
}
|
||||
}
|
||||
|
||||
/// Represents a physical length (mozmm) based on DPI
|
||||
#[derive(Clone, PartialEq, Copy, Debug)]
|
||||
#[cfg(feature = "gecko")]
|
||||
pub struct PhysicalLength(pub CSSFloat);
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl PhysicalLength {
|
||||
fn is_zero(&self) -> bool {
|
||||
self.0 == 0.
|
||||
}
|
||||
|
||||
/// Computes the given character width.
|
||||
pub fn to_computed_value(&self, context: &Context) -> Au {
|
||||
use gecko_bindings::bindings;
|
||||
// Same as Gecko
|
||||
const MM_PER_INCH: f32 = 25.4;
|
||||
|
||||
let physical_inch = unsafe {
|
||||
let pres_context = &*context.device.pres_context;
|
||||
bindings::Gecko_GetAppUnitsPerPhysicalInch(&pres_context)
|
||||
};
|
||||
|
||||
let inch = self.0 / MM_PER_INCH;
|
||||
|
||||
to_au_round(inch, physical_inch as f32)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl ToCss for PhysicalLength {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
write!(dest, "{}mozmm", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl Mul<CSSFloat> for PhysicalLength {
|
||||
type Output = PhysicalLength;
|
||||
|
||||
#[inline]
|
||||
fn mul(self, scalar: CSSFloat) -> PhysicalLength {
|
||||
PhysicalLength(self.0 * scalar)
|
||||
}
|
||||
}
|
||||
|
||||
/// A `<length>` without taking `calc` expressions into account
|
||||
///
|
||||
/// https://drafts.csswg.org/css-values/#lengths
|
||||
|
@ -359,6 +404,10 @@ pub enum NoCalcLength {
|
|||
/// This cannot be specified by the user directly and is only generated by
|
||||
/// `Stylist::synthesize_rules_for_legacy_attributes()`.
|
||||
ServoCharacterWidth(CharacterWidth),
|
||||
|
||||
/// A physical length (mozmm) based on DPI
|
||||
#[cfg(feature = "gecko")]
|
||||
Physical(PhysicalLength),
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for NoCalcLength {
|
||||
|
@ -378,6 +427,8 @@ impl ToCss for NoCalcLength {
|
|||
NoCalcLength::ViewportPercentage(length) => length.to_css(dest),
|
||||
/* This should only be reached from style dumping code */
|
||||
NoCalcLength::ServoCharacterWidth(CharacterWidth(i)) => write!(dest, "CharWidth({})", i),
|
||||
#[cfg(feature = "gecko")]
|
||||
NoCalcLength::Physical(length) => length.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -392,6 +443,8 @@ impl Mul<CSSFloat> for NoCalcLength {
|
|||
NoCalcLength::FontRelative(v) => NoCalcLength::FontRelative(v * scalar),
|
||||
NoCalcLength::ViewportPercentage(v) => NoCalcLength::ViewportPercentage(v * scalar),
|
||||
NoCalcLength::ServoCharacterWidth(_) => panic!("Can't multiply ServoCharacterWidth!"),
|
||||
#[cfg(feature = "gecko")]
|
||||
NoCalcLength::Physical(v) => NoCalcLength::Physical(v * scalar),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -438,6 +491,8 @@ impl NoCalcLength {
|
|||
}
|
||||
Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmax(value)))
|
||||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
"mozmm" => Ok(NoCalcLength::Physical(PhysicalLength(value))),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
|
@ -453,6 +508,8 @@ impl NoCalcLength {
|
|||
pub fn is_zero(&self) -> bool {
|
||||
match *self {
|
||||
NoCalcLength::Absolute(length) => length.is_zero(),
|
||||
#[cfg(feature = "gecko")]
|
||||
NoCalcLength::Physical(length) => length.is_zero(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1539,7 +1539,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetLengthValue(declarations:
|
|||
unit: structs::nsCSSUnit) {
|
||||
use style::properties::{PropertyDeclaration, LonghandId};
|
||||
use style::properties::longhands::_moz_script_min_size::SpecifiedValue as MozScriptMinSize;
|
||||
use style::values::specified::length::{AbsoluteLength, FontRelativeLength};
|
||||
use style::values::specified::length::{AbsoluteLength, FontRelativeLength, PhysicalLength};
|
||||
use style::values::specified::length::{LengthOrPercentage, NoCalcLength};
|
||||
|
||||
let long = get_longhand_from_id!(property);
|
||||
|
@ -1550,6 +1550,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetLengthValue(declarations:
|
|||
structs::nsCSSUnit::eCSSUnit_Inch => NoCalcLength::Absolute(AbsoluteLength::In(value)),
|
||||
structs::nsCSSUnit::eCSSUnit_Centimeter => NoCalcLength::Absolute(AbsoluteLength::Cm(value)),
|
||||
structs::nsCSSUnit::eCSSUnit_Millimeter => NoCalcLength::Absolute(AbsoluteLength::Mm(value)),
|
||||
structs::nsCSSUnit::eCSSUnit_PhysicalMillimeter => NoCalcLength::Physical(PhysicalLength(value)),
|
||||
structs::nsCSSUnit::eCSSUnit_Point => NoCalcLength::Absolute(AbsoluteLength::Pt(value)),
|
||||
structs::nsCSSUnit::eCSSUnit_Pica => NoCalcLength::Absolute(AbsoluteLength::Pc(value)),
|
||||
structs::nsCSSUnit::eCSSUnit_Quarter => NoCalcLength::Absolute(AbsoluteLength::Q(value)),
|
||||
|
@ -2220,4 +2221,3 @@ pub extern "C" fn Servo_StyleSet_ResolveForDeclarations(raw_data: RawServoStyleS
|
|||
parent_style,
|
||||
declarations.clone()).into_strong()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue