ReplacedFormattingContext.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "ReplacedFormattingContext.h"
  2. #include "../../../Include/RmlUi/Core/ComputedValues.h"
  3. #include "../../../Include/RmlUi/Core/Element.h"
  4. #include "BlockFormattingContext.h"
  5. #include "ContainerBox.h"
  6. #include "LayoutDetails.h"
  7. namespace Rml {
  8. UniquePtr<LayoutBox> ReplacedFormattingContext::Format(ContainerBox* parent_container, Element* element, const Box* override_initial_box)
  9. {
  10. RMLUI_ASSERT(element->IsReplaced());
  11. // Replaced elements provide their own rendering, we just set their box here and notify them that the element has been sized.
  12. auto replaced_box = MakeUnique<ReplacedBox>(element);
  13. Box& box = replaced_box->GetBox();
  14. if (override_initial_box)
  15. box = *override_initial_box;
  16. else
  17. {
  18. const Vector2f containing_block = LayoutDetails::GetContainingBlock(parent_container, element->GetPosition()).size;
  19. LayoutDetails::BuildBox(box, containing_block, element);
  20. }
  21. // Submit the box and notify the element.
  22. replaced_box->Close();
  23. // Usually, replaced elements add children to the hidden DOM. If we happen to have any normal DOM children, e.g.
  24. // added by the user, we format them using normal block formatting rules. Since replaced elements provide their
  25. // own rendering, this could cause conflicting or strange layout results, and is done at the user's own risk.
  26. if (element->HasChildNodes())
  27. {
  28. RootBox root(box);
  29. BlockFormattingContext::Format(&root, element, &box);
  30. }
  31. return replaced_box;
  32. }
  33. void ReplacedBox::Close()
  34. {
  35. element->SetBox(box);
  36. element->OnLayout();
  37. }
  38. String ReplacedBox::DebugDumpTree(int depth) const
  39. {
  40. return String(depth * 2, ' ') + "ReplacedBox";
  41. }
  42. } // namespace Rml