BorderRadiusStyleValue.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334
  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. #include "BorderRadiusStyleValue.h"
  10. namespace Web::CSS {
  11. ErrorOr<String> BorderRadiusStyleValue::to_string() const
  12. {
  13. if (m_properties.horizontal_radius == m_properties.vertical_radius)
  14. return m_properties.horizontal_radius.to_string();
  15. return String::formatted("{} / {}", TRY(m_properties.horizontal_radius.to_string()), TRY(m_properties.vertical_radius.to_string()));
  16. }
  17. ValueComparingNonnullRefPtr<StyleValue const> BorderRadiusStyleValue::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
  18. {
  19. if (m_properties.horizontal_radius.is_percentage() && m_properties.vertical_radius.is_percentage())
  20. return *this;
  21. auto absolutized_horizontal_radius = m_properties.horizontal_radius;
  22. auto absolutized_vertical_radius = m_properties.vertical_radius;
  23. if (!m_properties.horizontal_radius.is_percentage())
  24. absolutized_horizontal_radius = absolutized_length(m_properties.horizontal_radius.length(), viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height).value_or(m_properties.horizontal_radius.length());
  25. if (!m_properties.vertical_radius.is_percentage())
  26. absolutized_vertical_radius = absolutized_length(m_properties.vertical_radius.length(), viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height).value_or(m_properties.vertical_radius.length());
  27. return BorderRadiusStyleValue::create(absolutized_horizontal_radius, absolutized_vertical_radius);
  28. }
  29. }