Commit graph

479 commits

Author SHA1 Message Date
Tim Ledbetter
a467005855 LibWeb: Make node cloning methods const 2025-01-11 23:10:09 +01:00
Psychpsyo
31b20e38ee LibWebView: Fix capitalization in devtools 2025-01-11 16:28:51 -05:00
Shannon Booth
64eeda6450 LibWeb: Return a representation of an 'Agent' in 'relevant agent'
This makes it more convenient to use the 'relvant agent' concept,
instead of the awkward dynamic casts we needed to do for every call
site.

mutation_observers is also changed to hold a GC::Root instead of raw
GC::Ptr. Somehow this was not causing problems before, but trips up CI
after these changes.
2025-01-11 10:39:48 -05:00
Sam Atkins
f11347739a LibWeb/HTML: Stop observing lazy-loaded iframes when navigating 2025-01-11 11:10:43 +01:00
Sam Atkins
97616fa108 LibWeb/DOM: Move "stop intersection observing..." code into a method
We'll need to call it from elsewhere.

Also add a missing step 5 from where we previously called it.
2025-01-11 11:10:43 +01:00
Sam Atkins
c6a18f795d LibWeb/HTML: Pass user_involvement through navigables code
This corresponds to part of https://github.com/whatwg/html/pull/10818
2025-01-11 11:10:43 +01:00
Jelle Raaijmakers
9750896af3 LibWeb: Implement the "push down values" editing algorithm 2025-01-10 23:33:35 +01:00
Jelle Raaijmakers
e21ee10b3c LibWeb: Add command state & value overrides to DOM::Document 2025-01-10 23:33:35 +01:00
Jelle Raaijmakers
d08febcf67 LibWeb: Add Node::for_each(_inclusive)_ancestor()
Allows for easy iteration over the chain of ancestors for a node.
2025-01-10 23:33:35 +01:00
Jelle Raaijmakers
4323669939 LibWeb: Add Range::for_each_contained()
This centralizes the logic for iterating over a Range's contained nodes.
2025-01-10 23:33:35 +01:00
Aliaksandr Kalenik
cf57efd252 LibWeb: Unload fonts when adopted style sheet is removed
Add missing unloading step that we do for regular style sheets but
mistakenly missed for adopted style sheets.
2025-01-10 19:12:48 +03:00
Shannon Booth
1f4c7ac62b LibWeb/DOM: Remove uneccessary ExceptionOr for NodeIterator::create 2025-01-10 08:08:46 +00:00
Shannon Booth
17c92d7c2b LibWeb/DOM: Create TreeWalker in document's realm 2025-01-10 08:08:46 +00:00
Shannon Booth
84f22cb6b3 LibWeb/DOM: Create NodeIterator in document's realm 2025-01-10 08:08:46 +00:00
sideshowbarker
173368bd5e LibWeb: Allow accessible-name computation to skip role-attribute lookup
Per https://w3c.github.io/aria/#document-handling_author-errors_roles,
determining whether to ignore certain specified landmark roles requires
first determining whether the element for which the role is specified
has an accessible name.

But if we then try to retrieve a role for such elements, we end up
calling right back into the accessible-name computation code — which
would cause the calls to loop infinitely.

So to avoid that — and to have handling for any other future cases the
spec may introduce of such recursive calls that will loop indefinitely —
this change introduces a parameter that callers can pass to cause
role-attribute lookup to be skipped during accessible-name computation.
2025-01-09 14:08:23 +00:00
sideshowbarker
9f01eebff3 LibWeb: Add a to_element function to ARIAMixin
This change adds a virtual to_element function to ARIAMixin, and
overrides it in DOM::Element so it can then be used back inside
ARIAMixin to get an element when needed (for example, when computing a
role requires checking the roles of ancestors of an element).
2025-01-09 14:08:23 +00:00
Jelle Raaijmakers
e6334d217b LibWeb: Update implementation of Range::partially_contains_node()
This accurately reflects the spec it's implementing. This algorithm is
used in 5 spots in the spec but the old buggy behavior was never
triggered:

  * In both ::extract() and ::clone_the_contents(), invocations to this
    method are guarded by a check to see if the start node is the
    inclusive ancestor of the end node, or vice versa - effectively
    resulting in the inequality checks to be accidentally correct.

  * In ::surround_contents(), we forego the usage of this algorithm as
    stated in the spec, and instead use a correct and more optimized
    version that simply compares the start and end nodes.

A lot of words to say: no functional changes :^)
2025-01-09 10:15:55 +00:00
Gingeh
4a0ac312cc LibWeb: Obtain theme-color on meta element removal and modification 2025-01-08 11:18:13 +00:00
Gingeh
df70455d3f LibWeb: Implement the color-scheme meta tag name 2025-01-08 11:18:13 +00:00
Gingeh
ce5cd012b9 LibWeb/CSS: Implement the color-scheme CSS property 2025-01-08 11:18:13 +00:00
Sam Atkins
89296b88a0 LibWeb: Bring fragment parsing up to spec
Corresponds to https://github.com/whatwg/html/pull/10874

Also, parse_fragment() returns ExceptionOr, so stop voiding the error
from append_child().
2025-01-07 16:05:59 +01:00
Sam Atkins
7d502df807 LibWeb/DOM: Add Document::in_limited_quirks_mode() helper 2025-01-07 16:05:59 +01:00
Aliaksandr Kalenik
5cac301bb7 LibWeb: Optimize hover style invalidation for shadow trees
With this change we skip all :hover selectors that don't belong to a
"style scope" (document or shadow root) of old/new hovered node.
2025-01-06 12:15:06 +01:00
Tim Ledbetter
7356093af3 LibWeb: Fix selectionchange typo
This was a typo in the spec itself, which has since been fixed.
2025-01-06 08:55:00 +00:00
Shannon Booth
172d5f6987 LibWeb: Implement definition of remaining global event handlers 2025-01-05 16:19:19 +00:00
Andreas Kling
49a7a0f378 LibWeb: Avoid invalidation on .textContent setter no-op
When setting the textContent of an element with no children to null or
the empty string, nothing happens. Even so, we were still invalidating
style, layout and collections, causing pointless churn.

Skipping invalidation in this case also revealed that we were missing
invalidation when changing the selected state of HTMLOptionElement.
This was all caught by existing tests already in-tree. :^)
2025-01-05 13:36:17 +01:00
Aliaksandr Kalenik
482e5deb85 LibWeb: Further optimize :hover style invalidation
Previously, we optimized hover style invalidation to mark for style
updates only those elements that were matched by :hover selectors in the
last style calculation.

This change takes it a step further by invalidating only the elements
where the set of selectors that use :hover changes after hovered element
is modified. The implementation is as follows:
1. Collect all elements whose styles might be affected by a change in
   the hovered element.
2. Retrieve a list of all selectors that use :hover.
3. Test each selector against each element and record which selectors
   match.
4. Update m_hovered_node to the newly hovered element.
5. Repeat step 3.
6. For each element, compare the previous and current sets of matched
   selectors. If they differ, mark the element for style recalculation.
2025-01-04 20:32:35 +01:00
Aliaksandr Kalenik
e465e922bd LibWeb: Optimize :hover style invalidation
Instead of recalculating styles for all nodes in the common ancestor of
the new and old hovered nodes' subtrees, this change introduces the
following approach:
- While calculating ComputedProperties, a flag is saved if any rule
  applied to an element is affected by the hover state during the
  execution of SelectorEngine::matches().
- When the hovered element changes, styles are marked for recalculation
  only if the flag saved in ComputedProperties indicates that the
  element could be affected by the hover state.
2025-01-04 20:32:35 +01:00
Sam Atkins
938ffe183e LibWeb/DOM: Update validate_and_extract to latest spec
The "strictly split" infra algorithm feels like an inefficient way of
doing basically what our existing split() does, except working with
code points instead of bytes. It didn't seem worth it to implement now.
2025-01-04 18:08:15 +00:00
Sam Atkins
c60ad5b0b8 LibWeb/DOM: Update node cloning to latest spec
Main difference is that a chunk of the "clone a node" steps are pulled
out into a "clone a single node" algorithm.

Reflects these spec PRs:
https://github.com/whatwg/dom/pull/1332
https://github.com/whatwg/dom/pull/1334

Though this code is quite old so there may also be older spec changes
included here.
2025-01-04 12:14:25 +00:00
Psychpsyo
331b1b22f5 LibWeb: Implement some viewport proximity features 2025-01-04 11:53:39 +00:00
Shannon Booth
2066ed2318 LibWeb: Correctly initialize Storage objects on the Document
Instead of storing all storage objects in static memory, we now
follow the the spec by lazily creating a unique Storage object
on each document object.

Each Storage object now holds a 'proxy' to the underlying backing
storage. For now, this proxy is simply a reference to the backing
object. In the future, it will need to be some type of interface
object that stores on a SQLite database or similar.

Session storage is now correctly stored / tracked as part of the
TraversableNavigable object.

Local storage is still stored in a static map, but eventually this
should be factored into something that is stored at the user agent
level.
2025-01-02 11:31:15 +01:00
sideshowbarker
1be55fe793 LibWeb: Support the ariaActiveDescendantElement IDL attribute 2025-01-01 11:00:53 +00:00
Lucas CHOLLET
abc0418710 LibWeb/DOM: Convert elapsedTime to seconds when firing AnimationEvents
This makes all three subtests from this test to pass:
 - css/css-animations/animationevent-types.html
2024-12-30 11:05:37 +01:00
Lucas CHOLLET
61b444d538 LibWeb/DOM: Allow the animationiteration event to be fired
This event is fired while both the previous and the current phase are
active.

This prevents this test from timing out:
- css/css-animations/animationevent-types.txt
2024-12-30 11:05:37 +01:00
Lucas CHOLLET
906b7bf4e3 LibWeb/DOM: Conserve references to pending animations
This fixes a crash in:
 - css/css-animations/CSSAnimation-effect.tentative.html
2024-12-30 11:04:55 +01:00
Timothy Flynn
27478ec7d4 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-19 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")
2024-12-28 05:39:32 -08:00
Lucas CHOLLET
9585aeafda LibWeb/DOM: Don't assume that Animations have an associated effect
Fixes a crash on:
 - css/css-transitions/CSSTransition-effect.tentative.html
2024-12-28 10:37:44 +01:00
Lucas CHOLLET
589538ec8f LibWeb/DOM: Visit the animation of Document's pending animations 2024-12-27 11:50:11 -08:00
Andreas Kling
1a0f5d3180 LibWeb: Remove unused pointer from DOM::Text to its "owner" element
This is a leftover from an earlier implementation of text input.
2024-12-27 12:27:03 +01:00
Andreas Kling
ceefe7d858 LibWeb: Make CustomElementDefinition relationship with GC more sane
1. Stop using GC::Root in member variables, since that usually creates
   a realm leak.

2. Stop putting OrderedHashMap<FlyString, GC::Ptr> on the stack while
   setting these up, since that won't protect the objects from GC.
2024-12-27 10:02:58 +01:00
sideshowbarker
062e33438e LibWeb: Space-separate parts of multi-label accessible names
This change ensures that when an accessible name is computed from
multiple labels, the parts computed from each label are separated by
spaces. Otherwise, without this change, the parts are run together in
the accessible name, with no space in between.
2024-12-26 20:44:14 +00:00
Andreas Kling
3bfb0534be LibGC: Rename MarkedVector => RootVector
Let's try to make it a bit more clear that this is a Vector of GC roots.
2024-12-26 19:10:44 +01:00
Lucas CHOLLET
1c61ccef40 LibWeb/DOM: Fire transition[cancel,start,run,end] events 2024-12-25 17:14:08 +01:00
Glenn Skrzypczak
08589741f5 LibWeb: Correctly implement event listeners default passive attribute
This commit implements the default value of the passive attribute of
event listeners according to the spec.
2024-12-25 14:57:22 +00:00
Andreas Kling
f45e24864b LibWeb: Skip unneeded style invalidation on custom element state change
If there are no :defined pseudo-class selectors anywhere in the
document, we don't have to invalidate style at all when an element's
custom element state changes.
2024-12-25 13:26:51 +01:00
Saksham Goyal
8ebf2c3007 LibWeb: Add missing attributes in Event Handlers 2024-12-25 12:01:56 +01:00
Andreas Kling
b981e6f7bc LibWeb: Avoid many style invalidations on DOM attribute mutation
Many times, attribute mutation doesn't necessitate a full style
invalidation on the element. However, the conditions are pretty
elaborate, so this first version has a lot of false positives.

We only need to invalidate style when any of these things apply:

1. The change may affect the match state of a selector somewhere.
2. The change may affect presentational hints applied to the element.

For (1) in this first version, we have a fixed list of attribute names
that may affect selectors. We also collect all names referenced by
attribute selectors anywhere in the document.

For (2), we add a new Element::is_presentational_hint() virtual that
tells us whether a given attribute name is a presentational hint.

This drastically reduces style work on many websites. As an example,
https://cnn.com/ is once again browseable.
2024-12-24 17:17:09 +01:00
Andreas Kling
d5bbf8dcf8 LibWeb: Do lighter style invalidation for style attribute changes
When the `style` attribute changes, we only need to update style on the
element itself (unless there are [style] attribute selectors somewhere).

Descendants of the element don't need a full style update, a simple
inheritance propagation is enough.
2024-12-23 17:05:09 +01:00
Andreas Kling
dc8343cc23 LibWeb: Add mechanism to invalidate only inherited styles
We can now mark an element as needing an "inherited style update" rather
than a full "style update". This effectively means that the next style
update will visit the element and pull all of its inherited properties
from the relevant ancestor element.

This is now used for descendants of elements with animated style.
2024-12-23 17:05:09 +01:00