1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 21:58:10 +00:00

LibWeb: Resolve style for logical-side length properties

For now, we just hard-code the logical sides to physical ones, but at
least the hard-coding is all in one place. :^)
This commit is contained in:
Sam Atkins 2023-09-29 13:13:18 +01:00 committed by Sam Atkins
parent 2fa1df2ec4
commit 44836cd8ed

View file

@ -136,6 +136,28 @@ static NonnullRefPtr<StyleValue const> style_value_for_sided_shorthand(ValueComp
return StyleValueList::create(StyleValueVector { move(top), move(right), move(bottom), move(left) }, StyleValueList::Separator::Space); return StyleValueList::create(StyleValueVector { move(top), move(right), move(bottom), move(left) }, StyleValueList::Separator::Space);
} }
enum class LogicalSide {
BlockStart,
BlockEnd,
InlineStart,
InlineEnd,
};
static RefPtr<StyleValue const> style_value_for_length_box_logical_side(Layout::NodeWithStyle const&, LengthBox const& box, LogicalSide logical_side)
{
// FIXME: Actually determine the logical sides based on layout_node's writing-mode and direction.
switch (logical_side) {
case LogicalSide::BlockStart:
return style_value_for_length_percentage(box.top());
case LogicalSide::BlockEnd:
return style_value_for_length_percentage(box.bottom());
case LogicalSide::InlineStart:
return style_value_for_length_percentage(box.left());
case LogicalSide::InlineEnd:
return style_value_for_length_percentage(box.right());
}
VERIFY_NOT_REACHED();
}
RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const
{ {
// A limited number of properties have special rules for producing their "resolved value". // A limited number of properties have special rules for producing their "resolved value".
@ -189,19 +211,19 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
// FIXME: -> block-size // FIXME: -> block-size
// -> height // -> height
// FIXME: -> inline-size // FIXME: -> inline-size
// FIXME: -> margin-block-end // -> margin-block-end
// FIXME: -> margin-block-start // -> margin-block-start
// -> margin-bottom // -> margin-bottom
// FIXME: -> margin-inline-end // -> margin-inline-end
// FIXME: -> margin-inline-start // -> margin-inline-start
// -> margin-left // -> margin-left
// -> margin-right // -> margin-right
// -> margin-top // -> margin-top
// FIXME: -> padding-block-end // -> padding-block-end
// FIXME: -> padding-block-start // -> padding-block-start
// -> padding-bottom // -> padding-bottom
// FIXME: -> padding-inline-end // -> padding-inline-end
// FIXME: -> padding-inline-start // -> padding-inline-start
// -> padding-left // -> padding-left
// -> padding-right // -> padding-right
// -> padding-top // -> padding-top
@ -212,16 +234,32 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
// Otherwise the resolved value is the computed value. // Otherwise the resolved value is the computed value.
case PropertyID::Height: case PropertyID::Height:
return style_value_for_size(layout_node.computed_values().height()); return style_value_for_size(layout_node.computed_values().height());
case PropertyID::MarginBlockEnd:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().margin(), LogicalSide::BlockEnd);
case PropertyID::MarginBlockStart:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().margin(), LogicalSide::BlockStart);
case PropertyID::MarginBottom: case PropertyID::MarginBottom:
return style_value_for_length_percentage(layout_node.computed_values().margin().bottom()); return style_value_for_length_percentage(layout_node.computed_values().margin().bottom());
case PropertyID::MarginInlineEnd:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().margin(), LogicalSide::InlineEnd);
case PropertyID::MarginInlineStart:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().margin(), LogicalSide::InlineStart);
case PropertyID::MarginLeft: case PropertyID::MarginLeft:
return style_value_for_length_percentage(layout_node.computed_values().margin().left()); return style_value_for_length_percentage(layout_node.computed_values().margin().left());
case PropertyID::MarginRight: case PropertyID::MarginRight:
return style_value_for_length_percentage(layout_node.computed_values().margin().right()); return style_value_for_length_percentage(layout_node.computed_values().margin().right());
case PropertyID::MarginTop: case PropertyID::MarginTop:
return style_value_for_length_percentage(layout_node.computed_values().margin().top()); return style_value_for_length_percentage(layout_node.computed_values().margin().top());
case PropertyID::PaddingBlockEnd:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().padding(), LogicalSide::BlockEnd);
case PropertyID::PaddingBlockStart:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().padding(), LogicalSide::BlockStart);
case PropertyID::PaddingBottom: case PropertyID::PaddingBottom:
return style_value_for_length_percentage(layout_node.computed_values().padding().bottom()); return style_value_for_length_percentage(layout_node.computed_values().padding().bottom());
case PropertyID::PaddingInlineEnd:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().padding(), LogicalSide::InlineEnd);
case PropertyID::PaddingInlineStart:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().padding(), LogicalSide::InlineStart);
case PropertyID::PaddingLeft: case PropertyID::PaddingLeft:
return style_value_for_length_percentage(layout_node.computed_values().padding().left()); return style_value_for_length_percentage(layout_node.computed_values().padding().left());
case PropertyID::PaddingRight: case PropertyID::PaddingRight:
@ -233,10 +271,10 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
// -> bottom // -> bottom
// -> left // -> left
// FIXME: -> inset-block-end // -> inset-block-end
// FIXME: -> inset-block-start // -> inset-block-start
// FIXME: -> inset-inline-end // -> inset-inline-end
// FIXME: -> inset-inline-start // -> inset-inline-start
// -> right // -> right
// -> top // -> top
// -> A resolved value special case property like top defined in another specification // -> A resolved value special case property like top defined in another specification
@ -245,6 +283,14 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
// Otherwise the resolved value is the computed value. // Otherwise the resolved value is the computed value.
case PropertyID::Bottom: case PropertyID::Bottom:
return style_value_for_length_percentage(layout_node.computed_values().inset().bottom()); return style_value_for_length_percentage(layout_node.computed_values().inset().bottom());
case PropertyID::InsetBlockEnd:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().inset(), LogicalSide::BlockEnd);
case PropertyID::InsetBlockStart:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().inset(), LogicalSide::BlockStart);
case PropertyID::InsetInlineEnd:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().inset(), LogicalSide::InlineEnd);
case PropertyID::InsetInlineStart:
return style_value_for_length_box_logical_side(layout_node, layout_node.computed_values().inset(), LogicalSide::InlineStart);
case PropertyID::Left: case PropertyID::Left:
return style_value_for_length_percentage(layout_node.computed_values().inset().left()); return style_value_for_length_percentage(layout_node.computed_values().inset().left());
case PropertyID::Right: case PropertyID::Right: