Commit Graph

26 Commits

Author SHA1 Message Date
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
edbf09ea29 LibHTML: Make the CSS and HTML parsers take StringViews
This allows us to avoid unnecessary making unnecessary String copies of
all the source text.
2019-10-07 19:11:33 +02:00
Andreas Kling
71e8ddcd1c LibHTML: Start adding support for <link rel="stylesheet">
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-07 19:06:47 +02:00
Andreas Kling
66caa7af2b LibHTML: Optionally pass document URL to the HTML parser
This makes the document URL available to all the parse_attributes()
callbacks, in case they need it for anything.
2019-10-06 21:13:24 +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
ef0613ea4c LibHTML: Unbreak parsing of standalone declarations
Oops, I forgot to update CSSParser::parse_standalone_declaration()
after making parse_property() return a property (or {} for failure.)
2019-10-06 11:43:38 +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
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
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
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
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
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
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
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
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
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
5b942b519c LibHTML: Add HTMLHeadingElement for <h1> through <h6> 2019-09-29 12:26:15 +02:00
Andreas Kling
b477aff843 LibHTML: Detect hovering over links
HtmlView now calls Node::enclosing_link_element() to find the nearest
ancestor <a> element.

This patch also adds HTMLElement and HTMLAnchorElement.
2019-09-29 11:59:38 +02:00
Andreas Kling
1b8509a0c9 LibHTML: Make sure every DOM Node belongs to a Document 2019-09-29 11:43:07 +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
db8a1a6aba LibHTML: Parse HTML escape sequences 2019-09-28 18:29:42 +02:00
Andreas Kling
9526b0e13a LibHTML: Add InheritStyleValue and InitialStyleValue.
These correspond to the 'inherit' and 'initial' CSS values respectively.
2019-07-08 07:15:56 +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