stylo: Support pixel and percent presentation attributes

This commit is contained in:
Manish Goregaokar 2017-02-12 16:02:29 -08:00 committed by Manish Goregaokar
parent 31945c287f
commit 5cc0fa5ec2
3 changed files with 129 additions and 8 deletions

View file

@ -40,6 +40,13 @@ impl Importance {
} }
} }
impl Default for Importance {
#[inline]
fn default() -> Self {
Importance::Normal
}
}
/// Overridden declarations are skipped. /// Overridden declarations are skipped.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]

View file

@ -368,6 +368,13 @@ pub enum Length {
Calc(Box<CalcLengthOrPercentage>, AllowedNumericType), Calc(Box<CalcLengthOrPercentage>, AllowedNumericType),
} }
impl From<NoCalcLength> for Length {
#[inline]
fn from(len: NoCalcLength) -> Self {
Length::NoCalc(len)
}
}
impl HasViewportPercentage for Length { impl HasViewportPercentage for Length {
fn has_viewport_percentage(&self) -> bool { fn has_viewport_percentage(&self) -> bool {
match *self { match *self {
@ -938,6 +945,20 @@ impl From<Length> for LengthOrPercentage {
} }
} }
impl From<NoCalcLength> for LengthOrPercentage {
#[inline]
fn from(len: NoCalcLength) -> Self {
LengthOrPercentage::Length(len)
}
}
impl From<Percentage> for LengthOrPercentage {
#[inline]
fn from(pc: Percentage) -> Self {
LengthOrPercentage::Percentage(pc)
}
}
impl HasViewportPercentage for LengthOrPercentage { impl HasViewportPercentage for LengthOrPercentage {
fn has_viewport_percentage(&self) -> bool { fn has_viewport_percentage(&self) -> bool {
match *self { match *self {
@ -1043,6 +1064,21 @@ pub enum LengthOrPercentageOrAuto {
Calc(Box<CalcLengthOrPercentage>), Calc(Box<CalcLengthOrPercentage>),
} }
impl From<NoCalcLength> for LengthOrPercentageOrAuto {
#[inline]
fn from(len: NoCalcLength) -> Self {
LengthOrPercentageOrAuto::Length(len)
}
}
impl From<Percentage> for LengthOrPercentageOrAuto {
#[inline]
fn from(pc: Percentage) -> Self {
LengthOrPercentageOrAuto::Percentage(pc)
}
}
impl HasViewportPercentage for LengthOrPercentageOrAuto { impl HasViewportPercentage for LengthOrPercentageOrAuto {
fn has_viewport_percentage(&self) -> bool { fn has_viewport_percentage(&self) -> bool {
match *self { match *self {

View file

@ -961,9 +961,26 @@ macro_rules! get_longhand_from_id {
return $retval return $retval
} }
} }
};
($id:expr) => {
get_longhand_from_id!($id, ())
} }
} }
macro_rules! match_wrap_declared {
($longhand:ident, $($property:ident => $inner:expr,)*) => (
match $longhand {
$(
LonghandId::$property => PropertyDeclaration::$property(DeclaredValue::Value($inner)),
)*
_ => {
error!("stylo: Don't know how to handle presentation property {:?}", $longhand);
return
}
}
)
}
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_PropertyIsSet(declarations: pub extern "C" fn Servo_DeclarationBlock_PropertyIsSet(declarations:
RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockBorrowed,
@ -1002,26 +1019,87 @@ pub extern "C" fn Servo_DeclarationBlock_SetIntValue(_: RawServoDeclarationBlock
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(_: pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(declarations:
RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockBorrowed,
_: nsCSSPropertyID, property: nsCSSPropertyID,
_: f32) { value: f32) {
use style::properties::{DeclaredValue, PropertyDeclaration, LonghandId};
use style::properties::longhands::border_spacing::SpecifiedValue as BorderSpacing;
use style::values::specified::length::NoCalcLength;
use style::values::specified::BorderWidth;
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
let long = get_longhand_from_id!(property);
let nocalc = NoCalcLength::from_px(value);
let prop = match_wrap_declared! { long,
Height => nocalc.into(),
Width => nocalc.into(),
BorderTopWidth => BorderWidth::Width(nocalc.into()),
BorderRightWidth => BorderWidth::Width(nocalc.into()),
BorderBottomWidth => BorderWidth::Width(nocalc.into()),
BorderLeftWidth => BorderWidth::Width(nocalc.into()),
MarginTop => nocalc.into(),
MarginRight => nocalc.into(),
MarginBottom => nocalc.into(),
MarginLeft => nocalc.into(),
PaddingTop => nocalc.into(),
PaddingRight => nocalc.into(),
PaddingBottom => nocalc.into(),
PaddingLeft => nocalc.into(),
BorderSpacing => Box::new(
BorderSpacing {
horizontal: nocalc.into(),
vertical: nocalc.into(),
}
),
};
declarations.write().declarations.push((prop, Default::default()));
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(_: pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(declarations:
RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockBorrowed,
_: nsCSSPropertyID, property: nsCSSPropertyID,
_: f32) { value: f32) {
use style::properties::{DeclaredValue, PropertyDeclaration, LonghandId};
use style::values::specified::length::Percentage;
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
let long = get_longhand_from_id!(property);
let pc = Percentage(value);
let prop = match_wrap_declared! { long,
Height => pc.into(),
Width => pc.into(),
MarginTop => pc.into(),
MarginRight => pc.into(),
MarginBottom => pc.into(),
MarginLeft => pc.into(),
};
declarations.write().declarations.push((prop, Default::default()));
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetAutoValue(_: pub extern "C" fn Servo_DeclarationBlock_SetAutoValue(declarations:
RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockBorrowed,
_: nsCSSPropertyID) { property: nsCSSPropertyID) {
use style::properties::{DeclaredValue, PropertyDeclaration, LonghandId};
use style::values::specified::LengthOrPercentageOrAuto;
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
let long = get_longhand_from_id!(property);
let auto = LengthOrPercentageOrAuto::Auto;
let prop = match_wrap_declared! { long,
Height => auto,
Width => auto,
MarginTop => auto,
MarginRight => auto,
MarginBottom => auto,
MarginLeft => auto,
};
declarations.write().declarations.push((prop, Default::default()));
} }
#[no_mangle] #[no_mangle]