From 715d7a8532caa0d6b818020f4c2f47e85791d2bf Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 4 Nov 2019 19:37:52 +0100 Subject: LibHTML: Add a convenient way to get from any layout node to the root --- Libraries/LibHTML/Layout/LayoutNode.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Libraries/LibHTML/Layout/LayoutNode.cpp') diff --git a/Libraries/LibHTML/Layout/LayoutNode.cpp b/Libraries/LibHTML/Layout/LayoutNode.cpp index 49e28bed18..b1ed18b827 100644 --- a/Libraries/LibHTML/Layout/LayoutNode.cpp +++ b/Libraries/LibHTML/Layout/LayoutNode.cpp @@ -63,6 +63,26 @@ const Document& LayoutNode::document() const return node()->document(); } +Document& LayoutNode::document() +{ + if (is_anonymous()) + return parent()->document(); + // FIXME: Remove this const_cast once we give up on the idea of a const link from layout tree to DOM tree. + return const_cast(node())->document(); +} + +const LayoutDocument& LayoutNode::root() const +{ + ASSERT(document().layout_node()); + return *document().layout_node(); +} + +LayoutDocument& LayoutNode::root() +{ + ASSERT(document().layout_node()); + return *document().layout_node(); +} + void LayoutNode::split_into_lines(LayoutBlock& container) { for_each_child([&](auto& child) { -- cgit v1.2.3