Skip to content

Commit

Permalink
Use logical longhands when shorthands are not supported
Browse files Browse the repository at this point in the history
Fixes #215
  • Loading branch information
devongovett committed Aug 22, 2022
1 parent c3ac11e commit 7dc1a00
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
37 changes: 37 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,43 @@ mod tests {
},
);

prefix_test(
r#"
.foo {
border-block-width: 2px;
}
"#,
indoc! {r#"
.foo {
border-block-start-width: 2px;
border-block-end-width: 2px;
}
"#
},
Browsers {
safari: Some(13 << 16),
..Browsers::default()
},
);

prefix_test(
r#"
.foo {
border-block-width: 2px;
}
"#,
indoc! {r#"
.foo {
border-block-width: 2px;
}
"#
},
Browsers {
safari: Some(15 << 16),
..Browsers::default()
},
);

prefix_test(
r#"
.foo {
Expand Down
9 changes: 5 additions & 4 deletions src/properties/border.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ impl<'i> BorderHandler<'i> {
self.has_any = false;

let logical_supported = context.is_supported(Feature::LogicalBorders);
let logical_shorthand_supported = context.is_supported(Feature::LogicalBorderShorthand);
macro_rules! logical_prop {
($ltr: ident, $ltr_key: ident, $rtl: ident, $rtl_key: ident, $val: expr) => {{
context.add_logical_rule(Property::$ltr($val.clone()), Property::$rtl($val.clone()));
Expand Down Expand Up @@ -1116,7 +1117,7 @@ impl<'i> BorderHandler<'i> {

if $is_logical && $block_start == $block_end && $block_start.is_valid() {
if logical_supported {
if (context.is_supported(Feature::LogicalBorderShorthand)) {
if logical_shorthand_supported {
prop!(BorderBlock => $block_start.to_border());
} else {
prop!(BorderBlockStart => $block_start.to_border());
Expand All @@ -1127,7 +1128,7 @@ impl<'i> BorderHandler<'i> {
prop!(BorderBottom => $block_start.to_border());
}
} else {
if $is_logical && logical_supported && !$block_start.is_valid() && !$block_end.is_valid() {
if $is_logical && logical_shorthand_supported && !$block_start.is_valid() && !$block_end.is_valid() {
logical_shorthand!(BorderBlockStyle, style, $block_start, $block_end);
logical_shorthand!(BorderBlockWidth, width, $block_start, $block_end);
logical_shorthand!(BorderBlockColor, color, $block_start, $block_end);
Expand All @@ -1139,7 +1140,7 @@ impl<'i> BorderHandler<'i> {

if $is_logical && $inline_start == $inline_end && $inline_start.is_valid() {
if logical_supported {
if (context.is_supported(Feature::LogicalBorderShorthand)) {
if logical_shorthand_supported {
prop!(BorderInline => $inline_start.to_border());
} else {
prop!(BorderInlineStart => $inline_start.to_border());
Expand All @@ -1151,7 +1152,7 @@ impl<'i> BorderHandler<'i> {
}
} else {
if $is_logical && !$inline_start.is_valid() && !$inline_end.is_valid() {
if logical_supported {
if logical_shorthand_supported {
logical_shorthand!(BorderInlineStyle, style, $inline_start, $inline_end);
logical_shorthand!(BorderInlineWidth, width, $inline_start, $inline_end);
logical_shorthand!(BorderInlineColor, color, $inline_start, $inline_end);
Expand Down

0 comments on commit 7dc1a00

Please sign in to comment.