1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:47:35 +00:00

LibWeb: Add PositionValue class to represent CSS <position>s

This class represents a <position> and handles resolving it to a
Gfx::FloatPoint relative to some rectangle.

It can handle all forms of <position>:

- Two presets:
  left center
- A preset + a length percentage:
  10% bottom
- Or relative to some edges:
  right 20% bottom 30px
This commit is contained in:
MacDue 2022-10-29 13:11:00 +01:00 committed by Linus Groh
parent 067759c0e9
commit e568c93404
2 changed files with 141 additions and 0 deletions

View file

@ -96,6 +96,45 @@ struct ColorStopListElement {
using LinearColorStopListElement = ColorStopListElement<LengthPercentage>;
using AngularColorStopListElement = ColorStopListElement<AnglePercentage>;
// FIXME: Named PositionValue to avoid conflicts with enums, but this represents a <position>
struct PositionValue {
enum class HorizontalPreset {
Left,
Center,
Right
};
enum class VerticalPreset {
Top,
Center,
Bottom
};
enum class HorizontalEdge {
Left,
Right
};
enum class VerticalEdge {
Top,
Bottom
};
inline static PositionValue center()
{
return PositionValue { HorizontalPreset::Center, VerticalPreset::Center };
}
Variant<HorizontalPreset, LengthPercentage> horizontal_position { HorizontalPreset::Left };
Variant<VerticalPreset, LengthPercentage> vertical_position { VerticalPreset::Top };
HorizontalEdge x_relative_to { HorizontalEdge::Left };
VerticalEdge y_relative_to { VerticalEdge::Top };
Gfx::FloatPoint resolved(Layout::Node const&, Gfx::FloatRect const&) const;
void serialize(StringBuilder&) const;
bool operator==(PositionValue const&) const;
};
struct EdgeRect {
Length top_edge;
Length right_edge;