LengthStyleValue.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  4. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.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/StyleValue.h>
  11. namespace Web::CSS {
  12. class LengthStyleValue : public StyleValueWithDefaultOperators<LengthStyleValue> {
  13. public:
  14. static ValueComparingNonnullRefPtr<LengthStyleValue> create(Length const&);
  15. virtual ~LengthStyleValue() override = default;
  16. Length const& length() const { return m_length; }
  17. virtual bool has_auto() const override { return m_length.is_auto(); }
  18. virtual bool has_length() const override { return true; }
  19. virtual bool has_identifier() const override { return has_auto(); }
  20. virtual ErrorOr<String> to_string() const override { return m_length.to_string(); }
  21. virtual Length to_length() const override { return m_length; }
  22. virtual ValueID to_identifier() const override { return has_auto() ? ValueID::Auto : ValueID::Invalid; }
  23. virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const override;
  24. bool properties_equal(LengthStyleValue const& other) const { return m_length == other.m_length; }
  25. private:
  26. explicit LengthStyleValue(Length const& length)
  27. : StyleValueWithDefaultOperators(Type::Length)
  28. , m_length(length)
  29. {
  30. }
  31. Length m_length;
  32. };
  33. }