Commit graph

419 commits

Author SHA1 Message Date
Andreas Kling
116cf92156 LibGfx: Rename Rect,Point,Size => IntRect,IntPoint,IntSize
This fits nicer with FloatRect,FloatPoint,FloatSize and gives a much
better visual clue about what type of metric is being used.
2020-06-10 10:59:04 +02:00
Andreas Kling
656b01eb0f LibWeb: Rework the layout engine to use relative offsets
The box tree and line boxes now all store a relative offset from their
containing block, instead of an absolute (document-relative) position.

This removes a huge pain point from the layout system which was having
to adjust offsets recursively when something moved. It also makes some
layout logic significantly simpler.

Every box can still find its absolute position by walking its chain
of containing blocks and accumulating the translation from the root.
This is currently what we do both for rendering and hit testing.
2020-06-10 10:46:57 +02:00
Andreas Kling
e836f09094 LibWeb: Fix parser interpreting """ as "&quot"
There was a logic mistake in the entity parser that chose the shorter
matching entity instead of the longer. Fix this and make the entity
lists constexpr while we're here.
2020-06-10 10:34:28 +02:00
Andreas Kling
28dcef4757 LibWeb: Add LayoutTableRowGroup to implement display: table-row-group 2020-06-09 21:53:16 +02:00
Andreas Kling
b4d4d6b32a LibWeb: Add some iteration helpers to LayoutNode
- for_each_child_of_type<T>
- previous_sibling_of_type<T>
2020-06-09 21:13:16 +02:00
Andreas Kling
883dc9260d LibWeb: Unbreak favicon notifications after Page refactoring
Favicon updates now get plumbed from FrameLoader to the PageClient.
2020-06-08 21:35:31 +02:00
Andreas Kling
e04d68a03a LibWeb: Remove unnecessary on_foo hooks from Frame
Frame can just call through the PageClient instead of using hooks.
2020-06-08 21:31:53 +02:00
Andreas Kling
5042e560ef LibJS: Make more Interpreter functions take a GlobalObject& 2020-06-08 21:25:16 +02:00
Andreas Kling
053863f35e LibJS: Interpreter::this_value() => this_value(GlobalObject&)
Once the Interpreter has no global object attached to it, we have to
provide it everywhere.
2020-06-08 21:12:20 +02:00
Andreas Kling
92392398a2 LibWeb: Add Page abstraction between PageView and main Frame
* A PageView is a view onto a Page object.
* A Page always has a main Frame (root of Frame tree.)
* Page has a PageClient. PageView is a PageClient.

The goal here is to allow building another kind of view onto
a Page while keeping the rest of LibWeb intact.
2020-06-08 21:12:20 +02:00
Andreas Kling
affc479e83 LibJS+LibWeb: Remove a bunch of calls to Interpreter::global_object()
Objects should get the GlobalObject from themselves instead. However,
it's not yet available during construction so this only switches code
that happens after construction.

To support multiple global objects, Interpreter needs to stop holding
on to "the" global object and let each object graph own their global.
2020-06-08 12:25:45 +02:00
Andreas Kling
9b17bf3dcd LibWeb: Use HTML::TagNames globals in the new HTML parser 2020-06-07 23:53:16 +02:00
Andreas Kling
992697d99f LibWeb: Add HTML::TagNames namespace for global tag name FlyStrings
Instead of "iframe", we can now say HTML::TagNames::iframe and avoid
a FlyString lookup.
2020-06-07 23:27:03 +02:00
Andreas Kling
10851d87a2 LibWeb: Add (stub) HTMLTable{,Cell,Row}Element C++ classes
We'll need a place to implement the various presentational attributes
for table parts, and more stuff.
2020-06-07 23:10:45 +02:00
Andreas Kling
1d94ca7cfc LibWeb: Fix codepoint_from_entity() never returning an error
If we don't find a matching entity, return an empty Optional.
2020-06-07 19:13:56 +02:00
Andreas Kling
ab4c03ce2d LibWeb: Fix tokenizer swallowing an extra token after a named entity 2020-06-07 19:09:03 +02:00
Andreas Kling
767daf1c12 LibWeb: Unbreak <a title> tooltips in the main frame
The main frame doesn't have a host element, so we can't go trying to
offset things by the host element's layout rect.
2020-06-07 19:09:03 +02:00
Andreas Kling
731685468a LibWeb: Start fleshing out support for relative CSS units
This patch introduces support for more than just "absolute px" units in
our Length class. It now also supports "em" and "rem", which are units
relative to the font-size of the current layout node and the <html>
element's layout node respectively.
2020-06-07 17:55:46 +02:00
Andreas Kling
d93bf78346 LibWeb: Fix broken paint invalidation after subframe changes
Now that PageView actually respects the invalidation rect provided by
the layout system, it turns out we were invalidating too little.

Unfortunately, this is not really fixable until the initial containing
block starts having the right size (same as viewport), but that will
require a bunch of work to make overflow work again. So it's a FIXME
for now, and we'll return to this.
2020-06-07 17:12:42 +02:00
Andreas Kling
3ae3729b4e LibWeb: Let subframes propagate paint invalidations via host element
When a paint invalidation occurs inside a subframe, it bubbles up to
Frame::set_needs_display(). From there, we call PageView if this is
the main frame, or otherwise invalidate the subframe host element.
2020-06-07 14:56:29 +02:00
Andreas Kling
59f9b32a44 LibWeb: Remove unused Document::on_layout_updated hook 2020-06-07 14:47:33 +02:00
Andreas Kling
747b21782e LibWeb: Open subframe links inside the subframe itself
We now only delegate to the Web::PageView embedded when clicking links
in the main frame. Links in subframes are handled internally.
2020-06-07 14:45:59 +02:00
Andreas Kling
d1852b4547 LibWeb: Add per-Frame EventHandler, handle mouse events recursively
We now handle mouse events by recursing into subframes. This makes
links, tooltips, etc, work inside <iframe> content.
2020-06-07 14:40:38 +02:00
Andreas Kling
896db187e5 LibWeb: Move Frame.{cpp,h} into a new Frame/ directory 2020-06-07 10:14:41 +02:00
Andreas Kling
5e9d1b2165 LibWeb: Whine in debug log instead of asserting on partial layout FIXME
We don't support incremental relayout of subtrees (only single nodes)
but let's not crash the browser just because this happens. We can keep
the browser up and just complain in the debug log instead.
2020-06-06 22:15:17 +02:00
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