Commit graph

58408 commits

Author SHA1 Message Date
MacDue
5cf1570f40 LibWeb: Add initial support for nesting SVG viewports
Previously, we were handling viewBoxes/viewports in a slightly hacky
way, asking graphics elements to figure out what viewBox to use during
layout. This does not work in all cases, and can't allow for more
complex SVGs where it is possible to have nested viewports.

This commit makes the SVGFormattingContext keep track of the
viewport/boxes, and it now lays out each viewport recursively, where
each nested `<svg>` or `<symbol>` can establish a new viewport.

This fixes some previous edge cases, and starts to allow nested
viewports (there's still some issues to resolve there).

Fixes #22931
2024-01-27 18:12:13 +01:00
Andreas Kling
546143e9a6 LibWeb: Fix vector OOB access when comparing some calc() values
Before comparing the elements of two vectors, we have to check that
they have the same length. :^)

Fixes a crash seen on https://chat.openai.com/
2024-01-27 17:06:43 +01:00
Timothy Flynn
9272d185ad LibWeb: Implement a slightly better ad-hoc Body::clone method
Just creating a stream on the JS heap isn't enough, as we will later
crash when trying to read from that stream as it hasn't been properly
initialized. Instead, until we have teeing implemented (which is a
rather huge part of the Streams spec), create streams using proper AOs
that do initialize the stream.
2024-01-27 16:01:56 +01:00
Timothy Flynn
c8c3866101 LibWeb: Implement the CreateReadableByteStream AO 2024-01-27 16:01:56 +01:00
Andreas Kling
8e20a44380 LibWeb: Avoid expensive containing_block lookups in PaintableFragment
The paintable has the containing block cached, so it's better (and less
code in general) to ask for it there.
2024-01-27 14:31:47 +01:00
Andreas Kling
ad7e6878fe LibWeb: Allocate CSS::ComputedValues objects on the heap
This makes them cheap to move around, since we can store them in a
NonnullOwnPtr instead of memcopying 2584(!) bytes.

Drastically reduces the chance of stack overflow while building the
layout tree for deeply nested DOMs (since tree building was putting
these things on the stack).

This change also exposed a completely unnecessary ComputedValues deep
copy in block layout.
2024-01-27 12:27:44 +01:00
Nico Weber
d89e42902e LibGfx/JPEGLoader: Extract inverse_dct_8x8() function
No behavior change.
2024-01-27 10:21:33 +00:00
Nico Weber
494fc1234e LibGfx/JPEGWriter: Rename y<=>x, u<=>v
Usually x and u go horizontally and y and v go vertically.

No behavior change.
2024-01-27 10:20:56 +00:00
Andrew Kaster
08a3c562f3 LibWeb: Resolve postMessage test promises if iframes already loaded
For some reason on macOS with ASAN enabled, the test promises in
HTML/Window-postMessage do not resolve. These promises wait for both
the in-document and the blob url iframes to load. It's not clear why
this works fine in Linux nor why the onload handler doesn't fire
when the iframe has already loaded.
2024-01-27 07:51:30 +01:00
Sam Atkins
e025bcc4f9 LibWeb: Make use of transform-box when calculating transforms
We don't currently calculate the fill- or stroke-boxes of SVG elements,
so for now we use the content- and border-boxes respectively, as those
are the closest equivalents. The test will need updating when we do
support them.

Also, the test is a screenshot because of rendering differences when
applying transforms: a 20px box does not get painted the same as a 10px
box scaled up 2x. Otherwise that would be the more ideal form of test.
2024-01-27 07:46:37 +01:00
Sam Atkins
391cfdc085 LibWeb: Parse the CSS transform-box property 2024-01-27 07:46:37 +01:00
Nico Weber
c3c7707de4 LibGfx/JPEGWriter: Don't throw away highest-frequency component in FDCT 2024-01-26 20:19:55 -05:00
Timothy Flynn
83d2f59e2a LibWebView: Port the CookieJar to String 2024-01-26 20:22:39 +01:00
Timothy Flynn
30fae8fa1d LibSQL: Allow constructing SQL values from a String
LibSQL still uses ByteString internally for storage, but to help outside
application port to String, add helpers to construct values from String
and to convert a value to a String.
2024-01-26 20:22:39 +01:00
Timothy Flynn
c4820838bf LibWeb+WebContent: Port the did_request_named_cookie IPC to String 2024-01-26 20:22:39 +01:00
Timothy Flynn
9b957ead13 LibWebView+WebContent: Do not manually serialize cookie sources over IPC
LibIPC can serialize enumeration automatically (this was not the case
when these IPCs were added).
2024-01-26 20:22:39 +01:00
Timothy Flynn
85b8971a80 Ladybird+LibWeb+WebContent: Port the did_request_cookie IPC to String 2024-01-26 20:22:39 +01:00
Timothy Flynn
dcd9962d7b Browser: Remove some needless indirection from Cookie-related IPCs
We don't need to forward Cookie-related IPCs from the WebView through
the Tab to the BrowserWindow. We can skip the Tab like we do in other
chromes.

This is primarily to reduce overhead when changing Cookie IPCs in future
patches.
2024-01-26 20:22:39 +01:00
Timothy Flynn
8ea4e37c27 LibWebView: Convert trivial ByteString uses to StringView in CookieJar 2024-01-26 20:22:39 +01:00
Nico Weber
db4982bd29 LibGfx+image: Implement writing ICC profiles to jpeg files 2024-01-26 14:03:20 -05:00
Nico Weber
83ab9f7c2d LibGfx/PNM: Remove unnecessary line
This is already done at the caller decode() in
PortableImageLoaderCommon.h, as pointed out by @LucasChollet at
https://github.com/SerenityOS/serenity/pull/22935#discussion_r1467158789

No behavior change.
2024-01-26 14:53:33 +01:00
Nico Weber
c694d4326b Tests: Add a pam cmyk test file
Hand-written in a text editor.

I verified that `convert` converts it to a png that looks like the
rgb test expectations.
2024-01-26 07:36:53 +01:00
Nico Weber
c431cf4907 LibGfx: Add comparison operators to CMYK 2024-01-26 07:36:53 +01:00
Nico Weber
ba8f4e73bf Tests: Add a pam test file
Hand-written in a text editor.

I verified that `convert` converts it to a png that looks like the
test expectations.
2024-01-26 07:36:53 +01:00
Nico Weber
556addc5cb LibGFX/PAM: Allow reading CMYK .pam files
These are written by `mutool extract` for CMYK images.

They don't contain color profiles so they're not super convenient.
But `image` can convert them (*) to sRGB as long as you use it with
`--assign-color-profile` pointing to some CMYK icc profile of your
choice.

*: Once #22922 is merged.
2024-01-26 07:36:53 +01:00
Nico Weber
187862ebe0 LibGfx: Add a .pam loader
.pam is a "portrable arbitrarymap" as documented at
https://netpbm.sourceforge.net/doc/pam.html

It's very similar to .pbm, .pgm, and .ppm, so this uses the
PortableImageMapLoader framework. The header is slightly different,
so this has a custom header parsing function.

Also, .pam only exixts in binary form, so the ascii form support
becomes optional.
2024-01-26 07:36:53 +01:00
Aliaksandr Kalenik
0d76a9da17 LibWeb: Resolve text-decoration-thickness during layout commit
Refactoring towards stop resolving CSS lengths during paintable
commands recording.
2024-01-26 07:36:40 +01:00
Aliaksandr Kalenik
d5e3158cfe LibWeb: Use PaintableFragment::baseline() in paint_text_decoration()
No need to calculate baseline based on glyph height when we can get
this information from a fragment.
2024-01-26 07:36:40 +01:00
Aliaksandr Kalenik
1c4ce2c5f1 LibWeb: Don't check containing block of fragments in hit testing
We do not rely on existence of containing block in
`PaintableWithLines::hit_test()` so it should be safe to remove this
check.
2024-01-26 07:36:40 +01:00
Aliaksandr Kalenik
270bbf43ab LibWeb: Remove is<BlockContainer> check for fragments in hit testing
This change introduces a method for direct access to the paintable of
a PaintableFragment. This method is intended to replace the usage of
the layout node pointer. Currently, we are only eliminating the use
of `layout_node()` in hit testing.

Additionally, we no longer check if a fragment's layout node is a
`BlockContainer` before recursing into its children during hit testing.
This check was likely relevant when all fragments were owned by
`PaintableWithLines`, but now it should be safe to remove this check.
2024-01-26 07:36:40 +01:00
Timothy Flynn
09124fc3a5 LibWeb: Set up the Fetch response's body with the appropriate stream 2024-01-25 21:34:03 +01:00
Timothy Flynn
2bb751eab9 Meta: Port recent changes to the GN build
b12541b286
2024-01-25 21:34:03 +01:00
Aliaksandr Kalenik
a319037706 LibWeb: Remove SetFont painting command
It was only used in ImagePaintable for alt text and now it is replaced
by saving font inside DrawText command.
2024-01-25 21:33:54 +01:00
Andrew Kaster
d85a0e306a headless-browser: Add option to filter which tests are run with a glob
This is the same feature that run-tests has on Serenity.
2024-01-25 09:44:42 -07:00
Nico Weber
550937f5dd Tests: Add a test cmyk jpeg file with an embedded color profile
I opened Base/res/graphics/buggie.png in Photoshop, converted it
to U.S. Web Coated (SWOP) v2, flattened the image so we don't have
CMYK with alpha, and saved it as a jpeg (with color profile embedded).
2024-01-25 15:53:44 +01:00
Nico Weber
fac48fdda4 image: Allow converting CMYK inputs to RGB
This worked in PDFs for a while, but now `image` can also do
CMYK->RGB conversions that actually use color profiles :^)
2024-01-25 15:53:44 +01:00
Nico Weber
88b49a639e LibGfx/ICC: Add a convert_cmyk_image() method
It converts from a CMYKBitmap to an (rgb) bitmap, using a real
color profile.

The API design here isn't super scalable (what if we want to also
handle grayscale inputs? What if we also want to convert _to_ cmyk
or grayscale?), but we have to start somewhere. Uses of this can
inform future API improvements.
2024-01-25 15:53:44 +01:00
Nico Weber
11b623b1fd LibGfx: Add data_size() accessors to Bitmap and CMYKBitmap
These return the size of the data in bytes.
2024-01-25 15:53:44 +01:00
Nico Weber
0acc370f7b image: Load images that contain CMYK data into a CMYKBitmap
Every single of images's functions then go ahead and error out on
CMYKBitmaps for now.

(Alternatively, we could make them the low-quality CMYK->RGB
conversion that previously happened implicitly, but let's go
with this for now.)

(With this structure, we could also do something smarter for
Vector images in the future.)

Here's how this looks:

    % Build/lagom/bin/image \
        -o out.png Tests/LibGfx/test-inputs/jpg/ycck-2111.jpg
    Runtime error: Can't save CMYK bitmaps yet, convert to RGB first
                   with --convert-to-color-profile

    % Build/lagom/bin/image \
        --convert-to-color-profile serenity-sRGB.icc \
        -o out.png Tests/LibGfx/test-inputs/jpg/ycck-2111.jpg
    Runtime error: No source color space embedded in image.
                   Pass one with --assign-color-profile.

    % Build/lagom/bin/image \
        --assign-color-profile path/to/CMYK/USWebCoatedSWOP.icc \
        --convert-to-color-profile serenity-sRGB.icc \
        -o out.png Tests/LibGfx/test-inputs/jpg/ycck-2111.jpg
    Runtime error: Psych, can't convert CMYK bitmaps yet either

As usual, serenity-sRGB.icc is from
`Build/lagom/bin/icc  -n sRGB --reencode-to serenity-sRGB.icc` and
the adobe cmyk profiles are available at
https://www.adobe.com/support/downloads/iccprofiles/iccprofiles_win.html
which ultimately leads to:
https://download.adobe.com/pub/adobe/iccprofiles/win/AdobeICCProfilesCS4Win_end-user.zip
2024-01-25 15:53:44 +01:00
Nico Weber
c6eac16d00 LibGfx: Remove unused parameter from cmyk_frame() 2024-01-25 15:53:44 +01:00
Nico Weber
2c40886851 image: Update an error string
We have been able to write .jpg files for a while now.
2024-01-25 15:53:44 +01:00
Nico Weber
8a56abf48b image: Move image writers up that don't return bytes
Makes the early returns a bit easier to see.

Also alphabetize them while touching these lines.

No behavior change.
2024-01-25 15:53:44 +01:00
Nico Weber
96c71b7042 image: Move image loading code into a separate function
Haters will say this is overkill, but this function will do a bit more
once we allow loading CMYK data.

No behavior change.
2024-01-25 15:53:44 +01:00
Nico Weber
653b614611 image: Move image saving code into helper function
No behavior change.
2024-01-25 15:53:44 +01:00
Nico Weber
0681df7f3b image: Move profile conversion code into helper function
No behavior change.
2024-01-25 15:53:44 +01:00
Nico Weber
48a0fb1e8e image: Introduce a struct "LoadedImage" to hold bitmap and icc data
This makes it easier to move the color space conversion code out
into a helper function, and will be used to pass around CMYK bitmaps.

No behavior change.
2024-01-25 15:53:44 +01:00
Nico Weber
a339f297d1 image: Move image modification code to helper functions
No behavior change.
2024-01-25 15:53:44 +01:00
Nico Weber
da243ebb8b image: Use Error::from_string_view() for errors
...instead of warn() + manual return.

Before:

    % Build/lagom/bin/image -o out.asdf in.png
    can only write .bmp, .png, .ppm, and .qoi

Now:

    % Build/lagom/bin/image -o out.asdf in.png
    Runtime error: can only write .bmp, .png, .ppm, and .qoi

That doesn't look worse, and it's less code (and makes moving the
code into helper functions easier).
2024-01-25 15:53:44 +01:00
Aliaksandr Kalenik
c02820759b LibWeb: Test nested elements in InlinePaintable::hit_test()
Before this change we were ignoring nested paintables inside inline
paintable during hit-testing, but now we recurse into subtree.

Fixes https://github.com/SerenityOS/serenity/issues/22927
2024-01-25 15:53:18 +01:00
Andreas Kling
1583e6ce07 LibWeb: Clamp justification space between flex items to 0
Before this change, it was possible for flex lines with negative
remaining space (due to overflowing items) to put a negative amount
of space between items for some values of `justify-content`.

This makes https://polar.sh/SerenityOS look much better :^)
2024-01-25 15:10:21 +01:00