Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Add 'vertical-align' #31

Merged
merged 1 commit into from
Aug 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions computed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ impl<'self> ComputedStyle<'self> {
convert_net_line_height_value(self.inner.line_height())
}

pub fn vertical_align(&self) -> CSSValue<CSSVerticalAlign> {
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
Expand Down Expand Up @@ -395,6 +399,26 @@ fn convert_net_line_height_value(value: n::v::CssLineHeightValue) -> CSSValue<CS
}
}

fn convert_net_vertical_align_value(value: n::v::CssVerticalAlignValue) -> CSSValue<CSSVerticalAlign> {
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,
Expand Down
12 changes: 11 additions & 1 deletion test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down