From 8b0e6ea46eb746df1b0c558ce906b3a8dd501c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 23 Apr 2017 11:21:39 +0200 Subject: [PATCH] style: Refactor overflow fixup to account for overflow: clip. This is the missing piece to make the remaining contain tests not assert on Gecko. --- .../style/properties/properties.mako.rs | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 30ed8e3afc1..439829b8f25 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2436,33 +2436,55 @@ pub fn apply_declarations<'a, F, I>(device: &Device, use computed_values::overflow_x::T as overflow; use computed_values::overflow_y; - let overflow_x = style.get_box().clone_overflow_x(); - let overflow_y = style.get_box().clone_overflow_y().0; - match (overflow_x == longhands::overflow_x::computed_value::T::visible, - overflow_y == longhands::overflow_x::computed_value::T::visible) { - (true, true) => {} - (true, _) => { - style.mutate_box().set_overflow_x(overflow::auto); + let original_overflow_x = style.get_box().clone_overflow_x(); + let original_overflow_y = style.get_box().clone_overflow_y().0; + let mut overflow_x = original_overflow_x; + let mut overflow_y = original_overflow_y; + + // CSS3 overflow-x and overflow-y require some fixup as well in some + // cases. overflow: clip and overflow: visible are meaningful only when + // used in both dimensions. + if overflow_x != overflow_y { + // If 'visible' is specified but doesn't match the other dimension, + // it turns into 'auto'. + if overflow_x == overflow::visible { + overflow_x = overflow::auto; } - (_, true) => { - style.mutate_box().set_overflow_y(overflow_y::T(overflow::auto)); + if overflow_y == overflow::visible { + overflow_y = overflow::auto; } - _ => {} + + % if product == "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; + } + % endif } % if product == "gecko": use properties::longhands::contain; // When 'contain: paint', update overflow from 'visible' to 'clip'. - let contain = style.get_box().clone_contain(); - if contain.contains(contain::PAINT) { - if let longhands::overflow_x::computed_value::T::visible = overflow_x { - style.mutate_box().set_overflow_x(overflow::clip); + if style.get_box().clone_contain().contains(contain::PAINT) { + if overflow_x == overflow::visible { + overflow_x = overflow::clip; } - if let longhands::overflow_x::computed_value::T::visible = overflow_y { - style.mutate_box().set_overflow_y(overflow_y::T(overflow::clip)); + if overflow_y == overflow::visible { + overflow_y = overflow::clip; } } % endif + + if overflow_x != original_overflow_x || + overflow_y != original_overflow_y { + let mut box_style = style.mutate_box(); + box_style.set_overflow_x(overflow_x); + box_style.set_overflow_y(overflow_y::T(overflow_y)); + } } % if product == "gecko":