Commit graph

71222 commits

Author SHA1 Message Date
Timothy Flynn
1f88e6819a LibWeb: Ensure hit testing is grapheme aware
Previously, clicking in the middle of a multi-code point grapheme would
place the cursor at a code unit index somewhere in the middle of the
grapheme. This was not only visually misleading, but the user could then
start typing and insert characters in the middle of the cluster. This
also made text select pretty wonky.

The main issue was that we were treating the glyph index in a glyph run
as a code unit index. We must instead map that glyph index back to a
code unit index with help from LibGfx (via harfbuzz).

The distance computation used here was also a bit off, especially for
the last glyph in a glyph run. We essentially want the cursor to end
up on whichever edge of the clicked glyph it is closest to. The result
of the distance computation limited us to the left edge of the last
glyph. Instead, we can use the same edge tracking we use for form-
associated elements to handle this for us.
2025-08-22 14:06:46 +02:00
Timothy Flynn
c3f4d32162 LibWeb: Extract FormAssociatedElement's grapheme edge code to a helper
The edge detection will be used at least in hit testing.
2025-08-22 14:06:46 +02:00
Timothy Flynn
047f521c4c LibGfx+LibWeb: Add some extra fields to glyph run data
We currently have a mixup in LibWeb between code unit offset and glyph
offset during hit testing. These extra fields will allow us to correct
this discrepency.
2025-08-22 14:06:46 +02:00
Timothy Flynn
b1fe816336 AK: Provide a length_in_code_units API for UTF-8 strings
This is just to afford API symmetry with UTF-16 strings to help in
templated methods.
2025-08-22 14:06:46 +02:00
zac
41eaf0d966 Tests: Add tests for some common image types in TestLibCoreMimeType 2025-08-22 08:03:28 -04:00
zac
b8f95a091c LibCore: Add AVIF to registered types in MimeData 2025-08-22 08:03:28 -04:00
Callum Law
5c2fe12772 LibWeb: Don't consider null -> null as a change for invalidation
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This avoids excessive invalidation within `recompute_inherited_style`
where we inherit a value but not an animated value.
2025-08-22 12:17:55 +02:00
Callum Law
cecd5b3b5b LibWeb: Compute invalidation before value is moved
`set_animated_property` will move `new_animated_value` away so we need
to compute invalidation before we call it
2025-08-22 12:17:55 +02:00
Andreas Kling
3c808de270 LibWeb: Use XML parser for SVG-as-image documents
We were already using the XML parser for SVG files when opening at the
top level. This patch makes things consistent by using the same code
path when parsing SVG-as-image.

We also make some tweaks in SVG presentation attribute handling since
we can no longer rely on the HTML length attribute parsing quirk when
parsing width/height attributes.
2025-08-22 11:35:59 +02:00
Andreas Kling
b7595013c1 LibWeb+LibXML: Preserve element attribute order in XML documents
We now use OrderedHashMap instead of HashMap to ensure that attributes
on XML elements retain their original order.
2025-08-22 11:35:59 +02:00
Sam Atkins
da88db04cf LibWeb/CSS: Implement the "numeric factory" methods (CSS.px() and pals) 2025-08-22 09:48:30 +01:00
Sam Atkins
24017e4ab7 LibWeb/CSS: Reify numbers, dimensions and percentages as CSSUnitValue 2025-08-22 09:48:30 +01:00
Sam Atkins
5384338788 LibWeb/CSS: Implement CSSUnitValue 2025-08-22 09:48:30 +01:00
Sam Atkins
0fa1099ce5 LibWeb/CSS: Support creating a NumericType from Flex units 2025-08-22 09:48:30 +01:00
Sam Atkins
6cb8e92bd4 LibWeb/CSS: Stub out CSSNumericValue
Most of the methods on this rely on its subclasses existing, so for now
it's very basic.
2025-08-22 09:48:30 +01:00
Sam Atkins
5bdc2981e3 LibWeb/CSS: Rename CSSNumericType to NumericType
The CSSNumericType defined in the spec is a simple dictionary which is
only used for OM purposes. This NumericType class is used internally
and matches the more abstract definition of a "type".
2025-08-22 09:48:30 +01:00
rmg-x
43d071e3b7 LibWeb/WebIDL: Remove unused AK/Diagnostics.h import in DOMException 2025-08-22 09:47:01 +01:00
rmg-x
1678231eed LibWeb: Fix else-after-return in hash_algorithm_identifier_from_value
and constify it :^)
2025-08-22 09:47:01 +01:00
rmg-x
3ef65e45d7 LibWeb/Crypto: Avoid heap allocation for AesGcm tag lengths 2025-08-22 09:47:01 +01:00
Callum Law
6373ab68ee LibWeb: Use inherited value of math-style when computing math-depth
The spec calls for us to use the inherited value but we were using our
own value.
2025-08-22 09:48:52 +02:00
Callum Law
4efbd0dc4d LibWeb: Support relative lengths in math-depth calcs
As this is computed before font-size we use the parent's length
resolution context.
2025-08-22 09:48:52 +02:00
Callum Law
944b985929 LibWeb: Remove handling of invalid values in compute_math_depth
This was unnecessary as the parser will never produce values other than
MathDepthStyleValue
2025-08-22 09:48:52 +02:00
Callum Law
a2c9ab9c9a LibWeb: Return AbstractElement from element_to_inherit_style_from
No functional changes.
2025-08-22 09:48:52 +02:00
Sam Atkins
8af99388a6 LibGC: Make GC::Root bool operator explicit
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Not having this led to a sneaky bug where, given a Variant like so:

  Variant<double, GC::Root<T>>

An incorrectly-written visit() branch for the Root would just cause it
to be cast to a double and call that branch instead.

With the cast made explicit, we get a compiler error, which is far more
useful.

Co-authored-by: Jelle Raaijmakers <jelle@ladybird.org>
2025-08-21 12:50:43 -04:00
Erik Kurzinger
ce03b8b3b1 LibGfx+LibWeb: Only compile dma-buf-related code on Linux
Shareable Vulkan image allocation on Linux relies on the dma-buf
interface, which is a Linux-specific thing. Therefore, we should only be
compiling it (and any code that uses it) on Linux. This change adds
preprocessor guards to do that. Enabling similar functionality on other
operating systems will need to leverage analogous interfaces on those
platforms, e.g. win32 handles on Windows.

All Vulkan image code will now be guarded by the USE_VULKAN_IMAGES
preprocessor definition, currently enabled on Linux if Vulkan is
available. Additionally, we shuffle around some code in
OpenGLContext.cpp to simplify the preprocessor conditionals.
2025-08-21 14:42:41 +02:00
Jelle Raaijmakers
871838dda3 Meta: Add Gregory Bertilson to maintainer list :^) 2025-08-21 14:20:45 +02:00
Callum Law
9122d0d014 LibWeb: Remove compute_defaulted_{values|property_value}
These functions are unused.
2025-08-21 13:49:21 +02:00
Callum Law
ce0fef7c45 LibWeb: Initialize properties before calling compute_{math_depth|font}
`StyleComputer::create_document_style` was the only place this wasn't
the case so we can remove the calls to
`compute_defaulted_property_value`. The call to
`compute_defaulted_values` in `create_document_style` is now redundant
so has been removed`
2025-08-21 13:49:21 +02:00
Callum Law
b267012ba7 LibWeb: Handle color: currentcolor in compute_properties
This was the last thing that `compute_defaulted_values` was doing when
called from here.

It also comes with the added benefit of us correctly inheriting animated
colors.
2025-08-21 13:49:21 +02:00
Callum Law
48832972b1 LibWeb: Handle -libweb-inherit-or-center in compute_text_align
This seems like a more natural place to handle this
2025-08-21 13:49:21 +02:00
Callum Law
ca9cb42ed4 LibWeb: Handle unset immediately in compute_properties
Previously we would hand off to `compute_defaulted_properties` to
resolve these values but there is no need as we can just resolve them
immediately.
2025-08-21 13:49:21 +02:00
Dan Vittegleo
c9fbc2db0b LibWeb: Implement CSS border radius overlapping algorithm
Fixes rendering of elements with large border-radius values by scaling
radii proportionally when they exceed element dimensions per CSS spec.

Co-authored-by: Samyat Gautam <thesamyatgautam@gmail.com>
2025-08-21 11:52:38 +02:00
Callum Law
9330bf4b72 LibWeb: Propagate animated values in recompute_inherited_style
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
As `recompute_inherited_style` works in-place rather than building
ComputedProperties from scratch we need to keep track of which animated
properties are inherited to know whether we should remove them when we
have no more inherited value.
2025-08-21 10:46:55 +01:00
Sam Atkins
0fc512e56d LibWeb/CSS: Reify UnresolvedStyleValue as CSSUnparsedValue 2025-08-21 10:21:54 +01:00
Sam Atkins
6428c9990d LibWeb/CSS: Implement CSSUnparsedValue and CSSVariableReferenceValue
We don't serialize these the way WPT expects, because we don't implement
the comment-insertion rules from CSS-Syntax. We don't implement that
for regular serialization either, so it's something we can worry about
later.
2025-08-21 10:21:54 +01:00
Sam Atkins
213a548b1f LibWeb/CSS: Implement CSSStyleValue.parse() and .parseAll()
The "subdivide into iterations" part is left as a FIXME for now, until
we have a way of knowing if a property is a list or not.

The parse_a_css_style_value() helper has an unwieldy return type because
of the requirement that it return either one value or a list of values,
but sticking to the spec here seems worthwhile for now.
2025-08-21 10:21:54 +01:00
Sam Atkins
3613181f54 LibWeb/CSS: Reify idents as CSSKeywordValue
For us, that's KeywordStyleValue and CustomIdentStyleValue.

CustomIdentStyleValue now has a .cpp file to reduce the number of
includes in its header file.
2025-08-21 10:21:54 +01:00
Sam Atkins
a93c6a347f LibWeb/CSS: Implement CSSKeywordValue
CSSStyleValue is adjusted to allow for subclasses. Serialization for
CSSKeywordValue is implemented differently than the spec says because
of a spec bug: https://github.com/w3c/csswg-drafts/issues/12545
2025-08-21 10:21:54 +01:00
Tim Ledbetter
030e670fcb LibWeb/SVG: Resolve stroke URI reference values
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
2025-08-21 00:33:53 +02:00
Tim Ledbetter
05432d7157 LibWeb/SVG: Resolve fill URI reference values 2025-08-21 00:33:53 +02:00
Jelle Raaijmakers
8d46a11748 CI: Pin js-benchmarks to current master
The output format for js-benchmarks is going to change, and while the
webhook parsing the results has not yet been updated pin the
js-benchmark checkout to a specific commit.
2025-08-21 00:30:42 +02:00
Ben Eidson
96b142e10b LibWeb/WebAudio: Add renderQuantumSize
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Adds this attribute to BaseAudioContext.idl and adds associated test for
OfflineAudioContext. This gives a set value that can be used to start
implementing OfflineAudioContext::start_rendering(). Updates idlharness
test to account for now implemented renderQuantumSize.
2025-08-20 14:51:01 +02:00
quonverbat
97d7316254 Documentation: Fix grammar error 2025-08-20 14:48:29 +02:00
quonverbat
cb742ee2ba Documentation: Fix capitalization and add Markdown
Some words were not capitalized and some tools were not in code blocks
2025-08-20 14:48:29 +02:00
Tim Ledbetter
4906afb2ae LibWeb: Set the initial value of stroke-dashoffset to 0px
Previously, an initial value of 0 was being used.
2025-08-20 14:30:51 +02:00
Jelle Raaijmakers
1a52fcd6ad LibWeb: Draw selected text with its own color
Other browsers such as Chrome and Firefox retain the text's color when
the text is part of a selection, so let's mimic them.
2025-08-20 14:30:16 +02:00
Jelle Raaijmakers
9887b52663 LibWeb: Convert fragment's enclosing device rect to IntRect just once
No functional changes.
2025-08-20 14:30:16 +02:00
Jelle Raaijmakers
51ce46859e LibWeb: Make DOM::Position's node mandatory
We can only construct positions if there's a node involved, which was
already enforced by Position::create() only accepting a GC::Ref.
2025-08-20 12:25:00 +01:00
Jelle Raaijmakers
cd08b3b6f4 LibWeb: Reset cursor blink cycle, even if there's no viewport paintable
If we programmatically set a selection in an editable element during
document load, we failed to start the cursor blink cycle timer. The
cursor blink logic already takes care of us not having the paintable
yet, so start it unconditionally.
2025-08-20 12:36:01 +02:00
Jamie Mansfield
97746fb574 LibGfx: Fix colour with Photoshop JPEG files using CMYK
This is based on the original functionality Lucus wrote prior to using
libjpeg.

Co-authored-by: Lucas CHOLLET <lucas.chollet@free.fr>
2025-08-20 12:04:39 +02:00