mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
LibWeb: Implement <script src> support for synchronous scripts
Scripts loaded in this way will block the parser until they finish executing. This means that they see the DOM before the whole document has been fully parsed. This is all normal, of course. To make this work, I changed the way we notify DOM nodes about tree insertion. The inserted_into() callbacks are now incrementally invoked during parse, as each node is appended to its parent. To accomodate inline scripts and inline style sheets, we now also have a children_changed() callback which is invoked on any parent when it has children added/removed.
This commit is contained in:
parent
18d45d1082
commit
56ca91b9f8
10 changed files with 69 additions and 27 deletions
|
@ -108,9 +108,9 @@ public:
|
|||
|
||||
bool is_ancestor_of(const TreeNode&) const;
|
||||
|
||||
void prepend_child(NonnullRefPtr<T> node, bool call_inserted_into = true);
|
||||
void append_child(NonnullRefPtr<T> node, bool call_inserted_into = true);
|
||||
NonnullRefPtr<T> remove_child(NonnullRefPtr<T> node, bool call_removed_from = true);
|
||||
void prepend_child(NonnullRefPtr<T> node);
|
||||
void append_child(NonnullRefPtr<T> node);
|
||||
NonnullRefPtr<T> remove_child(NonnullRefPtr<T> node);
|
||||
void donate_all_children_to(T& node);
|
||||
|
||||
bool is_child_allowed(const T&) const { return true; }
|
||||
|
@ -200,7 +200,7 @@ private:
|
|||
};
|
||||
|
||||
template<typename T>
|
||||
inline NonnullRefPtr<T> TreeNode<T>::remove_child(NonnullRefPtr<T> node, bool call_removed_from)
|
||||
inline NonnullRefPtr<T> TreeNode<T>::remove_child(NonnullRefPtr<T> node)
|
||||
{
|
||||
ASSERT(node->m_parent == this);
|
||||
|
||||
|
@ -220,16 +220,17 @@ inline NonnullRefPtr<T> TreeNode<T>::remove_child(NonnullRefPtr<T> node, bool ca
|
|||
node->m_previous_sibling = nullptr;
|
||||
node->m_parent = nullptr;
|
||||
|
||||
if (call_removed_from)
|
||||
node->removed_from(static_cast<T&>(*this));
|
||||
node->removed_from(static_cast<T&>(*this));
|
||||
|
||||
node->unref();
|
||||
|
||||
static_cast<T*>(this)->children_changed();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void TreeNode<T>::append_child(NonnullRefPtr<T> node, bool call_inserted_into)
|
||||
inline void TreeNode<T>::append_child(NonnullRefPtr<T> node)
|
||||
{
|
||||
ASSERT(!node->m_parent);
|
||||
|
||||
|
@ -243,13 +244,14 @@ inline void TreeNode<T>::append_child(NonnullRefPtr<T> node, bool call_inserted_
|
|||
m_last_child = node.ptr();
|
||||
if (!m_first_child)
|
||||
m_first_child = m_last_child;
|
||||
if (call_inserted_into)
|
||||
node->inserted_into(static_cast<T&>(*this));
|
||||
node->inserted_into(static_cast<T&>(*this));
|
||||
(void)node.leak_ref();
|
||||
|
||||
static_cast<T*>(this)->children_changed();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void TreeNode<T>::prepend_child(NonnullRefPtr<T> node, bool call_inserted_into)
|
||||
inline void TreeNode<T>::prepend_child(NonnullRefPtr<T> node)
|
||||
{
|
||||
ASSERT(!node->m_parent);
|
||||
|
||||
|
@ -263,9 +265,10 @@ inline void TreeNode<T>::prepend_child(NonnullRefPtr<T> node, bool call_inserted
|
|||
m_first_child = node.ptr();
|
||||
if (!m_last_child)
|
||||
m_last_child = m_first_child;
|
||||
if (call_inserted_into)
|
||||
node->inserted_into(static_cast<T&>(*this));
|
||||
node->inserted_into(static_cast<T&>(*this));
|
||||
(void)node.leak_ref();
|
||||
|
||||
static_cast<T*>(this)->children_changed();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue