FieldSetBox.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2024, Kostya Farber <kostya.farber@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Forward.h>
  7. #include <LibWeb/HTML/HTMLLegendElement.h>
  8. #include <LibWeb/Layout/FieldSetBox.h>
  9. #include <LibWeb/Layout/LegendBox.h>
  10. #include <LibWeb/Painting/FieldSetPaintable.h>
  11. namespace Web::Layout {
  12. GC_DEFINE_ALLOCATOR(FieldSetBox);
  13. FieldSetBox::FieldSetBox(DOM::Document& document, DOM::Element& element, GC::Ref<CSS::ComputedProperties> style)
  14. : BlockContainer(document, &element, move(style))
  15. {
  16. }
  17. FieldSetBox::~FieldSetBox() = default;
  18. bool FieldSetBox::has_rendered_legend() const
  19. {
  20. // https://html.spec.whatwg.org/#rendered-legend
  21. bool has_rendered_legend = false;
  22. if (has_children()) {
  23. for_each_child_of_type<Box>([&](Box const& child) {
  24. if (child.is_anonymous())
  25. return IterationDecision::Continue;
  26. if (!child.is_legend_box())
  27. return IterationDecision::Break;
  28. has_rendered_legend = child.computed_values().float_() == CSS::Float::None
  29. && child.computed_values().position() != CSS::Positioning::Absolute
  30. && child.computed_values().position() != CSS::Positioning::Fixed;
  31. return IterationDecision::Break;
  32. });
  33. }
  34. return has_rendered_legend;
  35. }
  36. GC::Ptr<Painting::Paintable> FieldSetBox::create_paintable() const
  37. {
  38. return Painting::FieldSetPaintable::create(*this);
  39. }
  40. }