Commit graph

66966 commits

Author SHA1 Message Date
Jelle Raaijmakers
e7add9abc6 LibWeb: Remove unnecessary const_casts from TextPaintable 2025-01-31 13:37:15 +01:00
Jelle Raaijmakers
cbe78454fc LibWeb: Remove unused includes from PaintableFragment 2025-01-31 13:37:15 +01:00
Jelle Raaijmakers
342cb7addf LibGfx+LibWeb: Reuse DisplayListPlayer and PaintingSurface when possible
Previously, we were reinstantiating the DisplayListPlayer and
PaintingSurface on every paint.
2025-01-31 13:28:09 +01:00
Jelle Raaijmakers
a4639b3d8e LibGfx: Remove superfluous Gfx::s from PaintingSurface
No functional changes.
2025-01-31 13:28:09 +01:00
Jelle Raaijmakers
7b3d4a9edb LibWeb: Cache Skia backend context in TraversableNavigable
We just need to create the backend context once and let Skia handle the
context's state.

On my machine, this reduces the load time for https://tweakers.net from
7.5s to 3.5s.
2025-01-31 13:28:09 +01:00
Jelle Raaijmakers
1d81c4d8eb LibGfx: Use same order for macOS and Vulkan specific code
No functional changes.
2025-01-31 13:28:09 +01:00
Jelle Raaijmakers
4fbeea6482 LibWeb+Services: Remove unused #includes
No functional changes.
2025-01-31 13:28:09 +01:00
Jelle Raaijmakers
20fbd38b77 LibWeb: Remove MetalContext from TraversableNavigable
There's no need for TraversableNavigable to keep track of the
MetalContext; our SkiaBackendContext keeps a reference to it.
2025-01-31 13:28:09 +01:00
sideshowbarker
738cb24691 LibWeb: Fire keypress event for Enter, Shift+Enter, and Ctrl+Enter keys
For web compat and interop with other engines, this change makes us fire
“keypress” events for the Enter key and for the combination of the Enter
key with the Shift or Ctrl keys — despite the fact the UI Events spec
states at https://w3c.github.io/uievents/#event-type-keypress it must be
fired “if and only if that key normally produces a character value”.

See https://github.com/w3c/uievents/issues/183#issuecomment-448091687
and https://github.com/w3c/uievents/issues/266#issuecomment-1887917756.
2025-01-31 12:07:17 +00:00
Tim Ledbetter
be38acfad9 Revert "WebWorker: Prefer the default EventLoopManager over Qt's…"
…specialization"

This was causing WPT tests using Workers to time out.

This reverts commit a1cf5271c2.
2025-01-31 10:58:31 +00:00
Feng Yu
30d1eb4caf LibWeb/Fetch: Sync with spec update (whatwg/fetch#1569)
This patch synchronizes changes from whatwg/fetch#1569 and
resolves a related FIXME: "Refactor this to the new version of the
spec introduced with whatwg/fetch@464326e.”
2025-01-30 16:24:50 -07:00
Aliaksandr Kalenik
a4c331c199 LibWeb: Fix unnecessary wheel event consumption with overflow: scroll
Allow wheel event to be consumed by a `overflow: scroll` box only if it
has content that overflows a scrollport.

This fixes the timing issue in the
`Text/input/scroll-window-using-wheel-event.html` test, where a `<body>`
element with `overflow: scroll` was incorrectly consuming wheel events
that should have propagated to the window.
2025-01-31 00:11:34 +01:00
Aliaksandr Kalenik
74dde4dc0f LibWeb: Rename is_scrollable() to could_be_scrolled_by_wheel_event()
Previous name for misleading because it checks if box could be scrolled
by user input event which is diffent from checking if box is scrollable.
For example box with `overflow: hidden` is scrollable but it can't be
scrolled by user input event.
2025-01-31 00:11:34 +01:00
Luke Warlow
dd37d1c536 LibWeb: Implement dialog.requestClose() 2025-01-30 15:50:06 -07:00
Gingeh
b056e27afd LibWeb: Hide visible popover when type is changed 2025-01-30 15:46:52 -07:00
Gingeh
e670caeb0c LibWeb: Ignore DOM state when hiding removed popovers
Using https://github.com/whatwg/html/pull/9457
(with some changes made to catch up with the current spec)
to fix a spec bug and a crash when removing a visible popover.
2025-01-30 15:46:52 -07:00
Gingeh
108f3a9aac LibWeb: Implement popovertarget buttons 2025-01-30 15:46:52 -07:00
Lucas CHOLLET
a1cf5271c2 WebWorker: Prefer the default EventLoopManager over Qt's specialization 2025-01-30 15:34:02 -07:00
Lucas CHOLLET
e015a43b51 LibCore: Remove unused methods from EventLoop 2025-01-30 15:34:02 -07:00
Feng Yu
37e1d6ece1 LibWeb: Implement nagivator.serviceWorker.getRegistration() 2025-01-30 15:18:43 -07:00
Shannon Booth
8e410f959c LibWeb/FileAPI: Implement aborting a FileReader read
This fixes a timeout for the included WPT test.
2025-01-30 14:25:27 -07:00
Shannon Booth
33e80fbf51 LibWeb/FileAPI: Correctly fire an error event on error reading file
I can't find of a way to trigger this codepath, and there is for sure no
correpsonding WPT test, but let's fix this up for whenever it does
become relevant.
2025-01-30 14:25:27 -07:00
Shannon Booth
b58ba2e1bd LibJS: Localize popping of execution context in AsyncFunctionDriver
Instead of adding a flag for the two callers that need a pop of the
execution context stack when invoking continue_async_execution inline
the pop of the execution context.

This makes the management of these stacks and surrounding VERIFY calls
much more obvious.
2025-01-30 13:57:29 -07:00
Shannon Booth
d1f9e3be90 LibJS: Only run queued promise jobs if there is no embedder
This has no functional difference as run_queued_promise jobs does
nothing when LibWeb is used as it has a different implementation of
enqueuing and running promise jobs. But this change makes it more
obvious that run_queued_promise jobs does nothing when there is an
embedder, and adjusts the comment to reflect what the code is
actually achieving.
2025-01-30 13:57:29 -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
Luke Wilde
b35979c3f7 LibWeb: Set Sec-Fetch-Site header to same-site where appropriate
This also fixes it looking at the request's current URL origin instead
of the request's actual origin.
2025-01-30 19:32:57 +01:00
Sam Atkins
f8cc990bcd LibWeb/CSS: Remove ad-hoc calc simplification from var/attr() expansion
Now that we simplify calculations after parsing them, this is redundant.
2025-01-30 19:31:54 +01:00
Sam Atkins
ee712bd98f LibWeb/CSS: Simplify calculations after parsing them
If a calculation was simplified down to a single numeric node, then most
of the time we can instead return a regular StyleValue, for example
`calc(2px + 3px)` would be simplified down to a `5px` LengthStyleValue.
This means that parse_calculated_value() can't return a
CalculatedStyleValue directly, and its callers all have to handle
non-calculated values as well as calculated ones.

This simplification is reflected in the new test results. Serialization
is not yet correct in all cases but we're closer than we were. :^)
2025-01-30 19:31:54 +01:00
Sam Atkins
39cefd7abf LibWeb/CSS: Tell CalculationContext whether to treat numbers as integers
Calc simplification eventually produces a single style-value as its
output. This extra context data will let us know whether a calculated
number should be treated as a `<number>` or an `<integer>`, so that for
example, `z-index: 12` and `z-index: calc(12)` both produce an
`IntegerStyleValue` containing 12.
2025-01-30 19:31:54 +01:00
Sam Atkins
91831438e0 LibWeb/CSS: Implement "simplify a calculation" algorithm
This is not yet called anywhere.
2025-01-30 19:31:54 +01:00
Sam Atkins
581f5dfc86 LibWeb/CSS: Remove inaccurate VERIFY from CalculationResult::from_value
The goal of this VERIFY was to ensure that we didn't mess up the logic
for calculating the correct type. However, it's now unable to do so
because it doesn't have access to the CalculationContext, which
determines what type percentages are. This makes it crash when running
the simplification algorithm. The benefits of this check are small, and
it meant doing extra work, so let's just remove it.
2025-01-30 19:31:54 +01:00
Sam Atkins
b947ae60db LibWeb/CSS: Remove custom <integer> parsing from math-depth 2025-01-30 19:31:54 +01:00
Sam Atkins
37f6c09984 LibWeb/CSS: Add some FIXME comments for missing math-function features 2025-01-30 19:31:54 +01:00
Sam Atkins
46b9497a66 LibWeb/CSS: Make non-finite Numbers serialize as themselves
We're required to serialize NaN, infinity, and -infinity as their
keyword names, even after they've been converted to Numbers.
2025-01-30 19:31:54 +01:00
Sam Atkins
c3d61020e7 LibWeb/CSS: Make CalculationNodes ref-counted
Calc simplification (which I'm working towards) involves repeatedly
deriving a new calculation tree from an existing one, and in many
cases, either the whole result or a portion of it will be identical to
that of the original. Using RefPtr lets us avoid making unnecessary
copies. As a bonus it will also make it easier to return either `this`
or a new node.

In future we could also cache commonly-used nodes, similar to how we do
so for 1px and 0px LengthStyleValues and various keywords.
2025-01-30 19:31:54 +01: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
Sam Atkins
1d71662f31 LibWeb/CSS: Wrap calc()-resolution data in a struct
Initially I added this to the existing CalculationContext, but in
reality, we have some data at parse-time and different data at
resolve-time, so it made more sense to keep those separate.

Instead of needing a variety of methods for resolving a Foo, depending
on whether we have a Layout::Node available, or a percentage basis, or
a length resolution context... put those in a
CalculationResolutionContext, and just pass that one thing to these
methods. This also removes the need for separate resolve_*_percentage()
methods, because we can just pass the percentage basis in to the regular
resolve_foo() method.

This also corrects the issue that *any* calculation may need to resolve
lengths, but we previously only passed a length resolution context to
specific types in some situations. Now, they can all have one available,
though it's up to the caller to provide it.
2025-01-30 19:31:54 +01:00
Andreas Kling
ad9d9bb684 LibWeb: Ensure size constraints apply to non-BFC-root abspos boxes
BFC roots behave differently in that their height is computed twice,
before and after inside layout, since automatic height depends on the
results of inside layout. Other formatting contexts only require the
"before" pass, and so we can treat their content sizes as definite
before proceeding with inside layout.

This makes https://play.tailwind.com/ look beautiful. :^)
2025-01-30 19:31:07 +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
fac88b698f LibWeb: Disable time origin WPT test
This test's use of Workers causes intermittent failures on MacOS.
2025-01-30 18:37:53 +01:00
Tim Ledbetter
0fd8270783 LibWeb: Disable flaky navigation timing test 2025-01-30 18:37:53 +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
Tim Ledbetter
39445d6dd6 LibWeb: Implement basic high resolution time coarsening
Several interfaces that return a high resolution time require that
time to be coarsened, in order to prevent timing attacks. This
implementation simply reduces the resolution of the returned timestamp
to the minimum values given in the specification. Further work may be
needed to make our implementation more robust to the kind of attacks
that this mechanism is designed to prevent.
2025-01-30 18:37:53 +01:00