Commit graph

25 commits

Author SHA1 Message Date
Andreas Kling
5aeab9878e LibWeb: Rename LayoutNode classes and move them into Layout namespace
Bring the names of various boxes closer to spec language. This should
hopefully make things easier to understand and hack on. :^)

Some notable changes:

- LayoutNode -> Layout::Node
- LayoutBox -> Layout::Box
- LayoutBlock -> Layout::BlockBox
- LayoutReplaced -> Layout::ReplacedBox
- LayoutDocument -> Layout::InitialContainingBlockBox
- LayoutText -> Layout::TextNode
- LayoutInline -> Layout::InlineNode

Note that this is not strictly a "box tree" as we also hang inline/text
nodes in the same tree, and they don't generate boxes. (Instead, they
contribute line box fragments to their containing block!)
2020-11-22 15:56:27 +01:00
Andreas Kling
f358f2255f LibWeb: Rename LayoutNode::node() => LayoutNode::dom_node() 2020-11-22 14:46:36 +01:00
Luke
7902d215b3 LibWeb: Implement <template> parsing
Note that there is currently no way to display them as we can't
currently clone nodes.

Adds special case for templates for dumping to console.
Doesn't add it to the DOM inspector as I'm not sure how to do it.
2020-08-21 11:57:11 +02:00
Andreas Kling
1f008c95b6 LibWeb: Move CSS classes into the Web::CSS namespace 2020-07-26 20:05:15 +02:00
Andreas Kling
11ff9d0f17 LibWeb: Move DOM classes into the Web::DOM namespace
LibWeb keeps growing and the Web namespace is filling up fast.
Let's put DOM stuff into Web::DOM, just like we already started doing
with SVG stuff in Web::SVG.
2020-07-26 20:05:15 +02:00
Andreas Kling
71556e39a4 LibWeb: Switch to using AK::is and AK::downcast 2020-07-26 17:51:00 +02:00
Andreas Kling
3cb50a4714 LibWeb: Rename Element::tag_name() => local_name()
To prepare for fully qualified tag names, let's call this local_name.
Note that we still keep an Element::tag_name() around since that's what
the JS bindings end up calling into for the Element.tagName property.
2020-07-23 18:18:13 +02:00
Andreas Kling
5e83a97fa2 LibWeb: Rename LayoutNode::style() => specified_style()
Let's make way for a slightly-more-cooked style() that will eventually
replace the raw specified_style() for layout and paint purposes.
2020-06-24 13:54:31 +02:00
Andreas Kling
f742b245b7 LibWeb: Turn BoxModelMetrics into a simple struct
Using getters for this thing was just cumbersome and didn't achieve
anything of value so just turn it into a plain struct.
2020-06-24 11:22:34 +02:00
Andreas Kling
c7d9229a0f LibWeb: Reorganize layout algorithm
Previously, layout recursively performed these steps (roughly):

1. Compute own width
2. Compute own position
3. Layout in-flow children
4. Compute own height
5. Layout absolutely positioned descendants

However, step (2) was pretty inconsistent. Some things computed their
own position, others had their parent do it for them, etc.
To get closer to CSS spec language, and make things easier in general,
this patch reorganizes the algorithm into:

1. Compute own width & height
2. Compute width & height of in-flow managed descendants
3. Move in-flow managed descendants to their final position
4. Layout absolutely positioned descendants

Block layout is now driven by the containing block, which will iterate
the descendants it's responsible for. There are a lot of inefficient
patterns in this logic right now, but they can easily be replaced with
better iteration functions once we settle on a long-term architecture.

Since the ICB (LayoutDocument) is at (0, 0), it doesn't rely on a
containing block to move it into place.

This code is still evolving along with my understanding of CSS layout,
so it's likely that we'll reorganize this again sooner or later. :^)
2020-06-14 19:01:54 +02:00
Andreas Kling
2b47ba6c3f LibWeb: Dump layout node style properties in alphabetical order 2020-06-14 18:47:21 +02:00
Andreas Kling
ae3e5e9d37 LibWeb: Include selector pseudo-class in style sheet dumps 2020-06-13 00:43:06 +02:00
Andreas Kling
260427f0ad LibWeb: Some improvements to absolute positioning
Absolutely positioned blocks now register themselves with their
containing block (and note that the containing block of an absolutely
positioned box is the nearest non-statically positioned block ancestor
or the ICB as fallback.)

Containing blocks then drive the layout of their tracked absolutely
positioned descendants as a separate layout pass.

This is very far from perfect but the general direction seems good.
2020-06-12 13:43:46 +02:00
Andreas Kling
ff2c949d70 LibWeb: Include class names in layout tree dumps
This makes it a lot easier to see which layout node is which DOM node.
2020-06-12 13:23:07 +02:00
Andreas Kling
65c4e5cacf LibWeb: Parse and match basic "contains" attribute selectors (~=) 2020-06-10 15:43:41 +02:00
Andreas Kling
656b01eb0f LibWeb: Rework the layout engine to use relative offsets
The box tree and line boxes now all store a relative offset from their
containing block, instead of an absolute (document-relative) position.

This removes a huge pain point from the layout system which was having
to adjust offsets recursively when something moved. It also makes some
layout logic significantly simpler.

Every box can still find its absolute position by walking its chain
of containing blocks and accumulating the translation from the root.
This is currently what we do both for rendering and hit testing.
2020-06-10 10:46:57 +02:00
Andreas Kling
731685468a LibWeb: Start fleshing out support for relative CSS units
This patch introduces support for more than just "absolute px" units in
our Length class. It now also supports "em" and "rem", which are units
relative to the font-size of the current layout node and the <html>
element's layout node respectively.
2020-06-07 17:55:46 +02:00
Andreas Kling
2149820260 LibWeb: Use HTML::AttributeNames::foo instead of FlyString("foo")
To avoid the costly instantiation of FlyStrings whenever we're looking
up attributes, use the premade HTML::AttributeNames globals. :^)
2020-06-03 21:53:00 +02:00
Andreas Kling
a01fd7ecc5 LibWeb: Colorize tag names in layout tree dumps + show element IDs
Showing element IDs in layout tree dumps makes it much easier to
compare against the DOM.
2020-05-23 21:08:25 +02:00
Andreas Kling
06aec9667e LibWeb: Support more advanced selectors in document.querySelectorAll()
I made some mistakes in the selector parsing code. It's now able to
parse selectors composed of multiple complex selectors, instead of just
one complex selector.
2020-03-30 11:35:39 +02:00
Andreas Kling
0f7bcd4111 LibWeb: Add naive support for document.querySelectorAll()
This currently returns a JS::Array of elements matching a selector.
The more correct behavior would be to return a static NodeList, but as
we don't have NodeLists right now, that'll be a task for the future.
2020-03-30 11:35:39 +02:00
Elisée Maurer
d01b97b50a
Base: Replace <!DOCTYPE> with <!DOCTYPE html> in a few files (#1511)
<!DOCTYPE> by itself is not a valid document type declaration.
2020-03-26 07:37:12 +01:00
Andreas Kling
5b87043221 LibWeb: Make dump_tree() look okay for DocumentFragments 2020-03-25 18:49:29 +01:00
Andreas Kling
7309642ca8 LibWeb: Use FlyString for Element tag names
This makes selector matching a lot more efficient, and also reduces the
number of strings on the heap.
2020-03-22 19:12:10 +01:00
Andreas Kling
830a57c6b2 LibWeb: Rename directory LibHTML => LibWeb
Let's rename this to LibWeb since it aims to provide more parts of the
web platform than just HTML. :^)
2020-03-07 10:32:51 +01:00
Renamed from Libraries/LibHTML/Dump.cpp (Browse further)