Position.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/CSS/PercentageOr.h>
  8. #include <LibWeb/PixelUnits.h>
  9. namespace Web::CSS {
  10. // FIXME: Named PositionValue to avoid conflicts with enums, but this represents a <position>
  11. struct PositionValue {
  12. enum class HorizontalPreset {
  13. Left,
  14. Center,
  15. Right
  16. };
  17. enum class VerticalPreset {
  18. Top,
  19. Center,
  20. Bottom
  21. };
  22. enum class HorizontalEdge {
  23. Left,
  24. Right
  25. };
  26. enum class VerticalEdge {
  27. Top,
  28. Bottom
  29. };
  30. static PositionValue center()
  31. {
  32. return PositionValue { HorizontalPreset::Center, VerticalPreset::Center };
  33. }
  34. Variant<HorizontalPreset, LengthPercentage> horizontal_position { HorizontalPreset::Left };
  35. Variant<VerticalPreset, LengthPercentage> vertical_position { VerticalPreset::Top };
  36. HorizontalEdge x_relative_to { HorizontalEdge::Left };
  37. VerticalEdge y_relative_to { VerticalEdge::Top };
  38. CSSPixelPoint resolved(Layout::Node const& node, CSSPixelRect const& rect) const;
  39. void serialize(StringBuilder&) const;
  40. bool operator==(PositionValue const&) const = default;
  41. };
  42. }