Commit graph

410 commits

Author SHA1 Message Date
Feng Yu
37e1d6ece1 LibWeb: Implement nagivator.serviceWorker.getRegistration() 2025-01-30 15:18:43 -07:00
Shannon Booth
ebd6d49415 LibWeb/HTML: Add fastpath to skip selectedness update on option insert
This extends the optimization introduced in the previous commit to
also apply to the inserted steps for an option element. This makes
the test:

https://wpt.live/html/select/options-length-too-large.html

Go from not ever completing due to how slow it was to running, to
finishing in 800ms on my PC :^)
2025-01-30 13:55:40 -07:00
Shannon Booth
075c7ea63e LibWeb/HTML: Add fastpath to skip selectedness update on children change
We can definitely expand on this a bunch more, but using the metadata
provided in the children change notification we are able to skip
runnning the expensive selectedness algorithm on the <select> element.

This removes children changed from appearing in the profile of:

https://wpt.live/html/select/options-length-too-large.html
2025-01-30 13:55:40 -07:00
Shannon Booth
903c8860f8 LibWeb: Add metadata to children update steps invocation
Currently, this metadata is only provided on the insertion steps,
though I believe it would be useful to extend to the other cases
as well. This metadata can aid in making optimizations for these
steps by providing extra context into the type of change which
was made on the child.
2025-01-30 13:55:40 -07:00
Shannon Booth
6c1470994b LibWeb/HTML: Add a helper for getting parent <select> for <option> 2025-01-30 13:55:40 -07:00
Shannon Booth
5b6b4d93a3 LibWeb/HTML: Add a cache for the list of Options for HTMLSelectElement
This is still called _way_ too often, and we need to be much smarter
about when this needs to run. But we get two wins from this very
naive implementation:

  1. There is a inner text setter nested within the selectedness
     steps uses this list of elements. This saves us building
     up a list of elements again within these steps.
  2. More importantly, it caches the number of selected elements.
     This already allows us to skip a minor amount of work iterating
     over the children again. But in future commits, this will serve
     as one of the criteria for skipping running the selectedness
     algorithm altogether for certain cases, which is a very big win.

A example future idea might be to append to this list directly when
something like appendChild is run instead of iterating over all of
the children again. But that's left as future work.
2025-01-30 13:55:40 -07:00
Shannon Booth
c647ac407d LibWeb/HTML: Avoid double lookup of size attribute 2025-01-30 13:55:40 -07:00
Shannon Booth
319b447fdd LibWeb/HTML: Remove uneeded FIXMEs about global being a Window
The spec only refers to this property as something that is on a
Window object, and as far as I can tell this API is only ever
exposed on a Window object anyhow.
2025-01-30 13:55:40 -07:00
Shannon Booth
1db568d06f LibWeb/HTML: Remove microtask invocation of update selectedness
This is fundametally broken. A microtask only finishes after all
javascript has finished running. The selectedness of a select element
is observable by javascript, so any changes which are made as a result
of children changing associated with a select element should be made
through the children update steps and friends.
2025-01-30 13:55:40 -07:00
Sam Atkins
385c3d273a LibWeb/CSS: Update CalculatedOr API to use CalculationResolutionContext
To be properly compatible with calc(), the resolved() methods all need:
- A length resolution context
- To return an Optional, as the calculation might not be resolvable

A bonus of this is that we can get rid of the overloads of `resolved()`
as they now all behave the same way.

A downside is a scattering of `value_or()` wherever these are used. It
might be the case that all unresolvable calculations have been rejected
before this point, but I'm not confident, and so I'll leave it like
this for now.
2025-01-30 19:31:54 +01:00
Luke Wilde
bf34b63439 LibWeb: Don't compare the focus chain's GC::Root contents by reference
The focus chain always consists of newly created GC::Root objects, so
the condition always produced `false`. The fix is to use GC::Root's
overloaded operator== method, which compares the pointers of the stored
type.

This fixes Figma dropdowns and context menus instantly disappearing
upon opening them. This is because they become focused when they insert
them. Because of this bug, it would fire blur events all the way up to
and including the window. Figma listens for the blur event on the
window, and when received, it will instantly hide dropdowns and context
menus. The intention behind this seems to be hiding them when the user
clicks off the browser window, or switches tab.
2025-01-30 19:30:44 +01:00
Tim Ledbetter
11acd54463 LibWeb: Change default window ESO crossOriginIsolated value to false
This is a safer default value for this property since we don't
currently implement the mechanisms required for this value to be true.
2025-01-30 18:37:53 +01:00
Sam Atkins
3775f3399c LibWeb: Fix various typos
Corresponds to:
- https://github.com/whatwg/html/pull/10934
- https://github.com/whatwg/html/pull/10950
2025-01-30 15:00:16 +00:00
Sam Atkins
c5d793c4a9 LibWeb: Split out CanvasSettings IDL interface mixin
Corresponds to https://github.com/whatwg/html/pull/10904

However, we don't implement most of what is changed in that PR, so this
simply moves the FIXME'd getContextAttributes() method from one place
to another.
2025-01-30 15:00:16 +00:00
Sam Atkins
3e4b1056b5 LibWeb: Consistently use navigables for WebDriver BiDi
Corresponds to https://github.com/whatwg/html/pull/10909
2025-01-30 15:00:16 +00:00
Sam Atkins
f0c597a446 LibWeb/HTML: Use WorkerGlobalScope as Trusted Type sink global name
Corresponds to https://github.com/whatwg/html/pull/10913
2025-01-30 15:00:16 +00: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
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
Psychpsyo
67ed676831 LibWeb: Implement CSS 'contain' property 2025-01-28 11:24:40 +00: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
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
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
Luke Warlow
391a08bf17 LibWeb: Update spec comments for dialog, popover and close watcher 2025-01-25 03:40:08 +00:00
Sam Atkins
d7ea949d2f LibWeb/HTML: Convert drop-shadow() lengths to pixels
Using the raw value meant that 1em would be incorrectly treated as 1px,
for example.

I've updated our canvas-filters test to demonstrate this - without the
code change this would instead have an x-offset of 2px.
2025-01-24 13:55:52 +01:00
Luke Warlow
f5860a3b7d LibWeb: Implement hidden="until-found" IDL support
Follow-ups will implement the actual behaviour.
2025-01-24 09:08:37 +01:00
Andreas Kling
adc25af8e2 LibWeb: Make "assign slottables for a tree" fast when there are no slots
We achieve this by keeping track of the number of HTMLSlotElements
inside each ShadowRoot (do via ad-hoc insertion and removal steps.)

This allows slottables assignment to skip over entire shadow roots when
we know they have no slots anyway.

Massive speedup on https://wpt.fyi/ which no longer takes minutes/hours
to load, but instead a "mere" 19 seconds. :^)
2025-01-23 21:38:31 +01:00
Andreas Kling
003c045589 LibWeb: Add missing base class upcalls in Node::inserted() overrides 2025-01-23 21:38:31 +01:00
Andreas Kling
7269fc3e52 LibWeb: Pass old parent's root to Node::removed_from()
This will allow nodes to access the root they've just been removed from.
2025-01-23 21:38:31 +01:00
Jelle Raaijmakers
336684bc5c LibWeb: Support inserting non-inline elements into inline elements
Our layout tree requires that all containers either have inline or
non-inline children. In order to support the layout of non-inline
elements inside inline elements, we need to do a bit of tree
restructuring. It effectively simulates temporarily closing all inline
nodes, appending the block element, and resumes appending to the last
open inline node.

The acid1.txt expectation needed to be updated to reflect the fact that
we now hoist its <p> elements out of the inline <form> they were in.
Visually, the before and after situations for acid1.html are identical.
2025-01-23 09:33:10 +01:00
Shannon Booth
fd27eef0d1 LibWeb: Return OptionalNone from DOMURL::parse on failure
This ports one more function away from needing to use the awkward
valid state of the URL class.
2025-01-22 12:33:55 +00:00
Psychpsyo
d5c21301db LibWeb: Fix context menu and select dropdown position in iframe 2025-01-22 12:25:48 +00:00
Shannon Booth
ca3d9d9ee0 LibURL+LibWeb+LibIPC: Represent blob URL entry's object using structs
Instead of just putting in members directly, wrap them up in structs
which represent what a URL blob entry is meant to hold per the spec.
This makes more obvious what this is meant to represent, such as the
ByteBuffer being used to represent the bytes behind a Blob.

This also allows us to use a stronger type for a function that needs
to return a Blob URL entry's object.
2025-01-21 19:22:07 +00:00
Sam Atkins
d40ccb97ec LibWeb/HTML: Update Navigable::choose_a_navigable() to latest spec
This corresponds to part of https://github.com/whatwg/html/pull/10818
2025-01-21 18:17:18 +01:00
Timothy Flynn
85b424464a AK+Everywhere: Rename verify_cast to as
Follow-up to fc20e61e72.
2025-01-21 11:34:06 -05:00
Andreas Kling
a0b44ff5e7 LibWeb: Iterate over a copy of associated form controls in form.reset()
DOM structure may change during reset algorithm invocation, which may
lead to form controls being unregistered.
2025-01-21 17:02:51 +01:00
Shannon Booth
ef793d8679 LibWeb/HTML: Support blob URLs in HTMLLinkElement
We are meant to apply the 'URL parser' here, which indicates that
this should work with Blob URLs.
2025-01-21 10:49:39 +00:00
Gingeh
bf36d829ef LibWeb: Only reload link on rel change if it became a stylesheet 2025-01-20 18:21:20 +01:00
Shannon Booth
fe7d7f6f6b LibWeb/HTML: Enable callbacks in postMessage deserialization
Interestingly, the spec has a note saying:

> window.postMessage() performs StructuredSerializeWithTransfer on
> its arguments, but is careful to do so immediately, inside the
> synchronous portion of its algorithm. Thus it is able to use the
> algorithms without needing to prepare to run script and prepare
> to run a callback.

But there is no note about the deserialization steps. In any case, we do
need callbacks enabled here.
2025-01-20 07:52:30 -05:00
Shannon Booth
bfbc0124c0 LibWeb/HTML: Pubically expose entangled port and post message steps
These are needed for the implementation of Transferable streams.
2025-01-20 07:52:30 -05:00
Shannon Booth
9f0660c8f0 LibWeb/HTML: Start MessagePort's port messsge queue in onmessage setter
...Which doesn't do anything given start() itself doesn't do anything,
but this is a subtle enough point of the spec that it seems worthwhile
to implement now for whenever this does become meaningful.
2025-01-20 07:52:30 -05:00
Shannon Booth
f8df624171 LibWeb/HTML: Do not use macro to implement MessagePort event handlers
This is not really any more code, and will make it easier to implement
the custom behaviour specified for the onmessage setter.
2025-01-20 07:52:30 -05:00
Timothy Flynn
43dc0f52a6 LibWeb: Do not run microtasks when the event loop is paused
For example, running `alert(1)` will pause the event loop, during which
time no JavaScript should execute. This patch extends this disruption to
microtasks. This avoids a crash inside the microtask executor, which
asserts the JS execution context stack is empty.

This makes us behave the same as Firefox in the following page:

    <script>
        queueMicrotask(() => {
            console.log("inside microtask");
        });

        alert("hi");
    </script>

Before the aforementioned assertion was added, we would execute that
microtask before showing the alert. Firefox does not do this, and now
we don't either.
2025-01-19 20:47:50 +00:00
Gingeh
58c78cb003 LibWeb: Update the select label when option's children are changed 2025-01-19 19:22:32 +01:00
Timothy Flynn
59a4203cf0 LibWeb: Implement the exclusive <details> accordion
This is a relatively new feature which allows naming <details> groups to
ensure only one <details> element in that group is opened at a time.
2025-01-17 10:13:35 +01:00
Timothy Flynn
1fb1d5fcb9 LibWeb: Update the HTMLDetailsElement attribute change steps
No functional change here, but this contains spec steps to handle the
'name' attribute (not implemented here).
2025-01-17 10:13:35 +01:00
Shannon Booth
ac9670fb55 LibWeb/HTML: Fix grammar in spec note for error checking serialization
See: 90720ff
2025-01-17 10:08:42 +01:00
Shannon Booth
76397c9ecd LibWeb: Use finalize for cleaning up all navigables
The use of this HashMap looks very spooky, but let's at least use
finalize when cleaning them up on destruction to make things slightly
less dangerous looking.
2025-01-17 10:08:42 +01:00
Tim Ledbetter
3d20587911 LibWeb: Fetch source file when HTMLTrackElement src attribute changes
This commit begins to implement the track processing model. When the
`src` attribute is updated, we now fetch the given source file.
Currently, we always fire an `error` event once fetching is completed,
as we don't support processing the fetched data.
2025-01-15 20:59:18 +01:00