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

Commit 7062261

Browse files
committed
Merge pull request #31 from june0cho/vertical_align
Add 'vertical-align'
2 parents f02576d + 40ab82e commit 7062261

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

complete.rs

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ impl<'self> CompleteStyle<'self> {
193193
strip(self.inner.line_height())
194194
}
195195

196+
pub fn vertical_align(&self) -> CSSVerticalAlign {
197+
strip(self.inner.vertical_align())
198+
}
199+
196200
// CSS 2.1, Section 11 - Visual effects
197201

198202
// CSS 2.1, Section 12 - Generated content, automatic numbering, and lists

computed.rs

+24
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ impl<'self> ComputedStyle<'self> {
113113
convert_net_line_height_value(self.inner.line_height())
114114
}
115115

116+
pub fn vertical_align(&self) -> CSSValue<CSSVerticalAlign> {
117+
convert_net_vertical_align_value(self.inner.vertical_align())
118+
}
119+
116120
// CSS 2.1, Section 11 - Visual effects
117121

118122
// 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<CS
395399
}
396400
}
397401

402+
fn convert_net_vertical_align_value(value: n::v::CssVerticalAlignValue) -> CSSValue<CSSVerticalAlign> {
403+
match value {
404+
n::v::CssVerticalAlignInherit => Inherit,
405+
n::v::CssVerticalAlignBaseline => Specified(CSSVerticalAlignBaseline),
406+
n::v::CssVerticalAlignSub => Specified(CSSVerticalAlignSub),
407+
n::v::CssVerticalAlignSuper => Specified(CSSVerticalAlignSuper),
408+
n::v::CssVerticalAlignTop => Specified(CSSVerticalAlignTop),
409+
n::v::CssVerticalAlignTextTop => Specified(CSSVerticalAlignTextTop),
410+
n::v::CssVerticalAlignMiddle => Specified(CSSVerticalAlignMiddle),
411+
n::v::CssVerticalAlignBottom => Specified(CSSVerticalAlignBottom),
412+
n::v::CssVerticalAlignTextBottom => Specified(CSSVerticalAlignTextBottom),
413+
n::v::CssVerticalAlignDimension(v) => {
414+
match convert_net_unit_to_length_or_percent(v) {
415+
Left(val) => Specified(CSSVerticalAlignLength(val)),
416+
Right(val) => Specified(CSSVerticalAlignPercentage(val))
417+
}
418+
}
419+
}
420+
}
421+
398422
fn convert_net_unit_to_length(unit: n::t::CssUnit) -> Length {
399423
match convert_net_unit_to_length_or_percent(unit) {
400424
Left(v) => v,

test.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,17 @@ fn test_line_height() {
408408
}
409409
}
410410
411-
411+
#[test]
412+
fn test_vertical_align() {
413+
let style = "div { vertical-align: 20%; }";
414+
do single_div_test(style) |computed| {
415+
assert!(computed.vertical_align() == Specified(CSSVerticalAlignPercentage(20.0)));
416+
}
417+
let style = "div { vertical-align: text-top; }";
418+
do single_div_test(style) |computed| {
419+
assert!(computed.vertical_align() == Specified(CSSVerticalAlignTextTop));
420+
}
421+
}
412422
413423
fn child_test(style: &str, f: &fn(&ComputedStyle)) {
414424
let sheet = Stylesheet::new(test_url(), style_stream(style));

0 commit comments

Comments
 (0)