Commit Graph

25 Commits

Author SHA1 Message Date
Andreas Kling
d19d4da14a LibHTML: Implement compound selectors
This patch moves the Selector object model closer to the specification
objects in Selectors Level 4.

A "Selector" in LibHTML is now a { Vector<ComplexSelector> }, which is
a { Relation, CompoundSelector }. A CompoundSelector is really just
a Vector<SimpleSelector>, and SimpleSelector is "Component" renamed.

This makes a lot more selectors actually match on the Ubuntu Apache2
default homepage. :^)
2019-11-27 20:37:36 +01:00
Andreas Kling
8946e50986 LibHTML: Implement some attribute selector support
This patch adds a[foo] and a[foo=bar] attribute selectors.

Note that an attribute selector is an optional part of a selector
component, and not a component on its own.
2019-11-21 20:07:43 +01:00
Andreas Kling
1fe2cca439 LibHTML: Use LayoutText::text_for_rendering() in layout tree dumps
This way the fragment offsets make a lot more sense, since they assume
whitespace has already been collapsed.
2019-11-19 18:36:33 +01:00
Andreas Kling
56dad2272c LibHTML: Implement the universal selector ("*") 2019-11-19 18:23:09 +01:00
Andreas Kling
89a0d873ba LibHTML: Update tree dumping code now that everything is floating point 2019-11-18 20:26:15 +01:00
Andreas Kling
e6e41e4fb8 LibHTML: Start building a simple code generator for CSS properties
Code for parsing and stringifying CSS properties is now generated based
on LibHTML/CSS/Properties.json

At the moment, the file tells us three things:

- The name of a property
- Its initial value
- Whether it's inherited

Also, for shorthand properties, it provides a list of all the longhand
properties it may expand too. This is not actually used in the engine
yet though.

This *finally* makes layout tree dumps show the names of CSS properties
in effect, instead of "CSS::PropertyID(32)" and such. :^)
2019-11-18 11:48:41 +01:00
Andreas Kling
4814253589 LibHTML: Introduce LayoutBox and LayoutNodeWithStyleAndBoxModelMetrics
To streamline the layout tree and remove irrelevant data from classes
that don't need it, this patch adds two new LayoutNode subclasses.

LayoutNodeWithStyleAndBoxModelMetrics should be inherited by any layout
node that cares about box model metrics (margin, border, and padding.)
LayoutBox should be inherited by any layout node that can have a rect.

This makes LayoutText significantly smaller (from 140 to 40 bytes) and
clarifies a lot of things about the layout tree.

I'm also adding next_sibling() and previous_sibling() overloads to
LayoutBlock that return a LayoutBlock*. This is okay since blocks only
ever have block siblings.

Do also note that the semantics of is<T> slightly change in this patch:
is<T>(nullptr) now returns true, to facilitate allowing to<T>(nullptr).
2019-10-15 16:48:38 +02:00
Andreas Kling
3309bdf722 LibHTML: Add some convenient geometry getters on LayoutNode
Add x(), y(), size() and position() and use them around the codebase.
2019-10-13 18:47:16 +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
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
31ac19543a LibHTML: Use an enum for CSS property ID's
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-08 15:35:05 +02:00
Andreas Kling
f52f2736e1 LibHTML: Add is<ElementType> and to<ElementType> helper functions
These will help us write node-type-aware template functions.
2019-10-06 20:38:26 +02:00
Andreas Kling
bedb00603c LibHTML: Add adjacent (+) and general (~) sibling combinators
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-06 19:59:07 +02:00
Andreas Kling
2a266db05b LibHTML: Parse descendant relations in CSS selectors
"div p" now generates a Selector with two components where the second
component is a type=TagName, value="p", relation=Descendant.

We still don't handle matching of these, but at least we parse them.
2019-10-06 11:07:57 +02:00
Andreas Kling
306b9dfb51 LibHTML: Various little improvements to the CSS parser
The parser now kinda recognizes immediate child selectors, !important,
and various other little things.

It's still extremely far from robust and/or correct. :^)
2019-10-06 09:28:58 +02:00
Andreas Kling
a7ca719c4e LibHTML: Rename LayoutNode::style_properties() to LayoutNode::style() 2019-10-04 15:56:36 +02:00
Andreas Kling
9c0e9a1a20 LibHTML: Rename ComputedStyle to BoxModelMetrics
There was nothing left in ComputedStyle except the box model metrics,
so this patch gives it a more representative name.

Note that style information is fetched directly from StyleProperties,
which is basically the CSS property name/value pairs that apply to
an element.
2019-10-04 15:50:50 +02:00
Andreas Kling
1d65cf367f LibHTML: Rewrite inline and text layout
Inline layout is now done by LayoutBlock. Blocks with inline children
will split them into line boxes during layout.

A LayoutBlock can have zero or more LineBox objects. Each LineBox
represents one visual line.

A LineBox can have any number of LineBoxFragment children. A fragment
is an offset+length into a specific LayoutNode.

To paint a LayoutBlock with inline children, we walk its line boxes,
and walk their fragments, painting each fragment at a time by calling
LineBoxFragment::render(), which in turn calls the LayoutNode via
LayoutText::render_fragment(). Hit testing works similarly.

This is very incomplete and has many bugs, but should make it easier
for us to move forward with this code.
2019-10-03 15:20:13 +02:00
Andreas Kling
9290117b77 LibHTML: Let's put debug output on the debugger stream 2019-10-03 10:25:34 +02:00
Andreas Kling
8d797fc62e LibHTML: Fix incorrect CSS object model
A StyleRule has a StyleDeclaration which has many StyleProperty. :^)
2019-09-30 20:06:17 +02:00
Sergey Bugaev
93003bfda1 LibHTML: Implement LayoutText 2019-09-28 18:29:42 +02:00
Sergey Bugaev
fd0aa5dd43 LibHTML: Get rid of the style tree
We now create a layout tree directly from the DOM tree.
This way we don't actually lose text nodes ^)
2019-09-28 18:29:42 +02:00
Andreas Kling
fc43cf929d LibHTML: Implement basic block height computation
..and add vertical box properties to the layout tree dumps.
2019-08-18 08:39:52 +02:00
Andreas Kling
70eca3b500 LibHTML: Finish the block width calculation
Also add horizontal box values to the layout tree dump.
2019-08-18 08:39:52 +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