Commit graph

3191 commits

Author SHA1 Message Date
Andreas Kling d4e86f10ac LibWeb: Don't crash on CSS all: revert
Not every value in a StyleProperties will be non-null by the time we
perform `revert`, so let's make a specialized function for reverting a
property instead of using the path that requires the value to be
non-null.

(cherry picked from commit a10610a1cad56294089fc9457e713eb7083312cd)
2024-09-27 22:18:42 -04:00
Nico Weber a1ea398ca0 Tests: Add a (manual) test pdf for paths
Lovingly hand-written. Uses various line cap and line join styles.

Offsets fixed up with:

    mutool clean Tests/LibPDF/paths.pdf Tests/LibPDF/paths.pdf
2024-09-27 20:19:24 -04:00
Nico Weber c1ea8fa01c LibGfx+Tests: Fix infinite loop in butt line cap drawing
Sometimes going across would put is one active range away from
being in-bounds, so check the two neighboring ranges too.
2024-09-27 20:18:55 -04:00
Nico Weber c30188cd6a LibWeb: Hook up canvas lineCap and plumb it to LibGfx
To rebaseline image test expecatations, I ran:

    out/gn/Ladybird.app/Contents/MacOS/headless-browser \
        --resources $PWD/out/gn/Ladybird.app/Contents/Resources \
        --dump-failed-ref-tests \
        --run-tests $PWD/Tests/LibWeb \
        --filter 'canvas-*'

I then copied over the new baselines with

    D=Tests/LibWeb/Ref/reference/images
    cp test-dumps/canvas-implict-moves-and-lines.png \
        $D/canvas-implict-moves-and-lines-ref.png

(Note: No `-ref` suffix on first path, yes suffix on second path.)

We currently don't track if a path is open or closed, and paint
butt linecaps at the end of closed paths too. We did that with
round linecaps as well, but there that wasn't visible. This makes
closed paths look a bit weird now; we'll have to fix this in a
follow-up. In a way, this just exposes another not-yet-implemented
feature.
2024-09-27 15:05:30 -04:00
Nico Weber 5ba5a599de LibGfx/Path: Make round end caps show up more consistently
On macOS, when going from the right end of a horizontal line
to the left, and when slope_now is pi, and the current
range.end is 0 (i.e. current_angle = pi, target_angle = 0),
clockwise() would set target_angle to 2 * pi, and
`target_angle - current_angle` (ie 2 * pi - pi) would end up
being ever so sligthly more than `pi` (handwavingly due to
floating point in accuracies), and we'd go in the wrong direction.

Add an explicit check for that, and a reftest that catches this.

No observed behavior change on linux, but the reftest only passes
on macOS with the code change.
2024-09-25 15:59:58 -04:00
Marcus Nilsson 66bdb3bf43 LibGfx: Respect order of image data in TGAImageDecoderPlugin
Previously, the order of data was incorrectly based on x_origin and
y_origin, which are meant for where on the screen the image should be
placed (TarGA is an image format meant for graphic cards), instead of
Image descriptor bits 4 and 5, which specify the direction.

This fixes a problem where tga files generated with magick would render
up-side-down.

The test images where created in GIMP, 4 simple 2x2 images
exported as .tga, no compression, origin: Bottom Left

square-bottom-left.tga:
Red, Green
Blue, Magenta

square-bottom-right.tga:
Green, Red
Magenta, Blue

square-top-left.tga:
Blue, Magenta
Red, Green

square-top-right.tga:
Magenta, Blue
Green, Red

then this script was ran:
```python
def update_tga_descriptor(file_path, top_to_bottom, left_to_right):
    with open(file_path, 'r+b') as f:
        header = f.read(18)
        descriptor = header[17]

        descriptor &= ~(1 << 4);
        descriptor &= ~(1 << 5);

        if left_to_right:
            descriptor |= 1 << 4;

        if top_to_bottom:
            descriptor |= 1 << 5;

        header = header[:17] + bytes([descriptor])
        f.seek(0)
        f.write(header)

update_tga_descriptor('square-bottom-left.tga', False, False)
update_tga_descriptor('square-bottom-right.tga', False, True)
update_tga_descriptor('square-top-left.tga', True, False)
update_tga_descriptor('square-top-right.tga', True, True)
```
2024-09-18 06:34:19 -04:00
Marcus Nilsson 76301a6894 LibGfx: Support UncompressedBlackAndWhite in TGAImageDecoderPlugin
Test image generated with `magick buggie-bottom-left-uncompressed.tga
-colorspace Gray -compress None buggie-black-and-white-uncompressed.tga`
2024-09-18 06:34:19 -04:00
kleines Filmröllchen a3077203fe AK: Don't implicitly convert Optional<T&> to Optional<T>
C++ will jovially select the implicit conversion operator, even if it's
complete bogus, such as for unknown-size types or non-destructible
types. Therefore, all such conversions (which incur a copy) must
(unfortunately) be explicit so that non-copyable types continue to work.
2024-09-14 13:30:27 +02:00
Sönke Holz b41365d11d Tests/Kernel: Add some more EFAULT tests 2024-09-11 12:45:56 -04:00
Sönke Holz c2aea15c9b Tests/Kernel: Build TestMemoryDeviceMmap only on x86
This test is very x86-specific, it expects specific memory regions
to be present at certain physical addresses.
2024-09-11 12:45:56 -04:00
Lucas CHOLLET ba9875c56f LibGfx/JPEGXL: Add support for decoding embedded ICC profiles
The test case was generated by opening `modular_property_8.jxl` in
Krita, then changing the Color Profile to Apple RGB and then exporting
as PNG. Finally, the conversion to JPEGXL was made with:
`cjxl --container=0 --modular=1 -d 0 -e 9 file.png icc.jxl`

Note that, we can't use Krita to export a jxl as it always create a
container instead of a raw stream. Also, this needs an old version of
`cjxl` (I used 0.7), as more recent version reencode the ICC profile
using the JPEGXL's internal representation for color profile, which is
encoded differently.
2024-09-09 21:18:38 -04:00
kleines Filmröllchen d21ee3206e AK: Add IPv6 subnet and address category handling
IPv6Address can now determine the broad address
categories as defined in various RFCs, and check
if addresses belong to certain subnets.
2024-09-08 18:27:55 -04:00
Nico Weber af0fe2374d Tests: Modernize TestDeflate a bit
- Use TRY_OR_FAIL() instead of MUST() in a few places
- Use for-each loop in two tests
- Use StringView literals instead of u8 arrays in a few places

No behavior change.
2024-08-23 14:54:37 -04:00
Lucas CHOLLET 3fc784c442 AK/FuzzyMatch: Return the best possible score in case of equality
This fixes cases where fuzzy matching would return a better score for
a different pattern than a needle perfectly matching the haystack.

As an example, when searching for "fire" in emojis, "Fire Engine" would
have scored 168, while "Fire" was giving only 160.
This patch makes the latter have the best possible score.
2024-08-23 14:14:05 -04:00
Nico Weber a3258d4094 LibGfx/ICC: Tolerate v2 profiles with D65 PCS illuminant
They do happen in practice.

We might have to do more to do actual color conversions with
these profiles, but for now let's at least load them.

Fixes rendering of a few images in my thesis in LibPDF.
The images were created in OmniGraffle in 2008, then saved as
PDF, then converted to eps using LaTeX tooling.
2024-08-20 09:43:06 -04:00
Nico Weber 0a4f8736e3 LibGfx/PNGWriter: Add support for inter-frame compression of apngs
Brings wow.apng from 1.2M to 606K, while reducing encoding time from
233 ms to 167 ms.

(For comparison, writing wow.webp currently takes 88ms and produces
a 255K file. The input wow.gif is 184K.)
2024-08-15 06:35:48 -04:00
Nico Weber a2b59b9c98 LibGfx/PNGWriter: Implement support for writing animated PNGs
Based on #24021.

Co-Authored-By: Pixel Brush <letsplaytvirtmann@gmail.com>
2024-08-15 06:35:48 -04:00
Aliaksandr Kalenik 0283f334af LibWeb: Apply scroll offset and clip rectangle to table borders
Moves paint_table_borders() call into PaintableBox::paint() to make
scroll offset and clip rectangle of enclosing scrollable be applied
in ::before_paint().

(cherry picked from commit 2cc2646f5585e4a1f617ac809806bf05e8e515a4)
2024-08-13 15:44:11 -04:00
BenJilks 736c931a15 LibWeb: Add additional padding to the end of the scrollable overflow
Adds additional padding to the end-side of the scrollable overflow
rectangle as necessary to enable a scroll position that satisfies
the requirements of `place-content: end` alignment.

(cherry picked from commit 963cf1c2c4e4b1cd482c41d6f673b7207bbcc067)
2024-08-13 15:43:28 -04:00
Nico Weber 4492de4e37 Tests: Add a test for paeth_predictor() 2024-08-10 13:07:01 -04:00
Nico Weber a1586e9c03 Tests: Add a benchmark for the PNG paeth predictor 2024-08-10 13:07:01 -04:00
brody-qq e0242abf93 Tests/Kernel: Add test for Ext2FS reads and writes
This commit adds a new test case which carries out the following steps:
* write() to a block of an ext2 file, verify the write() was successful
* read() the same block back, verify the read() was successful
* verify that the data from the read() is identical to the data that was
  written in the write()

The test runs the above steps on the following blocks of an ext2 file:
* the first and last direct blocks
* the first and last singly indirect blocks
* the first and last doubly indirect blocks
* the first and last triply indirect blocks
2024-08-08 19:04:04 -04:00
Jamie Mansfield f82e976df4 LibWeb: Implement DOMStringList
(cherry picked from commit 75216182c9a04741b2f773eb2f26ceb7a96bfbba)
(cherry picked from commit 2a55ab13ef9c735a16674006a518c0e5acf7c88f)

Co-authored-by: Sam Atkins <atkinssj@serenityos.org>
2024-07-29 09:14:06 -04:00
Tim Ledbetter 92ef7f08df LibWeb: Set correct prototype for WorkerLocation
(cherry picked from commit 354e5a6624a92952b1f3b86f98d9b1d0cb0ec048)
2024-07-28 20:48:58 -04:00
Sam Atkins 94674c6999 LibWeb/CSS: Parse custom-idents more consistently
These have a few rules that we didn't follow in most cases:
- CSS-wide keywords are not allowed. (inherit, initial, etc)
- `default` is not allowed.
- The above and any other disallowed identifiers must be tested
  case-insensitively.

This introduces a `parse_custom_ident_value()` method, which takes a
list of disallowed identifier names, and handles the above rules.

(cherry picked from commit 6ae2b8c3d901d8a7255046a4517fddd8b0fa84c4)
2024-07-28 20:21:39 -04:00
Shannon Booth ff5358d9b8 WebAudio: Add IDL interface for AudioDestinationNode
This is an AudioNode representing the final audio destination and is
what the user will ultimately hear.

This node is used as one of the connecting nodes in athenacrisis.com

Add a placeholder for the interface without anything backing it for now.

(cherry picked from commit 5eb80b8697d458ea2b70112a995e066f64b37ca6)
2024-07-28 20:21:18 -04:00
Jamie Mansfield 9bbf50b755 LibWeb: Stub BroadcastChannel interface
This is enough to get the 1Password login page to load :^)

(cherry picked from commit d4a7cfb68fddbcfaaaddbd7f159c502c869281bf)
2024-07-28 16:44:35 -04:00
Tim Ledbetter f1cfe231af LibWeb: Perform DOMTokenList token validation in the correct order
(cherry picked from commit 0127190dcf7fd0ee27a935cf1f3f5c74b77c0fc9)
2024-07-28 14:13:20 -04:00
Tim Ledbetter a88effd0fe LibWeb: Follow the specification steps to serialize a DOMTokenList
This ensures that calling `element.classList.toString()` always
produces the correct value.

(cherry picked from commit ec1f7779cb16223dab0ef9f7bf875c3f7b5724a9)
2024-07-28 14:13:20 -04:00
Tim Ledbetter 66280e96e9 LibWeb: Update Element class list is when class attribute is removed
(cherry picked from commit 21e21abeed122b8b9ebd1bb98ad2201d7edae4f7)
2024-07-28 14:13:20 -04:00
Tim Ledbetter a439fe0d5b LibWeb: Make document.createElementNS() case-sensitive
Previously, when creating a HTML element with
`document.createElementNS()` we would convert the given local name to
lowercase before deciding which element type to return. We now no
longer perform this lower case conversion, so if an uppercase local
name is provided, an element of type `HTMLUnknownElement` will be
returned. This aligns our implementation with the specification.

(cherry picked from commit 5a796629c61221261c1856e19dd829973e6158f0)
2024-07-28 14:13:11 -04:00
Sam Atkins fc6c6573b1 LibWeb: Prevent elements with no layout box from modifying counters
(cherry picked from commit 696ccc1aa992fdd7e22a44571d8be7d89738261d)
2024-07-28 13:31:02 -04:00
Sam Atkins 6ab5a043e6 Last: LibWeb: Add counter() and counters() functions to content property
These let you format counters' current values as strings for use in
generated content.

(cherry picked from commit 898e3bd89878ddb87df06e056031673dc770be2b)
2024-07-28 13:31:02 -04:00
Sam Atkins 1bc896fa60 LibWeb: Implement counter-[increment,reset,set] properties
These control the state of CSS counters.

Parsing code for `reversed(counter-name)` is implemented, but disabled
for now until we are able to resolve values for those.

(cherry picked from commit 017d6c3314d57d4e351764f328c1d25dbc9d033a)
2024-07-28 13:31:02 -04:00
Jamie Mansfield b1ebaee65f LibWeb/DOM: Check if name is valid in Element.toggleAttribute
This resolves a test in https://wpt.live/dom/nodes/attributes.html.

(cherry picked from commit f774d75f890e89a8483e5c7459de4fd96ce1b479)
2024-07-28 13:17:47 -04:00
Sam Atkins c847487f30 LibWeb: Reserve enough space for span>1 columns in BorderConflictFinder
This code previously only allocated enough space in
m_col_elements_by_index for 1 slot per column, meaning that columns
with a span > 1 would write off the end of it.

(cherry picked from commit 9e32c9329acd89d73eeff3494a5e728077962513)
2024-07-28 13:00:11 -04:00
Sam Atkins 1ea6e6c395 LibWeb: Correct logic for removing end nodes from HTMLOptionsCollection
This test case would previously crash.

Found with domato.

(cherry picked from commit 0cec68ea996623ee652900986c7232c8d538a209)
2024-07-28 13:00:11 -04:00
Timur Sultanov ff18de7f46 Tests: Add test for selection option in <select>
Verify that we can select option using JS

(cherry picked from commit 1ce9bbdd6dcf0f1634014e57d700b697635a79d8)
2024-07-28 12:59:58 -04:00
Timur Sultanov 9e36f7c86c LibWeb: Improve HTMLSelectElement spec compliance
Set default `size` value according to spec

(cherry picked from commit ad7b2b7c26c343504be32b9da8961e4fb5df3e86)
2024-07-28 12:59:58 -04:00
Nico Weber 6ab69b1cc1 LibGfx/WebPWriterLossless: Use predictor transform
...for images that don't use a color indexing transform.

For now, write the predictor transform unconditionally, and predict
every pixel as its left neighbor (that is, use predictor 1 everywhere).

This will grow a better heuristic in time, and eventually we might want
to use more than 1 of the 13 different predictor modes. But on average,
doing this unconditionally is better than not doing it unconditionally.
(Also, it's possible to disable this transform using `image`'s
`--webp-allowed-transforms` flag.)

Using the same benchmark as in #24819, this reduces the total size
of the test images further, from 88M to 69M (21.6%). It does increase
runtime for compressing all these images from about 4.4s to 4.7s,
a 6.8% slowdown.

For the usual test image (no effect on the two animations, which use
the color indexing transform):

    sunset_retro.png (876K):
        1.2M -> 730K, 31.4 ms ± 0.8 ms -> 31.4 ms ± 0.7 ms

From 37% larger than the input to 16% _smaller_ than the input :^)
(A 39% size reduction for this image.)

Compressing sunset_retro.png with zopflipng produces a 820K image,
so we're smaller even than what the best PNG encoder can do with
this image.

It's not a win for all images: For example, the size of
qoi_benchmark_suite/screenshot_web/sublime.png goes from 1.0M to 1.5M,
a fairly dramatic size increase. Hopefully we can get that back in
the future with better heuristics. (The input sublime.png is 1.3M,
and sublime.png encoded using our QOI encoder creates a 1.6M file,
so the 1.5M isn't atrocious, even though it's much bigger than the
size without the predictor transform.)

Our WebP Lossless writer currently now has a similar feature set
to our QOI writer: RLE, color cache, left prediction, and
subtract green is somewhat similar to QOI's luma chunk. The WebP
writer also writes huffman trees, which QOI doesn't do. For most
images, the WebP writer creates smaller files than the QOI writer,
while being about 50% slower. The WebP writer also writes smaller
files than Serenity OS's png writer, while being ~40x as fast
(for sunset_retro, ~30ms instead of ~1.3s; 730K output instead of
999K).

Only doing RLE and using a single predictor for the entire image is
similar to what fpng is doing (...but fpng uses the T predictor always).

We still don't write a meta prefix image to keep the huffman trees
flatter, we still don't do full LZ77 backward matches, and we still
don't write color transforms. But the writer has now enough features
to be in usable shape. It's now Serenity OS's best-compressing lossless
image writer.

The test_webp_color_indexing_transform_single_channel test uses a
linear horizontal gradient, which the predictor transform compresses
so well that encoded_data_without_color_indexing ends up being
smaller than the color indexed file. Just disable the predictor
transform in that test for now.
2024-07-28 12:35:41 -04:00
Andreas Kling 94c1066f68 LibWeb: Inherit CSS variables across shadow boundaries
This fixes a bunch of issues on https://wpt.fyi/

(cherry picked from commit de2b9eebe6012e321c85cdae0ca14b4be40de624)
2024-07-28 07:33:15 -04:00
Jamie Mansfield a28019e98b LibWeb/HTML: Implement HTMLMediaElement.addTextTrack
Removes some noise from the console when browsing bbc.co.uk :^)

(cherry picked from commit 793248aec977d4b15006d6e55a960da2e115a734,
amended to s/UIEvents::KeyCode/KeyCode/ to resolve cherry-pick conflict)
2024-07-28 07:32:58 -04:00
doctortheemh 5d1beff35f LibWeb: Parse fill and stroke values
Use the CSS color data type using the CSS parser.

(cherry picked from commit 9cbb3fac123d0ce12bc1d0127d22ed26417dffd7)
2024-07-28 07:32:47 -04:00
Tim Ledbetter 8c56eb0743 LibWeb: Calculate length for all CharacterData type nodes correctly
We now ensure that `Node::is_character_data()` returns true for all
nodes of type character data.

Previously, calling `Node::length()` on `CDataSection` or
`ProcessingInstruction` nodes would return an incorrect value.

(cherry picked from commit 3802d9ccc4ea4428b82c6d584c3667c040cb46c7)
2024-07-28 07:32:31 -04:00
Tim Ledbetter 6a6c0ae791 LibWeb: Don't crash when cloning a CDATASection node
(cherry picked from commit 72ed62a560c654370e6a3583bc8bd078732f44db)
2024-07-28 07:32:31 -04:00
Andreas Kling a8a5463d33 LibWeb: Make offsetTop and offsetLeft behave more like other browsers
We now follow the rules from the spec more closely, along with an
unspecified quirk for when the offsetParent is a non-positioned body
element. (Spec bug linked in a comment.)

This fixes a whole bunch of css-flexbox tests on WPT, which already had
correct layout, but the reported metrics from JS API were wrong.

(cherry picked from commit d49ae5af32044cb83bc14073b92676a1662c3bc1)
2024-07-28 07:32:17 -04:00
Tim Ledbetter aa3f3a827a Tests: Add test for Node.nodeName
(cherry picked from commit 97436e7d6574a4fe90e27661e10a6ab4caa68ec1)
2024-07-28 07:32:04 -04:00
Edwin Hoksberg dd843ae282 LibWeb: Implement grid-template function fit-content()
(cherry picked from commit e5deaa1c073f4762fe2cdc7d36f90099f0ca4d11)
2024-07-28 07:31:47 -04:00
Andreas Kling de66b176d1 LibWeb: Execute the correct script in XMLDocumentBuilder::element_end()
We were mistakenly executing the current node's script instead of the
document's pending parsing-blocking script.

This caused ~1000 WPT tests to time out, since we never ended up firing
a load event for XHTML pages that load multiple external scripts.

(cherry picked from commit 007c292af3202a85eb146b121720d988a66ed64b)
2024-07-28 07:30:38 -04:00
Timur Sultanov a74e721c09 Tests: Add tests for <select> element behavior
Check that `<select>` element has options available immediately

(cherry picked from commit 2bf37cb91444dbdaa8e0ccf965b7c9e84717da12)
2024-07-28 07:30:11 -04:00