Skip to content

Commit f9f20b6

Browse files
committed
Fix bugs in border handler
1 parent f904900 commit f9f20b6

File tree

5 files changed

+122
-22
lines changed

5 files changed

+122
-22
lines changed

src/lib.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,61 @@ mod tests {
250250
}
251251
"#, indoc! {".foo{border:0}"
252252
});
253+
254+
minify_test(".foo { border-width: 0 0 1px; }", ".foo{border-width:0 0 1px}");
255+
test(r#"
256+
.foo {
257+
border-block-width: 1px;
258+
border-inline-width: 1px;
259+
}
260+
"#, indoc! {r#"
261+
.foo {
262+
border-width: 1px;
263+
}
264+
"#
265+
});
266+
test(r#"
267+
.foo {
268+
border-block-start-width: 1px;
269+
border-block-end-width: 1px;
270+
border-inline-start-width: 1px;
271+
border-inline-end-width: 1px;
272+
}
273+
"#, indoc! {r#"
274+
.foo {
275+
border-width: 1px;
276+
}
277+
"#
278+
});
279+
test(r#"
280+
.foo {
281+
border-block-start-width: 1px;
282+
border-block-end-width: 1px;
283+
border-inline-start-width: 2px;
284+
border-inline-end-width: 2px;
285+
}
286+
"#, indoc! {r#"
287+
.foo {
288+
border-block-width: 1px;
289+
border-inline-width: 2px;
290+
}
291+
"#
292+
});
293+
test(r#"
294+
.foo {
295+
border-block-start-width: 1px;
296+
border-block-end-width: 1px;
297+
border-inline-start-width: 2px;
298+
border-inline-end-width: 3px;
299+
}
300+
"#, indoc! {r#"
301+
.foo {
302+
border-block-width: 1px;
303+
border-inline-start-width: 2px;
304+
border-inline-end-width: 3px;
305+
}
306+
"#
307+
});
253308
}
254309

255310
#[test]

src/properties/border.rs

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -265,24 +265,48 @@ impl PropertyHandler for BorderHandler {
265265
BorderRightColor(val) => property!(border_right, color, val, Physical),
266266
BorderBlockStartColor(val) => property!(border_block_start, color, val, Logical),
267267
BorderBlockEndColor(val) => property!(border_block_end, color, val, Logical),
268+
BorderBlockColor(val) => {
269+
property!(border_block_start, color, val, Logical);
270+
property!(border_block_end, color, val, Logical);
271+
}
268272
BorderInlineStartColor(val) => property!(border_inline_start, color, val, Logical),
269273
BorderInlineEndColor(val) => property!(border_inline_end, color, val, Logical),
274+
BorderInlineColor(val) => {
275+
property!(border_inline_start, color, val, Logical);
276+
property!(border_inline_end, color, val, Logical);
277+
}
270278
BorderTopWidth(val) => property!(border_top, width, val, Physical),
271279
BorderBottomWidth(val) => property!(border_bottom, width, val, Physical),
272280
BorderLeftWidth(val) => property!(border_left, width, val, Physical),
273281
BorderRightWidth(val) => property!(border_right, width, val, Physical),
274282
BorderBlockStartWidth(val) => property!(border_block_start, width, val, Logical),
275283
BorderBlockEndWidth(val) => property!(border_block_end, width, val, Logical),
284+
BorderBlockWidth(val) => {
285+
property!(border_block_start, width, val, Logical);
286+
property!(border_block_end, width, val, Logical);
287+
}
276288
BorderInlineStartWidth(val) => property!(border_inline_start, width, val, Logical),
277289
BorderInlineEndWidth(val) => property!(border_inline_end, width, val, Logical),
290+
BorderInlineWidth(val) => {
291+
property!(border_inline_start, width, val, Logical);
292+
property!(border_inline_end, width, val, Logical);
293+
}
278294
BorderTopStyle(val) => property!(border_top, style, val, Physical),
279295
BorderBottomStyle(val) => property!(border_bottom, style, val, Physical),
280296
BorderLeftStyle(val) => property!(border_left, style, val, Physical),
281297
BorderRightStyle(val) => property!(border_right, style, val, Physical),
282298
BorderBlockStartStyle(val) => property!(border_block_start, style, val, Logical),
283299
BorderBlockEndStyle(val) => property!(border_block_end, style, val, Logical),
300+
BorderBlockStyle(val) => {
301+
property!(border_block_start, style, val, Logical);
302+
property!(border_block_end, style, val, Logical);
303+
}
284304
BorderInlineStartStyle(val) => property!(border_inline_start, style, val, Logical),
285305
BorderInlineEndStyle(val) => property!(border_inline_end, style, val, Logical),
306+
BorderInlineStyle(val) => {
307+
property!(border_inline_start, style, val, Logical);
308+
property!(border_inline_end, style, val, Logical);
309+
}
286310
BorderTop(val) => set_border!(border_top, val, Physical),
287311
BorderBottom(val) => set_border!(border_bottom, val, Physical),
288312
BorderLeft(val) => set_border!(border_left, val, Physical),
@@ -451,37 +475,49 @@ impl BorderHandler {
451475
($prop: expr, $key: ident) => {{
452476
let has_prop = $block_start.$key.is_some() && $block_end.$key.is_some() && $inline_start.$key.is_some() && $inline_end.$key.is_some();
453477
if has_prop {
454-
dest.push($prop(Rect::new($block_start.$key.clone().unwrap(), $block_end.$key.clone().unwrap(), $inline_start.$key.clone().unwrap(), $inline_end.$key.clone().unwrap())));
478+
if !$is_logical || ($block_start.$key == $block_end.$key && $block_end.$key == $inline_start.$key && $inline_start.$key == $inline_end.$key) {
479+
let rect = Rect::new(
480+
std::mem::take(&mut $block_start.$key).unwrap(),
481+
std::mem::take(&mut $inline_end.$key).unwrap(),
482+
std::mem::take(&mut $block_end.$key).unwrap(),
483+
std::mem::take(&mut $inline_start.$key).unwrap()
484+
);
485+
dest.push($prop(rect));
486+
}
487+
}
488+
}};
489+
}
490+
491+
macro_rules! logical_shorthand {
492+
($prop: expr, $key: ident, $start: expr, $end: expr) => {{
493+
let has_prop = $start.$key.is_some() && $start.$key == $end.$key;
494+
if has_prop {
495+
dest.push($prop(std::mem::take(&mut $start.$key).unwrap()));
496+
$end.$key = None;
455497
}
456498
has_prop
457499
}};
458500
}
459501

460-
let has_style = shorthand!(BorderStyle, style);
461-
let has_width = shorthand!(BorderWidth, width);
462-
let has_color = shorthand!(BorderColor, color);
502+
shorthand!(BorderStyle, style);
503+
shorthand!(BorderWidth, width);
504+
shorthand!(BorderColor, color);
463505

464506
macro_rules! side {
465507
($val: expr, $shorthand: ident, $width: ident, $style: ident, $color: ident) => {
466508
if $val.is_valid() {
467509
dest.push(Property::$shorthand($val.to_border()));
468510
} else {
469-
if !has_style {
470-
if let Some(style) = &$val.style {
471-
dest.push($style(style.clone()));
472-
}
511+
if let Some(style) = &$val.style {
512+
dest.push($style(style.clone()));
473513
}
474514

475-
if !has_width {
476-
if let Some(width) = &$val.width {
477-
dest.push($width(width.clone()));
478-
}
515+
if let Some(width) = &$val.width {
516+
dest.push($width(width.clone()));
479517
}
480518

481-
if !has_color {
482-
if let Some(color) = &$val.color {
483-
dest.push($color(color.clone()));
484-
}
519+
if let Some(color) = &$val.color {
520+
dest.push($color(color.clone()));
485521
}
486522
}
487523
};
@@ -490,13 +526,25 @@ impl BorderHandler {
490526
if $is_logical && $block_start == $block_end && $block_start.is_valid() {
491527
dest.push(BorderBlock($block_start.to_border()))
492528
} else {
529+
if $is_logical && !$block_start.is_valid() && !$block_end.is_valid() {
530+
logical_shorthand!(BorderBlockStyle, style, $block_start, $block_end);
531+
logical_shorthand!(BorderBlockWidth, width, $block_start, $block_end);
532+
logical_shorthand!(BorderBlockColor, color, $block_start, $block_end);
533+
}
534+
493535
side!($block_start, $block_start_prop, $block_start_width, $block_start_style, $block_start_color);
494536
side!($block_end, $block_end_prop, $block_end_width, $block_end_style, $block_end_color);
495537
}
496538

497539
if $is_logical && $inline_start == $inline_end && $inline_start.is_valid() {
498540
dest.push(BorderBlock($block_start.to_border()))
499541
} else {
542+
if $is_logical && !$inline_start.is_valid() && !$inline_end.is_valid() {
543+
logical_shorthand!(BorderInlineStyle, style, $inline_start, $inline_end);
544+
logical_shorthand!(BorderInlineWidth, width, $inline_start, $inline_end);
545+
logical_shorthand!(BorderInlineColor, color, $inline_start, $inline_end);
546+
}
547+
500548
side!($inline_start, $inline_start_prop, $inline_start_width, $inline_start_style, $inline_start_color);
501549
side!($inline_end, $inline_end_prop, $inline_end_width, $inline_end_style, $inline_end_color);
502550
}

src/properties/border_image.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ pub(crate) struct BorderImageHandler {
249249
width: Option<Rect<BorderImageSideWidth>>,
250250
outset: Option<Rect<LengthOrNumber>>,
251251
repeat: Option<BorderImageRepeat>,
252-
vendor_prefix: VendorPrefix,
253-
decls: Vec<Property>
252+
vendor_prefix: VendorPrefix
254253
}
255254

256255
impl BorderImageHandler {

src/properties/border_radius.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ pub(crate) struct BorderRadiusHandler {
5757
top_right: Option<(Size2D<LengthPercentage>, VendorPrefix)>,
5858
bottom_left: Option<(Size2D<LengthPercentage>, VendorPrefix)>,
5959
bottom_right: Option<(Size2D<LengthPercentage>, VendorPrefix)>,
60-
logical: Vec<Property>,
61-
decls: Vec<Property>
60+
logical: Vec<Property>
6261
}
6362

6463
impl BorderRadiusHandler {

src/properties/flex.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ pub(crate) struct FlexHandler {
388388
preferred_size: Option<(LengthPercentageOrAuto, VendorPrefix)>,
389389
order: Option<(f32, VendorPrefix)>,
390390
box_ordinal_group: Option<(BoxOrdinalGroup, VendorPrefix)>,
391-
flex_order: Option<(f32, VendorPrefix)>,
392-
decls: Vec<Property>
391+
flex_order: Option<(f32, VendorPrefix)>
393392
}
394393

395394
impl FlexHandler {

0 commit comments

Comments
 (0)