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

Commit 09d2db8

Browse files
committed
Merge pull request #14 from eric93/master
Make percent width/height/margin/padding not crash
2 parents 89d6854 + 75a6958 commit 09d2db8

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

computed.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,30 +187,54 @@ fn convert_net_border_width(width: n::v::CssBorderWidthValue) -> CSSValue<CSSBor
187187
fn convert_net_margin(margin: n::v::CssMarginValue) -> CSSValue<CSSMargin> {
188188
match margin {
189189
n::v::CssMarginInherit => Inherit,
190-
n::v::CssMarginSet(length) => Specified(CSSMarginLength(convert_net_unit_to_length(length))),
190+
n::v::CssMarginSet(value) => {
191+
let length = convert_net_unit_to_length_or_percent(value);
192+
match length {
193+
Left(abs) => Specified(CSSMarginLength(abs)),
194+
Right(percent) => Specified(CSSMarginPercentage(percent))
195+
}
196+
}
191197
n::v::CssMarginAuto => Specified(CSSMarginAuto)
192198
}
193199
}
194200

195201
fn convert_net_padding(padding: n::v::CssPaddingValue) -> CSSValue<CSSPadding> {
196202
match padding {
197203
n::v::CssPaddingInherit => Inherit,
198-
n::v::CssPaddingSet(length) => Specified(CSSPaddingLength(convert_net_unit_to_length(length)))
204+
n::v::CssPaddingSet(value) => {
205+
let length = convert_net_unit_to_length_or_percent(value);
206+
match length {
207+
Left(abs) => Specified(CSSPaddingLength(abs)),
208+
Right(percent) => Specified(CSSPaddingPercentage(percent))
209+
}
210+
}
199211
}
200212
}
201213

202214
fn convert_net_width_value(value: n::v::CssWidthValue) -> CSSValue<CSSWidth> {
203215
match value {
204216
n::v::CssWidthInherit => Inherit,
205-
n::v::CssWidthSet(length) => Specified(CSSWidthLength(convert_net_unit_to_length(length))),
217+
n::v::CssWidthSet(value) => {
218+
let length = convert_net_unit_to_length_or_percent(value);
219+
match length {
220+
Left(abs) => Specified(CSSWidthLength(abs)),
221+
Right(percent) => Specified(CSSWidthPercentage(percent))
222+
}
223+
}
206224
n::v::CssWidthAuto => Specified(CSSWidthAuto)
207225
}
208226
}
209227

210228
fn convert_net_height_value(value: n::v::CssHeightValue) -> CSSValue<CSSHeight> {
211229
match value {
212230
n::v::CssHeightInherit => Inherit,
213-
n::v::CssHeightSet(length) => Specified(CSSHeightLength(convert_net_unit_to_length(length))),
231+
n::v::CssHeightSet(value) => {
232+
let length = convert_net_unit_to_length_or_percent(value);
233+
match length {
234+
Left(abs) => Specified(CSSHeightLength(abs)),
235+
Right(percent) => Specified(CSSHeightPercentage(percent))
236+
}
237+
}
214238
n::v::CssHeightAuto => Specified(CSSHeightAuto)
215239
}
216240
}
@@ -364,7 +388,7 @@ fn convert_net_line_height_value(value: n::v::CssLineHeightValue) -> CSSValue<CS
364388
fn convert_net_unit_to_length(unit: n::t::CssUnit) -> Length {
365389
match convert_net_unit_to_length_or_percent(unit) {
366390
Left(v) => v,
367-
Right(*) => Px(100.0), // FIXME(pcwalton): fill this in.
391+
Right(*) => fail!(~"unexpected percentage unit"),
368392
}
369393
}
370394

0 commit comments

Comments
 (0)