Commit Graph

210 Commits

Author SHA1 Message Date
Andreas Kling
17d26b92f8 LibWeb: Just ignore <script> elements that failed to load the script
We're never gonna be able to run them if we can't load them so just
let it go.
2020-06-15 18:37:48 +02:00
Andreas Kling
84f8c91a6f LibWeb: Use the URL encoder from AK instead of rolling a custom one 2020-06-15 17:56:00 +02:00
Andreas Kling
d883607e8f LibWeb: Force a full relayout if an element's CSS display changes
Not doing this was causing the wrong kind of LayoutNode to stay around
even though we had the final "display" value.
2020-06-15 17:56:00 +02:00
Andreas Kling
73c9f7ebf4 LibWeb: Move "visible in viewport" state tracking to ImageLoader
This should technically apply to any LayoutImage, so let's just move
it to ImageLoader.
2020-06-14 19:32:23 +02:00
Andreas Kling
c45615128b LibWeb: Move bitmap animation from HTMLImageElement to ImageLoader
Since ImageLoader manages the image decoder anyway, let it manage
animation as well.
2020-06-14 19:26:25 +02:00
Andreas Kling
ec39f419e5 LibWeb: Remove some unused functions from HTMLImageElement 2020-06-14 19:05:36 +02:00
Andreas Kling
a93fb7299f LibWeb: Don't choke when trying to render a document-less <iframe>
Just paint it like an empty box if there's no document in the frame.
2020-06-14 15:32:38 +02:00
Andreas Kling
3cc0c477db LibWeb: Add basic <object> element support
This patch implements a simple <object> element with fallback content.
If the URL from the data attribute fails to load (including 404),
we render the DOM tree inside the <object> as fallback content.

This works by generating a different layout tree for the <object>
depending on the state and success of the data load. Since we cannot
currently do incremental layout tree updates, we have to force a
complete layout tree rebuild when the resource load finishes/fails.
2020-06-13 22:24:49 +02:00
Andreas Kling
95d70addd8 LibWeb: Split out image loading logic from HTMLImageElement
Since more DOM nodes are going to want to load images (<object>, ...)
this patch splits out the image loading logic into an ImageLoader class
and then HTMLImageElement simply has an ImageLoader.

LayoutImage is then given a const ImageLoader& at construction and can
then provide layout and rendering for many kinds of DOM nodes.
2020-06-13 22:22:54 +02:00
Andreas Kling
d6d248c328 LibWeb: Add "data" to HTML::AttributeNames 2020-06-13 22:21:25 +02:00
Andreas Kling
502b5b76c8 LibWeb: Have DOM nodes start out in "needs style update" state
Otherwise we won't get the first fully styled look until you interact
with the page (e.g via hovering an element.)
2020-06-13 20:10:43 +02:00
Andreas Kling
2650005af8 LibWeb: <link rel> is actually a space-separated list of tokens
...so when we check for rel=stylesheet, we have to split it up into
parts first. :^)
2020-06-13 20:02:36 +02:00
Andreas Kling
7e8945601a LibWeb: Turn <td align> into CSS text-align
Note that align=center and align=middle both behave like the <center>
element, and not like text-align:center.
2020-06-13 15:16:56 +02:00
Andreas Kling
6de937a689 LibWeb: Turn <table bgcolor> into CSS background-color
More presentational attribute stuff. HN looking more and more like it's
supposed to. :^)
2020-06-13 12:49:20 +02:00
Andreas Kling
256898431c LibWeb: Simplify Node::is_link()
No need to check for presence of the href attribute as that is already
checked by enclosing_link_element().
2020-06-13 00:23:32 +02:00
Andreas Kling
0306ada1ff LibWeb: Add "colspan" to HTML::AttributeNames 2020-06-13 00:11:14 +02:00
Andreas Kling
c5a3d99dd5 LibWeb: Turn <table width> into the CSS width property 2020-06-12 22:52:38 +02:00
Andreas Kling
ca41c2e4a0 LibWeb: Turn <td bgcolor> into background-color 2020-06-12 22:47:51 +02:00
Andreas Kling
e9e2226544 LibWeb: Add "bgcolor" to HTML::AttributeNames 2020-06-12 22:47:41 +02:00
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Andreas Kling
ff2c949d70 LibWeb: Include class names in layout tree dumps
This makes it a lot easier to see which layout node is which DOM node.
2020-06-12 13:23:07 +02:00
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
28dcef4757 LibWeb: Add LayoutTableRowGroup to implement display: table-row-group 2020-06-09 21:53:16 +02:00
Andreas Kling
5042e560ef LibJS: Make more Interpreter functions take a GlobalObject& 2020-06-08 21:25:16 +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
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
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
896db187e5 LibWeb: Move Frame.{cpp,h} into a new Frame/ directory 2020-06-07 10:14:41 +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
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
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
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
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
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
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
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
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
7af337764e LibWeb: Add a naive Resource cache
This patch introduces a caching mechanism in ResourceLoader. It's keyed
on a LoadRequest object which is what you provide to load_resource()
when you want to load a resource.

We currently never prune the cache, so resources will stay in there
forever. This is obviously not gonna stay that way, but we're just
getting started here. :^)

This should drastically reduce the number of requests when loading
some sites (like Twitter) that reuse the same images over and over.
2020-06-01 21:58:29 +02:00
Andreas Kling
5ed66cb8d9 LibWeb: Start building a new Resource class to share more resources
A Resource represents a resource that we're loading, have loaded or
will soon load. Basically, it's a downloadable resource that can be
shared by multiple clients.

A typical usecase is multiple <img> elements with the same src.
In a future patch, we will try to make sure that those <img> elements
get the same Resource if possible. This will reduce network usage,
memory usage, and CPU usage. :^)

For now, this first patch simply introduces the mechanism.

You get a Resource by calling ResourceLoader::load_resource().
To get notified about changes to a Resource's load status, you inherit
from ResourceClient and implement the callbacks you're interested in.

This patch turns HTMLImageElement into a ResourceClient.
2020-06-01 21:36:43 +02:00
Andreas Kling
6ed11f1d1c LibWeb: Move ResourceLoader into a new Loader/ directory 2020-06-01 20:42:50 +02:00
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
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
e1e9fb8290 LibWeb: Turn <input type=button> into an actual button :^) 2020-05-30 11:59:10 +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
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
772b51038e LibWeb: Parse "input" tags during the "in body" insertion mode 2020-05-28 12:19:18 +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
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
Emanuele Torre
8d8c33833f LibWeb: s_initialized should be static in the AttributeNames initialiser 2020-05-27 09:57:38 +02:00
Andreas Kling
82444048de LibWeb: Add cached global attribute name FlyStrings
Instead of creating extremely common FlyStrings like "id" and "class"
on demand every time they are needed, we now have AttributeNames.h,
which provides Web::HTML::AttributeNames::{id,class_}

This avoids a bunch of string allocations during selector matching.
2020-05-26 23:45:43 +02:00
Andreas Kling
5069d380a8 LibWeb: Let Element cache its list of classes
Instead of string splitting every time you call Element::has_class(),
we now split the "class" attribute value when it changes, and cache
the individual classes as FlyStrings in Element::m_classes.

This makes has_class() significantly faster and moves the pain point
of selector matching somewhere else.
2020-05-26 23:07:19 +02:00
Andreas Kling
7bb69bb9bf LibWeb: Implement immediate execution in HTMLScriptElement preparation
In some cases, Dr. HTML says we should execute the script right away
even if other scripts are running.
2020-05-26 15:55:18 +02:00
Sergey Bugaev
602c3fdb3a AK: Rename FileSystemPath -> LexicalPath
And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
2020-05-26 14:35:10 +02:00
Linus Groh
67b742bf32 LibWeb: Add document.querySelector() 2020-05-26 00:12:20 +02:00
Andreas Kling
45da08a1e6 LibWeb: A whole bunch of work towards spec-compliant <script> elements
This is still very unfinished, but there's at least a skeleton of code.
2020-05-24 23:54:22 +02:00
Andreas Kling
128eaf9295 LibWeb: Add some helpers to the DOM Node class
This patch adds the following things needed by the HTML spec:

- Node::child_text_content()
- Node::is_connected()
- Node::root()
2020-05-24 23:54:22 +02:00
Andreas Kling
31db3f21ae LibWeb: Start implementing character token parsing
Now that we've gotten rid of the misguided character buffering in the
tokenizer, it actually spits out character tokens that we have to deal
with in the parser.

This patch implements enough to bring us back to speed with simple.html
2020-05-24 23:54:22 +02:00
Andreas Kling
a9fba2fb91 LibWeb: Add "name" to DocumentType nodes 2020-05-24 00:12:00 +02:00
Andreas Kling
120cd44011 LibWeb: Move Attribute to its own header file
This will allow us to use it without including Element.h
2020-05-22 21:45:00 +02:00
Linus Groh
14dffe4721 LibWeb: Set window object as this value in set{Interval,Timeout}() 2020-05-21 15:18:08 +02:00
Linus Groh
a0f3e3c50e LibWeb: Add CanvasRenderingContext2D.canvas 2020-05-21 01:24:36 +02:00
Linus Groh
abb33d425e LibWeb: Let HTMLCanvasElement.getContext() return null for unknown types
Currently we would assert. Also make it case sensitive.
2020-05-21 01:24:36 +02:00
Andreas Kling
3b11e471bd LibWeb: Allow reloading the current page with location.reload() 2020-05-18 22:05:13 +02:00
Andreas Kling
efdfdbabdb LibWeb: Allow navigating to a new URL by setting window.location.href 2020-05-18 21:52:50 +02:00
Linus Groh
91f70a9258 LibWeb: Log URL when loading <script> with src attribute
This makes it easier to debug failing scripts as most websites don't
inline huge amounts of JavaScript.
2020-05-16 21:47:16 +02:00
Linus Groh
ad3871b64e AK: Fix URL's operator<<() and use it 2020-05-16 21:47:16 +02:00
Linus Groh
33defef267 LibJS: Let parser keep track of errors
Rather than printing them to stderr directly the parser now keeps a
Vector<Error>, which allows the "owner" of the parser to consume them
individually after parsing.

The Error struct has a message, line number, column number and a
to_string() helper function to format this information into a meaningful
error message.

The Function() constructor will now include an error message when
throwing a SyntaxError.
2020-05-15 09:53:52 +02:00
Andreas Kling
977863ea07 LibGUI: Include keyboard modifier state with button on_click calls
This will allow you us to implement special behavior when Ctrl+clicking
a button.
2020-05-12 20:31:16 +02:00
Andreas Kling
0e60e7aef0 LibWeb: Add Document create_element() and create_text_node() helpers 2020-05-10 22:32:12 +02:00
Linus Groh
54c4cd8a66 Meta: Delete empty .cpp files 2020-05-09 23:45:16 +02:00
AnotherTest
ce36071447 LibWeb: Implicitly close all subpaths when canvas.fill() is called 2020-05-09 23:25:39 +02:00
Peter Nelson
b8f5b81019 LibWeb: Add support for animated images to HTMLImageElement
Uses a Core::Timer (similar to HTMLBlinkElement) to transition between
frames of an animated image. Also keeps track of the number of animation
loops.
2020-05-09 12:01:59 +02:00
AnotherTest
a82419469f LibWeb: Add canvas.fill
This implements only one of the two forms of this function,
ctx.fill(winding_rule).
Also tweaks the quadratic curve demo to have a nice looking filled
shape.
2020-05-06 14:50:29 +02:00
Andreas Kling
e73ad78ba6 LibWeb: Add support for "display: inline-block"
This display type is implemented using a LayoutBlock that is_inline().
Basically it behaves like a block internally, and its children are laid
out in the normal block layout fashion. Externally however, it behaves
like an atomic inline-level box.

Layout of inline-block boxes happens in three stages:

1. The outer dimensions of the block are computed during the recursive
   normal layout pass. We skip positioning, but lay out children.

2. Later on, during line layout in the *containing block*, the inline
   block now contributes a linebox fragment. When linebox fragments are
   positioned, we learn the final position of the inline block. That's
   when we set the inline block's position.

3. We re-layout the inline block's children once again. This is done to
   make sure they end up in the right position. The layout tree doesn't
   use relative offsets, so after we position the inline block in (2),
   its children will not have its positions updated. Relayout moves
   all children of inline blocks to the right place.

This is a rather naive approach but it does get the basic behavior into
place so we can iterate on it. :^)
2020-05-05 16:18:28 +02:00
Andreas Kling
493cbb7956 LibWeb: Fall back to LayoutInline for any unrecognized CSS display
Let's at least try to keep going and see what we can render.
2020-05-05 15:50:28 +02:00
Shadowfacts
fcd922f7b1 LibWeb: Add basic URL encoder for individual values and param lists 2020-05-05 11:19:38 +02:00
Shadowfacts
7f538ea7eb LibWeb: When creating form action URL, only include value for the submit
that was used to submit the form
2020-05-05 11:19:38 +02:00
Shadowfacts
4d5dc5950a LibWeb: Improve <form> submit method handling
The spec defines the only valid methods to be get, post, and dialog.
Post and dialog are currently unhandled and do nothing, any other value
(or no value specified) is defined by the spec to use the get method.
2020-05-05 11:19:38 +02:00
AnotherTest
0a55679de4 LibWeb: Add canvas.quadraticCurveTo()
Also adds a test, and removes debug spam ™️
2020-05-05 09:21:07 +02:00
Andreas Kling
9df71afdb3 LibWeb: Respect the <input size> attribute a bit more :^)
We now use the size attribute to determine the width of a text input.
2020-05-04 22:43:00 +02:00
Andreas Kling
6886c6efa6 LibWeb: Don't generate a layout node for <input type="hidden"> 2020-05-04 22:33:49 +02:00
Andreas Kling
eb6e35a1be ProtocolServer: Pass HTTP response headers to the client
We now store the response headers in a download object on the protocol
server side and pass it to the client when finishing up a download.

Response headers are passed as an IPC::Dictionary. :^)
2020-05-03 23:01:58 +02:00
Andreas Kling
aaf35112a4 LibJS: Pass JS::Function around by reference more 2020-04-29 13:43:57 +02:00
Andreas Kling
97382677bd LibWeb: Make EventListener::function() return a reference 2020-04-29 12:46:20 +02:00
Linus Groh
061205b3b3 LibWeb: Pass link target to HtmlView's on_link_click callback 2020-04-24 14:34:11 +02:00
Linus Groh
602a36970f LibWeb: Add XMLHttpRequest.readyState and constants 2020-04-23 11:03:17 +02:00
Andreas Kling
ef69f900c7 LibWeb: Invalidate the canvas element after put_image_data()
This makes sure we repaint it right away so we can see the changes.
2020-04-22 00:09:23 +02:00
Andreas Kling
2d4c91df8e LibWeb: Add ImageData objects and implement 2D context putImageData()
An ImageData is a wrapper around a Bitmap wrapper around a
JS::Uint8ClampedArray.
2020-04-21 23:49:51 +02:00
Andreas Kling
54133c683d LibWeb: Hack requestAnimationFrame() to provide a (very fake) timestamp 2020-04-21 23:49:09 +02:00
Andreas Kling
f7a1696087 LibJS: Add MarkedValueList and use it for argument passing
A MarkedValueList is basically a Vector<JS::Value> that registers with
the Heap and makes sure that the stored values don't get GC'd.

Before this change, we were unsafely keeping Vector<JS::Value> in some
places, which is out-of-reach for the live reference finding logic
since Vector puts its elements on the heap by default.

We now pass all the JavaScript tests even when running with "js -g",
which does a GC on every heap allocation.
2020-04-19 17:34:33 +02:00