LengthStyleValue.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 "LengthStyleValue.h"
  10. namespace Web::CSS {
  11. ValueComparingNonnullRefPtr<LengthStyleValue> LengthStyleValue::create(Length const& length)
  12. {
  13. if (length.is_auto()) {
  14. static auto value = adopt_ref(*new LengthStyleValue(CSS::Length::make_auto()));
  15. return value;
  16. }
  17. if (length.is_px()) {
  18. if (length.raw_value() == 0) {
  19. static auto value = adopt_ref(*new LengthStyleValue(CSS::Length::make_px(0)));
  20. return value;
  21. }
  22. if (length.raw_value() == 1) {
  23. static auto value = adopt_ref(*new LengthStyleValue(CSS::Length::make_px(1)));
  24. return value;
  25. }
  26. }
  27. return adopt_ref(*new LengthStyleValue(length));
  28. }
  29. ValueComparingNonnullRefPtr<StyleValue const> LengthStyleValue::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
  30. {
  31. if (auto length = absolutized_length(m_length, viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height); length.has_value())
  32. return LengthStyleValue::create(length.release_value());
  33. return *this;
  34. }
  35. }