Commit Graph

99 Commits

Author SHA1 Message Date
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
48f43a7429 LibHTML: Anonymous blocks *should* inherit some properties
Okay, I got that a bit wrong. Here's what CSS 2.1 says:

"The properties of anonymous boxes are inherited from the enclosing
non-anonymous box. Non-inherited properties have their initial value."

This patch implements a better behavior by only copying the inherited
properties from the parent style.
2019-10-05 23:47:06 +02:00
Andreas Kling
958b395418 LibHTML: Support rendering <img src> with file:// URLs
We can now show images loaded from local file:// URLs. Pretty neat :^)
2019-10-05 23:41:14 +02:00
Andreas Kling
9858e2632c LibHTML: Let's not have anonymous blocks inherit their parent's style
This was introducing a bunch of unwanted margins.
2019-10-05 23:29:01 +02:00
Andreas Kling
ee567cdc3d LibHTML: Implement basic layout for inline <img alt>
LayoutReplaced objects can now participate in inline layout.

It's very hackish, but basically LayoutReplaced will just add itself to
the last line in the containing block.

This patch gets rid of the idea that only LayoutInline subclasses can
be split into lines, by moving the split_into_lines() virtual up to
LayoutNode and overriding it in LayoutReplaced.
2019-10-05 23:29:01 +02:00
Andreas Kling
f150134de9 LibHTML: Make Node::create_layout_node() virtual
Instead of branching on the Node type, let subclasses decide how their
layout nodes get constructed.

This will allow elements to create custom layout nodes if they want.
2019-10-05 23:29:01 +02:00
Andreas Kling
09dccb3224 LibHTML: Flesh out <img> element with LayoutImage and LayoutReplaced
This patch adds parsing of <img> into HTMLImageElement objects.
It also adds LayoutImage and its parent class LayoutReplaced, which is
going to represent CSS "replaced elements."
2019-10-05 23:29:01 +02:00
Andreas Kling
56d1ae98bc LibHTML: Always fill the entire paint event rect with background
And do the filling before translating the painter.

This fixes a bug where scrolling down in the Help app would render the
bottom part of the page with a different background color.
2019-10-05 21:53:09 +02:00
Andreas Kling
a8297657ab LibHTML: Fire the HtmlView::on_title_change hook after a load finishes 2019-10-05 10:30:14 +02:00
Andreas Kling
319f0d2d18 LibHTML: Render list markers in the same color as text 2019-10-05 10:27:59 +02:00
Andreas Kling
78d65c1c64 LibHTML: Add load(URL) and reload() functions to HtmlView
You can now pass a file:/// URL to HtmlView and it will take care of
the loading logic for you. Each Document remembers the URL it was
loaded from, which allows us to also have reload().

This patch also adds a very simple function for resolving relative
URL's into absolute ones.
2019-10-05 10:17:33 +02:00
Andreas Kling
ee64d99a96 LibHTML: Make StyleResolver responsible for loading the default style
Instead of HtmlView clients having to worry about parsing and loading
the default CSS, just take care of it inside StyleResolver.

The default style is automatically inserted into the stylesheet list,
at the very start, so everyone else gets a chance to override it.
2019-10-05 09:02:29 +02:00
Andreas Kling
77218b1c2a LibHTML: Make CSS inheritance slightly less hacky
Add a simple is_inherited_property(name) lookup function and use that
to implement CSS property inheritance.

It's a bug that "text-decoration" is inherited, but we currently rely
on this in order to propagate e.g underline into linkified line boxes.
2019-10-04 22:52:49 +02:00
Andreas Kling
8fb979148d LibHTML: Add support for <font color>
This was pleasantly trivial to implement with the new support for
presentational hints. :^)
2019-10-04 21:14:59 +02:00
Andreas Kling
9808d35554 LibHTML: Add support for <body bgcolor="#rrggbb" text="#rrggbb">
This patch implements basic support for presentational hints, which are
old-school HTML attributes that affect style.

You add support for a presentational hint attribute by overriding
Element::apply_presentational_hints(StyleProperties&) and setting all
of the corresponding CSS properties as appropriate.

To make the background color fill the entire document, not just the
bounds of the <body> element's LayoutNode, we special-case it in the
HtmlView::paint_event() code for now. I'm not entirely sure what the
nicest solution would be, but I'm sure we'll discover it eventually.
2019-10-04 21:05:52 +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
7bc9310170 LibHTML: Add a Frame class and use it for document layout width
Each HtmlView now has a main_frame(), which represents the main frame
of the web page. Frame inherits from TreeNode<Frame>, which will allow
us to someday implement a Frame tree (to support the <frame> element.)
2019-10-04 15:50:04 +02:00
Andreas Kling
b1758ae2b3 LibHTML: Remove unused FontStyle enum 2019-10-04 15:49:43 +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
d68c1effcb LibHTML: Remove unused LayoutInline::layout()
Inline layout now happens in the containing block, specifically in
LayoutBlock::layout_inline_children().
2019-10-03 17:36:06 +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
c51366b22c LibHTML: Prettify ColorStyleValue::to_string() a little bit
I don't know why I made this say "COLOR: #rrggbbaa" when it can also
just say "#rrggbbaa" :^)
2019-10-03 16:12:45 +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
5966fcff31 LibHTML: Reduce debug spam from mouse events 2019-10-03 14:52:36 +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
786494b62d LibHTML: Adjust mouse event positions before using them for hit testing
This fixes the issue where you couldn't click on links at the bottom of
scrollable documents. :^)
2019-10-03 09:17:27 +02:00
Andreas Kling
8f842375a2 LibHTML: Implement the <hr> element
This also meant I had to implement basic support for the border-styles
"inset" and "outset". If it's neither of those, we default to "solid".
2019-10-01 20:50:11 +02:00
Andreas Kling
53fae2af4f LibHTML: Implement basic border rendering
We currently assume the border-style is solid, and simply draw a box
around the padded LayoutNode rect. :^)
2019-10-01 20:31:56 +02:00
Andreas Kling
7573e3c46d LibHTML: Include padding when rendering background colors 2019-10-01 20:25:31 +02:00
Andreas Kling
86b7dd6d5d LibHTML: Tweak default CSS to bring it a bit closer to HTML4 2019-10-01 20:16:42 +02:00
Andreas Kling
4bfd4dc6c7 AK: Remove empty files JsonArray.cpp and JsonObject.cpp 2019-10-01 11:24:54 +02:00
Andreas Kling
a5e5a3fab7 LibHTML: Implement basic support for inline style attributes
You can now style elements with inline styles:

    <div style="color: #ff0000">This is red!</div>

Pretty neat :^)
2019-09-30 20:25:33 +02:00
Andreas Kling
b2a0d20580 LibHTML: Refactor the CSS parser into a class
Also added a parser function for standalone style declarations.
2019-09-30 20:24:38 +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
Andreas Kling
c9bab8b870 LibHTML: Reduce debug spam in HtmlView mouse event handlers 2019-09-29 18:10:39 +02:00
Andreas Kling
37a37accd4 LibHTML: Implement basic support for background-color 2019-09-29 18:05:37 +02:00
Andreas Kling
a4fccc02ec LibHTML: Add a simple <style> element for inline CSS 2019-09-29 17:45:42 +02:00
Andreas Kling
7912592f89 LibHTML: Add inserted_into() and removed_from() TreeNode callbacks
These will be called when a Node or LayoutNode is inserted or removed
from a tree. They get the parent node as an argument.
2019-09-29 17:40:39 +02:00
Andreas Kling
402c6de5c9 LibHTML: Make <div> elements display: block 2019-09-29 17:26:52 +02:00
Andreas Kling
830e18e486 LibHTML: Fix broken parsing of ID and class selectors
We were forgetting to consume the '#' and '.' characters.
2019-09-29 17:26:05 +02:00
Andreas Kling
ed39e0f6f7 LibHTML: Non-element (Text) Nodes should get style from their parent
Text nodes don't have style of their own, so just inherit all the style
from the parent element.
2019-09-29 17:22:44 +02:00
Andreas Kling
b94c7665a9 LibHTML: Add a way to get a Document's title
You can now query Document::title() to get a String containing whatever
is inside the document's <title> tag.

In support of this, this patch adds the <html>, <head> and <title>
elements.
2019-09-29 16:24:57 +02:00
Andreas Kling
0c6af2d5b4 LibHTML: Add Node::text_content()
This returns a String built from all of a Node's text descendants,
including itself.
2019-09-29 16:23:09 +02:00
Andreas Kling
5b942b519c LibHTML: Add HTMLHeadingElement for <h1> through <h6> 2019-09-29 12:26:15 +02:00
Andreas Kling
f38b0f667e LibHTML: Implement basic HTMLElement.title support
We now show a tooltip for the hovered node's enclosing HTML element's
title attribute, if one is present.

This patch also adds HTMLHeadingElement. The tags h1-h6 will now create
the right kind of objects.
2019-09-29 12:26:13 +02:00
Andreas Kling
92aae72025 LibHTML: Detect link clicks
Clicking on a link in an HtmlView will now call on_link_click(String)
if present, allowing you to implement basic hypertext navigation. :^)
2019-09-29 12:04:02 +02:00