1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 03:08:13 +00:00

LibWeb: Move PositionValue into its own files

It's in Position.{h,cpp} because it represents a <position> in CSS, even
though it's currently named PositionValue to avoid collisions.
This commit is contained in:
Sam Atkins 2023-03-30 14:37:00 +01:00 committed by Andreas Kling
parent bcebca62d3
commit d64ddeaec4
8 changed files with 165 additions and 133 deletions

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/Percentage.h>
#include <LibWeb/PixelUnits.h>
namespace Web::CSS {
// 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
};
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 };
CSSPixelPoint resolved(Layout::Node const& node, CSSPixelRect const& rect) const;
ErrorOr<void> serialize(StringBuilder&) const;
bool operator==(PositionValue const&) const = default;
};
}