Commit Graph

121 Commits

Author SHA1 Message Date
Andreas Kling
2e9b12d327 LibWeb: Update HTML image loading algorithm with null checks from spec
The spec has been updated to fix the missing null checks we found:
8f3d1fc6d1
2023-06-11 10:32:09 +02:00
Timothy Flynn
e129c8049b LibWeb: Restore protection against empty HTMLImageElement resources
This if-statement was erroneously dropped in commit 8ff8309.
2023-05-30 05:50:07 +02:00
Timothy Flynn
8ff8309202 LibWeb: Update workarounds for fetching CORS cross-origin responses
Now that the processResponseConsumeBody algorithm receives the internal
response body of the fetched object, we do not need to go out of our way
to read its body from outside of fetch.

However, several elements do still need to manually inspect the internal
response for other data, such as response headers and status. Note that
HTMLScriptElement already does the new workaround as a proper spec step.
2023-05-29 17:12:46 +02:00
Andi Gallo
29d29134ba LibWeb: Skip children based on media when updating the source set
If child has a media attribute and its value does not match the
environment, continue to the next child.
2023-05-28 12:11:10 +02:00
PrestonLTaylor
5d3b7a5ecc LibWeb: Return DOMException instead of crashing when setting attributes 2023-05-26 05:23:09 +02:00
Andreas Kling
624f43c12b LibWeb: Do the CORS cross-origin workaround to find MIME type for images
This makes cross-origin image loads actually see the MIME type the
server tells us. :^)
2023-05-25 12:53:41 -07:00
Andreas Kling
3c7b0192fa LibWeb: Load external images with image/svg+xml as SVG-as-image 2023-05-21 07:44:29 +02:00
Andreas Kling
41ab0837fa LibWeb: Render SVG-as-image into an isolated top-level browsing context
In order to separate the SVG content from the rest of the engine, it
gets its very own Page, PageClient, top-level browsing context, etc.

Unfortunately, we do have to get the palette and CSS/device pixel ratios
from the host Page for now, maybe that's something we could refactor in
the future.

Note that this doesn't work visually yet, since we don't calculate the
intrinsic sizes & ratio for SVG images. That comes next. :^)
2023-05-21 07:44:29 +02:00
Andreas Kling
e63f68661f LibWeb: Have ImageProvider bitmap getter take optional size argument
This allows the painting subsystem to request a bitmap with the exact
size needed for painting, instead of being limited to "just give me a
bitmap" (which was perfectly enough for raster images, but not for
vector graphics).
2023-05-21 07:44:29 +02:00
Andreas Kling
8d3240d633 LibWeb: Make ImageBox ask ImageProvider for intrinsic size and ratio
This paves the way for ImageProvider to have something vector-based
underneath. :^)
2023-05-21 07:44:29 +02:00
Andreas Kling
4ee1e5b224 LibWeb: Make DecodedImageData an abstract class
The existing implementation moves down into a new subclass called
AnimatedBitmapDecodedImageData.

The purpose of this change is to create an extension point where we can
plug in an SVG renderer. :^)
2023-05-21 07:44:29 +02:00
Sam Atkins
9c2d496dbe LibWeb: Make processBodyError take an optional exception
Changed here:
018ac19838
2023-05-15 16:28:16 +02:00
Andreas Kling
719f1db6c9 LibWeb: Protect against dereferencing a null pending image request
The spec seems to neglect the potential nullity of an image's pending
request in various cases.

Let's protect against crashing and mark these cases with a FIXME about
figuring out whether they are really spec bugs or not.
2023-05-14 10:25:25 +02:00
Andreas Kling
9d78619b59 LibWeb: Let HTMLImageElement delay the document load event again 2023-05-13 09:08:42 +02:00
Andreas Kling
c648e24cff LibWeb: Don't force HTMLImageElement to have a legacy ImageLoader
We achieve this by adding a new Layout::ImageProvider class and having
both HTMLImageElement and HTMLObjectElement inherit from it.

The HTML spec is vague on how object image loading should work, which
is why this first pass is focusing on image elements.
2023-05-13 09:08:42 +02:00
Andreas Kling
3cf73ca0b3 LibWeb: Implement enough of "update the image data" to load images
This first pass is enough to get us:
- Image loading via fetch
- Source selection via srcset and sizes attributes
2023-05-13 09:08:42 +02:00
Linus Groh
d58b671ff6 LibWeb/DOM: Rename Node::{paint => paintable}_box()
It returns a PaintableBox, not a 'PaintBox'.
2023-04-20 20:43:30 +02:00
Kenneth Myhra
ad5cbdc51b LibWeb: Port {Mouse,UI,Wheel,}Event to new String
This ports MouseEvent, UIEvent, WheelEvent, and Event to new String.
They all had a dependency to T::create() in
WebDriverConnection::fire_an_event() and therefore had to be ported in
the same commit.
2023-04-07 22:41:01 +02:00
Kenneth Myhra
4d87072201 LibWeb: Port {HTML,UIEvents,XHR}::EventNames to new String 2023-04-06 23:49:08 +02:00
Andreas Kling
2413de7e10 LibWeb: Make HTMLImageElement loads delay the document load event
This is something we're supposed to do according to the HTML spec.
Note that image loading is currently completely ad-hoc, and this just
adds a simple DocumentLoadEventDelayer to the existing implementation.

This will allow us to use images in layout tests, which rely on the
document load event firing at a predictable time.
2023-04-02 06:45:44 +02:00
Kenneth Myhra
c120c46acc LibWeb: Make factory methods of DOM::Event fallible
Because of interdependencies between DOM::Event and UIEvents::MouseEvent
to template function fire_an_event() in WebDriverConnection.cpp, the
commit: 'LibWeb: Make factory methods of UIEvents::MouseEvent fallible'
have been squashed into this commit.
2023-02-18 00:52:47 +01:00
Linus Groh
8556d47240 LibWeb: Move ARIA-related code into the Web::ARIA namespace
ARIA has its own spec and is not part of the DOM spec, which is what the
Web::DOM namespace is for (https://www.w3.org/TR/wai-aria-1.2/).

This allows us to stay closer to the spec with function names and don't
have to add the word "ARIA" to identifiers constantly - the namespace
now provides that clarity.
2023-01-29 00:02:55 +00:00
Timothy Flynn
2692db8699 LibJS+Everywhere: Allow Cell::initialize overrides to throw OOM errors
Note that as of this commit, there aren't any such throwers, and the
call site in Heap::allocate will drop exceptions on the floor. This
commit only serves to change the declaration of the overrides, make sure
they return an empty value, and to propagate OOM errors frm their base
initialize invocations.
2023-01-29 00:02:45 +00:00
MacDue
890b4d7980 LibWeb: Replace ARIA role static FlyStrings with an enum
This replaces the FlyStrings for ARIA roles that were constructed in
a [[gnu::constructor]] with a single enum. I came across this as the
DOM inspector was crashing due to a null FlyString for an ARIA role.

After fixing that, I was confused as to why these roles were not an
enum. Looking at the spec there's a fixed list of roles and switching
from references to static strings to an enum was pretty much an
exercise in find and replace :).

No functional changes (outside of fixing the mentioned crash).
2023-01-28 22:09:18 +00:00
Timothy Flynn
834202aeb9 LibWeb: Move setting of Web object prototypes to initialize()
This needs to happen before prototype/constructor intitialization can be
made lazy. Otherwise, GC could run during the C++ constructor and try to
collect the object currently being created.
2023-01-10 16:08:14 +01:00
Timothy Flynn
f3db548a3d AK+Everywhere: Rename FlyString to DeprecatedFlyString
DeprecatedFlyString relies heavily on DeprecatedString's StringImpl, so
let's rename it to A) match the name of DeprecatedString, B) write a new
FlyString class that is tied to String.
2023-01-09 23:00:24 +00:00
Jonah
e63d9d4925 LibWeb: Add Support for the ARIA Element Properties
Element now supports getting and setting ARIA properties from
JS and HTML.
2023-01-07 10:51:53 +00:00
Sam Atkins
ab49dbf137 LibWeb: Convert Paintable coordinates to new pixel units
This fixes a few sizing issues too. The page size is now correct in most
cases! \o/

We get to remove some of the `to_type<>()` shenanigans, though it
reappears in some other places.
2022-12-14 16:47:57 +00:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Linus Groh
acfb546048 LibWeb: Handle currently ignored WebIDL::ExceptionOr<T>s 2022-10-31 14:12:44 +00:00
Andreas Kling
268b9c5d90 LibWeb: Make the layout tree GC-allocated
This removes a set of complex reference cycles between DOM, layout tree
and browsing context.

It also makes lifetimes much easier to reason about, as the DOM and
layout trees are now free to keep each other alive.
2022-10-20 15:16:23 +02:00
Andreas Kling
a0e6882d99 LibWeb: Remove Layout::Node::set_inline()
Now that this flag is no longer used, we can stop setting it.
2022-10-06 15:29:38 +02:00
Andreas Kling
0455af4441 LibWeb: Implement HTMLImageElement.complete
This was fairly straightforward, although a small part had to be ad-hoc
since we don't yet load images through Fetch.

With this, we can now see annotation labels on deskto.ps :^)
2022-10-03 17:22:08 +02:00
Andrew Kaster
f0c5f77f99 LibWeb: Remove unecessary dependence on Window from HTML classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct HTML classes.
2022-10-01 21:05:32 +01:00
Andreas Kling
faf9746244 LibWeb: Cache width of "alt" text in ImageBox
We were constantly measuring and re-measuring the "alt" attribute text
of ImageBox layout nodes, even when the alt text didn't change. By
caching this, we avoid a *lot* of repeated text measurement work.
2022-09-07 17:47:33 +02:00
Andreas Kling
ffad902c07 LibWeb: Use cached_web_prototype() as much as possible
Unlike ensure_web_prototype<T>(), the cached version doesn't require the
prototype type to be fully formed, so we can use it without including
the FooPrototype.h header. It's also a bit less verbose. :^)
2022-09-06 00:27:09 +02:00
Andreas Kling
6f433c8656 LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
2022-09-06 00:27:09 +02:00
Andreas Kling
7c3db526b0 LibWeb: Make DOM::Event and all its subclasses GC-allocated 2022-09-06 00:27:09 +02:00
Igor Pissolati
ae519c6fef LibWeb: Improve HTMLImageElement::{width,height}()
With this change, it will correctly return the width/height when the
image element has an assigned width/height attribute.
2022-04-12 19:42:16 +02:00
Igor Pissolati
e5d978af9f LibWeb: Bring HTMLImageElement closer to spec 2022-04-12 19:42:16 +02:00
Andreas Kling
b1a6a8600a LibWeb: Honor "display:block" on IMG elements
Previously we forced all image elements to be inline-level. Now they can
participate in block layout if they prefer. :^)
2022-04-11 01:03:47 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Andreas Kling
fda25f9505 LibWeb: Move HTML dimension value parsing from CSS to HTML namespace
These are part of HTML, not CSS, so let's not confuse things.
2022-03-26 17:31:01 +01:00
Andreas Kling
0e806f58fe LibWeb: Support the hspace and vspace attributes on img elements
These map HTML dimension values to CSS margin values.
2022-03-26 17:31:01 +01:00
Andreas Kling
c92d28b4ea LibWeb: Treat img width/height attributes as HTML dimension values 2022-03-26 17:31:01 +01:00
Timothy Flynn
5608bc4eaf LibWeb: Remove inheritance of FormAssociatedElement from HTMLElement
HTMLObjectElement will need to be both a FormAssociatedElement and a
BrowsingContextContainer. Currently, both of these classes inherit from
HTMLElement. This can work in C++, but is generally frowned upon, and
doesn't play particularly well with the rest of LibWeb.

Instead, we can essentially revert commit 3bb5c62 to remove HTMLElement
from FormAssociatedElement's hierarchy. This means that objects such as
HTMLObjectElement individually inherit from FormAssociatedElement and
HTMLElement now.

Some caveats are:

* FormAssociatedElement still needs to know when the HTMLElement is
  inserted into and removed from the DOM. This hook is automatically
  injected via a macro now, while still allowing classes like
  HTMLInputElement to also know when the element is inserted.

* Casting from a DOM::Element to a FormAssociatedElement is now a
  sideways cast, rather than directly following an inheritance chain.
  This means static_cast cannot be used here; but we can safely use
  dynamic_cast since the only 2 instances of this already use RTTI to
  verify the cast.
2022-03-24 03:35:11 +01:00
Lenny Maiorani
c37820b898 Libraries: Use default constructors/destructors in LibWeb
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-17 17:23:49 +00:00
Andreas Kling
a403086940 LibWeb: Schedule a relayout after <image> and <object> elements load
Otherwise we'll be stuck with the intrinsic dimensions of the
replacement content.
2022-03-16 23:13:05 +01:00
Andreas Kling
ba606d9057 LibWeb: Move PaintingBox to its own .cpp and .h files 2022-03-11 00:21:49 +01:00
Andreas Kling
f6497b64ac LibWeb: Rename Painting::Box => Paintable
Calling this "Box" made it very confusing to look at code that used both
Layout::Box and Painting::Box. Let's try calling it Paintable instead.
2022-03-11 00:21:49 +01:00
Andreas Kling
a4d51b3dc2 LibWeb: Add Painting::Box and move things from Layout::Box into it
The "paintable" state in Layout::Box was actually not safe to access
until after layout had been performed.

As a first step towards making this harder to mess up accidentally,
this patch moves painting information from Layout::Box to a new class:
Painting::Box. Every layout can have a corresponding paint box, and
it holds the final used metrics determined by layout.

The paint box is created and populated by FormattingState::commit().

I've also added DOM::Node::paint_box() as a convenient way to access
the paint box (if available) of a given DOM node.

Going forward, I believe this will allow us to better separate data
that belongs to layout vs painting, and also open up opportunities
for naturally invalidating caches in the paint box (since it's
reconstituted by every layout.)
2022-03-11 00:21:49 +01:00
Andreas Kling
17f34488f6 LibWeb: Implement HTMLImageElement.width and HTMLImageElement.height 2022-02-25 19:38:31 +01:00
Andreas Kling
1b6ed558bb LibWeb: Move QualifiedName into the Web::DOM namespace 2022-02-19 14:45:59 +01:00
Luke Wilde
3bb5c6207f LibWeb: Make FormAssociatedElement inherit from HTMLElement
The new event target implementation requires us to downcast an
EventTarget to a FormAssociatedElement to check if the current Element
EventTarget has a form owner to setup a with scope for the form owner.

This also makes all form associated elements inherit from
FormAssociatedElement where it was previously missing.

https://html.spec.whatwg.org/#form-associated-element
2022-02-08 17:47:44 +00:00
Andreas Kling
7e1bf4d300 LibWeb: Compute element style in Layout::TreeBuilder
Instead of making each Layout::Node compute style for itself, we now
compute it in TreeBuilder before even calling create_layout_node().

For non-element DOM nodes, we create the style and layout tree node
in TreeBuilder. This allows us to move create_layout_node() from
DOM::Node to DOM::Element.
2022-02-05 22:50:39 +01:00
Andreas Kling
177320ee9c LibWeb: Update <img> style on resource load/failure 2021-10-18 10:40:30 +02:00
Andreas Kling
85a0772147 LibWeb: Start work towards modern CSS "display" values
Until now, we've internally thought of the CSS "display" property as a
single-value property. In practice, "display" is a much more complex
property that comes in a number of configurations.

The most interesting one is the two-part format that describes the
outside and inside behavior of a box. Switching our own internal
representation towards this model will allow for much cleaner
abstractions around layout and the various formatting contexts.

Note that we don't *parse* two-part "display" yet, this is only about
changing the internal representation of the property.

Spec: https://drafts.csswg.org/css-display
2021-10-06 19:12:52 +02:00
Andreas Kling
0264ae23bc LibWeb: Make CSS layout lazier
Instead of doing layout synchronously whenever something changes,
we now use a basic event loop timer to defer and coalesce relayouts.

If you did something that requires a relayout of the page, make sure
to call Document::set_needs_layout() and it will get coalesced with all
the other layout updates.

There's lots of room for improvement here, but this already makes many
web pages significantly snappier. :^)

Also, note that this exposes a number of layout bugs where we have been
relying on multiple relayouts to calculate the correct dimensions for
things. Now that we only do a single layout in many cases, these kind of
problems are much more noticeable. That should also make them easier to
figure out and fix. :^)
2021-10-06 17:14:22 +02:00
Andreas Kling
f8dd3e14ba LibWeb: Rename CSS::StyleResolver => StyleComputer
Resolved style is a spec concept that refers to the weird mix of
computed style and used style reflected by getComputedStyle().

The purpose of this class is to produce the *computed* style for a given
element, so let's call it StyleComputer.
2021-09-24 15:12:15 +02:00
Andreas Kling
e1fb8bef09 LibWeb: Rename Document::complete_url() => parse_url()
This better matches the spec nomenclature.
2021-09-09 21:25:10 +02:00
Andreas Kling
33f67e4c0f LibWeb: Use the task queue to fire "load" and "error" events on images 2021-09-09 02:30:53 +02:00
Sam Atkins
3bd14941c7 LibWeb: Switch to new CSS Parser :^)
Change all the places that were including the deprecated parser, to
include the new one instead, and then delete the old parser code.

`ParentNode::query_selector[_all]()` now treat their input as a
comma-separated list of selectors, instead of just one, and return
elements that match any of the selectors in that list. This is according
to these specs:

- querySelector/querySelectorAll:
https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselector%E2%91%A0
- selector matching algorithm:
https://www.w3.org/TR/selectors-4/#match-against-tree
2021-08-02 19:01:25 +04:30
Tobias Christiansen
9a1ac662f1 LibWeb: Don't try to load anything if src is empty in <img>
Previously we tried to load "" if the src was present but empty and
essentially only waited for RequestServer to time out.
2021-05-24 17:45:09 +01:00
Andreas Kling
b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Timothy Flynn
0cacc52990 LibWeb: Set Cookie header on <img> and <object> resource requests
This required passing a reference to the owning HTML*Element to
ImageLoader, the same way that CSSLoader has a reference to its owner.
2021-04-15 09:46:49 +02:00
Andreas Kling
16cde3f14a LibWeb: Rename CSSParser => DeprecatedCSSParser 2021-03-09 17:35:57 +01:00
Andreas Kling
fefb05f6f3 LibWeb: Split CSS::StyleSheet into StyleSheet and CSSStyleSheet
This is a little convoluted but matches the CSSOM specification.
2021-03-07 17:45:15 +01:00
Andreas Kling
330c3fcb59 LibWeb: Use move semantics for QualifiedName more often 2021-02-07 11:20:15 +01:00
Andreas Kling
7449c1b27f ImageDecoder+LibImageDecoder+LibWeb: Support animations in ImageDecoder
The ImageDecoder service now returns a list of image frames, each with
a duration value.

The code for in-process image decoding is removed from LibWeb, an all
image decode requests are sent out-of-process to ImageDecoder. :^)

This won't scale super well to very long and/or large animations, but
we can work on improving that separately. The main goal here is simply
to stop doing any image decoding inside LibWeb.

Fixes #5165.
2021-01-29 22:38:22 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00