mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:07:34 +00:00
LibHTML: Add LayoutNode::document() for easy access
Every LayoutNode indirectly belongs to some Document. For anonymous LayoutNodes, we simply traverse the parent chain until we find someone with a Node from which we can get a Document&.
This commit is contained in:
parent
1b8509a0c9
commit
754e6e0f67
2 changed files with 11 additions and 1 deletions
|
@ -55,3 +55,10 @@ HitTestResult LayoutNode::hit_test(const Point& position) const
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Document& LayoutNode::document() const
|
||||||
|
{
|
||||||
|
if (is_anonymous())
|
||||||
|
return parent()->document();
|
||||||
|
return node()->document();
|
||||||
|
}
|
||||||
|
|
|
@ -8,10 +8,11 @@
|
||||||
#include <LibHTML/RenderingContext.h>
|
#include <LibHTML/RenderingContext.h>
|
||||||
#include <LibHTML/TreeNode.h>
|
#include <LibHTML/TreeNode.h>
|
||||||
|
|
||||||
class Node;
|
class Document;
|
||||||
class Element;
|
class Element;
|
||||||
class LayoutBlock;
|
class LayoutBlock;
|
||||||
class LayoutNode;
|
class LayoutNode;
|
||||||
|
class Node;
|
||||||
|
|
||||||
struct HitTestResult {
|
struct HitTestResult {
|
||||||
RefPtr<LayoutNode> layout_node;
|
RefPtr<LayoutNode> layout_node;
|
||||||
|
@ -33,6 +34,8 @@ public:
|
||||||
bool is_anonymous() const { return !m_node; }
|
bool is_anonymous() const { return !m_node; }
|
||||||
const Node* node() const { return m_node; }
|
const Node* node() const { return m_node; }
|
||||||
|
|
||||||
|
const Document& document() const;
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
inline void for_each_child(Callback callback) const
|
inline void for_each_child(Callback callback) const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue