Commit graph

3218 commits

Author SHA1 Message Date
Andreas Kling
7f22e2a3c4 LibWeb: Use the globals from HTML::AttributeNames in style resolution
Using these avoids the FlyString lookups, so we should basically always
prefer them over string literal attribute names.
2020-05-30 13:06:26 +02:00
Andreas Kling
770372ad02 LibWeb: Handle end-of-file token during "in body" insertion mode 2020-05-30 12:40:12 +02:00
Andreas Kling
5833359065 LibWeb: Add default UA style for <hgroup> element 2020-05-30 12:39:51 +02:00
Andreas Kling
368044eabd LibWeb: Flesh out the "in head" insertion mode and add missing cases 2020-05-30 12:28:12 +02:00
Andreas Kling
e82226f3fb LibWeb: Handle two kinds of deferred script executions
This patch adds two script lists to Document:

- Scripts to execute when parsing has finished
- Scripts to execute as soon as possible

Since we don't actually load scripts asynchronously yet (we just do a
synchronous load when parsing the <script> element for simplicity),
these are already loaded by the time we get to "The end" of parsing.
2020-05-30 12:26:15 +02:00
Andreas Kling
0d5be35c1f LibWeb: Don't render list item markers for "list-style-type: none" 2020-05-30 12:04:15 +02:00
Andreas Kling
e1e9fb8290 LibWeb: Turn <input type=button> into an actual button :^) 2020-05-30 11:59:10 +02:00
Andreas Kling
3c6801c3a5 LibWeb: Naive support for CSS "background" shorthand
Many sites simply use "background" as an alias for "background-color"
so let's at least support that.
2020-05-30 11:58:05 +02:00
Andreas Kling
62885b5646 LibWeb: Fix accidental swallow of self-closing tag tokens
Instead of dropping self-closing tags on the floor, we now emit them
into the token stream. :^)
2020-05-30 11:31:49 +02:00
Andreas Kling
fbd52047bb LibWeb: Parse "form" tags during the "in body" insertion mode 2020-05-30 11:31:49 +02:00
Andreas Kling
851a0f983a LibWeb: Tokenizing a semicolon-less HTML entity is (just a) parse error
No need to blow chunks over this.
2020-05-30 11:31:49 +02:00
Andreas Kling
b9d5d45eff LibWeb: Handle an error condition for "a" start tag during "in body"
If we have an <a> element on the list of active formatting elements
when hitting another "a" start tag, that's a parse error. Recover by
using the AAA.
2020-05-30 11:31:49 +02:00
Andreas Kling
c8e0426ab9 LibWeb: Parser should prefer the longest matchable HTML entity
If we can match both "&copy" and "&copy;" we should prefer the latter.

Also remove invalid FIXME's about case insensitive entities.
2020-05-30 11:31:49 +02:00
Andreas Kling
1ef5d609d9 AK+LibC: Add TODO() as an alternative to ASSERT_NOT_REACHED()
I've been using this in the new HTML parser and it makes it much easier
to understand the state of unfinished code branches.

TODO() is for places where it's okay to end up but we need to implement
something there.

ASSERT_NOT_REACHED() is for places where it's not okay to end up, and
something has gone wrong.
2020-05-30 11:31:49 +02:00
Andreas Kling
cfbd95f42a LibWeb: Turn a bunch of ASSERT_NOT_REACHED() in the parser into TODO() 2020-05-30 11:31:49 +02:00
Andreas Kling
6854f726ce LibWeb: Improve support for "a" and "li" during "in body" insertion
We can now parse welcome.html once again, without resorting to hacks
or fallbacks during "in body" :^)
2020-05-30 11:31:49 +02:00
Andreas Kling
30d64fccde LibWeb: Parse "li" start tags in the "in body" insertion mode 2020-05-30 11:31:49 +02:00
Andreas Kling
2b1517f215 LibWeb: Add all branches from the parsing spec to "in body"
This makes us crash in TODO() more often, but it's better that we know
what's missing instead of incorrectly ending up on the fallback path.
2020-05-30 11:31:49 +02:00
FalseHonesty
7ca562b200 LibMarkdown: Change MD Document parse API to return a RefPtr
Markdown documents are now obtained via the static Document::parse
method, which returns a RefPtr<Document>, or nullptr on failure.
2020-05-30 00:32:12 +02:00
Emanuele Torre
937d0be762 Meta: Add a script check the presence of "#pragma once" in header files
.. and make travis run it.

I renamed check-license-headers.sh to check-style.sh and expanded it so
that it now also checks for the presence of "#pragma once" in .h files.

It also checks the presence of a (single) blank line above and below the
"#pragma once" line.

I also added "#pragma once" to all the files that need it: even the ones
we are not check.
I also added/removed blank lines in order to make the script not fail.

I also ran clang-format on the files I modified.
2020-05-29 07:59:45 +02:00
Andreas Kling
68b1bdc234 LibWeb: Add a way to stop the new HTML parser
Some things are specced to "stop parsing", which basically just means
to stop fetching tokens and jump to "The end"
2020-05-28 18:55:18 +02:00
Andreas Kling
00b44ab148 LibWeb: Implement more of the "after body" insertion mode 2020-05-28 18:52:32 +02:00
Andreas Kling
cba5d59adc LibWeb: Parse comments in the "in body" insertion mode 2020-05-28 18:46:39 +02:00
Andreas Kling
bb2f22577b LibWeb: Implement a bunch more script-related tokenization states 2020-05-28 18:44:17 +02:00
Andreas Kling
4788bcd6f8 LibWeb: Add HTMLToken::make_character()
It's tedious to make character tokens manually all the time.
2020-05-28 18:43:52 +02:00
Andreas Kling
42243d2e06 LibWeb: Rename Web::HtmlView => Web::PageView
This widget doesn't just view HTML, it views a web page. :^)
2020-05-28 18:22:54 +02:00
Andreas Kling
5f8cbe6a1b LibWeb: Fix HTMLDocumentParser build 2020-05-28 18:20:55 +02:00
Andreas Kling
308cb69329 LibWeb: Remove a misplaced call to close_a_p_element() in "in body"
This should only be done for the corresponding start tags.
2020-05-28 18:18:20 +02:00
Andreas Kling
c84212aaba LibWeb: Add a StackOfOpenElements helper for "popping until a tag name" 2020-05-28 18:18:20 +02:00
Matthew Olsson
5ae9419a06 LibJS: Object index properties have descriptors; Handle sparse indices
This patch adds an IndexedProperties object for storing indexed
properties within an Object. This accomplishes two goals: indexed
properties now have an associated descriptor, and objects now gracefully
handle sparse properties.

The IndexedProperties class is a wrapper around two other classes, one
for simple indexed properties storage, and one for general indexed
property storage. Simple indexed property storage is the common-case,
and is simply a vector of properties which all have attributes of
default_attributes (writable, enumerable, and configurable).

General indexed property storage is for a collection of indexed
properties where EITHER one or more properties have attributes other
than default_attributes OR there is a property with a large index (in
particular, large is '200' or higher).

Indexed properties are now treated relatively the same as storage within
the various Object methods. Additionally, there is a custom iterator
class for IndexedProperties which makes iteration easy. The iterator
skips empty values by default, but can be configured otherwise.
Likewise, it evaluates getters by default, but can be set not to.
2020-05-28 17:17:13 +02:00
Emanuele Torre
0b0036f430 LibWeb: replace some tab characters with spaces
also add missing "#pragma once" in StylePropertiesModel.h
2020-05-28 17:01:31 +02:00
Andreas Kling
0e777c0ac6 LibWeb: Fall back to block layout for unimplemented CSS display values
This seems to have a higher chance of generating somewhat recognizable
content compared to inline layout. This problem will gradually go away
as we implement more display values.
2020-05-28 12:44:34 +02:00
Andreas Kling
3d09bac888 LibWeb: Add default UA style for some table-related elements 2020-05-28 12:43:29 +02:00
Andreas Kling
5e53c45113 LibWeb: Plumb content encoding into the new HTML parser
We still don't handle non-ASCII input correctly, but at least now we'll
convert e.g ISO-8859-1 to UTF-8 before starting to tokenize.
This patch also makes "view source" work with the new parser. :^)
2020-05-28 12:35:19 +02:00
Andreas Kling
772b51038e LibWeb: Parse "input" tags during the "in body" insertion mode 2020-05-28 12:19:18 +02:00
Andreas Kling
7aa7a2078f LibWeb: Parse "td" start tags during "in cell" insertion mode 2020-05-28 11:46:08 +02:00
Andreas Kling
5c35f3c9ba LibWeb: Support named character references (e.g "&amp;") 2020-05-28 11:44:19 +02:00
Andreas Kling
ebb1649a52 LibWeb: Implement more table support in the new HTML parser
This is enough to parse the Google front page! (Note: I did have to
hack the tokenizer while parsing Google, in order to avoid named
character references screwing everything up. We'll fix that too soon
enough!)
2020-05-28 00:27:46 +02:00
Andreas Kling
7f18c51f4c LibWeb: Flesh out "reset the insertion mode appropriately" algorithm 2020-05-28 00:27:00 +02:00
Andreas Kling
2a97127faa LibWeb: Handle various self-closing tags during "in body" insertion
We can now parse self-closing "<img>" tags correctly! :^)
2020-05-28 00:25:56 +02:00
Andreas Kling
f69001339f LibWeb: Handle inline stylesheets a bit better in the new parser
While we're still supporting both the old and the new parser, we have
to deal with the way they load inline stylesheet (and scripts) a bit
differently.

The old parser loads all the text content up front, and then notifies
the containing element. The new parser creates the containing element
up front and appends text inside it afterwards.

For now, we simply do an empty "children_changed" notification when
first inserting a text node inside an element. This at least prevents
the CSS parser from choking on a single-character stylesheet.
2020-05-28 00:23:34 +02:00
Andreas Kling
3ce1af27dc LibWeb: Parse documents without DOCTYPE gracefully
Seems like SOMEONE forgot to put a <!DOCTYPE html> on serenityos.org..
No matter, now we can handle it in the new parser! :^)
2020-05-28 00:22:08 +02:00
Andreas Kling
422e00c806 LibWeb: Add a "quirks mode" flag to Document
This doesn't do anything yet, but it will sooner or later. :^)
2020-05-28 00:20:36 +02:00
Andreas Kling
d25ffd3ed8 LibWeb: Fire a DOMContentLoaded event when the new parser is finished
With this change, we can finally load and render welcome.html :^)
2020-05-27 23:32:50 +02:00
Andreas Kling
db6cf9b37d LibWeb: Implement the first half of the Adoption Agency Algorithm
The AAA is a somewhat daunting algorithm you have to run for certain
tag when inserted inside the <body> element. The purpose of it is to
resolve issues with mismatched tags.

This patch implements the first half of the AAA. We also move the
"list of active formatting elements" to its own class, since it kept
accumulating little behaviors. "Marker" entries are now signified by
null Element pointers in the list.
2020-05-27 23:22:42 +02:00
Andreas Kling
4c9c6b3a7b LibWeb: Bring up basic external script execution in the new parser
This only works in some narrow cases, but should be enough for our own
welcome.html at least. :^)
2020-05-27 23:02:03 +02:00
Andreas Kling
2cb50f6750 LibWeb+Browser: Add ability to run Browser with the new HTML parser
You can now pass "-n" to the browser to use the new HTML parser.
It's not turned on by default since it's still very immature, but this
is a huge step towards bringing it into maturity. :^)
2020-05-27 21:57:30 +02:00
Andreas Kling
35040dd2c4 LibWeb: LayoutMode line_break_policy => LayoutMode layout_mode 2020-05-27 19:52:18 +02:00
Andreas Kling
39b5494aeb LibWeb: Implement the "after attribute name" tokenizer state
One little step at a time towards parsing the monster blob of HTML we
get from twitter.com :^)
2020-05-27 18:30:29 +02:00
Andreas Kling
1b0c39ca60 LibWeb: Handle more benign parse errors in the "in body" insertion mode 2020-05-27 18:30:29 +02:00