LayoutNode.cpp 637 B

1234567891011121314151617181920212223242526272829
  1. #include <LibHTML/Layout/LayoutBlock.h>
  2. #include <LibHTML/Layout/LayoutNode.h>
  3. #include <LibHTML/CSS/StyledNode.h>
  4. LayoutNode::LayoutNode(const Node* node, const StyledNode* styled_node)
  5. : m_node(node)
  6. , m_styled_node(styled_node)
  7. {
  8. }
  9. LayoutNode::~LayoutNode()
  10. {
  11. }
  12. void LayoutNode::layout()
  13. {
  14. for_each_child([](auto& child) {
  15. child.layout();
  16. });
  17. }
  18. const LayoutBlock* LayoutNode::containing_block() const
  19. {
  20. for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
  21. if (ancestor->is_block())
  22. return static_cast<const LayoutBlock*>(ancestor);
  23. }
  24. return nullptr;
  25. }