Commit Graph

7937 Commits

Author SHA1 Message Date
Shannon Booth
11371acfaf LibWeb/WebIDL: Implement ConvertToInt and IntegerPart AOs
These are used when converting JS::Values to integers in IDL, as opposed
to our current AD-HOC solution.
2024-01-02 10:01:26 +01:00
Shannon Booth
f1f369b6c6 LibWeb: Add IDL integer typedefs
To make it easier to work out what the correctly sized type should be,
instead of needing to consult the spec or IDL generator.
2024-01-02 10:01:26 +01:00
Luke Wilde
6231aee761 LibWeb: Add missing DOMRectList::visit_edges 2024-01-01 18:41:14 +01:00
Luke Wilde
5af058d2b6 LibWeb: Only reload iframe on src/srcdoc attribute changes, not all
Fixes Cloudflare Turnstile suddenly going blank and stopping when it
changes the style attribute after doing some setup on the iframe.
2024-01-01 18:41:14 +01:00
Andreas Kling
6eeda29642 LibWeb: Paint 1x1 backgrounds as color fill instead of tiling bitmap
This yields a huge speedup on pages that use this weird but
not-entirely-uncommon technique.
2024-01-01 15:16:58 +01:00
Aliaksandr Kalenik
e8f04be3ae LibWeb/CSS: Fix crashing when calc() is used for border-radius
`BorderRadiusStyleValue::absolutized` should not try to extract length
from LengthPercentage that represents calculated.
2024-01-01 10:12:20 +01:00
MacDue
8c59f359eb LibWeb: Implement the default sizing algorithm steps for backgrounds
This now correctly handles sizing SVG backgrounds that have no natural
width/height, but do have a natural aspect ratio.

Fixes #20992
2023-12-30 23:23:19 +01:00
MacDue
d2c96e213f LibWeb: Add AbstractImageStyleValue::natural_aspect_ratio() 2023-12-30 23:23:19 +01:00
Aliaksandr Kalenik
e394971209 AK+LibWeb: Use segmented vector to store commands in RecordingPainter
Using a vector to represent a list of painting commands results in many
reallocations, especially on pages with a lot of content.

This change addresses it by introducing a SegmentedVector, which allows
fast appending by representing a list as a sequence of fixed-size
vectors. Currently, this new data structure supports only the
operations used in RecordingPainter, which are appending and iterating.
2023-12-30 23:02:46 +01:00
Aliaksandr Kalenik
97f676dbf2 LibWeb: Avoid copying commands in RecordingPainter 2023-12-30 23:02:46 +01:00
Sam Atkins
4ee3090a7d LibWeb: Remove duplicate check for unitless lengths and zero
We call `parse_dimension()` immediately after this, which already deals
with lengths that have no unit. Also the comment here is woefully
outdated.
2023-12-30 20:11:24 +01:00
Sam Atkins
8b69f41bcd LibWeb: Remove old parse_length(ComponentValue const&) method 2023-12-30 20:11:24 +01:00
Sam Atkins
0811a39392 LibWeb: Use new parse_length() in filter parsing 2023-12-30 20:11:24 +01:00
Sam Atkins
e0875b99cc LibWeb: Use new parse_length() in shadow parsing 2023-12-30 20:11:24 +01:00
Sam Atkins
bf05aa88bc LibWeb: Add method for converting a FooOrCalculated to a StyleValue 2023-12-30 20:11:24 +01:00
Sam Atkins
306acf43c4 LibWeb: Convert parse_source_size_value() to TokenStream 2023-12-30 20:11:24 +01:00
Sam Atkins
a76f29e56b LibWeb: Allow creating a TokenStream from a single token
This is quite niche, but lets us convert parsing methods to accepting
TokenStream, while still being able to call them when we just have a
lone token. Specifically we'll use this in the next commit, but it's
likely to also be useful as a stop-gap measure when converting more
parsing methods.
2023-12-30 20:11:24 +01:00
Sam Atkins
2f5379bc9b LibWeb: Use parse_length() for rect() parsing 2023-12-30 20:11:24 +01:00
Sam Atkins
8200fdeddc LibWeb: Use parse_length_percentage() for border-radius parsing 2023-12-30 20:11:24 +01:00
Sam Atkins
30a11dc133 LibWeb: Use parsing helpers in parse_media_feature_value() 2023-12-30 20:11:24 +01:00
Sam Atkins
12bcd029ff LibWeb: Use parse_length_percentage() for radial-gradient radii 2023-12-30 20:11:24 +01:00
Sam Atkins
e62d692205 LibWeb: Implement helpers for parsing CSS numeric types
Frequently we want to parse "anything that's a `<length-percentage>`" or
similar, which could be a constant value or a calculation, but didn't
have a nice way of doing so. That meant repeating the same "try and
parse a dimension, see if it's the right type, then maybe try and parse
a calculation and see if that's the right type" boilerplate code. Or
more often, forgetting about calculations entirely.

These helpers should make that a lot more convenient to do. And they
also use TokenStream, so we can eventually drop the old `parse_length()`
method.
2023-12-30 20:11:24 +01:00
Sam Atkins
30dcbc306c LibWeb: Make resolution calculable
No tests unfortunately, because no CSS property we currently support
accepts `<resolution>`.
2023-12-30 20:11:24 +01:00
Sam Atkins
e907ad44c3 LibWeb: Fill in some missing FooOrCalculated types 2023-12-30 20:11:24 +01:00
Aliaksandr Kalenik
07928129dd LibWeb: Wait until new document becomes active before running scripts
Fixes https://github.com/SerenityOS/serenity/issues/22485

With this change WebContent does not crash when `location.reload()` is
invoked but `Navigable::reload()` still not working because of spec
issue (https://github.com/whatwg/html/issues/9869) so we can't add a
test yet.
2023-12-30 19:32:31 +01:00
Luke Wilde
7e8d3e370f LibWeb: Treat BufferSource as a DataView/ArrayBuffer/TA in IDL overloads
Required by WebAssembly.instantiate.
2023-12-30 18:50:29 +01:00
Luke Wilde
54972e3ceb LibWeb: Implement SVGUseElement#href
Required by Ruffle.
b196c8d1bc/web/packages/core/src/shadow-template.ts (L601-L602)
2023-12-30 18:50:29 +01:00
Luke Wilde
968bec9844 LibWeb: Add SVGURIReference 2023-12-30 18:50:29 +01:00
Luke Wilde
55646893d8 LibWeb: Add xlink:href to SVG attribute names 2023-12-30 18:50:29 +01:00
Luke Wilde
ddf601830a LibWeb: Implement SVGAnimatedString 2023-12-30 18:50:29 +01:00
Aliaksandr Kalenik
c7e22c7a72 LibWeb: Skip empty paint borders commands in RecordingPainter
With this change, we create substantially fewer border painting
commands, which means fewer reallocations of the vector that stores
commands.

This makes the rendering of
https://html.spec.whatwg.org/multipage/browsing-the-web.html visibly
faster, where we allocated ~10 of such commands now vs ~8000 before.
2023-12-30 17:07:11 +01:00
Andreas Kling
7e2d9bfd53 LibWeb: Avoid String<->ByteString src conversion in HTMLImageElement
We already have the src attribute stored as a String, so it's completely
wasteful to convert it to a ByteString. We were even doing it twice when
loading each image.
2023-12-30 13:49:50 +01:00
Andreas Kling
9ce267944c LibWeb: Fix crash in HTML encoding detection when handling non-ASCII
The fix here was to stop using StringBuilder::append(char) when told to
append a code point, and switch to StringBuilder::append_code_point(u32)

There's probably a bunch more issues like this, and we should stop using
append(char) in general since it allows building of garbage strings.
2023-12-30 13:49:50 +01:00
Andreas Kling
83f43310fa LibWeb: Add spec comments and fixups to "get an attribute" prescan algo
In particular, make some minor adjustments so it flows a little more
like the spec.
2023-12-30 13:49:50 +01:00
Andreas Kling
bf5ad56085 LibWeb: Ignore preconnect requests for file: and data: URLs
I noticed while debugging a fully downloaded page that it was trying
to preconnect to a file:// host. That doesn't make any sense, so let's
add a tiny bit of logic to ignore preconnect requests for file: and
data: URLs.
2023-12-30 13:49:50 +01:00
Aliaksandr Kalenik
ac6b3c989d LibWeb: Apply scroll boxes offsets after painting commands recording
With this change, instead of applying scroll offsets during the
recording of the painting command list, we do the following:
1. Collect all boxes with scrollable overflow into a PaintContext,
   each with an id and the total amount of scrolling offset accumulated
   from ancestor scrollable boxes.
2. During the recording phase assign a corresponding scroll_frame_id to
   each command that paints content within a scrollable box.
3. Before executing the recorded commands, translate each command that
   has a scroll_frame_id by the accumulated scroll offset.

This approach has following advantages:
- Implementing nested scrollables becomes much simpler, as the
  recording phase only requires the correct assignment of the nearest
  scrollable's scroll_frame_id, while the accumulated offset from
  ancestors is applied subsequently.
- The recording of painting commands is not tied to a specific offset
  within scrollable boxes, which means in the future, it will be
  possible to update the scrolling offset and repaint without the need
  to re-record painting commands.
2023-12-30 11:10:24 +01:00
Andrew Kaster
d3025668a4 Revert "Kernel+Userland: Implement support for PS2 scan code set 2"
This reverts commit 61a385fc01.

The commit broke the shift and caps lock key from working.
2023-12-29 22:02:19 +01:00
Liav A
61a385fc01 Kernel+Userland: Implement support for PS2 scan code set 2
This scan code set is more advanced than the basic scan code set 1, and
is required to be supported for some bare metal hardware that might not
properly enable the PS2 first port translation in the i8042 controller.

LibWeb can now also generate bindings for keyboard events like the Pause
key, as well as other function keys (such as Right Alt, etc).

The logic for handling scan code sets is implemented by the PS2 keyboard
driver and is abstracted from the main HID KeyboardDevice code which
only handles "standard" KeyEvent(s).
2023-12-29 16:40:59 +01:00
Aliaksandr Kalenik
d4a6564e5a LibWeb: Do not use Optional for aa_translation in RecordingPainter
This allows to remove checks whether translation has value, as it does
not change anything because default value for point is zero.
2023-12-29 09:23:27 +01:00
Andreas Kling
6fe6166607 LibWeb: Put a cap on how many image loads we'll batch up before flushing
The BatchingDispatcher mechanism is used by HTMLImageElement to avoid
decoding one image at a time, since interleaving decode/layout/repaint
over and over takes way more time than doing many decodes followed by
a single layout/repaint pair.

Before this change, we didn't have a limit on how many batched loads
we'd allow ourselves to queue up, which could lead to situations where
more and more images kept being added to the queue, and never getting
processed.

This fixes the issue by putting an arbitrary limit (16) on the number
of batched image loads, and then allowing the flush to happen after
that instead of re-deferring processing.
2023-12-28 14:39:15 +01:00
Andreas Kling
473f3a0931 LibWeb: Stop rendering the src (URL) as image alt attribute fallback
If an image element has no alt attribute, other browsers don't fall back
to using the src attribute like we did.

This gave us a janky look while loading pages that other browsers don't
have, and it's not like seeing a partial URL is really helpful to the
user anyway.
2023-12-28 14:39:15 +01:00
Aliaksandr Kalenik
522302d5d6 LibWeb: Skip erroneous blit/sample corner commands in RecordingPainter
Fixes https://github.com/SerenityOS/serenity/issues/22451
2023-12-27 20:00:16 +01:00
Bastiaan van der Plaat
009729d5e3 LibWeb: Use resources to find internal HTML template paths 2023-12-27 10:54:07 -05:00
Bastiaan van der Plaat
f8feca5d21 LibWeb: Use directory page when viewing a resource schemed directory URL 2023-12-27 10:54:07 -05:00
Bastiaan van der Plaat
b39d99cf2f LibWeb: Use resource scheme for icons in internal pages 2023-12-27 10:54:07 -05:00
Andreas Kling
89da988da1 LibWeb: Honor User-Agent spoofing in Fetch headers
This makes spoofing consistent between legacy ResourceLoader loads,
Fetch loads, and the JavaScript `navigator` APIs.
2023-12-27 11:43:14 +01:00
Andreas Kling
bd9989b08a LibWeb: Don't pass StringView to RecordingPainter, to avoid copy
Instead, we now pass String if we have one. In particular, this fixes an
issue where image elements with a data: URL src would copy the entire
URL string every time we painted (before the image had been decoded).
This was very noticeable on "fully downloaded" web pages where every
single image has been turned into a data: URL.
2023-12-27 11:41:15 +01:00
Andreas Kling
0c7b1d27b4 LibWeb: Remove incomplete attempt to avoid repaints outside viewport
This code didn't account for position:fixed elements, which meant that
we'd swallow repaints for such elements when the viewport wasn't
scrolled to the top of the page.

We replace the incomplete optimization with a FIXME noting that this
needs to be handled correctly when reintroduced.
2023-12-27 09:46:06 +01:00
Shannon Booth
462f97b28a LibWeb: Port Element::get_attribute_value from ByteString 2023-12-27 09:23:44 +01:00
MacDue
daecf741d4 LibWeb: Ensure DocumentObserver document_completely_loaded() is called
This stopped being called for anything without a navigable container
after 76a97d8, due to the early return. This broke SVG <use> elements
that reference elements defined later in the document.
2023-12-26 21:37:04 +01:00