Commit Graph

8686 Commits

Author SHA1 Message Date
Andreas Kling
34954f49b6 LibWeb: Log a FIXME when encountering an unexpected block-level box
I've seen a crash when trying to verify_cast some block-level box to a
BlockContainer when it's actually something else.

This patch adds a debug log message so we can learn more about it next
time it happens somewhere.
2024-03-22 06:43:57 +01:00
Andreas Kling
8aae50f4ee LibWeb: Never claim "rendering opportunity" for SVG-as-image documents
Since we drive painting for SVG-as-image manually anyway, there's no
need for them to say they are "ready to paint", since that just causes
unnecessary extra processing in the HTML event loop.
2024-03-22 06:43:57 +01:00
Aliaksandr Kalenik
42d5883d57 LibWeb: Set animation update flag from Animation::invalidate_effect()
Fixes regressed animation tests.
2024-03-21 16:10:26 +01:00
Aliaksandr Kalenik
b7d28ee57d LibWeb: Change update_style() to update animated style only if needed
Instead of invalidating animated style properties whenever
`Document::update_style()` is called, now we only do that when
animations might have actually progressed. We still have to ensure
animated properties are up-to-date in `update_style()` to ensure that
JS methods can access updated style properties.
2024-03-21 11:29:02 +01:00
MacDue
6b799a739c LibWeb: Use ensure_subpath() in CanvasPath::arc_to()
No behaviour change.
2024-03-21 09:19:22 +01:00
MacDue
d73c21b6fe LibWeb: Implement missing CanvasPath::ellipse() steps 2024-03-21 09:19:22 +01:00
MacDue
cf1f00943a LibWeb: Implement missing CanvasPath::bezierCurveTo() steps 2024-03-21 09:19:22 +01:00
MacDue
877a0e06c4 LibWeb: Implement missing CanvasPath::quadraticCurveTo() steps 2024-03-21 09:19:22 +01:00
MacDue
d951ee399f LibWeb: Implement missing CanvasPath::lineTo() steps 2024-03-21 09:19:22 +01:00
MacDue
6128a28f17 LibWeb: Implement missing CanvasPath::moveTo() steps 2024-03-21 09:19:22 +01:00
Aliaksandr Kalenik
96d67ded3e LibWeb: Always run layout and style updates from event loop processing
Before this change, we ran style and layout updates from both event
loop processing and update timers. This could have caused missed resize
observer updates and unnecessary updating of style or layout more than
once before repaint.

Also, we can now be sure unnecessary style or layout updates won't
happen in `EventLoop::spin_processing_tasks_with_source_until()`.
2024-03-20 20:28:21 +01:00
Aliaksandr Kalenik
e09816c37c LibWeb: Run only tasks with navigation source in "apply history step"
In our implementation of the "apply the history step" algorithm, we
have to spin-wait for the completion of tasks queued on the event loop.
Before this change, we allowed tasks from any source to be executed
while we were waiting. It should not be possible because it allows to
interrupt history step application by anything, including another
history step application.

Fixes https://github.com/SerenityOS/serenity/issues/23598
2024-03-20 20:28:21 +01:00
Andrew Kaster
f26dd29b4d LibWeb: Print more information about thrown DOMExceptions in the console
This doesn't quite match the behavior of other engines, but by golly is
it helpful.
2024-03-20 15:18:44 -04:00
Timothy Flynn
6e2685f091 LibWeb: Remove FLATTEN attribute from SelectorEngine::fast_matches
This causes compilation time with GCC to increase far too much.
2024-03-20 10:33:16 -04:00
Matthew Olsson
0d70311c90 LibWeb: Resolve unresolved style values eagerly in KeyframeEffect
This isn't required as the StyleComputer will do this when animating,
but this allows the properties to be resolved once instead of on
every animation frame.

Note that we still pass AllowUnresolved::Yes because the properties will
not be resolved if there is no target.
2024-03-20 09:17:33 +01:00
Matthew Olsson
3dd9f2715f LibWeb: Resolve unresolved style values when animating properties 2024-03-20 09:17:33 +01:00
Matthew Olsson
b2fb9cc7d3 LibWeb: Allow ignoring unresolved style values when iterating properties
When iterating through a @keyframes rule, it isn't possible to resolve
unresolved style properties since there are no elements. This change
allows those properties to simply pass through this helper function.
2024-03-20 09:17:33 +01:00
Matthew Olsson
1f53727a3f LibWeb: Remove Badge from CSS::Parser::resolve_unresolved_style_value
KeyframeEffect needs to use this method to resolve unresolved properties
in the same way that StyleComputer does.
2024-03-20 09:17:33 +01:00
Matthew Olsson
ebfc6c33a6 LibWeb: Remove "resolved" from the name of Keyframe's property map
These will need to store unresolved styles as well, since they may be
built during parsing of a @keyframes rule. In that case there is no
target element or pseudo-element, and thus the value cannot be resolved.
2024-03-20 09:17:33 +01:00
Kenneth Myhra
c92f556aa5 LibWeb: Add {,de}serialization steps for FileList 2024-03-20 09:16:01 +01:00
Kenneth Myhra
5397340724 LibWeb: Add {,de}serialization steps for DOMQuad 2024-03-20 09:16:01 +01:00
Kenneth Myhra
d086d0cd92 LibWeb: Remove 'FIXME' on comment which is already implemented 2024-03-20 09:16:01 +01:00
Kenneth Myhra
52f056503d LibWeb: Add {,de}serialization steps for CryptoKey 2024-03-20 09:16:01 +01:00
Kenneth Myhra
ca54691ecf LibWeb: Add structured_deserialize_internal()
structured_deserialize_internal() is added to support sub
deserialization from serializable interfaces serialization steps which
needs the ability to pass onto the current position in the deserialized
data.
2024-03-20 09:16:01 +01:00
Kenneth Myhra
31f345fcb0 LibWeb: Add DeserializationMemory parameter to deserialization_steps()
We want to bring with us the value of DeserializationMemory to
Serializable::deserialization_steps() when doing sub serialization.
2024-03-20 09:16:01 +01:00
Kenneth Myhra
4669c1ba31 LibWeb: Add SerializationMemory parameter to serialization_steps()
We want to bring with us the value of SerializationMemory to
Serializable::serialization_steps() when doing sub serialization.
2024-03-20 09:16:01 +01:00
Tim Ledbetter
c8b219914e LibWeb: Use ErrorOr to propagate SVG attribute parsing errors
If an unexpected token is encountered when parsing an SVG attribute it
is now immediately propagated with ErrorOr. Previously, some situations
where an unexpected token was encountered could cause a crash.
2024-03-20 09:09:35 +01:00
Tim Ledbetter
a55394c383 LibWeb: Fix typo in SVG attribute parser method name 2024-03-20 09:09:35 +01:00
Tim Ledbetter
c1b1233575 LibWeb: Avoid duplicating SVG viewbox height calculation 2024-03-20 09:09:35 +01:00
Andreas Kling
f58ca99a66 LibWeb: Parse the ::backdrop pseudo element
We don't do anything with this yet, but let's at least not reject
selectors with ::backdrop in the parser.
2024-03-19 20:59:41 +01:00
Andreas Kling
6bb4a2bfaa LibWeb: Let HTMLCollection cache its element list
Use the new DOM tree version mechanism to allow HTMLCollection to
remember its internal list of elements instead of rebuilding it on
every access.

This avoids thousands of full DOM walks while loading our GitHub repo.

~15% speed-up on jQuery subtests in Speedometer 3.0 :^)
2024-03-19 20:59:36 +01:00
Andreas Kling
cf60f52a78 LibWeb: Add DOM tree version counter
This patch adds a u64 version counter to DOM::Document that increments
whenever the tree structure changes (via node insertion or removal),
or an element attribute is changed somehow.

This will be used as a crude invalidation mechanism for HTMLCollection
to cache its elements.
2024-03-19 20:59:36 +01:00
Aliaksandr Kalenik
cf7c933312 LibWeb: Add fast path to calculate invalidations for animated css props
- Compare only the animated properties
- Clone only the hash map containing animated properties, instead of
  the entire StyleProperties.

Reduces `KeyframeEffect::update_style_properties()` from 10% to 3% in
GitHub profiles.
2024-03-19 17:30:34 +01:00
Andreas Kling
ce2bfb4a12 LibWeb: Make CSSStyleRule::declaration() return a more specific type
This removes the need for some hot verify_casts in StyleComputer.
2024-03-19 16:48:22 +01:00
Andreas Kling
7c9368f402 LibWeb: Support most simple pseudo classes in the fast selector matcher
Non-recursive pseudo classes are easy to evaluate, so let's allow them
on the fast path.

Increases fast path coverage when loading our GitHub repo from 48% to
56% of all selectors evaluated.
2024-03-19 16:48:22 +01:00
Andreas Kling
3c3e591f03 LibWeb: Add a fast (iterative) selector matcher for trivial selectors
If we determine that a selector is simple enough, we now run it using a
special matching loop that traverses up the DOM ancestor chain without
recursion.

The criteria for this fast path are:

- All combinators involved must be either descendant or child.
- Only tag name, class, ID and attribute selectors allowed.

It's definitely possible to increase the coverage of this fast path,
but this first version already provides a substantial reduction in time
spent evaluating selectors.

48% of the selectors evaluated when loading our GitHub repo are now
using this fast path.

18% speed-up on the "Descendant and child combinators" subtest of
StyleBench. :^)
2024-03-19 16:48:22 +01:00
Andreas Kling
432536f0b3 LibWeb: Make SelectorEngine::matches_namespace() a standalone function
This will allow me to reuse it in the next commit.
2024-03-19 16:48:22 +01:00
Andreas Kling
a6c23d3db5 LibWeb: Make Element::has_class() an inline function
This is extremely hot when running CSS selectors, so let's make it
easier for it to be inlined.
2024-03-19 16:48:22 +01:00
Andreas Kling
b40f0415ef LibWeb: Make Node::parent_element() an inline function
Also remove a redundant verify_cast<Element> while we're here.
2024-03-19 16:48:22 +01:00
Andreas Kling
4e4b9f440f Revert "LibWeb: Run IntersectionObserver steps only when needed"
This reverts commit 11b4216e65.
2024-03-19 13:04:39 +01:00
Aliaksandr Kalenik
6fc59039c4 LibWeb: Skip cells layout in table box width calculation
There is no need to run full table layout if we are only interested in
calculating its width.

This change reduces compute_table_box_width_inside_table_wrapper()
from ~30% to ~15% in profiles of "File changed" pages on github.
2024-03-19 11:51:49 +01:00
Andreas Kling
08a956f544 LibWeb: Ignore all pseudo element rules when matching non-pseudo element 2024-03-19 09:44:25 +01:00
Andreas Kling
4679dbc9df LibWeb: Make Element::inline_style() return specific declaration type
This removes a bunch of RTTI checks in StyleComputer.
2024-03-19 09:44:25 +01:00
Andreas Kling
25c22bb5e5 LibWeb: Reorder MatchingRule members to make it smaller
By packing the members more efficiently, it goes from 64 to 56 bytes.
2024-03-19 09:44:25 +01:00
Andreas Kling
963aa213c5 LibWeb: Avoid two calls to Selector::specificity() when sorting rules 2024-03-19 09:44:25 +01:00
Andreas Kling
22465e80fe LibWeb: Avoid FlyString copy when matching tag selector namespace URI 2024-03-19 09:44:25 +01:00
Aliaksandr Kalenik
e3e6af39bc LibWeb: Add basic implementation of has_a_rendering_opportunity()
Return true only if we are ready to repaint. This fixes the issue where
requestAnimationFrame() was invoked more than once between repaints.
2024-03-19 07:54:14 +01:00
Shannon Booth
e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00
Andreas Kling
21bfa001b1 LibWeb: Make StyleProperties::m_property_values a bit smaller
Instead of wrapping every entry in Optional, use the null state of the
style pointer for the same purpose.

This shrinks StyleProperties by 1752 bytes per instance.
2024-03-18 13:42:16 +01:00
Andreas Kling
7be0aed4b6 LibWeb: Keep StyleProperties animated properties in a HashMap
Instead of a gigantic array with space for every possible CSS property
being animated at the same time.

This shrinks StyleProperties by 3480 bytes per instance.
2024-03-18 13:42:16 +01:00