Commit Graph

13 Commits

Author SHA1 Message Date
Andreas Kling
196a3eb239 LibWeb: Ignore invisible boxes and stacking contexts during hit testing 2022-03-21 15:43:37 +01:00
Andreas Kling
01662b2320 LibWeb: Remove now-unused PaintableBox::for_each_child_in_paint_order() 2022-03-21 14:57:00 +01:00
Andreas Kling
a779ace6a1 LibWeb: Don't compute fragment absolute rect twice while hit testing 2022-03-21 13:03:33 +01:00
Andreas Kling
996f3228a2 LibWeb: Fix O(n^2) traversal in hit testing
We already walk the entire paint tree within each stacking context in
the main hit testing function (StackingContext::hit_test()), so there's
no need for each individual paintable to walk its own children again.

By not doing that, we remove a source of O(n^2) traversal which made hit
testing on deeply nested web pages unbearably slow.
2022-03-21 13:03:33 +01:00
Andreas Kling
0ba785894c LibWeb: Make hit testing functions return Optional<HitTestResult>
Using "HitTestResult with null paintable" as a way to signal misses was
unnecessarily confusing. Let's use Optional instead. :^)
2022-03-21 13:03:33 +01:00
Andreas Kling
59afdb959f LibWeb: Build stacking context tree lazily
There's no actual need to build the stacking context tree before
performing layout. Instead, make it lazy and build the tree when it's
actually needed for something.

This avoids a bunch of work in situations where multiple synchronous
layouts are forced (typically by JavaScript) without painting or hit
testing taking place in between.

It also opens up for style invalidations that only target the stacking
context tree.
2022-03-21 13:03:33 +01:00
Andreas Kling
8cc757b92b LibWeb: Always call Layout::Box::did_set_rect()
Since paintables have a default content size of 0x0, we were neglecting
to notify the corresponding layout node about size changes, if the used
content size came out to 0x0.

This fixes an issue where resizing an iframe to 0x0 didn't take effect.
2022-03-20 19:03:43 +01:00
Simon Wanner
48efdaa8c4 LibWeb: Update hit_test for CSS Transforms
This now also takes a FloatPoint instead of an IntPoint to avoid
excessive rounding when multiple transforms apply on top of each other.
2022-03-18 18:51:42 +01:00
Andreas Kling
15dc48b431 LibWeb: Make PaintableBox::enclosing_stacking_context() cheaper
No need to call the expensive establishes_stacking_context() here, as
we've already built the stacking context tree and can simply test for
the presence of existing stacking contexts.
2022-03-18 15:18:48 +01:00
Andreas Kling
be5f0b5ac4 LibWeb: Move text fragment painting to PaintableWithLines
All the other painting code has moved to paintables already.
2022-03-16 23:13:05 +01:00
Andreas Kling
b14c6eaef3 LibWeb: Let paintables cache their containing block and absolute rect
The absolute rect of a paintable is somewhat expensive to compute. This
is because all coordinates are relative to the nearest containing block,
so we have to traverse the containing block chain and apply each offset
to get the final rect.

Paintables will never move between containing blocks, nor will their
absolute rect change. If anything changes, we'll simpl make a new
paintable and replace the old one.

Take advantage of this by caching the containing block and absolute rect
after first access.
2022-03-12 00:39:31 +01:00
Andreas Kling
5779a910e5 LibWeb: Move hit testing to the painting tree 2022-03-11 00:21:49 +01:00
Andreas Kling
ba606d9057 LibWeb: Move PaintingBox to its own .cpp and .h files 2022-03-11 00:21:49 +01:00