Commit graph

8835 commits

Author SHA1 Message Date
Sam Atkins
8877a4f691 LibWeb/CSS: Hide "No property (from N properties) matched foo" message
This greatly reduces the amount of log spam on certain websites.
2025-01-29 12:04:14 +00:00
devgianlu
12ca074671 LibCrypto: Always handle SECPxxxr1 scalars with leading zeros
It may happen that the scalars used by SECPxxxr1 turn out to be slightly
smaller than their actual size when serialized to `UnsignedBigInteger`,
especially for P521. Handle this case by serializing zeros instead of
failing.

Originally discovered as a flaky WPT test.
2025-01-29 12:46:46 +01:00
Shannon Booth
1126049b91 LibWeb/DOM: Remove FIXME dbgln about unknown element name creation
Now that we have implemented most of the element types, this dbgln
is a lot less useful for detecting issues on live sites, and is in
my experience more likely to log cases that are not a FIXME. It also
cleans up some of the log spam from running tests.
2025-01-29 11:28:11 +01:00
Aliaksandr Kalenik
d762d16938 LibWeb: Use invalidation sets for :has() invalidation
Prior to this change, we invalidated all elements in the document if it
used any selectors with :has(). This change aims to improve that by
applying a combination of techniques:
- Collect metadata for each element if it was matched against a selector
  with :has() in the subject position. This is needed to invalidate all
  elements that could be affected by selectors like `div:has(.a:empty)`
  because they are not covered by the invalidation sets.
- Use invalidation sets to invalidate elements that are affected by
  selectors with :has() in a non-subject position.

Selectors like `.a:has(.b) + .c` still cause whole-document invalidation
because invalidation sets cover only descendants, not siblings. As a
result, there is no performance improvement on github.com due to this
limitation. However, youtube.com and discord.com benefit from this
change.
2025-01-29 09:30:18 +01:00
Aliaksandr Kalenik
e33037ad52 LibWeb: Add method to check if element affected by invalidation set
...by replacing existing method to check if an element is affected by
invalidation property. It turned out there is no need to check if an
element is affected only by some specific property, so it's more
convenient to have a method that accepts the whole set.
2025-01-29 09:30:18 +01:00
Aliaksandr Kalenik
74dc335b28 LibWeb: Allow to early break from InvalidationSet::for_each_property() 2025-01-29 09:30:18 +01:00
Luke Wilde
3295ed17ea LibWeb: Use application/octet-stream for unknown FormData file types
Required by web.whatsapp.com, which uses fetch() to send FormData
bodies containing Files with empty types.
Ref https://github.com/LadybirdBrowser/ladybird/issues/2941
2025-01-29 09:25:40 +01:00
Luke Wilde
18b75afef8 LibWeb: Fire resize event at VisualViewport in the resize steps
Used on x.com to determine the layout to use on resize.
2025-01-29 09:23:52 +01:00
Luke Wilde
d21bac8028 LibWeb: Mark the Window resize event as trusted 2025-01-29 09:23:52 +01:00
Luke Wilde
f4649aa40d LibWeb/WebGL: Implement copyTexSubImage2D
Used by d3wasm for effects that use the current framebuffer as the
texture, such as screen wipes.
2025-01-28 19:01:40 +01:00
Luke Wilde
46f986bc2b LibWeb/WebGL: Implement copyTexImage2D
Used by d3wasm for effects that use the current framebuffer as the
texture, such as screen wipes.
2025-01-28 19:01:40 +01:00
Aliaksandr Kalenik
748d316973 LibWeb: Avoid separate tree traversal to mark for inherited style update
...in hover style invalidation. Instead, pass down a flag that indicates
all subsequent nodes in tree traversal have to be marked for inherited
style update.
2025-01-28 18:55:42 +01:00
Aliaksandr Kalenik
db47fa3db1 LibWeb: Use ancestor filters for hover style invalidation
By using ancestor filters some selectors could be early rejected
skipping selector engine invocation. According to my measurements it's
30-80% hover selectors depending on the website.
2025-01-28 18:55:42 +01:00
Aliaksandr Kalenik
b153420feb LibWeb: Reduce memory usage in hover style invalidation
Instead of allocating 3 vectors with size equal to the number of
elements potentially affected by hover:
- for the elements themselves
- for selector match state of each element before hovered node change
- for selector match state of each element after hovered node change

now we allocate none of them, but mark element for style recalculation
as we traverse the tree.
2025-01-28 18:55:42 +01:00
Shannon Booth
eca68aad88 LibWeb/FileAPI: Implement FileReader readAsBinaryString 2025-01-28 11:39:23 +00:00
Aliaksandr Kalenik
d79bb1aac2 LibWeb: Fix underinvalidation when inline style has custom properties
We have an optimization that allows us to invalidate only the style of
the element itself and mark descendants for inherited properties update
when the "style" attribute changes (unless there are any CSS rules that
use the "style" attribute, then we also invalidate all descendants that
might be affected by those rules). This optimization was not taking into
account that when the inline style has custom properties, we also need
to invalidate all descendants whose style might be affected by them.

This change fixes this bug by saving a flag in Element that indicates
whether its style depends on any custom properties and then invalidating
all descendants with this flag set when the "style" attribute changes.
Unlike font relative lengths invalidation, for elements that depend on
custom properties, we need to actually recompute the style, instead of
individual properties, because values without expanded custom properties
are gone after cascading, and it has to be done again.

The test added for this change is a version of an existing test we had
restructured such that it doesn't trigger aggressive style invalidation
caused by DOM structured changes until the last moment when test results
are printed.
2025-01-28 11:38:06 +00:00
Tim Ledbetter
8b5a25e47f LibWeb: Generate correct timestamp values when updating animations
Previously, we were generating timestamps relative to the current time
of the monotonic clock. We now generate timestamps relative to the
event loop's last render opportunity time, per the spec.
2025-01-28 11:31:46 +00:00
Timothy Flynn
5372d07c5c LibJS: Simplify ParseTemporalCalendarString
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/1b1fd9f
2025-01-28 11:25:42 +00:00
Psychpsyo
67ed676831 LibWeb: Implement CSS 'contain' property 2025-01-28 11:24:40 +00:00
Andreas Kling
c53c781745 LibWeb: Inline CSSStyleValue::to_keyword()
Shaves 120 ms of loading time off of https://wpt.fyi/
2025-01-28 01:12:45 +01:00
Andreas Kling
30cbd4bcfb LibWeb: Avoid unnecessary copies in BorderRadiusStyleValue::absolutize()
Shaves 30ms off of the load time on https://wpt.fyi/
2025-01-28 01:12:45 +01:00
Andreas Kling
b5e70908aa LibWeb: Segregate StyleComputer rule caches per Document-or-ShadowRoot
This means we only need to consider rules from the document and the
current shadow root, instead of the document and *every* shadow root.

Dramatically reduces the amount of rules processed on many pages.

Shaves 2.5 seconds of load time off of https://wpt.fyi/ :^)
2025-01-28 01:12:45 +01:00
Jelle Raaijmakers
e8bc6e9e8e LibWeb: Set float Y offset using margin box bottom instead of height
When positioning floats against an edge, we are taking all current
relevant floats at that side into account to determine the Y offset at
which to place the new float. However, we were using the margin box
height instead of the absolute bottom position, which disregards the
current float's Y-position within the root, and we were setting the Y
offset to that height, instead of taking the new float's Y position
inside of the root into account.

The new code determines the lowest margin bottom value within the root
of the current floats, and adds the difference between that value and
the new float's Y position to the Y offset.
2025-01-28 01:12:23 +01:00
Jelle Raaijmakers
0cfc7f2c8a LibWeb: Move LayoutState::set_content_* methods inline
I see no good reason to keep them out of line, and having the methods
named differently than the property they're updating caused me some
confusion initially.
2025-01-28 01:12:23 +01:00
Shannon Booth
d4649db55e LibWeb/URLPattern: Add initial stub for URLPattern interface 2025-01-27 18:07:17 +00:00
Shannon Booth
46bfced9ad LibURL: Add representations of URLPattern{Init,Options,Input}
The URLPattern spec is intended to be implemented inside of LibURL, with
LibWeb only responsible for the IDL conversion layer, in a similar
manner to how URL is implemented.
2025-01-27 18:07:17 +00:00
Tim Ledbetter
05351dfe45 LibWeb: Return wall time from PerformanceTiming interface
This matches the behavior of other browsers.
2025-01-27 14:53:33 +01:00
Tim Ledbetter
7488136a51 LibWeb: Report performance based timestamps relative to ESO time origin 2025-01-27 14:53:33 +01:00
Tim Ledbetter
8963e62a5e LibWeb: Add a time origin property for all ESOs
This acts as a baseline for performance related timestamps.
2025-01-27 14:53:33 +01:00
Tim Ledbetter
a8904451ff LibWeb: Set navigation start time when creating a new Document
This currently uses a non spec-compliant property on the Response
object, which represents the time that the Response was created.

Setting this value allows `Performance.timeOrigin` to return a
reasonable value.
2025-01-27 14:53:33 +01:00
Tim Ledbetter
ddea1c6248 LibWeb: Store response creation time as MonotonicTime
This non-standard value is used for calculating durations relative to
when the response was created. MonotonicTime is more suitable for this
use case.
2025-01-27 14:53:33 +01:00
devgianlu
1d207aa0d8 LibCrypto: De-templetize and move SECPxxxr1 methods out of line 2025-01-27 12:24:48 +01:00
devgianlu
cceb7110fc LibCrypto: Remove old SECPxxxr1 math 2025-01-27 12:24:48 +01:00
devgianlu
cf5ce8277f LibCrypto: Use OpenSSL for SECPxxxr1 sign/verify operations 2025-01-27 12:24:48 +01:00
devgianlu
f2e530ec14 LibCrypto: Make SECPxxxr1Signature carry the scalar size
Our `UnsignedBigInteger` implementation cannot handle numbers whose
size is not a multiple of 4. For this reason we need to carry the real
size around for P-521 support.
2025-01-27 12:24:48 +01:00
devgianlu
fd2014f5c2 LibCrypto: Use OpenSSL for SECPxxxr1 point computation 2025-01-27 12:24:48 +01:00
devgianlu
aefffa9455 LibCrypto: Use OpenSSL for SECPxxxr1 key generation 2025-01-27 12:24:48 +01:00
devgianlu
de6f77e7e3 LibCrypto: Print all descriptive OpenSSL errors
The code was printing one error message only, but multiple can be
generated in one call. Additionally, using this builtin produces
a much more descriptive output.
2025-01-27 12:24:48 +01:00
stasoid
c580763743 LibCore: Don't search fonts in system_data_directories() on Windows
Fonts on Windows are stored only in %WINDIR%\Fonts and
%LOCALAPPDATA%\Microsoft\Windows\Fonts, see https://stackoverflow.com/a/67078786

And system_data_directories() is not implemented on Windows yet.
2025-01-27 09:25:17 +00:00
Shannon Booth
802529bafc LibWeb/HTML: Iterate over select options in tree order
This also saves us from iterating twice over the children, and
instead do it in a single pass.
2025-01-27 00:10:14 +00:00
Shannon Booth
4f80c7a5f3 LibWeb/DOM: Use as_if for node of type checks in iteration helpers
These are very hot functions in profiles, so let's avoid a potential
double dynamic_cast or virtual call. For consistency, port all of
these classes of function over to 'as_if' instead.
2025-01-27 00:10:14 +00:00
Shannon Booth
31dc1fa662 LibWeb/HTML: Only get list of options once in 'update selectedness'
It is not cheap to do this, so only do it once within this function.
There is definitely some caching that we can do here, but this will
require some smart invalidation to detect _relevant_ changes in
the children.
2025-01-27 00:10:14 +00:00
Shannon Booth
14eb081af8 LibWeb: Add missing calls to Base::children_changed
Also making sure that it is called at the top of the implementation
for consistency.
2025-01-27 00:10:14 +00:00
Shannon Booth
22a7cd9700 LibWeb: Port Document encoding_parse_url and parse_url to Optional<URL>
This ports two more APIs away from URL::is_valid.
2025-01-27 00:03:07 +00:00
Aliaksandr Kalenik
cfe9b7a82b LibWeb: Recompute relative units in Element::recompute_inherited_style()
Properties with relative units has to be recomputed in inherited style
update as they depend on the parent's style.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/3364
2025-01-26 23:10:58 +01:00
Andreas Kling
f35152cf61 LibWeb: Defer entire-subtree style invalidations
Instead of traversing the entire DOM subtrees and marking nodes for
style update, this patch adds a new mechanism where we can mark a
subtree root as "entire subtree needs style update".

A new pass in Document::update_style() then takes care of coalescing
all these invalidations in a single traversal of the DOM.

This shaves *minutes* of loading time off of https://wpt.fyi/ subpages.
2025-01-26 22:58:42 +01:00
Jelle Raaijmakers
84c4702b10 LibWeb: Handle continuation chain during hit-testing instead of after it
My previous attempt at resolving the continuation chain tried to deal
with `pointer-events: none` by repeatedly falling back to the parent
paintable until one was found that _would_ want to handle pointer
events. But since we were no longer performing hit-tests on those
paintables, false positives could pop up. This could happen for
out-of-flow block elements that did not overlap with their parent rects,
for example.

This approach works much better since it only handles the continuation
case that's relevant (the "middle" anonymous box) and it does so during
hit-testing instead of after, allowing all the other relevant logic to
come into play.
2025-01-26 17:30:00 +01:00
Jelle Raaijmakers
522aa41667 LibWeb: Honor pointer-events for PaintableBox in own stacking context
If a block element with its own stacking context has `pointer-events:
none` set, it should be ignored as far as hit-testing goes.

Fixes #3357.
2025-01-26 17:30:00 +01:00
Andreas Kling
a87ae785fd LibWeb: Cache style sheet's default namespace in MatchingRule
This avoids looking up the default namespace rule for every rule we
consider running.

Shaves ~900ms of loading time off of https://wpt.fyi/
2025-01-26 15:07:23 +01:00
Andreas Kling
801b3f434f LibWeb: Avoid calling Element::is_shadow_host() for each CSS rule
Instead just cache the element's shadow root locally, if any. This
shaves ~1 second off the loading time of https://wpt.fyi/
2025-01-26 15:07:23 +01:00