diff options
author | Andreas Kling <kling@serenityos.org> | 2022-02-28 11:27:57 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-28 14:17:44 +0100 |
commit | 20caea2f86e3f48320b8749dcc8118cc775bdbcc (patch) | |
tree | 2c760e67a7bf3137d3039500ffc1bb7639374c55 /Userland | |
parent | cd5c17d88e7ef5d9d883884453720d64749f6cd9 (diff) | |
download | serenity-20caea2f86e3f48320b8749dcc8118cc775bdbcc.zip |
LibWeb: Split CSS box type transformations into a helper function
Let's have one function that determines the type of transformation
needed, and another to actually perform the transformation.
This makes it much easier to read, and we don't have to duplicate the
logic for doing the transformation.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 4686931859..6cd2c26a45 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -917,8 +917,29 @@ void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const } } +enum class BoxTypeTransformation { + None, + Blockify, + Inlinify, +}; + +static BoxTypeTransformation required_box_type_transformation(StyleProperties const& style, DOM::Element const&, Optional<CSS::Selector::PseudoElement> const&) +{ + auto display = style.display(); + + // Absolute positioning or floating an element blockifies the box’s display type. [CSS2] + if (style.position() == CSS::Position::Absolute || style.position() == CSS::Position::Fixed || style.float_() != CSS::Float::None) + return BoxTypeTransformation::Blockify; + + // FIXME: Containment in a ruby container inlinifies the box’s display type, as described in [CSS-RUBY-1]. + + // FIXME: A parent with a grid or flex display value blockifies the box’s display type. [CSS-GRID-1] [CSS-FLEXBOX-1] + + return BoxTypeTransformation::None; +} + // https://drafts.csswg.org/css-display/#transformations -void StyleComputer::transform_box_type_if_needed(StyleProperties& style, DOM::Element const&, Optional<CSS::Selector::PseudoElement>) const +void StyleComputer::transform_box_type_if_needed(StyleProperties& style, DOM::Element const& element, Optional<CSS::Selector::PseudoElement> pseudo_element) const { // 2.7. Automatic Box Type Transformations @@ -926,8 +947,6 @@ void StyleComputer::transform_box_type_if_needed(StyleProperties& style, DOM::El // which sets the box’s computed outer display type to block or inline (respectively). // (This has no effect on display types that generate no box at all, such as none or contents.) - // Additionally: - // FIXME: If a block box (block flow) is inlinified, its inner display type is set to flow-root so that it remains a block container. // // FIXME: If an inline box (inline flow) is inlinified, it recursively inlinifies all of its in-flow children, @@ -940,16 +959,20 @@ void StyleComputer::transform_box_type_if_needed(StyleProperties& style, DOM::El // Inlinification has no effect on layout-internal boxes. (However, placement in such an inline context will typically cause them // to be wrapped in an appropriately-typed anonymous inline-level box.) - // Absolute positioning or floating an element blockifies the box’s display type. [CSS2] auto display = style.display(); - if (!display.is_none() && !display.is_contents() && !display.is_block_outside()) { - if (style.position() == CSS::Position::Absolute || style.position() == CSS::Position::Fixed || style.float_() != CSS::Float::None) - style.set_property(CSS::PropertyID::Display, IdentifierStyleValue::create(CSS::ValueID::Block)); - } - - // FIXME: Containment in a ruby container inlinifies the box’s display type, as described in [CSS-RUBY-1]. + if (display.is_none() || display.is_contents()) + return; - // FIXME: A parent with a grid or flex display value blockifies the box’s display type. [CSS-GRID-1] [CSS-FLEXBOX-1] + switch (required_box_type_transformation(style, element, pseudo_element)) { + case BoxTypeTransformation::None: + break; + case BoxTypeTransformation::Blockify: + style.set_property(CSS::PropertyID::Display, IdentifierStyleValue::create(CSS::ValueID::Block)); + break; + case BoxTypeTransformation::Inlinify: + style.set_property(CSS::PropertyID::Display, IdentifierStyleValue::create(CSS::ValueID::Inline)); + break; + } } NonnullRefPtr<StyleProperties> StyleComputer::create_document_style() const |