Commit Graph

394 Commits

Author SHA1 Message Date
Andreas Kling
37b21cfd7d LibWeb: Make Frame::page_view() always go via main_frame()
When you ask a subframe for its PageView, you'll now always get the
main frame's PageView. Subframes don't have a PageView of their own.
2020-06-06 16:36:18 +02:00
Andreas Kling
be6abce44f LibWeb: Handle EOF tokens during "text" insertion 2020-06-06 16:36:18 +02:00
Andreas Kling
38ada2d102 LibWeb: Delay sub-Frame construction until host Document is attached
While we're parsing a new document, we don't have a Frame to grab at.
We now use the Node::document_did_attach_to_frame() notification hook
to delay subframe construction.

With this, subframes now always have a valid reference to their
enclosing main frame.
2020-06-06 16:36:18 +02:00
Andreas Kling
285a4165f3 LibWeb: Add Node notifications for Document<=>Frame attach/detach
Some DOM nodes will want to do stuff when we attach/detach from a Frame
and this seems like a simple enough way to let them know.
2020-06-06 16:36:18 +02:00
Andreas Kling
71da52482c LibWeb: Show error page if we can't handle a frame's main resource
If we can't figure out how to make a Document for the main resource
in a Frame, just show an error page.
2020-06-06 14:14:43 +02:00
Andreas Kling
f88146c7c9 LibWeb: Let Resource figure out its own encoding and MIME type
Also, if the request URL is a data: URL, use the MIME type from the URL
itself if available. This makes it possible to load arbitrary MIME type
data: URLs in the browser :^)
2020-06-06 14:14:43 +02:00
Andreas Kling
efe9d36eba LibWeb: Always scroll PageView to top when a new document is set 2020-06-06 14:14:43 +02:00
Andreas Kling
de6028dfa7 LibWeb: Turn FrameLoader into a ResourceClient
We now use the new resource-based loader for the main resource in each
Frame. This gives us access to caching and sharing. :^)
2020-06-06 14:14:43 +02:00
Andreas Kling
52fcaae71c LibWeb: Make Document::url() return URL by value
Returning it by reference can lead to unpleasant situations if we use
this getter when the document may go away. Better to make the getter
return a copy than have to think about this everywhere.
2020-06-06 14:14:43 +02:00
Andreas Kling
5c0ee72b30 LibWeb: Use FrameLoader to load iframes :^) 2020-06-06 14:14:43 +02:00
Andreas Kling
075bd75859 LibWeb: Add a FrameLoader class and move PageView's loading logic there
Each Frame now has a FrameLoader which will be responsible for handling
loading inside that frame.
2020-06-06 14:14:43 +02:00
Luke
9de92ae4c1 LibWeb: Fix location.reload.length
This was accidentally being set to JS::Attribute::Enumerable
instead of 0.
2020-06-06 09:55:30 +02:00
Luke
61d5bec739 LibWeb: Fully implement all script tokenizer states
Also fixes RAWTEXTLessThanSign having a separate emit and reconsume.
2020-06-06 09:55:15 +02:00
Andreas Kling
422bbe98a5 LibWeb: Start adding support for the <iframe> element! :^)
This patch introduces a bunch of things:

- Subframes (Web::Frame::create_subframe())
- HTMLIFrameElement (loads and owns the hosted Web::Frame)
- LayoutFrame (layout and rendering of the hosted frame)

There's still a huge number of things missing, like scrolling, overflow
handling, event handling, scripting, etc. But we can make a little
iframe in a document and it actually renders another document there.
I think that's pretty cool! :^)
2020-06-05 23:36:02 +02:00
Andreas Kling
f2aa21ebc4 LibWeb: Assert that we don't reuse cached resources with wrong type 2020-06-05 23:35:08 +02:00
Andreas Kling
5dc8c4a24c LibWeb: Fix mismatching Resource subclass types
This was a confusing bug: ImageStyleValue loaded its image resource as
a Generic resource, while HTMLImageElement loaded as Image.

This patch fixes the issue and adds an assertion to verify that we only
share resources that have the same C++ client class type.
2020-06-05 23:32:23 +02:00
Andreas Kling
3337365000 LibWeb: Parse param/source/track start tags during "in body" insertion 2020-06-05 21:59:46 +02:00
Andreas Kling
11f2c59219 LibWeb: Simplify LayoutWidget layout
Set the intrinsic size up front and let LayoutReplaced do the work.
2020-06-05 21:50:03 +02:00
Andreas Kling
83cda9e79e LibWeb: Don't assign style to LayoutWidgets
The only CSS property we care about for widgets is "display:none".
For everything else, we ignore it and use a native look & feel. :^)
2020-06-05 21:48:46 +02:00
Andreas Kling
b656fac00e LibWeb: Make <canvas> use the generic replaced layout algorithm
LayoutCanvas now communicates intrinsic size to LayoutReplaced so it
can use the normal replaced algorithm.
2020-06-05 19:23:49 +02:00
Andreas Kling
4d5ecf6e32 LibWeb: Start implementing proper layout of replaced elements
LayoutReplaced now has intrinsic width, height and ratio. Only some of
the values may be present. The layout algorithm takes the various
configurations into account per the CSS specification.

This is still pretty immature but at least we're moving forward. :^)
2020-06-05 19:15:20 +02:00
Andreas Kling
7fcf61be35 LibWeb: Improve computation of a layout node's containing block
In particular, we now compute the containing block of boxes with
position:absolute and position:fixed (more) correctly.
2020-06-05 19:15:20 +02:00
Andreas Kling
762617a028 LibWeb: Don't create a layout node for <noscript> when scripting enabled
This makes stuff inside <noscript> correctly not show up since we run
with scripting enabled.

In the future, we can add a way to disable scripting, but for now,
Document::is_scripting_enabled() just returns true.
2020-06-05 19:15:20 +02:00
Andreas Kling
b4591f0037 LibWeb: Fix parsing of "<textarea></textarea>"
When handling a "textarea" start tag, we have to ignore the next token
if it's an LF ('\n'). However, we were not switching the tokenizer
state before fetching the lookahead token, and this caused us to force
the tokenizer into the RCDATA state too late, effectively getting it
stuck in that state for way longer than it should be.

Fixes #2508.
2020-06-05 12:05:42 +02:00
Andreas Kling
4e71684a3a LibWeb: Fix missing tokenizer state change in RCDATALessThanSign
We can't RECONSUME_IN after we've used EMIT_CHARACTER since we'll have
returned from the function.
2020-06-05 12:02:30 +02:00
Andreas Kling
b59f4632d5 LibWeb: Unbreak character reference and DOCTYPE parsing post-UTF-8
Oops, these were still using the byte-offset cursor. My goodness is it
unergonomic to index into UTF-8 strings, but Dr. Bugaev says it's good.

There is lots of room for improvement here. Just like the rest of the
tokenizer and parser. We'll have to do a few optimization passes over
them once they mature.
2020-06-04 22:09:36 +02:00
Andreas Kling
b6288163f1 LibWeb: Make the new HTML parser parse input as UTF-8
We already convert the input to UTF-8 before starting the tokenizer,
so all this patch had to do was switch the tokenizer to use an Utf8View
for its input (and to emit 32-bit codepoints.)
2020-06-04 21:12:17 +02:00
Andreas Kling
19190267a6 LibWeb: Fix incorrectly consumed characters after reference tokens
The NumericCharacterReferenceEnd tokenizer state should not advance
the input stream.
2020-06-04 16:49:21 +02:00
Andreas Kling
959de19418 LibWeb: Process style sheets in document order
Until now we would simply apply stylesheets in the order they finished
loading. This patch adds a StyleSheetList object that hangs off of each
Document and contains all the style sheets in document order.

There's still a lot of work to do for a proper cascade, but at least
this makes us consistently wrong every time. :^)
2020-06-04 16:06:32 +02:00
Andreas Kling
ec1891837f LibWeb: Fix <body> and <img> elements not parsing their class attribute
Subclasses that override Element::parse_attribute() must always call to
base class since otherwise we might forget to parse some attributes.

This makes class selectors work on <body> and <img> elements. :^)
2020-06-04 16:04:52 +02:00
Andreas Kling
ca33bc7895 LibWeb: Fix tokenization of attributes with empty attributes
We were neglecting to emit start tags for tags where the last attribute
had no value.

Also fix a parse error TODO that I hit while looking at this.
2020-06-04 12:00:09 +02:00
Kyle McLean
b9549078cc LibWeb: Handle "html" end tag during "in body" 2020-06-04 09:09:33 +02:00
Kyle McLean
a3bf3a5d68 LibWeb: Handle "xmp" start tag during "in body" 2020-06-04 09:09:33 +02:00
Kyle McLean
c70bd0ba58 LibWeb: Handle "nobr" start tag during "in body" 2020-06-04 09:09:33 +02:00
Kyle McLean
22521e57fd LibWeb: Handle "form" end tag during "in body" if stack of open elements does not contain "template" 2020-06-04 09:09:33 +02:00
Kyle McLean
4edd0643a6 LibWeb: Handle NULL character during "in body" 2020-06-04 09:09:33 +02:00
Kyle McLean
5e3972a946 LibWeb: Parse "body" end tags during "in body" 2020-06-04 09:09:33 +02:00
Kyle McLean
1ad81e4833 LibWeb: Parse "br" end tags during "in body" 2020-06-04 09:09:33 +02:00
Kyle McLean
9fca4b56d3 LibWeb: Parse end tags for "applet", "marquee", and "object" during "in body" 2020-06-04 09:09:33 +02:00
Andreas Kling
3c2fbc825c LibWeb: Call children_changed() on text nodes when flushing characters
Now that we flush characters in a single place, we can call the Text's
children_changed() from there instead of having a goofy targeted hack
for <style> elements. :^)
2020-06-03 22:13:29 +02:00
Andreas Kling
21957745f7 LibWeb: Special-case initialization of HTML::AttributeNames::class_
Just do it after all the others instead of trying to be clever.
2020-06-03 22:06:52 +02:00
Andreas Kling
c40de9275a LibWeb: Buffer text node character insertions in the new parser
Instead of appending character-at-a-time, we now buffer character
insertions in a StringBuilder, and flush them to the relevant node
whenever we start inserting into a new node (and when parsing ends.)
2020-06-03 21:53:08 +02:00
Andreas Kling
2149820260 LibWeb: Use HTML::AttributeNames::foo instead of FlyString("foo")
To avoid the costly instantiation of FlyStrings whenever we're looking
up attributes, use the premade HTML::AttributeNames globals. :^)
2020-06-03 21:53:00 +02:00
Andreas Kling
b750843797 LibWeb: Remove assertion in HTMLImageElement::resource_did_load()
We might end up here with a non-null decoder if the Resource fires load
callbacks again for the resource. It's harmless since we'll just get
the same decoder again.
2020-06-02 22:05:29 +02:00
Andreas Kling
d4ddb0013c LibWeb: Share decoded images at the Resource level :^)
This patch adds ImageResource as a subclass of Resource. This new class
also keeps a Gfx::ImageDecoder so that we can share decoded bitmaps
between all clients of an image resource inside LibWeb.

With this, we now share both encoded and decoded data for images. :^)

I had to change how the purgeable-volatile flag is updated to keep the
volatile-images-outside-the-visible-viewport optimization working.
HTMLImageElement now inherits from ImageResourceClient (a subclass of
ResourceClient with additional image-specific stuff) and informs its
ImageResource about whether it's inside the viewport or outside.

This is pretty awesome! :^)
2020-06-02 20:32:38 +02:00
Andreas Kling
a3936f10eb LibWeb: Fix tokenizing scripts with '<' in them
The EMIT_CHARACTER_AND_RECONSUME_IN was emitting the current token
instead of the specified codepoint.
2020-06-02 14:27:53 +02:00
Andreas Kling
f3799b501e LibWeb: Port ImageStyleValue to the ResourceClient interface 2020-06-02 14:26:10 +02:00
Andreas Kling
ca8398bc19 LibWeb: Avoid an unnecessary temporary variable in HTMLImageElement 2020-06-02 13:51:57 +02:00
Andreas Kling
7197adbd55 LibWeb: Port HTMLLinkElement to the ResourceClient interface 2020-06-02 13:51:57 +02:00
Andreas Kling
410fa5abe0 LibWeb: Parse barebones document without doctype, <html>, etc.
Last night I tried making a little test page that had a bunch of <img>
elements and nothing else. It didn't work.

Fix this by correctly adding a synthesized <html> element to the
document if we get something else in the "before html insertion mode.
2020-06-02 08:50:33 +02:00