Commit Graph

7029 Commits

Author SHA1 Message Date
Praise-Garfield
6a3b9c5ffc LibWeb: Use correct condition and field for navigation initiator origin
The guard for setting top-level navigation initiator origin called
top_level_traversable()->parent() == nullptr, which is tautologically
true: top_level_traversable() already walks to the topmost traversable,
whose parent is always null. This caused the field to be set on every
navigation, including child navigable navigations inside iframes.

The value was also read from document_state()->origin() instead of
document_state()->initiator_origin(), giving the document's own origin
rather than the origin of whoever initiated the navigation.

Use is_top_level_traversable() and initiator_origin() to match the
spec step.
2026-02-23 13:07:32 +01:00
Callum Law
8d4084261a LibWeb: Resolve list item marker using registered counter styles 2026-02-23 11:21:09 +00:00
Callum Law
ca54cc6c79 LibWeb: Resolve <counter> functions using registered counter styles
Previously we only supported a subset of the predefined counter styles,
we now respect counter styles defined by `@counter-style` rules when
resolving the value of `counter()` and `counters()` functions
2026-02-23 11:21:09 +00:00
Callum Law
2008c6be5a LibWeb: Add predefined @counter-styles to UA stylesheet
There are some predefined counter styles (such as the longhand east
asian ones) which are too complex to be defined here and will need to be
implemented ad-hoc, this remains as a FIXME for now.
2026-02-23 11:21:09 +00:00
Callum Law
3e9cdb2cf4 LibWeb: Store whether sheet being parsed is a UA stylesheet
UA stylesheets allow some things that regular stylesheets don't, for
instance allowing use of "non-overridable" `@counter-style` names.
2026-02-23 11:21:09 +00:00
Callum Law
73b07d25ac LibWeb: Resolve and register counter styles from @counter-style rules
The tricky bit of this is resolving cycles in extending rules and
ensuring that counter styles are registered in the required order for
extension (i.e. for any pair of extended/extending rules the extended
one should be registered first).
2026-02-23 11:21:09 +00:00
Callum Law
3d150e46c2 LibWeb: Avoid template for StyleScope::for_each_stylesheet
This only ever takes a `Function<void(CSS::CSSStyleSheet&)` so there is
no need to use a template here.
2026-02-23 11:21:09 +00:00
Callum Law
2cc3fbb017 LibWeb: Pass callback as lvalue ref in for_each_active_stylesheet
Taking the callback as an rvalue ref meant we couldn't use the same
callback more than once
2026-02-23 11:21:09 +00:00
Callum Law
0002d1cfc3 LibWeb: Implement algorithm to generate a counter representation 2026-02-23 11:21:09 +00:00
Callum Law
63e2ed3cd9 LibWeb: Implement counter style fixed algorithm 2026-02-23 11:21:09 +00:00
Callum Law
fb239ceba0 LibWeb: Implement counter style symbolic algorithm 2026-02-23 11:21:09 +00:00
Callum Law
fddeb032b4 LibWeb: Implement counter style alphabetic algorithm 2026-02-23 11:21:09 +00:00
Callum Law
0a2fe1607c LibWeb: Implement counter style numeric algorithm 2026-02-23 11:21:09 +00:00
Callum Law
85c367667e LibWeb: Implement counter style cyclic algorithm 2026-02-23 11:21:09 +00:00
Callum Law
2827e12571 LibWeb: Implement counter style additive algorithm 2026-02-23 11:21:09 +00:00
Callum Law
cfa5bc44d5 LibWeb: Implement creating CounterStyle from CounterStyleDefinition 2026-02-23 11:21:09 +00:00
Callum Law
ff40e9e7ba LibWeb: Stub CounterStyle
Eventually this will be used to resolve counter representations but we
are yet to implement any of the algorithms to do so.
2026-02-23 11:21:09 +00:00
Callum Law
bb5c8bb5be LibWeb: Add CounterStyleDefinition
This serves as an intermediate step between `CSSCounterStyleRule` and a
fully built counter style which will be helpful for:
 - Determining whether a rule defines a counter style
 - Resolving extends cycles
 - Determining registration order
2026-02-23 11:21:09 +00:00
Callum Law
32b9ff21df LibWeb: Add generic int_from_style_value method
Reduces duplication in line with `number_from_style_value`,
`string_from_style_value` etc
2026-02-23 11:21:09 +00:00
Shannon Booth
665654a1c4 LibWeb: Begin serializing global object as part of serialized ESO
Instead of passing through window's associated document's URL as
an extra argument to starting up a worker. This will allow for
improving the representation of 'outside settings' when setting
up a Worker.
2026-02-23 11:42:20 +01:00
Shannon Booth
513830532b LibWeb/HTML: Specify enum size for CanUseCrossOriginAPIs
This is passed over IPC, so we really should be explicit with the
size here.
2026-02-23 11:42:20 +01:00
Jonathan Gamble
34742681de LibWeb: Avoid spin_until in HTMLImageElement::decode_image
Improve performance of overlapping decodes. Reject on src changes
during the operation.
2026-02-23 10:11:04 +01:00
Callum Law
49eb9d7a7a LibWeb: Support composition of mixed values
This exposes an existing issue with interpolation where it is not clear
in what situations zero-valued dimensions should be excluded from the
interpolated value of a dimension-percentage mix (e.g. `calc(50% + 0px)`
vs `50%`) - but this is just a serialization issue as both
representations are resolved to the same used value
2026-02-23 09:01:19 +00:00
Callum Law
f7e5e57233 LibWeb: Make get_value_type_of_numeric_style_value reusable
This will also be used in composition of mixed types
2026-02-23 09:01:19 +00:00
Tim Ledbetter
81f077adfd LibWeb: Ensure mspace presentation hint is valid before setting it
The height and depth attributes are parsed individually and then
combined into a `calc()` expression. Bare zero is valid as a standalone
CSS length but inside `calc()` it is typed as a number, so
`calc(0 + 0)` fails to parse as a length. We now check the parsed value
is valid to avoid a crash.
2026-02-23 09:57:32 +01:00
Zaggy1024
470248e00d LibMedia+LibWeb: Stop ref counting PlaybackManager
PlaybackManager's ref counting was only used to keep it alive in a few
callbacks. Instead, the callbacks can use weak references that can only
be used from the thread that the PlaybackManager was created on, to
ensure that the PlaybackManager can't be destroyed while being
accessed.

This ensures that:
- The PlaybackManager is destroyed immediately when it is reassigned
  by HTMLMediaElement
- No callbacks are invoked after that point

This fixes the crash initially being addressed by #8081. The test from
that PR has been included as a regression test.
2026-02-23 08:49:13 +00:00
Aliaksandr Kalenik
7e3b49e583 LibWeb: Remove unused cumulative_offset_of_enclosing_scroll_frame() 2026-02-23 08:59:11 +01:00
Zaggy1024
aa6a7026da LibWeb: Skip UA shadow tree nodes when opening context menus
This makes right clicking on media element controls open the media
element's context menu instead of the shadow DOM element's.
2026-02-23 07:27:31 +01:00
Zaggy1024
21019c2fa9 LibWeb: Use UA shadow DOM for media elements' controls
Instead of using a custom paintable to draw the controls for video and
audio elements, we build them out of plain old HTML elements within a
shadow root.

This required a few hacks in the previous commits in order to allow a
replaced element to host children within a shadow root, but it's
fairly self-contained.

A big benefit is that we can drive all the UI updates off of plain old
DOM events (except the play button overlay on videos, which uses the
video element representation), so we can test our media and input event
handling more thoroughly. :^)

The control bar visibility is now more similar to how other browsers
handle it. It will show upon hovering over the element, but if the
cursor is kept still for more than a second, it will hide again. While
dragging, the controls remain visible, and will then hide after the
mouse button is released.

The icons have been redesigned from scratch, and the mute icon now
visualizes the volume level along with indicating the mute state.
2026-02-23 07:27:31 +01:00
Zaggy1024
bacf689c88 LibWeb: Update the layout tree when setting shadow roots 2026-02-23 07:27:31 +01:00
Zaggy1024
dd0c821291 LibWeb: Allow replaced elements to host children
We add a new formatting context that simply runs layout for an
anonymous block formatting context within it. This allows replaced
elements to contain children, if the parent rewrites inline-flow to
inline-block.
2026-02-23 07:27:31 +01:00
Zaggy1024
bc60768cb0 LibWeb: Rewrite audio elements without controls to display:none
This is part of the rendering spec, but we had neglected to do this
before. It causes one WPT check to fail, but other browsers get the
same result on that check, so I guess we can call that a win. :^)
2026-02-23 07:27:31 +01:00
Zaggy1024
7bc9824578 LibWeb: Remove useless moves of computed styles in AudioBox/VideoBox
Fixes a clang-tidy warning.
2026-02-23 07:27:31 +01:00
Zaggy1024
e8182e7079 LibWeb: Move video element representation into the element class
This will be used in the shadow DOM controls to determine whether to
show the centered play button.
2026-02-23 07:27:31 +01:00
Zaggy1024
ab0a358a98 LibWeb: Move video/audio adjust_computed_style to HTMLMediaElement
These are the same code, so we may as well move them up the chain. This
becomes useful in a later commit, where it will be used to rewrite
inline-flow to inline-block for layout of shadow DOM.
2026-02-23 07:27:31 +01:00
Zaggy1024
5a615009ff LibWeb: Remove unused math.h include in HTMLMediaElement.h 2026-02-23 07:27:31 +01:00
Zaggy1024
228947b131 LibWeb: Include KeyCode.h where it's used
It was only transitively included through HTMLMediaElement.h in these
files.
2026-02-23 07:27:31 +01:00
Zaggy1024
83bc63ccb8 LibWeb: Traverse shadow roots when firing mouseenter/mouseleave 2026-02-23 07:27:31 +01:00
Aliaksandr Kalenik
eb210bb3af LibWeb: Replace OrderedHashMap with page-table Vector in LayoutState
Each NodeWithStyle is assigned a sequential layout index during the
pre-layout tree traversal. LayoutState stores UsedValues in a
PagedStore — a two-level page table indexed by layout_index that
gives O(1) lookup via two array accesses, with pages allocated
lazily on first write. UsedValues are stored directly in pages
(Optional<T>) rather than behind heap pointers, eliminating
per-entry malloc/free calls and improving cache locality.

This cuts ensure_used_values_for() from ~14% to ~7% in profiles
on https://www.nyan.cat/.
2026-02-23 01:13:35 +01:00
devgianlu
f14410c19f LibWeb: Do not pass GC::Ptr by reference
Also change it to `GC::Ref` since it's nonnull.
2026-02-22 14:55:30 -05:00
devgianlu
fd80acd730 LibWeb: Specify why origin is missing from credentials IDL
The spec is outdated with respect to what is actually implemented
by browsers. Point to a PR that aims to update the spec.
2026-02-22 14:55:30 -05:00
devgianlu
68c53f437e LibWeb: Make CredentialUserData accessors const
Also remove the default constructor.
2026-02-22 14:55:30 -05:00
devgianlu
1edf60bf08 LibWeb: Make {,Federated,Password}Credential accessors const 2026-02-22 14:55:30 -05:00
devgianlu
db5c63c774 LibWeb: Default impl of Credential.isConditionalMediationAvailable
Provide the default implementation for
`is_conditional_mediation_available`.
2026-02-22 14:55:30 -05:00
devgianlu
1fd1ea3b97 LibWeb: Remove Credential.willRequestConditionalCreation
This method has been removed from the spec as unused.
2026-02-22 14:55:30 -05:00
Adam Colvin
d2f10c76fd LibWeb: Reject invalid alt text values in CSS content property parsing
The CSS content property's alt text (after `/`) was incorrectly
accepting any content value. Per the CSS Content Module Level 3 spec,
alt text only accepts <string>, <counter>, and <attr()> values. This
change adds type validation in the alt text parsing branch to reject
URLs, quote keywords, images, and other non-alt-text value types.

This fixes 64 subtests in the content-invalid WPT test.
2026-02-22 13:55:22 -05:00
Aliaksandr Kalenik
55f4009163 LibWeb: Walk linked list directly in transform_rect_to_viewport()
The chain is already in element→root order, which matches the linked
list's natural traversal via parent pointers. No need to collect into
a Vector first.
2026-02-22 16:09:15 +01:00
Aliaksandr Kalenik
d79fbd903d LibWeb: Cache parsed CSS values for SVG width/height attributes
width_style_value_from_attribute() and
height_style_value_from_attribute() were showing up as hot functions
when profiling YouTube Music. They call parse_css_value() on every
invocation, but the underlying attributes rarely change. The call path
is SVGSVGBox::natural_size() → negotiate_natural_metrics() → these
functions, so they are invoked on every layout pass.
2026-02-22 16:09:15 +01:00
Tim Ledbetter
79d5fdc871 LibWeb: Avoid division by zero in multi-column column count calculation 2026-02-22 15:07:06 +01:00
Aliaksandr Kalenik
9f36972e06 LibWeb: Include zero-area boxes when measuring scrollable overflow
The CSS Overflow spec says scrollable overflow should include "the
scrollable overflow areas of all of the above boxes (including
zero-area boxes)", but we were skipping zero-area boxes entirely via
an early return. This meant elements like a position:relative container
that collapses to zero height (because its only child is absolutely
positioned) would never have their children's overflow counted.
2026-02-22 14:23:44 +01:00