style: Implement overflow:clip/visible combinations.

Differential Revision: https://phabricator.services.mozilla.com/D73717
This commit is contained in:
Mats Palmgren 2020-08-01 01:57:41 +00:00 committed by Emilio Cobos Álvarez
parent 9bfcb3d741
commit b29824bf75

View file

@ -469,48 +469,22 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
} }
} }
/// CSS3 overflow-x and overflow-y require some fixup as well in some /// CSS overflow-x and overflow-y require some fixup as well in some cases.
/// cases. /// https://drafts.csswg.org/css-overflow-3/#overflow-properties
/// /// "Computed value: as specified, except with `visible`/`clip` computing to
/// overflow: clip and overflow: visible are meaningful only when used in /// `auto`/`hidden` (respectively) if one of `overflow-x` or `overflow-y` is
/// both dimensions. /// neither `visible` nor `clip`."
fn adjust_for_overflow(&mut self) { fn adjust_for_overflow(&mut self) {
let original_overflow_x = self.style.get_box().clone_overflow_x(); let overflow_x = self.style.get_box().clone_overflow_x();
let original_overflow_y = self.style.get_box().clone_overflow_y(); let overflow_y = self.style.get_box().clone_overflow_y();
let mut overflow_x = original_overflow_x;
let mut overflow_y = original_overflow_y;
if overflow_x == overflow_y { if overflow_x == overflow_y {
return; return; // optimization for the common case
} }
// If 'visible' is specified but doesn't match the other dimension, if overflow_x.is_scrollable() != overflow_y.is_scrollable() {
// it turns into 'auto'.
if overflow_x == Overflow::Visible {
overflow_x = Overflow::Auto;
}
if overflow_y == Overflow::Visible {
overflow_y = Overflow::Auto;
}
#[cfg(feature = "gecko")]
{
// overflow: clip is deprecated, so convert to hidden if it's
// specified in only one dimension.
if overflow_x == Overflow::Clip {
overflow_x = Overflow::Hidden;
}
if overflow_y == Overflow::Clip {
overflow_y = Overflow::Hidden;
}
}
if overflow_x != original_overflow_x || overflow_y != original_overflow_y {
let box_style = self.style.mutate_box(); let box_style = self.style.mutate_box();
box_style.set_overflow_x(overflow_x); box_style.set_overflow_x(overflow_x.to_scrollable());
box_style.set_overflow_y(overflow_y); box_style.set_overflow_y(overflow_y.to_scrollable());
} }
} }