mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:18:14 +00:00
LibHTML: Add is<T> and to<T> helpers for LayoutNode class family
This commit is contained in:
parent
bbee1c5b98
commit
d14b60533f
6 changed files with 75 additions and 5 deletions
|
@ -53,3 +53,9 @@ void LayoutNode::for_each_fragment_of_this(Callback callback)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool is<LayoutBlock>(const LayoutNode& node)
|
||||
{
|
||||
return node.is_block();
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ void LayoutNode::layout()
|
|||
const LayoutBlock* LayoutNode::containing_block() const
|
||||
{
|
||||
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
|
||||
if (ancestor->is_block())
|
||||
return static_cast<const LayoutBlock*>(ancestor);
|
||||
if (is<LayoutBlock>(*ancestor))
|
||||
return to<LayoutBlock>(ancestor);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ public:
|
|||
virtual bool is_text() const { return false; }
|
||||
virtual bool is_block() const { return false; }
|
||||
virtual bool is_replaced() const { return false; }
|
||||
bool has_style() const { return m_has_style; }
|
||||
|
||||
bool is_inline() const { return m_inline; }
|
||||
void set_inline(bool b) { m_inline = b; }
|
||||
|
@ -136,3 +137,55 @@ inline const LayoutNodeWithStyle* LayoutNode::parent() const
|
|||
{
|
||||
return static_cast<const LayoutNodeWithStyle*>(TreeNode<LayoutNode>::parent());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool is(const LayoutNode&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool is(const LayoutNode* node)
|
||||
{
|
||||
return node && is<T>(*node);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool is<LayoutNode>(const LayoutNode&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool is<LayoutNodeWithStyle>(const LayoutNode& node)
|
||||
{
|
||||
return node.has_style();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline const T& to(const LayoutNode& node)
|
||||
{
|
||||
ASSERT(is<T>(node));
|
||||
return static_cast<const T&>(node);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T* to(LayoutNode* node)
|
||||
{
|
||||
ASSERT(is<T>(node));
|
||||
return static_cast<T*>(node);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline const T* to(const LayoutNode* node)
|
||||
{
|
||||
ASSERT(is<T>(node));
|
||||
return static_cast<const T*>(node);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T& to(LayoutNode& node)
|
||||
{
|
||||
ASSERT(is<T>(node));
|
||||
return static_cast<T&>(node);
|
||||
}
|
||||
|
|
|
@ -15,3 +15,9 @@ private:
|
|||
|
||||
virtual void split_into_lines(LayoutBlock& container) override;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<LayoutReplaced>(const LayoutNode& node)
|
||||
{
|
||||
return node.is_replaced();
|
||||
}
|
||||
|
|
|
@ -31,3 +31,9 @@ private:
|
|||
|
||||
String m_text_for_rendering;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<LayoutText>(const LayoutNode& node)
|
||||
{
|
||||
return node.is_text();
|
||||
}
|
||||
|
|
|
@ -10,8 +10,7 @@ void LineBoxFragment::render(RenderingContext& context)
|
|||
return;
|
||||
}
|
||||
|
||||
if (layout_node().is_text()) {
|
||||
auto& layout_text = static_cast<const LayoutText&>(layout_node());
|
||||
layout_text.render_fragment(context, *this);
|
||||
if (is<LayoutText>(layout_node())) {
|
||||
to<LayoutText>(layout_node()).render_fragment(context, *this);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue