From 159507f2a6a3a8b4ffd2eab68e26c7ec86197420 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 9 Oct 2019 21:33:34 +0200 Subject: [PATCH] LibHTML: Move is_ancestor_of() from LayoutNode to TreeNode This way it becomes available to all the different TreeNode subclasses. --- Libraries/LibHTML/Layout/LayoutNode.h | 11 ----------- Libraries/LibHTML/TreeNode.h | 13 +++++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Libraries/LibHTML/Layout/LayoutNode.h b/Libraries/LibHTML/Layout/LayoutNode.h index 78b77dd850..38cd663d8d 100644 --- a/Libraries/LibHTML/Layout/LayoutNode.h +++ b/Libraries/LibHTML/Layout/LayoutNode.h @@ -81,8 +81,6 @@ public: void set_needs_display(); - bool is_ancestor_of(const LayoutNode&) const; - template void for_each_fragment_of_this(Callback); @@ -130,12 +128,3 @@ inline const LayoutNodeWithStyle* LayoutNode::parent() const { return static_cast(TreeNode::parent()); } - -inline bool LayoutNode::is_ancestor_of(const LayoutNode& other) const -{ - for (auto* ancestor = other.parent(); ancestor; ancestor = ancestor->parent()) { - if (ancestor == this) - return true; - } - return false; -} diff --git a/Libraries/LibHTML/TreeNode.h b/Libraries/LibHTML/TreeNode.h index 467ab83cfb..f384dd0a1c 100644 --- a/Libraries/LibHTML/TreeNode.h +++ b/Libraries/LibHTML/TreeNode.h @@ -33,6 +33,8 @@ public: const T* first_child() const { return m_first_child; } const T* last_child() const { return m_last_child; } + bool is_ancestor_of(const TreeNode&) const; + void prepend_child(NonnullRefPtr node, bool call_inserted_into = true); void append_child(NonnullRefPtr node, bool call_inserted_into = true); void donate_all_children_to(T& node); @@ -98,3 +100,14 @@ inline void TreeNode::donate_all_children_to(T& node) m_first_child = nullptr; m_last_child = nullptr; } + + +template +inline bool TreeNode::is_ancestor_of(const TreeNode& other) const +{ + for (auto* ancestor = other.parent(); ancestor; ancestor = ancestor->parent()) { + if (ancestor == this) + return true; + } + return false; +}