Commit Graph

61722 Commits

Author SHA1 Message Date
Jamie Mansfield
3095daa7c8 LibWeb: Implement HTMLImageElement.currentSrc
Removes some console noise from lner.co.uk :)
2024-05-27 17:34:59 +02:00
Jamie Mansfield
600daea544 LibWeb: Implement HTMLIFrameElement.loading 2024-05-27 17:34:59 +02:00
Jamie Mansfield
9ee061ea14 LibWeb: Implement HTMLImageElement.loading
Removes some console noise while loading mmu.ac.uk :)
2024-05-27 17:34:59 +02:00
Jamie Mansfield
c484625631 LibWeb: Add IDL enum for lazy loading attribute 2024-05-27 17:34:59 +02:00
Aliaksandr Kalenik
f989ebe180 LibWeb: Replace visit() with ifelseif chain in CommandList::execute()
Deeply nested stack traces caused by using visit() were really hard to
read in profiles.
2024-05-27 17:33:40 +02:00
Aliaksandr Kalenik
eff9bbf4c8 LibWeb: Pass whole command by reference into painting command executor
Now after making a change in a painting command we could avoid updating
method's parameters list across 3 classes.
2024-05-27 17:33:40 +02:00
Andreas Kling
2aab56bf71 LibJS: Null-check current executable in VM::dump_backtrace()
If there is no current executable (because we're in a native function
call), we shouldn't try to dereference it.
2024-05-27 17:33:29 +02:00
Andreas Kling
802af5ad9d LibWeb: Allow Element.insertAdjacentHTML on the document element
This fixes wpt/domparsing/insert_adjacent_html.html
2024-05-27 17:33:29 +02:00
Andreas Kling
f12dae7ea4 LibWeb: Update spec link & comments in Element.insertAdjacentHTML()
This has moved from DOM Parsing to HTML, and the comments are slightly
different.
2024-05-27 17:33:29 +02:00
Andreas Kling
e7febd347b LibWeb: Don't advertise the empty string as HTMLCollection property name
This fixes wpt/dom/collections/HTMLCollection-empty-name.html
2024-05-27 17:33:29 +02:00
MacDue
8988dce93d LibGfx: Add early bounds checking to accumulate_non_zero_scanline()
Nonzero fills are much more common (as the default fill rule), so if
this does result in any speed-up it makes sense to do it here too.
2024-05-27 13:02:17 +02:00
MacDue
9a3470c2c5 LibGfx: Fix bounds checking in accumulate_even_odd_scanline()
`edge_extent.max_x` is inclusive so it must be < `m_scanline.size()`.
2024-05-27 13:02:17 +02:00
Diego
e345d65def LibWasm: Use TRY macro when possible
This removes a lot of the error handling boilerplate, and is more
consistent with the rest of the codebase.
2024-05-27 12:44:21 +02:00
Aliaksandr Kalenik
0eeae7ff24 LibWeb: Use stack to represent blit/sample corners commands state
...instead of allocating separate BorderRadiusCornerClipper for each
executed sample/blit commands pair.

With this change a vector of BorderRadiusCornerClipper has far fewer
items. For example on twitter profile page its size goes down from
~3000 to ~3 items.
2024-05-27 04:26:17 +02:00
Aliaksandr Kalenik
9b65a2731b LibWeb: Remove clipper creation error check in sample_under_corners()
Before, this check was needed to prevent crashing when attempting to
allocate zero-size bitmap for sampled corners, which could have happened
if a corner had 0 radius in one axis.

Now, since SampleUnderCorners command is not emmited when radius is 0
in one axis, this check is no longer needed.
2024-05-27 04:26:17 +02:00
Aliaksandr Kalenik
9be65e35b5 Revert "LibGfx+LibWeb: Do not ignore corner radius if it is defined..."
This reverts commit 6b7b9ca1c4b32e76e0afef6bca0cb300e615b576.

The whole corner radius is invisible if it has 0 radius in any axis, so
the reverted commit was a mistake that led to error checking during
painting command execution b61aab66d9 to
avoid crashing on attempt to allocate 0 size bitmap.
2024-05-27 04:26:17 +02:00
Aliaksandr Kalenik
49f75d2c0f LibWeb: Verify each sample corners command has matching blit command 2024-05-27 04:26:17 +02:00
Aliaksandr Kalenik
1a6cf7fadc LibWeb: Fix blit corner clipping command recording order
Before:
- sample corners id = 0
- sample corners id = 1
- sample corners id = 2
- blit corners   id = 0
- blit corners   id = 1
- blit corners   id = 2

After:
 - sample corners id = 0
 - sample corners id = 1
 - sample corners id = 2
 - blit corners   id = 2
 - blit corners   id = 1
 - blit corners   id = 0
2024-05-27 04:26:17 +02:00
Nico Weber
1a9d8e8fbe LibCompress: When limiting huffman tree depth, sacrifice bottom of tree
Deflate and WebP can store at most 15 bits per symbol, meaning their
huffman trees can be at most 15 levels deep.

During construction, when we hit this level, we used to try again
with an ever lower frequency cap per symbol. This had the effect
of giving the symbols with the highest frequency lower frequencies
first, causing the most-frequent symbols to be merged. For example,
maybe the most-frequent symbol had 1 bit, and the 2nd-frequent
two bits (and everything else at least 3). With the cap, the two
most frequent symbols might both have 2 symbols, freeing up bits
for the lower levels of the tree.

This has the effect of making the most-frequent symbols longer at
first, which isn't great for file size.

Instead of using a frequency cap, ignore ever more of the low
bits of the frequency. This sacrifices resolution where it hurts
the lower levels of the tree first, and those are stored less
frequently.

For deflate, the 64 kiB block size means this doesn't have a big
effect, but for WebP it can have a big effect:

sunset-retro.png (876K): 2.02M -> 1.73M -- now (very slightly) smaller
than twice the input size! Maybe we'll be competitive one day.

(For wow.webp and 7z7c.webp, it has no effect, since we don't hit
the "tree too deep" case there, since those have relatively few
colors.)

No behavior change other than smaller file size. (No performance
cost either, and it's less code too.)
2024-05-26 21:00:55 +02:00
Nico Weber
2023e8d8d9 LibCompress: Use saturating add in generate_huffman_lengths()
For our deflate, block size is limited to less than 64 kiB, so the sum
of all byte frequencies always fits in a u16 by construction.

But while I haven't hit this in practice, but it can conceivably happen
when writing WebP files, which currently use a single huffman tree
(per channel) for a while image -- which is often much larger than
64 kiB.

No dramatic behavior change in practice, just feels more correct.
2024-05-26 21:00:55 +02:00
Nico Weber
0711e9d749 LibGfx/WebPWriter: Use huffman compression
This implements some of basic webp compression: Huffman coding.
(The other parts of the basics are backreferences, and color cache
entries; and after that there are the four transforms -- predictor,
subtract green, color indexing, color.)

How much huffman coding helps depends on the input's entropy.
Constant-color channels are now encoded in constant space, but
otherwise a huffman code always needs at least one bit per symbol.
This means just huffman coding can at the very best reduce output
size to 1/8th of input size.

For three test input files:

sunset-retro.png (876K): 2.25M -> 2.02M
(helps fairly little; from 2.6x as big as the png input to 2.36x)

giphy.gif (184k): 11M -> 4.9M
(pretty decent, from 61x as big as the gif input to 27x as big)

7z7c.gif (11K): 775K -> 118K
(almost as good as possible an improvement for just huffman coding,
from 70x as big as the gif input to 10.7x as big)

No measurable encoding perf impact for encoding.

The code is pretty similar to Deflate.cpp in LibCompress, with just
enough differences that sharing code doesn't look like it's worth
it to me. I left comments outlining similarities.
2024-05-26 19:02:49 +02:00
Nico Weber
a01fdca2de LibCompress: Use named EndOfBlock constant
No behavior change.
2024-05-26 19:02:49 +02:00
Nico Weber
ff6d58f321 LibCompress: Pass ReadonlyBytes to encode_huffman_lengths()
...instead of Array and length. No behavior change.
2024-05-26 19:02:49 +02:00
Nico Weber
5c81b4b269 LibCompress: Make encode_block_lengths() a bit less clever
No behavior change.
2024-05-26 19:02:49 +02:00
Nico Weber
756a8fa02d LibGfx/WebP: Move kCodeLengthCodeOrder to WebPSharedLossless.h
...and make it an Array while at it.

(This makes it look a little less like the spec, but that seems
worth it.)

No behavior change.
2024-05-26 19:02:49 +02:00
Nico Weber
d95e4831be LibCompress: Move generate_huffman_lengths() to a .h file
To be used in WebPWriter.

JPEGWriter currently hardcodes huffman tables; maybe it can use this
to build data-dependent huffman tables in the future as well.

Pure code move (except for removing the `DeflateCompressor::` prefix
on the function's name, and putting the default argument for the 4th
argument in the function's definition), no behavior change.
2024-05-26 19:02:49 +02:00
Lucas CHOLLET
f0269daeb6 LibGfx: Make Color::NamedColor be an enum class
As this is used extensively across the codebase, the change would add a
lot of noise. To prevent it, let's also add an `using enum` declaration.
2024-05-26 18:51:52 +02:00
Lucas CHOLLET
5b2356b452 WebContent+WebWorker: Don't set the color value to the index of an enum
The NamedColor would be casted to its underlying int to fit the ARGB on
the left hand side.
2024-05-26 18:51:52 +02:00
Timothy Flynn
eb3b8f8ee4 LibWeb: Implement EventSource for server-sent events
EventSource allows opening a persistent HTTP connection to a server over
which events are continuously streamed.

Unfortunately, our test infrastructure does not allow for automating any
tests of this feature yet. It only works with HTTP connections.
2024-05-26 18:29:24 +02:00
Timothy Flynn
79223f3e1b LibWeb: Correctly check the document's salvageable state during cleanup
The condition here was flipped.
2024-05-26 18:29:24 +02:00
Timothy Flynn
88d46b51ed LibWeb: Implement operation to error a ReadableStream 2024-05-26 18:29:24 +02:00
Timothy Flynn
2a2c59e74b LibWeb: Partially implement the ReadableStream pull-from-bytes AO
We do not handle BYOB request views yet, as they are not needed for the
upcoming usage of this AO.
2024-05-26 18:29:24 +02:00
Timothy Flynn
9cc186b929 LibWeb: Implement the "queue a task" steps as a distinct AO
This will be needed by EventSource.
2024-05-26 18:29:24 +02:00
Timothy Flynn
b6f824a313 Browser: Don't assume downloads have a "total size" available
Ran into a crash here while testing LibProtocol changes. The method we
invoke here (did_progress) already accepts an Optional, and handles when
that Optional is empty. So there's no need to assume `total_size` is
non-empty.
2024-05-26 18:29:24 +02:00
Timothy Flynn
6056428cb5 LibWeb: Support unbuffered fetch requests
Supporting unbuffered fetches is actually part of the fetch spec in its
HTTP-network-fetch algorithm. We had previously implemented this method
in a very ad-hoc manner as a simple wrapper around ResourceLoader. This
is still the case, but we now implement a good amount of these steps
according to spec, using ResourceLoader's unbuffered API. The response
data is forwarded through to the fetch response using streams.

This will eventually let us remove the use of ResourceLoader's buffered
API, as all responses should just be streamed this way. The streams spec
then supplies ways to wait for completion, thus allowing fully buffered
responses. However, we have more work to do to make the other parts of
our fetch implementation (namely, Body::fully_read) use streams before
we can do this.
2024-05-26 18:29:24 +02:00
Timothy Flynn
1e97ae66e5 LibWeb: Support unbuffered resource load requests
This adds an alternate API to ResourceLoader to load HTTP/HTTPS/Gemini
requests unbuffered. Most of the changes here are moving parts of the
existing ResourceLoader::load method to helper methods so they can be
re-used by the new ResourceLoader::load_unbuffered.
2024-05-26 18:29:24 +02:00
Timothy Flynn
168d28c15f LibProtocol+Userland: Support unbuffered protocol requests
LibWeb will need to use unbuffered requests to support server-sent
events. Connection for such events remain open and the remote end sends
data as HTTP bodies at its leisure. The browser needs to be able to
handle this data as it arrives, as the request essentially never
finishes.

To support this, this make Protocol::Request operate in one of two
modes: buffered or unbuffered. The existing mechanism for setting up a
buffered request was a bit awkward; you had to set specific callbacks,
but be sure not to set some others, and then set a flag. The new
mechanism is to set the mode and the callbacks that the mode needs in
one API.
2024-05-26 18:29:24 +02:00
Timothy Flynn
086ddd481d Ladybird+LibWeb: Move User-Agent definitions to their own file
This is to avoid including any LibProtocol header in Objective-C source
files, which will cause a conflict between the Protocol namespace and a
@Protocol interface.

See Ladybird/AppKit/Application/ApplicationBridge.cpp for why this
conflict unfortunately cannot be worked around.
2024-05-26 18:29:24 +02:00
Timothy Flynn
a38144fb2a Meta: Port recent changes to the GN build
5f17d9b34a
2024-05-26 18:29:24 +02:00
Aliaksandr Kalenik
663cc753a7 LibWeb: Fix clip box calculation in PaintableWithLines
All painting commands except SetClipRect are shifted by scroll offset
before command list execution. This change removes scroll offset
translation for sample/blit corner commands in
`PaintableWithLines::paint` so it is only applied once in
`CommandList::apply_scroll_offsets()`.
2024-05-26 16:11:53 +01:00
Aliaksandr Kalenik
7855d4a8f5 LibWeb: Transform blit corner clipping rectangle to device pixels
Rectangle saved in this command is only used to filter by bounding box,
so the problem was not very visible before.
2024-05-26 16:11:53 +01:00
Aliaksandr Kalenik
3d8349eb88 LibWeb: Fix blit corner clip position in PaintableWithLines
Fixes the bug when blit and sample commands position didn't match.

Before:
1. Emit sample under corners
2. Apply scroll offset
3. Paint content
3. Blit corner clipping

After:
1. Emit sample under corners
2. Save state
3. Apply scroll offset
4. Paint content
5. Restore state
6. Blit corner clipping
2024-05-26 16:11:53 +01:00
Lucas CHOLLET
09f4032eeb LibGfx/PNG: Read metadata from the eXIf chunk
The test image comes from this WPT test:
http://wpt.live/png/exif-chunk.html
2024-05-26 14:54:43 +01:00
Shannon Booth
f28bb90d9b LibJS: Remove non-spec compliant code from internal_construct
It seems that we are now spec compliant enough to be able to remove this
code block :^)

Diff Tests:
    +2     -2 
2024-05-26 12:29:41 +02:00
MacDue
18d39deefe Tests/LibWeb: Add ref test for clip-path: polygon(...) 2024-05-26 07:55:50 +02:00
MacDue
9e2c4f84fd LibWeb: Paint/apply basic-shape clip paths to PaintableBoxes
Currently, these only work when there are no CSS transforms (as the
stacking context painting is not set up to handle that case yet). This
is still enough to get most chat/comment markers working on GitHub
though :^)
2024-05-26 07:55:50 +02:00
MacDue
517379ff80 LibWeb: Resolve basic-shape clip-paths
These will be ignored within SVGs (for now SVGs only support <clipPath>
elements), but will allow clipping standard HTML elements.
2024-05-26 07:55:50 +02:00
MacDue
0135af6e60 Meta: Add basic-shape as a CSS property value type 2024-05-26 07:55:50 +02:00
MacDue
120915048c LibWeb: Parse the polygon() basic shape function 2024-05-26 07:55:50 +02:00
MacDue
5f17d9b34a LibWeb: Add BasicShapeStyleValue to represent CSS basic shapes
See: https://www.w3.org/TR/css-shapes-1/#basic-shape-functions

This patch only implements the `polygon()` basic shape (with the rest
left as FIXMEs).
2024-05-26 07:55:50 +02:00