Commit Graph

24 Commits

Author SHA1 Message Date
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
92b6a7a18f LibHTML: Add StyleProperties::line_height()
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-12 13:42:58 +02:00
Andreas Kling
2ac190dc5f LibHTML: Collapse whitespace in LayoutText unless white-space: pre;
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-09 16:29:35 +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
749e3f0f30 LibHTML: Add LayoutNodeWithStyle class, make LayoutText style-less
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-07 10:56:44 +02:00
Andreas Kling
b9557bf876 LibHTML: Move font loading from LayoutText to StyleProperties
Since LayoutText inherits all of its style information from its parent
Element anyway, it makes more sense to load the font at a higher level.

And since the font depends only on the style and nothing else, this
patch moves font loading (and caching) into StyleProperties. This could
be made a lot smarter to avoid loading the same font many times, etc.
2019-10-06 11:26:34 +02:00
Andreas Kling
1b7aa00768 LibHTML: LayoutText should inherit from LayoutNode directly
There's no need for LayoutText to inherit from LayoutInline.
I had the wrong idea here: I was thinking that everything that can be
laid out inline should inherit from LayoutInline, but that's clearly
not sufficient for something like LayoutReplaced which can be laid out
in either way.
2019-10-06 11:26:31 +02:00
Andreas Kling
847072c2b1 LibHTML: Respect the link color set via <body link>
The default style for "a" tags now has { color: -libhtml-link; }.
We implement this vendor-specific property by querying the containing
document for the appropriate link color.

Currently we only use the basic link color, but in the future this can
be extended to remember visited links, etc.
2019-10-06 10:25:08 +02:00
Andreas Kling
a7ca719c4e LibHTML: Rename LayoutNode::style_properties() to LayoutNode::style() 2019-10-04 15:56:36 +02:00
Andreas Kling
4e35bbffdd LibHTML: LayoutText should always use parent's style properties
This patch makes StyleProperties heap-allocated and ref-counted so that
a LayoutNode can be without one. The ref-counting also allows anonymous
blocks to share style with their parent block.

LayoutText never needs a StyleProperties, since text always inherits
style from its parent element. This is handled by style_properties().
2019-10-04 12:12:39 +02:00
Andreas Kling
f908a2718a LibHTML: Make "white-space: pre" kinda work
This is not ideal, as refusing to break lines will easily overflow the
containing block, and we have no way of dealing with overflow yet.
But as long as you provide enough width, it does look nice. :^)
2019-10-03 16:57:17 +02:00
Andreas Kling
84ec286060 LibHTML: Forgot to account for -1 glyph spacing in text layout
Font::width(string) will subtract one Font::glyph_spacing() from the
result, since we don't put any spacing after the last glyph.

This was messing up text layout here, since we assumed each glyph
width also included the glyph spacing.
2019-10-03 16:07:20 +02:00
Andreas Kling
4a88caf8e7 LibHTML: Don't add whitespace line box fragments at start of line
Collapse whitespace at the start of a line so we don't end up with
" foo bar" :^)
2019-10-03 15:55:18 +02:00
Andreas Kling
279e1dbfc5 LibHTML: Tweak "text-decoration: underline" look in LayoutText
Also remove some debug spam.
2019-10-03 15:35:39 +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
13860e4dd8 LibHTML: Make hit testing work for LayoutText
LayoutText can't simply rely on its LayoutNode::rect() for hit testing.
Instead, we have to iterate over the individual runs and see if we're
hitting any of them.

Also, LayoutNode::hit_test() now always recurses into children, since
we can't trust the rect() to tell the truth (inline rects are wrong.)
2019-09-29 11:32:00 +02:00
Andreas Kling
8271ad40a5 LibHTML: Implement basic support for "text-decoration: underline" 2019-09-28 22:57:46 +02:00
Andreas Kling
62cbaa74f3 LibHTML: Respect the CSS "color" property for text
Also remove the color values from the ComputedStyle object and get them
via StyleProperties instead.

At the moment, we only handle colors that Color::from_string() parses.
2019-09-28 22:57:46 +02:00
Sergey Bugaev
6491493e26 LibHTML: Hide debugging output unless HTML_DEBUG is defined 2019-09-28 18:29:42 +02:00
Sergey Bugaev
235dee8c42 LibHTML: Implement rendering 2019-09-28 18:29:42 +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
fc127eb769 LibHTML: Create anonymous blocks around inline children of blocks. 2019-07-08 17:42:23 +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