Architecture Overview
LibWeb is organized into subsystems that mirror web specifications:- DOM: Document Object Model and tree structures
- HTML: HTML parsing, elements, and semantics
- CSS: Style computation and cascade
- Layout: Box model and positioning
- Painting: Rendering pipeline
- JavaScript: Integration with LibJS
- Fetch: Network resource loading
- Web APIs: Canvas, WebGL, Storage, and more
Core Subsystems
DOM (Document Object Model)
The root document object representing an HTML or XML document.Location:
LibWeb/DOM/Document.hNode Types
Node Types
LibWeb implements the complete DOM node hierarchy:
- Node: Base class for all DOM nodes
- Element: Elements with attributes and tag names
- Text: Text content nodes
- Comment: Comment nodes
- DocumentType: DOCTYPE declarations
- DocumentFragment: Lightweight document containers
- Attr: Attribute nodes
HTML Elements
Base class for all HTML elements.Location:
LibWeb/HTML/HTMLElement.hCommon HTML Elements:
- Layout:
HTMLDivElement,HTMLSpanElement - Forms:
HTMLFormElement,HTMLInputElement,HTMLButtonElement - Media:
HTMLImageElement,HTMLVideoElement,HTMLAudioElement - Semantic:
HTMLHeadingElement,HTMLParagraphElement - Tables:
HTMLTableElement,HTMLTableRowElement - Canvas:
HTMLCanvasElement
CSS (Cascading Style Sheets)
CSS Engine
CSS Engine
LibWeb implements a complete CSS3 engine:Subsystems:
- Parser: CSS syntax parsing
- Selectors: Complex selector matching
- Cascade: Specificity and inheritance
- StyleCompute: Property computation
- Values: All CSS value types
- Properties: Individual property handlers
- Flexbox and Grid layouts
- CSS animations and transitions
- CSS transforms (2D and 3D)
- Media queries
- Custom properties (CSS variables)
- Pseudo-classes and pseudo-elements
Layout Engine
LibWeb’s layout engine implements the CSS box model and positioning schemes.Layout Nodes
Layout Nodes
BlockContainer: Block formatting contextInlineNode: Inline contentFlexFormattingContext: Flexbox layoutGridFormattingContext: CSS Grid layoutTableBox: Table layoutSVGBox: SVG element layout
JavaScript Integration
Automatic bindings between C++ and JavaScript using Web IDL.LibWeb uses The IDL compiler generates wrapper classes for JavaScript access.Location:
.idl files to generate JavaScript bindings:LibWeb/Bindings/Web APIs
Implemented Web APIs:
- Canvas 2D: 2D drawing context
- WebGL: 3D graphics rendering
- Web Storage: localStorage and sessionStorage
- Fetch API: Modern HTTP requests
- WebSockets: Bidirectional communication
- Web Animations: Animation API
- Intersection Observer: Viewport observation
- Mutation Observer: DOM change observation
- File API: File and Blob handling
- Crypto API: Web Cryptography
Major Subsystems
ARIA (Accessibility)
Accessible Rich Internet Applications support.Location:
LibWeb/ARIA/Animations
Web Animations API
Web Animations API
LibWeb/Animations/CSS Subsystems
CSS Implementation
CSS Implementation
Core Components:
CSSStyleSheet: Stylesheet representationCSSRule: Style rules (selectors + declarations)CSSStyleDeclaration: Property declarationsStyleResolver: Matching and cascadeStyleComputer: Computed value generation
- Length values (px, em, rem, %, vh, vw)
- Colors (named, hex, rgb(), hsl(), etc.)
- Transforms and animations
- Filters and effects
LibWeb/CSS/Fetch API
Modern HTTP request API.Location:
LibWeb/Fetch/WebGL
WebGL Support
WebGL Support
LibWeb provides WebGL 1.0 support through LibGL:WebGL calls are translated to LibGL OpenGL operations.
Parsing and Tokenization
HTML Parser
HTML5 Parser
HTML5 Parser
LibWeb implements the HTML5 parsing algorithm:
- Tokenization: Character stream to tokens
- Tree Construction: Token stream to DOM
- Error Recovery: Robust error handling
- Foreign Content: SVG and MathML integration
- Document fragments
- Script execution during parsing
- Character encodings
- Quirks mode detection
LibWeb/HTML/Parser/CSS Parser
Robust CSS3 parsing with error recovery and vendor prefix support.Event System
Base class for objects that can receive events.
Event Types
Event Types
Mouse Events:
click,dblclickmousedown,mouseup,mousemovemouseenter,mouseleave
keydown,keyup,keypress
submit,change,input,focus,blur
DOMContentLoaded,load,unload
- User-defined event types
Rendering Pipeline
Paint System
Paint System
The rendering pipeline transforms layout to pixels:Location:
- Layout: Compute positions and sizes
- Stacking Context: Z-order determination
- Paint: Generate display list
- Composite: Layer composition
LibWeb/Painting/Storage APIs
Web Storage (localStorage/sessionStorage) implementation.Location:
LibWeb/HTML/Storage.hSVG Support
Scalable Vector Graphics rendering integrated into the layout engine.SVG Features:
- Basic shapes (rect, circle, ellipse, line, polygon)
- Paths with full path data support
- Text rendering
- Gradients and patterns
- Transformations
- Clipping and masking
LibWeb/SVG/Encoding and URLs
URL parsing and manipulation.Location:
LibWeb/DOMURL/Cookie Management
Cookie API
Cookie API
FileAPI
File and Blob handling for file uploads and processing.Location:
LibWeb/FileAPI/Performance and Timing
Performance APIs
Performance APIs
- Performance API: Navigation and resource timing
- requestAnimationFrame: Animation scheduling
- Intersection Observer: Viewport-based loading
- Resize Observer: Element size changes
Usage Example
Source Location
Directory:Userland/Libraries/LibWeb/
Major Subdirectories:
DOM/: Document Object ModelHTML/: HTML elements and parsingCSS/: Style systemLayout/: Layout enginePainting/: RenderingBindings/: JavaScript integrationFetch/: Network requestsWebGL/: 3D graphicsSVG/: Vector graphicsARIA/: AccessibilityAnimations/: Web Animations API
