diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-04 19:37:52 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-04 20:45:47 +0100 |
commit | 715d7a8532caa0d6b818020f4c2f47e85791d2bf (patch) | |
tree | d5e23105b82ef18459183cc533578aee0f4ac7c7 /Libraries/LibHTML/Layout/LayoutNode.cpp | |
parent | 2946b0e2d48d637c8058ef94141ad8b023ef189a (diff) | |
download | serenity-715d7a8532caa0d6b818020f4c2f47e85791d2bf.zip |
LibHTML: Add a convenient way to get from any layout node to the root
Diffstat (limited to 'Libraries/LibHTML/Layout/LayoutNode.cpp')
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutNode.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
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*>(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) { |