web engine - experimental web browser

DOM tree: Document, Element, Text, Comment node types #31

open opened by pierrelf.com

Phase 3, Issue 1: DOM Tree#

Implement the core DOM tree data structure in the dom crate.

Requirements#

Node types:

  • Document — root of the DOM tree
  • Element — has tag name, attributes (Vec of name/value pairs), namespace (optional)
  • Text — character data
  • Comment — comment text

Tree structure:

  • Arena-based or Rc<RefCell<>> tree (choose arena for performance)
  • Each node has: parent, first_child, last_child, next_sibling, prev_sibling
  • NodeId handle type for referring to nodes

Tree manipulation API:

  • Document::new() -> Document
  • Document::create_element(tag_name) -> NodeId
  • Document::create_text(data) -> NodeId
  • Document::create_comment(data) -> NodeId
  • Document::append_child(parent, child)
  • Document::insert_before(parent, new_child, reference_child)
  • Document::remove_child(parent, child)
  • Document::parent(node) -> Option<NodeId>
  • Document::children(node) -> impl Iterator<Item = NodeId>
  • Document::node_data(node) -> &NodeData (to inspect type, tag name, text, etc.)

Element-specific API:

  • Document::tag_name(node) -> Option<&str>
  • Document::get_attribute(node, name) -> Option<&str>
  • Document::set_attribute(node, name, value)

Acceptance criteria#

  • All node types implemented
  • Tree manipulation works correctly (append, insert, remove)
  • Can build a simple tree: <html><head><title>Test</title></head><body><p>Hello</p></body></html>
  • cargo clippy -p we-dom -- -D warnings passes
  • cargo test -p we-dom passes with comprehensive unit tests
  • No unsafe code
  • No external dependencies
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mfubrx2tlq2q