Skip to content

Commit

Permalink
stylo: Support pixel and percent presentation attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Feb 19, 2017
1 parent 31945c2 commit 5cc0fa5
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 8 deletions.
7 changes: 7 additions & 0 deletions components/style/properties/declaration_block.rs
Expand Up @@ -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))]
Expand Down
36 changes: 36 additions & 0 deletions components/style/values/specified/length.rs
Expand Up @@ -368,6 +368,13 @@ pub enum Length {
Calc(Box<CalcLengthOrPercentage>, AllowedNumericType),
}

impl From<NoCalcLength> for Length {
#[inline]
fn from(len: NoCalcLength) -> Self {
Length::NoCalc(len)
}
}

impl HasViewportPercentage for Length {
fn has_viewport_percentage(&self) -> bool {
match *self {
Expand Down Expand Up @@ -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 {
fn has_viewport_percentage(&self) -> bool {
match *self {
Expand Down Expand Up @@ -1043,6 +1064,21 @@ pub enum LengthOrPercentageOrAuto {
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 {
fn has_viewport_percentage(&self) -> bool {
match *self {
Expand Down
94 changes: 86 additions & 8 deletions ports/geckolib/glue.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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::<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]
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::<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]
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::<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]
Expand Down

0 comments on commit 5cc0fa5

Please sign in to comment.