FormattingContext.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "FormattingContext.h"
  2. #include "../../../Include/RmlUi/Core/ComputedValues.h"
  3. #include "../../../Include/RmlUi/Core/Element.h"
  4. #include "../../../Include/RmlUi/Core/Profiling.h"
  5. #include "BlockFormattingContext.h"
  6. #include "FlexFormattingContext.h"
  7. #include "LayoutBox.h"
  8. #include "ReplacedFormattingContext.h"
  9. #include "TableFormattingContext.h"
  10. namespace Rml {
  11. UniquePtr<LayoutBox> FormattingContext::FormatIndependent(ContainerBox* parent_container, Element* element, const Box* override_initial_box,
  12. FormattingContextType backup_context)
  13. {
  14. RMLUI_ZoneScopedC(0xAFAFAF);
  15. using namespace Style;
  16. if (element->IsReplaced())
  17. return ReplacedFormattingContext::Format(parent_container, element, override_initial_box);
  18. FormattingContextType type = backup_context;
  19. auto& computed = element->GetComputedValues();
  20. const Display display = computed.display();
  21. if (display == Display::Flex || display == Display::InlineFlex)
  22. {
  23. type = FormattingContextType::Flex;
  24. }
  25. else if (display == Display::Table || display == Display::InlineTable)
  26. {
  27. type = FormattingContextType::Table;
  28. }
  29. else if (display == Display::InlineBlock || display == Display::FlowRoot || display == Display::TableCell || computed.float_() != Float::None ||
  30. computed.position() == Position::Absolute || computed.position() == Position::Fixed || computed.overflow_x() != Overflow::Visible ||
  31. computed.overflow_y() != Overflow::Visible || !element->GetParentNode() || element->GetParentNode()->GetDisplay() == Display::Flex)
  32. {
  33. type = FormattingContextType::Block;
  34. }
  35. switch (type)
  36. {
  37. case FormattingContextType::Block: return BlockFormattingContext::Format(parent_container, element, override_initial_box);
  38. case FormattingContextType::Table: return TableFormattingContext::Format(parent_container, element, override_initial_box);
  39. case FormattingContextType::Flex: return FlexFormattingContext::Format(parent_container, element, override_initial_box);
  40. case FormattingContextType::None: break;
  41. }
  42. return nullptr;
  43. }
  44. } // namespace Rml