LengthStyleValue.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  4. * Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.org>
  5. * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #pragma once
  10. #include <LibWeb/CSS/Length.h>
  11. #include <LibWeb/CSS/StyleValues/CSSUnitValue.h>
  12. namespace Web::CSS {
  13. class LengthStyleValue final : public CSSUnitValue {
  14. public:
  15. static ValueComparingNonnullRefPtr<LengthStyleValue> create(Length const&);
  16. virtual ~LengthStyleValue() override = default;
  17. Length const& length() const { return m_length; }
  18. virtual double value() const override { return m_length.raw_value(); }
  19. virtual StringView unit() const override { return m_length.unit_name(); }
  20. virtual String to_string() const override { return m_length.to_string(); }
  21. virtual ValueComparingNonnullRefPtr<CSSStyleValue const> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override;
  22. bool equals(CSSStyleValue const& other) const override;
  23. private:
  24. explicit LengthStyleValue(Length const& length)
  25. : CSSUnitValue(Type::Length)
  26. , m_length(length)
  27. {
  28. }
  29. Length m_length;
  30. };
  31. }