From 5cc0fa5ec2d185f46628b090adcdf069b8d6649c Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 12 Feb 2017 16:02:29 -0800 Subject: [PATCH] stylo: Support pixel and percent presentation attributes --- .../style/properties/declaration_block.rs | 7 ++ components/style/values/specified/length.rs | 36 +++++++ ports/geckolib/glue.rs | 94 +++++++++++++++++-- 3 files changed, 129 insertions(+), 8 deletions(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index e4b5b6be586..f9681e68361 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -40,6 +40,13 @@ impl Importance { } } +impl Default for Importance { + #[inline] + fn default() -> Self { + Importance::Normal + } +} + /// Overridden declarations are skipped. #[derive(Debug, PartialEq, Clone)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index d2e64481a39..0c41e6518c7 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -368,6 +368,13 @@ pub enum Length { Calc(Box, AllowedNumericType), } +impl From for Length { + #[inline] + fn from(len: NoCalcLength) -> Self { + Length::NoCalc(len) + } +} + impl HasViewportPercentage for Length { fn has_viewport_percentage(&self) -> bool { match *self { @@ -938,6 +945,20 @@ impl From for LengthOrPercentage { } } +impl From for LengthOrPercentage { + #[inline] + fn from(len: NoCalcLength) -> Self { + LengthOrPercentage::Length(len) + } +} + +impl From for LengthOrPercentage { + #[inline] + fn from(pc: Percentage) -> Self { + LengthOrPercentage::Percentage(pc) + } +} + impl HasViewportPercentage for LengthOrPercentage { fn has_viewport_percentage(&self) -> bool { match *self { @@ -1043,6 +1064,21 @@ pub enum LengthOrPercentageOrAuto { Calc(Box), } + +impl From for LengthOrPercentageOrAuto { + #[inline] + fn from(len: NoCalcLength) -> Self { + LengthOrPercentageOrAuto::Length(len) + } +} + +impl From for LengthOrPercentageOrAuto { + #[inline] + fn from(pc: Percentage) -> Self { + LengthOrPercentageOrAuto::Percentage(pc) + } +} + impl HasViewportPercentage for LengthOrPercentageOrAuto { fn has_viewport_percentage(&self) -> bool { match *self { diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 026ea2f8808..41302587fb2 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -961,9 +961,26 @@ macro_rules! get_longhand_from_id { 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] pub extern "C" fn Servo_DeclarationBlock_PropertyIsSet(declarations: RawServoDeclarationBlockBorrowed, @@ -1002,26 +1019,87 @@ pub extern "C" fn Servo_DeclarationBlock_SetIntValue(_: RawServoDeclarationBlock } #[no_mangle] -pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(_: +pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(declarations: RawServoDeclarationBlockBorrowed, - _: nsCSSPropertyID, - _: f32) { + property: nsCSSPropertyID, + 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::::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] -pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(_: +pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(declarations: RawServoDeclarationBlockBorrowed, - _: nsCSSPropertyID, - _: f32) { + property: nsCSSPropertyID, + value: f32) { + use style::properties::{DeclaredValue, PropertyDeclaration, LonghandId}; + use style::values::specified::length::Percentage; + let declarations = RwLock::::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] -pub extern "C" fn Servo_DeclarationBlock_SetAutoValue(_: +pub extern "C" fn Servo_DeclarationBlock_SetAutoValue(declarations: RawServoDeclarationBlockBorrowed, - _: nsCSSPropertyID) { + property: nsCSSPropertyID) { + use style::properties::{DeclaredValue, PropertyDeclaration, LonghandId}; + use style::values::specified::LengthOrPercentageOrAuto; + let declarations = RwLock::::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]