diff --git a/complete.rs b/complete.rs index 1788a65..0172a6a 100644 --- a/complete.rs +++ b/complete.rs @@ -193,6 +193,10 @@ impl<'self> CompleteStyle<'self> { strip(self.inner.line_height()) } + pub fn vertical_align(&self) -> CSSVerticalAlign { + strip(self.inner.vertical_align()) + } + // CSS 2.1, Section 11 - Visual effects // CSS 2.1, Section 12 - Generated content, automatic numbering, and lists diff --git a/computed.rs b/computed.rs index e4a1fb6..f02d3f7 100644 --- a/computed.rs +++ b/computed.rs @@ -113,6 +113,10 @@ impl<'self> ComputedStyle<'self> { convert_net_line_height_value(self.inner.line_height()) } + pub fn vertical_align(&self) -> CSSValue { + convert_net_vertical_align_value(self.inner.vertical_align()) + } + // CSS 2.1, Section 11 - Visual effects // CSS 2.1, Section 12 - Generated content, automatic numbering, and lists @@ -395,6 +399,26 @@ fn convert_net_line_height_value(value: n::v::CssLineHeightValue) -> CSSValue CSSValue { + match value { + n::v::CssVerticalAlignInherit => Inherit, + n::v::CssVerticalAlignBaseline => Specified(CSSVerticalAlignBaseline), + n::v::CssVerticalAlignSub => Specified(CSSVerticalAlignSub), + n::v::CssVerticalAlignSuper => Specified(CSSVerticalAlignSuper), + n::v::CssVerticalAlignTop => Specified(CSSVerticalAlignTop), + n::v::CssVerticalAlignTextTop => Specified(CSSVerticalAlignTextTop), + n::v::CssVerticalAlignMiddle => Specified(CSSVerticalAlignMiddle), + n::v::CssVerticalAlignBottom => Specified(CSSVerticalAlignBottom), + n::v::CssVerticalAlignTextBottom => Specified(CSSVerticalAlignTextBottom), + n::v::CssVerticalAlignDimension(v) => { + match convert_net_unit_to_length_or_percent(v) { + Left(val) => Specified(CSSVerticalAlignLength(val)), + Right(val) => Specified(CSSVerticalAlignPercentage(val)) + } + } + } +} + fn convert_net_unit_to_length(unit: n::t::CssUnit) -> Length { match convert_net_unit_to_length_or_percent(unit) { Left(v) => v, diff --git a/test.rs b/test.rs index 0363304..0a0bd01 100644 --- a/test.rs +++ b/test.rs @@ -408,7 +408,17 @@ fn test_line_height() { } } - +#[test] +fn test_vertical_align() { + let style = "div { vertical-align: 20%; }"; + do single_div_test(style) |computed| { + assert!(computed.vertical_align() == Specified(CSSVerticalAlignPercentage(20.0))); + } + let style = "div { vertical-align: text-top; }"; + do single_div_test(style) |computed| { + assert!(computed.vertical_align() == Specified(CSSVerticalAlignTextTop)); + } +} fn child_test(style: &str, f: &fn(&ComputedStyle)) { let sheet = Stylesheet::new(test_url(), style_stream(style));