Commit graph

15 commits

Author SHA1 Message Date
Andreas Kling
1aea8f116b LibHTML: Add TreeNode::for_each_in_subtree_of_type<T>()
This allows you to iterate a subtree and get a callback for every node
where is<T>(node) == true. This makes for quite pleasant DOM traversal.
2019-12-18 21:34:03 +01:00
Andreas Kling
e3d975e943 LibHTML+Browser: Add a simple DOM inspector popup window
LibHTML now provides a DOMTreeModel which can be used to view a given
Document's DOM tree. :^)
2019-11-09 11:31:03 +01:00
Andreas Kling
69883bea6f LibHTML: Update the removed node's siblings in TreeNode::remove_child()
Oops, we forgot to update the node's siblings' sibling pointers when
removing a node from the tree.

Thanks to Owlinated for pointing this out! :^)
2019-11-07 22:45:12 +01:00
Andreas Kling
26493a3039 LibHTML: Add TreeNode::remove_child()
This removes a child from the tree and returns it to the caller.
It optionally (but by default) calls removed_from(parent) on the child.
2019-11-06 20:26:17 +01:00
Andreas Kling
1466a7364c LibHTML: Add TreeNode::next_in_pre_order()
This function allows you to traverse in pre-order without recursing.
2019-11-05 18:36:06 +01:00
Andreas Kling
4d9740ecef LibHTML: Add Document::get_element_by_id() and get_elements_by_name()
These will be useful for implementing various things. They don't do any
caching at the moment, but that might become valuable in the future.

To facilitate this change, I also made it possible to abort a tree walk
with for_each_in_subtree() by returning IterationDecision::Break from
the callback.
2019-10-21 12:01:30 +02:00
Andreas Kling
b3a63e1d50 LibHTML: Add TreeNode<T>::for_each_in_subtree(callback)
This helper invokes a callback for the node and each of its descendants
in pre-order.
2019-10-19 18:14:54 +02:00
Andreas Kling
877ff6bc13 LibHTML: Make TreeNode inherit from Weakable by default
This makes Node and LayoutNode weakable. Frame was already weakable.
2019-10-19 09:42:20 +02:00
Andreas Kling
b083a233d8 LibHTML: Add Comment and CharacterData nodes and improve HTML parsing
This patch adds the CharacterData subclass of Node, which is now the
parent class of Text and a new Comment class.

A Comment node is one of these in HTML: <!--hello friends-->
Since these occur somewhat frequently on the web, we need to be able
to parse them.

This patch also adds a child rejection mechanism to the DOM tree.
Nodes can now override is_child_allowed(Node) and return false if they
don't want a particular Node to become a child of theirs. This is used
to prevent Document from taking on unwanted children.
2019-10-12 23:34:05 +02:00
Andreas Kling
796e63b34c LibHTML: Have TreeNode deref its children before deleting itself
This is definitely not the ideal ownership model here, but it's
something we'll have to iterate on as the engine grows.

At least this prevents us from leaking the entire world. :^)
2019-10-09 21:58:38 +02:00
Andreas Kling
159507f2a6 LibHTML: Move is_ancestor_of() from LayoutNode to TreeNode
This way it becomes available to all the different TreeNode subclasses.
2019-10-09 21:33:34 +02:00
Andreas Kling
fc53867937 LibHTML: Add basic <!DOCTYPE> parsing and a DocumentType class
Plus, Document::fixup() will now make sure that the document always
starts with a doctype node, followed by an <html> element.
2019-10-09 20:17:01 +02:00
Andreas Kling
7912592f89 LibHTML: Add inserted_into() and removed_from() TreeNode callbacks
These will be called when a Node or LayoutNode is inserted or removed
from a tree. They get the parent node as an argument.
2019-09-29 17:40:39 +02:00
Sergey Bugaev
c1ef63379c LibHTML: Add Document::normalize()
This method wraps the document tree in <html> and <body> elements if needed.
2019-09-28 18:29:42 +02:00
Andreas Kling
04b9dc2d30 Libraries: Create top level directory for libraries.
Things were getting a little crowded in the project root, so this patch
moves the Lib*/ directories into Libraries/.
2019-07-04 16:16:50 +02:00
Renamed from LibHTML/TreeNode.h (Browse further)