BorderRadiusShorthandStyleValue.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
  12. namespace Web::CSS {
  13. class BorderRadiusShorthandStyleValue final : public StyleValueWithDefaultOperators<BorderRadiusShorthandStyleValue> {
  14. public:
  15. static ValueComparingNonnullRefPtr<BorderRadiusShorthandStyleValue> create(
  16. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left,
  17. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right,
  18. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right,
  19. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left)
  20. {
  21. return adopt_ref(*new BorderRadiusShorthandStyleValue(move(top_left), move(top_right), move(bottom_right), move(bottom_left)));
  22. }
  23. virtual ~BorderRadiusShorthandStyleValue() override = default;
  24. auto top_left() const { return m_properties.top_left; }
  25. auto top_right() const { return m_properties.top_right; }
  26. auto bottom_right() const { return m_properties.bottom_right; }
  27. auto bottom_left() const { return m_properties.bottom_left; }
  28. virtual ErrorOr<String> to_string() const override;
  29. bool properties_equal(BorderRadiusShorthandStyleValue const& other) const { return m_properties == other.m_properties; }
  30. private:
  31. BorderRadiusShorthandStyleValue(
  32. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left,
  33. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right,
  34. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right,
  35. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left)
  36. : StyleValueWithDefaultOperators(Type::BorderRadiusShorthand)
  37. , m_properties { .top_left = move(top_left), .top_right = move(top_right), .bottom_right = move(bottom_right), .bottom_left = move(bottom_left) }
  38. {
  39. }
  40. struct Properties {
  41. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left;
  42. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right;
  43. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right;
  44. ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left;
  45. bool operator==(Properties const&) const = default;
  46. } m_properties;
  47. };
  48. }