Commit graph

179 commits

Author SHA1 Message Date
Sam Atkins
b6ffea8990 LibWeb: Give Element a CustomStateSet, exposed by ElementInternals 2025-07-04 18:10:28 +01:00
Sam Atkins
ffd5503dcb LibWeb/DOM: Serialize pseudo-elements in the correct order
Make Element responsible for serializing all its children, so it can put
them in order.
2025-07-03 09:56:56 +01:00
Sam Atkins
4df472988c LibWeb/DOM: Only list pseudo-elements that actually exist
This stops `::before` and `::after` nodes showing up for every single
element in the inspector tree. Unfortunately there's no way for us to
detect that one of these doesn't exist in layout but has *some* style
specified for it, but that seems like a rare use case.
2025-07-03 09:56:56 +01:00
Sam Atkins
423cdd447d LibWeb+LibGfx: Apply editorial punctuation/whitespace/markup fixes
Corresponds to d426109ea1
and fd08f81d06
2025-06-25 03:12:19 +12:00
Sam Atkins
2e2b456009 LibWeb/DOM: Update spec steps for scrolling into view
Corresponds to dad91f49ef

The spec text doesn't actually require any changes from us, but I
noticed we were incorrectly calling `is_shadow_including_ancestor_of()`
instead of `is_shadow_including_inclusive_ancestor_of()`, so that's
fixed.
2025-06-25 03:12:19 +12:00
Sam Atkins
f98312d022 LibWeb/DOM: Move pseudo-element scroll offsets into PseudoElement 2025-06-19 12:35:31 +01:00
Sam Atkins
c1d4323cf7 LibWeb: Support counter-* properties on pseudo-elements
There are multiple things happening here which are interconnected:

- We now use AbstractElement to refer to the source of a counter, which
  means we also need to pass that around to compute `content`.

- Give AbstractElement new helper methods that are needed by
  CountersSet, so it doesn't have to care whether it's dealing with a
  true Element or PseudoElement.

- The CountersSet algorithms now walk the layout tree instead of DOM
  tree, so TreeBuilder needs to wait until the layout node exists
  before it resolves counters for it.

- Resolve counters when creating a pseudo-element's layout node. We
  awkwardly compute the `content` value up to twice: Once to figure out
  what kind of node we need to make, and then if it's a string, we do
  so again after counters are resolved so we can get the true value of
  any `counter()` functions. This will need adjusting in the future but
  it works for now.
2025-06-19 12:35:31 +01:00
Sam Atkins
a57595faf5 LibWeb: Make [resolve,inherit]_counters() take AbstractElement
This is one of those cases where the spec says "element" and
means "element or pseudo-element". The easiest way to handle both is to
make these be free functions that take an AbstractElement, and then
give AbstractElement some helper methods so that the caller doesn't
have to care which it's dealing with.

There are some FIXMEs here because PseudoElement doesn't have a
CountersSet yet, and because the CountersSet currently uses a
UniqueNodeID to identify counter sources, which doesn't support
pseudo-elements.
2025-06-19 12:35:31 +01:00
Sam Atkins
ce380a59c7 LibWeb/DOM: Rename ElementReference to AbstractElement
This isn't some kind of identifier, it's a handle on an actual Element
or PseudoElement.
2025-06-19 12:35:31 +01:00
Sam Atkins
e7c2f0dd52 LibWeb: Make PseudoElement a class in its own right
It's getting a bit large and complicated to be a struct hidden in
DOM::Element.
2025-06-19 12:35:31 +01:00
Tim Ledbetter
ba641d4784 LibWeb: Update attribute name validation in Element.setAttribute()
This now follows the latest specification steps.
2025-06-19 11:00:53 +01:00
Tim Ledbetter
acf2d773d5 LibWeb: Update attribute name validation in Element.toggleAttribute
This now follows the latest specification steps.
2025-06-19 11:00:53 +01:00
Tim Ledbetter
4593c28769 LibWeb: Update validate_and_extract and its users to the latest spec 2025-06-19 11:00:53 +01:00
Gingeh
e96338dd63 LibWeb: Don't play initially-paused animations
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (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-06-18 17:17:29 +02:00
Jelle Raaijmakers
e8e6dbcee0 LibWeb: Fix document element's .scrollHeight and .scrollWidth
We were using the viewport's size as the viewport scrolling area, but
those are completely different things.
2025-06-17 17:17:34 +01:00
Jelle Raaijmakers
e104d896eb LibWeb: Rename Navigable::m_size to ::m_viewport_size
All other viewport-related dimensions are referenced to by 'viewport',
so let's rename the member that stores the viewport size to prevent
further confusion.
2025-06-17 17:17:34 +01:00
Manuel Zahariev
00d43b39d1 LibWeb: Retain calculated Element::ordinal_value for lists
`Element::ordinal_value` is called for every `li` element in
a list (ul, ol, menu).

Before:
  `ordinal_value` iterates through all of the children of the list
  owner. It is called once for each element: complexity $O(n^2)$.

After:
  - Save the result of the first calculation in `m_ordinal_value`
  then return it in subsequent calls.
  - Tree modifications are intercepted and trigger invalidation
    of the first node's `m_ordinal_value`:
    - insert_before
    - append
    - remove
  Results in noticeable performance improvement rendering' large
  lists: from 20s to 4s for 20K elements.
2025-06-16 12:44:58 +01:00
Manuel Zahariev
d27b43c1ee LibWeb: Add specialized fast_is for lists
Before:
  `is<HTMLOLListElement>` and other similar calls in this commit
  are resolved to `dynamic_cast`, which incurs runtime overhead
  for resolving the type. The Performance hit becomes apparent
  when rendering large lists. Callgrind analysis points to a
  significant performance hit from calls to `is<...>` in
  `Element::list_owner`.

Reference: Michael Gibbs and Bjarne Stroustrup (2006) Fast dynamic
casting. Softw. Pract. Exper. 2006; 36:139–156

After:
  Implement inline `fast_is` virtual method that immediately
  resolves the type. Results in noticeable performance improvement
  2x-ish for lists with 20K entries.

Bonus: Convert starting value for LI elements to signed integer
    The spec requires the start attribute and starting value to be
    "integer". Firefox and Chrome support a negative start attribute.

FIXME: At the time of this PR, about 134 other objects resolve
`is<...>` to `dynamic_cast`. It may be a good idea to coordinate
similar changes to at least [some of] the ones that my have impact
on performance (maybe open a new issue?).
2025-06-16 12:44:58 +01:00
Jelle Raaijmakers
15c436b332 LibWeb: Implement basic focus indication for :focus-visible
This causes links to no longer show an outline when clicked; only when
using keyboard navigation with the tab key will the outline show up.
2025-06-13 17:39:11 +02:00
Callum Law
fc46abb83f LibWeb: Make element_reference optional in create_resolved_style 2025-06-09 12:28:41 +01:00
Callum Law
610ad25555 LibWeb: Update m_inline_style when element style attribute is removed
Previously we would just throw it away and construct a new (empty) one
when required. This doesn't work as any existing references to the old
instance will contain out of date information. Now we retain and update
the existing instance instead.
2025-06-09 12:06:44 +01:00
Aliaksandr Kalenik
6a029fb6d9 LibWeb: Reset animated CSS properties for pseudo elements
Previously we were resetting animated properties if animation effect's
target is not a pseudo element.
2025-05-28 17:35:59 +01:00
Gingeh
7acc0f4a42 LibWeb: Implement :required/:optional pseudo-classes 2025-05-24 10:31:34 +01:00
Callum Law
279913a223 LibWeb: Implement the translate attribute 2025-05-23 14:34:06 +02:00
Shannon Booth
579730d861 LibWeb: Prefer using equals_ignoring_ascii_case
Which has an optmization if both size of the string being passed
through are FlyStrings, which actually ends up being the case
in some places during selector matching comparing attribute names.
Instead of maintaining more overloads of
Infra::is_ascii_case_insensitive_match, switch
everything over to equals_ignoring_ascii_case instead.
2025-05-21 13:45:02 +01:00
Psychpsyo
a0be82b2cb LibWeb: Move containment checks to Layout::Node
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
It fits better there and avoids having to reach into the Element
all the time.
2025-05-13 15:30:14 +03:00
Psychpsyo
31301ef08b LibWeb: Add support for trees of pseudo-elements
This is needed for CSS view transitions.
2025-05-13 12:38:42 +01:00
Andreas Kling
096eed35cc LibWeb: Avoid O(n^2) traversal in play-or-cancel-animations logic
Some checks are pending
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
The play_or_cancel_animations_after_display_property_change() helper
was being called by Node::inserted() and Node::removed_from() and then
recursing into the shadow-including subtree.

This had quadratic complexity since inserted() and removed_from() are
themselves already invoked recursively for everything in the
shadow-including subtree.

Only one caller of this API actually needed the recursive behavior,
so this patch moves that responsibility to the caller and puts the logic
in style recomputation instead.

1.02x speedup on Speedometer's TodoMVC-jQuery.
2025-05-11 20:22:17 +02:00
InvalidUsernameException
029bcf13fd Libweb: Invalidate layout for the value-attribute of li-elements 2025-05-11 01:14:31 +02:00
Jelle Raaijmakers
c56f7d9cde LibWeb: Invalidate sibling style for :only-child and :*-of-type
After f7a3f785a8, sibling nodes' styles
were no longer invalidated after a node was removed. This reuses the
flag for `:first-child` and `:last-child` to indicate that a node's
style might be affected by any structural change in its siblings.

Fixes #4631.

Resolves the `:only-child` ACID3 failure as documented in #1231.
2025-05-07 14:55:12 +03:00
Gingeh
004d1305c8 LibWeb: Don't accidentally create a layout node for display: none 2025-04-30 11:26:18 +01:00
Timothy Flynn
ac1c2a956a LibWeb: Implement caching of reflected element array attributes
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
For attributes like Element.ariaControlsElements, which are a reflection
of FrozenArray<Element>, we must return the same JS::Array object every
time the attribute is invoked - until its contents have changed. This
patch implements caching of the reflected array in accordance with the
spec.
2025-04-26 17:29:38 -04:00
Shannon Booth
31a3bc3681 LibWeb: Implement 'State-preserving atomic move integration'
This was recently added to both the HTML and DOM specifications,
introducing the new moveBefore DOM API, as well as the new internal
'removing steps'.

See:

 * 432e8fb
 * eaf2ac7
2025-04-26 08:45:37 -06:00
Shannon Booth
084cceab5c LibWeb: Split out SimilarOriginWindowAgent from HTML::Agent
To allow for adding the concept of a WorkerAgent to be reused
between shared and dedicated workers. An event loop is the
commonality between the different agent types, though, there
are some differences between those event loops which we customize
on the construction of the HTML::EventLoop.
2025-04-25 14:07:51 +02:00
Timothy Flynn
13ac6c4fde LibWeb: Implement ariaActiveDescendantElement spiritually closer to spec
Some checks are pending
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Lint Code / lint (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
We are meant to store a weak reference to the element indicated by this
attribute, rather than a GC-protected strong reference. This also hoists
the "get the attr-associated element" AO into its own function, rather
than being hidden in IDL, to match "get the attr-associated elements".
2025-04-25 01:20:12 +01:00
Timothy Flynn
f985ac8884 LibWeb: Implement element-referencing ARIA attributes
There are ARIA attributes, e.g. ariaControlsElements, which refer to a
list of elements by their ID. For example:

    <div aria-controls="item1 item2">

The div.ariaControlsElements attribute would be a list of elements whose
ID matches the values in the aria-controls attribute.
2025-04-25 01:20:12 +01:00
Timothy Flynn
0289df9357 LibWeb: Move ariaActiveDescendantElement to ARIAMixin
Not an issue right now, but all IDL types that include the ARIA mixin
will need this.
2025-04-25 01:20:12 +01:00
Andreas Kling
1242b9152e LibWeb: Turn Element.scroll(0, 0) into a no-op when possible
For unscrolled elements (already at 0, 0) that aren't eligible to be the
Document.scrollingElement, we can short-circuit here and avoid doing a
synchronous relayout of the page.

This avoids a bunch of synchronous layouts on Speedometer3's NewsSite
subtests.
2025-04-22 12:09:42 +02:00
Andreas Kling
545ed08519 LibWeb: Add debug logging of reasons for layout tree update
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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-04-21 00:31:08 +02:00
Andreas Kling
a6dfc74e93 LibWeb: Only set prototype once for object with IDL interface
Before this change, we were going through the chain of base classes for
each IDL interface object and having them set the prototype to their
prototype.

Instead of doing that, reorder things so that we set the right prototype
immediately in Foo::initialize(), and then don't bother in all the base
class overrides.

This knocks off a ~1% profile item on Speedometer 3.
2025-04-20 18:43:11 +02:00
Andreas Kling
7884e58b5c LibWeb: Make Element::html_uppercased_qualified_name() lazy
Many elements never end up needing this string, so instead of eagerly
generating it in the Element constructor, let's defer it until someone
actually requests it.

Knocks off a ~1% profile item on Speedometer3's jQuery test.
2025-04-20 18:43:11 +02:00
Andreas Kling
94cc4adefd LibWeb: Create Element::attributes (NamedNodeMap) lazily
Many elements have zero attributes, and they don't need a NamedNodeMap
until someone asks for it.
2025-04-20 18:43:11 +02:00
Shannon Booth
3e17b1c9ae LibWeb: Make Node::parent_element return GC::Ptr
This is useful for people like myself who run with debug mode to
more reliably get stacktraces without spinning up a debugger.
2025-04-18 10:49:02 +02:00
Shannon Booth
a14481ee05 LibWeb/HTML: Handle no parent element for Element::list_owner
Fixes a crash when running Speedometer 3.0 as reduced in the included
test case.
2025-04-18 10:48:47 +02:00
Andreas Kling
e1777f6e79 LibWeb: Make :hover invalidation logic reusable for all pseudo classes
We achieve this by keeping track of all checked pseudo class selectors
in the SelectorEngine code. We also give StyleComputer per-pseudo-class
rule caches.
2025-04-17 19:45:55 +02:00
Timothy Flynn
6dd2a4c945 LibWeb: Do not create a RootVector to invoke IDL callbacks
These callbacks are evaluated synchronously via JS::Call. We do not need
to construct an expensive RootVector container just to immediately
invoke the callbacks.

Stylistically, this also helps indicate where the actual arguments start
at the call sites, by wrapping the arguments in braces.
2025-04-16 07:32:02 -04:00
Sam Atkins
6ff2324f26 LibWeb/DOM: Actually stub out pointer-capture API
For real this time.

This makes panning the KendoReact map widget actually work:
https://www.telerik.com/kendo-react-ui/components/map
2025-04-14 12:55:44 +02:00
Andreas Kling
e068ff5a5d LibWeb: Always store ComputedProperties, even if no invalidations
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
Before this change, we'd skip storing the new ComputedProperties in
Element::recompute_style() if there was no invalidation needed.

This caused us to lose the information about which properties are
inherited and/or important (which is also carried by ComputedProperties,
but doesn't affect invalidation).

Consequently, we'd then fail to recompute inherited styles, since that
mechanism depends on this data.

The fix is simply to always store the new ComputedProperties.
2025-04-13 00:43:49 +02:00
Sam Atkins
9dbeecb73d LibWeb: Correct some spec typos
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
Corresponds to 285a58bf30
2025-04-10 04:01:37 +02:00
Gingeh
4b9f5c6fb8 LibWeb: Generate ::backdrop pseudo-elements 2025-04-09 12:10:42 +01:00