summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML
AgeCommit message (Collapse)Author
2019-10-15LibHTML: Move layout tree building to a LayoutTreeBuilder classAndreas Kling
Building a whole layout tree shouldn't be a concern of Node, so this patch moves it to a separate class.
2019-10-15LibHTML: Add is<T> and to<T> helpers for LayoutNode class familyAndreas Kling
2019-10-14LibHTML: Implement basic partial style invalidationAndreas Kling
This patch makes it possible to call Node::invalidate_style() and have that node and all of its ancestors recompute their style. We then figure out if the new style is visually different from the old style, and if so do a paint invalidation with set_needs_display(). Note that the "are they visually different" code is very incomplete! Use this to make hover effects a lot more efficient. They no longer cause a full relayout+repaint, but only a style invalidation. Style invalidations are still quite heavy though, and there's a lot of room for improvement there. :^)
2019-10-14LibHTML: Rename Document's invalidate_{style,layout}() to update_foo()Andreas Kling
2019-10-14LibHTML: Implement basic :hover pseudo-class supportAndreas Kling
This is currently very aggressive. Whenever the Document's hovered node changes, we invalidate all style and do a full relayout. It does look cool though. So cool that I'm adding it to the default stylesheet. :^)
2019-10-14LibHTML: Parse the :link and :hover CSS pseudo-classesAndreas Kling
We don't actually do anything with these yet, but now the values will be there for the selector engine to look at when it feels ready. :^)
2019-10-13LibHTML: Add some convenient geometry getters on LayoutNodeAndreas Kling
Add x(), y(), size() and position() and use them around the codebase.
2019-10-13LibHTML: Use LayoutBlock::add_line_box() in LayoutBreakAndreas Kling
2019-10-13LibHTML: Fix broken line splitting behavior in LayoutReplacedAndreas Kling
Replaced elements will now properly create line breaks when they use up the available horizontal space. This fixes an issue with <img>'s lining up instead of breaking.
2019-10-13LibHTML: Run second layout pass if first layout adds/removes scrollbarsAndreas Kling
If you do a layout and it turns out that the page contents don't fit in the viewport vertically, we add a vertical scrollbar. Since the scrollbar takes up some horizontal space, this reduces the amount of space available to the page. So we have to do a second layout pass. :^) Fixes #650.
2019-10-13LibHTML: Split layout invalidation into style and layout invalidationAndreas Kling
When style is invalidated (for example when an external stylesheet finishes loading) we delete the whole layout tree and build a new one. This is necessary since the new style information may result in a different layout tree. When layout is invalidated (window resized, image dimensions learned, etc..) we keep the existing layout tree but run the layout algorithm once again. There's obviously lots of room for improvement here. :^)
2019-10-13LibHTML: Move layout root from HtmlView to DocumentAndreas Kling
The layout root is now kept alive via Document::m_layout_root. This will allow us to do more layout-related things inside the inner layer of LibHTML without reaching out to the HtmlView. I'd like to keep HtmlView at a slightly higher level, to prevent it from getting too complex. This patch also fixes accidental disconnection of the layout tree from the DOM after doing a layout tree rebuild. ~LayoutNode() now only unsets the DOM node's layout_node() if it's itself.
2019-10-13LibHTML: Handle comments in the CSS parserAndreas Kling
Turn consume_whitespace() into consume_whitespace_or_comments() and have it swallow /* comments */ as well.
2019-10-12LibHTML: Add Comment and CharacterData nodes and improve HTML parsingAndreas Kling
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-12LibHTML+Browser: Add debug option to draw borders around line boxesAndreas Kling
This will be very useful when debugging line layout.
2019-10-12LibHTML: Implement the <br> element for line breakingAndreas Kling
The <br> element will produce a special LayoutBreak node in the layout tree, which forces a break in the line layout whenever encountered. This patch also makes LayoutBlock use the current line-height as the minimum effective height for each line box. This ensures that having multiple <br> elements in a row doesn't create 0-height line boxes.
2019-10-12LibHTML: Add StyleProperties::line_height()Andreas Kling
We currently hard-code the line height to 140% of the font glyph height and this patch doesn't fix the hard-coding, but at least moves it out of LayoutText and into StyleProperties where it can be re-used until the day we go and do a proper implementation of CSS line-height. :^)
2019-10-12LibHTML: Make all element tag names lowercase for nowAndreas Kling
This is not the correct-est way of doing this, but it does make a bunch of things simpler for now. We can revisit tag name case later on. :^)
2019-10-12LibHTML: Move Element construction to a separate fileAndreas Kling
We now have create_element(document, tag_name) in ElementFactory. This will be useful for constructing new elements outside of parsing.
2019-10-11LibHTML: Make sure the marker has the same inline state as siblingsAndreas Kling
Or LayoutBlock will assert when trying to layout its children since they have inconsistent inline state.
2019-10-11LibHTML: LayoutBlock::children_are_inline() should check is_inline()Andreas Kling
Instead of asking if the first child is not a block, ask if it thinks it's inline.
2019-10-11LibHTML: Add LayoutNode classes for "display: list-item" and its markerAndreas Kling
This patch removes the hard-coded hack for "display: list-item" from LayoutBlock and adds LayoutListItem and LayoutListItemMarker. Elements with "display: list-item" now generate a LayoutListItem, which may then also generate a LayoutListItemMarker if appropriate. :^)
2019-10-10LibHTML+Browser: Show the number of pending resource loadsAndreas Kling
For now this is simply a counter+hook exposed by ResourceLoader and shown in the Browser status bar. This is not very nuanced, and it would be nice to expose more info so we could eventually do something like a progress bar.
2019-10-10LibHTML: Show a hand cursor when hovering over a clickable link :^)Andreas Kling
2019-10-10LibHTML: Fix relative URL completion when document URL ends in a slashAndreas Kling
2019-10-09LibHTML: Have TreeNode deref its children before deleting itselfAndreas Kling
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-09LibHTML: Tear down the layout tree before changing the Frame's documentAndreas Kling
We don't want to deal with document().frame() being null inside layout tree code, so this makes sure we tear it down before the frame has a chance to get nulled out.
2019-10-09LibHTML: Document::detach_from_frame() should actually detachAndreas Kling
2019-10-09LibHTML: Move is_ancestor_of() from LayoutNode to TreeNodeAndreas Kling
This way it becomes available to all the different TreeNode subclasses.
2019-10-09LibHTML: Implement the <blink> elementAndreas Kling
Just in time for Serenity's 1st birthday, here is the <blink> element! This patch adds a bunch of different mechanisms to enable partial repaints of the layout tree (LayoutNode::set_needs_display())) It also adds LayoutNode::is_visible(), which can be toggled to prevent a LayoutNode from rendering anything (it still takes up space though.)
2019-10-09LibHTML: Add basic <!DOCTYPE> parsing and a DocumentType classAndreas Kling
Plus, Document::fixup() will now make sure that the document always starts with a doctype node, followed by an <html> element.
2019-10-09LibHTML: Rename Document::normalize() to fixup() and always do itAndreas Kling
Node.normalize() is a standard DOM API that coalesces Text nodes. To avoid clashing with that, rename it to fixup(). This patch also makes it happen automagically as part of parsing.
2019-10-09LibHTML: Handle CSS declarations that don't end in ';'Andreas Kling
2019-10-09LibHTML: Collapse whitespace in LayoutText unless white-space: pre;Andreas Kling
Before breaking the Text node contents into words, collapse all of the whitespace into single space (' ') characters. This fixes broken rendering of paragraphs with newlines in them. :^)
2019-10-09LibHTML: Use ResourceLoader in HTMLLinkElementAndreas Kling
This makes loading external stylesheets from http:// URLs work. :^)
2019-10-08LibHTML: Fire the file:// load completion callback asynchronouslyAndreas Kling
This makes it consistent with how http:// callbacks are fired. It would probably be fine to have file:// be synchronous, but at the same time it's nice to have consistency.
2019-10-08LibHTML: Add ResourceLoader to support protocol-agnostic URL loadingAndreas Kling
We now support loading both file:// and http:// URLs. Feel free to visit http://www.serenityos.org/ and enjoy the fancy good times. :^)
2019-10-08LibHTML: Use an enum for CSS property ID'sAndreas Kling
Instead of using string everywhere, have the CSS parser produce enum values, since they are a lot nicer to work with. In the future we should generate most of this code based on a list of supported CSS properties.
2019-10-08LibHTML: Move selector matching into a SelectorEngine namespaceAndreas Kling
2019-10-07LibHTML: Don't crash when calling set_document(nullptr)Andreas Kling
2019-10-07LibHTML: Make the CSS and HTML parsers take StringViewsAndreas Kling
This allows us to avoid unnecessary making unnecessary String copies of all the source text.
2019-10-07LibHTML: Start adding support for <link rel="stylesheet">Andreas Kling
This patch adds basic support for external stylesheets. It currently only works with file:// URLs. We do a synchronous full relayout after loading a stylesheet, which is definitely on the aggressive side, but it gives us something to work on improving. :^)
2019-10-07LibHTML: Add LayoutNodeWithStyle class, make LayoutText style-lessAndreas Kling
Since LayoutText always inherits style, it shouldn't store any style of its own. This patch adds a LayoutNodeWithStyle class to sit between LayoutNode and everyone who wants to inherit from LayoutNode except LayoutText :^) Since LayoutText can never have children, we also know that the parent of any LayoutNode is always going to be a LayoutNodeWithStyle. So this patch makes LayoutNode::parent() return LayoutNodeWithStyle*.
2019-10-07LibHTML: Rename "style_properties" to "style" everywhereAndreas Kling
2019-10-06LibHTML: Optionally pass document URL to the HTML parserAndreas Kling
This makes the document URL available to all the parse_attributes() callbacks, in case they need it for anything.
2019-10-06LibHTML: Add Node::first_ancestor_of_type<T>()Andreas Kling
Here's another helper for finding the first ancestor of a Node of a specific type.
2019-10-06LibHTML: Templatize Node::first_child_of_type<T>()Andreas Kling
This is a lot nicer than first_child_with_tag_name(...). The is<T>(Node) functions are obviously unoptimized at the moment, and this is about establishing pleasant patterns right now. :^)
2019-10-06LibHTML: Add is<ElementType> and to<ElementType> helper functionsAndreas Kling
These will help us write node-type-aware template functions.
2019-10-06LibHTML: Add adjacent (+) and general (~) sibling combinatorsAndreas Kling
This patch implements two more selector features: - "div + p" matches the <p> sibling immediately after a <div>. - "div ~ p" matches all <p> siblings after a <div>.
2019-10-06LibHTML: Add Node::{next,previous}_element_sibling()Andreas Kling
These helpers return the next/previous sibling Node that's actually an element. This will be useful in the CSS engine since CSS doesn't care about text nodes.