Commit Graph

21 Commits

Author SHA1 Message Date
Andreas Kling
268b9c5d90 LibWeb: Make the layout tree GC-allocated
This removes a set of complex reference cycles between DOM, layout tree
and browsing context.

It also makes lifetimes much easier to reason about, as the DOM and
layout trees are now free to keep each other alive.
2022-10-20 15:16:23 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Luke Wilde
46ce50f74e LibWeb: Make Range.setStart and Range.setEnd spec compliant
These functions are way more involved than simply setting their
respective boundary points :^)
2022-02-26 12:53:32 +01:00
Luke Wilde
af3c866898 LibWeb: Make TreeNode::child_count return size_t instead of int
The primary benefit of this is that it's unsigned, as you can't have a
negative amount of children. Plus, all the users of child_count expect
it to be size_t.
2022-02-26 12:53:32 +01:00
Andreas Kling
9358f108c4 LibWeb: Add TreeNode<T>::next_in_pre_order(T* stay_within) variant
This is a scoped variant of the pre-order traversal helper that aborts
when attempting to leave the `stay_within` node.
2022-01-23 01:22:41 +01:00
Andreas Kling
6f0d7245d7 LibWeb: Allow Document::ref() when ref-count is zero
DOM::Document has some special lifetime rules to support the DOM
lifetime semantics expected on the web. Any DOM node will keep its
document alive as well, even after the document's ref-count has reached
zero. This is achieved by the Document::m_referencing_node_count
counter.

Because of this mechanism, we can't VERIFY(m_ref_count) in TreeNode
where T may be a DOM::Document.
2021-10-03 16:42:34 +02:00
Brian Gianforcaro
2b57018196 LibWeb: Use default instead of an empty constructor/destructor
Default implementations allow for more optimizations.
See: https://pvs-studio.com/en/docs/warnings/v832/
2021-09-16 17:17:13 +02:00
Luke Wilde
e4d97add3d LibWeb: Implement ParentNode.children
Required by Web Platform Tests for the innerHTML/outerHTML tests.
2021-09-14 02:09:18 +02:00
Luke Wilde
1a28fc3cb5 LibWeb: Add preceding and following Node cases in tree constraints
This also does some east-const changes in TreeNode.
2021-09-07 22:06:39 +02:00
Andreas Kling
ee3a73ddbb AK: Rename downcast<T> => verify_cast<T>
This makes it much clearer what this cast actually does: it will
VERIFY that the thing we're casting is a T (using is<T>()).
2021-06-24 19:57:01 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Tobias Christiansen
c09ac536c5 LibWeb: Add capabilities to find the index of a child in its parent.
For Elements depending on the index they are inside their parent. Most
notably the <ol> element.
Also added a typed version to only count children of a certain type.

This patch is work towards #2059
2021-04-20 18:29:19 +02:00
AnotherTest
a6e4482080 AK+Everywhere: Make StdLibExtras templates less wrapper-y
This commit makes the user-facing StdLibExtras templates and utilities
arguably more nice-looking by removing the need to reach into the
wrapper structs generated by them to get the value/type needed.
The C++ standard library had to invent `_v` and `_t` variants (likely
because of backwards compat), but we don't need to cater to any codebase
except our own, so might as well have good things for free. :^)
2021-04-10 21:01:31 +02:00
Luke
5beacf08a2 LibWeb: Make the node mutation algorithms more spec compliant
The mutation algorithms now more closely follow the spec and
fixes some assertion failures in tests such as Acid3 and Dromaeo.

The main thing that is missing right now is passing exceptions to the
bindings layer. This is because of issue #6075. I spent a while trying
to work it out and got so frustrated I just left it as a FIXME. Besides
that, the algorithms bail at the appropriate points.

This also makes the adopting steps in the document more spec compliant
as it's needed by the insertion algorithm. While I was at it, I added
the adoptNode IDL binding.

This adds a bunch of ancestor/descendant checks to TreeNode as well.
I moved the "remove_all_children" function to Node as it needs to use
the full remove algorithm instead of simply removing it from
the child list.
2021-04-06 21:42:00 +02:00
Luke
e56c56128b LibWeb: Add non-inclusive variants of subtree traversal 2021-04-06 21:42:00 +02:00
Luke
ca71ac484b LibWeb: Rename "for_each_in_subtree(_of_type)" to "for_each_in_inclusive_subtree(_of_type)"
This is because it includes the initial node that the function was
called on, which makes it "inclusive" as according to the spec.

This is important as there are non-inclusive variants, particularly
used in the node mutation algorithms.
2021-04-06 21:42:00 +02:00
Luke
f482628fe5 LibWeb: Strip out the mutation event logic from TreeNode
This will instead be done by Node, as they need to occur at precise
steps of the mutation algorithms. Additionally, some of the events
may need to be run multiple times. For example, the removal steps
is run for all the shadow-including descendants of the node that
just got removed.
2021-04-06 21:42:00 +02:00
Andreas Kling
c70e0a4f29 LibWeb: Sever parent/child connections in ~TreeNode()
Also make sure to unref the children if there are any. Without this
it was very easy to leak TreeNodes.
2021-04-06 15:51:55 +02:00
Andreas Kling
41e5a0fe02 LibWeb: Remove duplicated code in TreeNode::remove_child()
We were assigning to m_first_child twice.
2021-04-06 14:27:44 +02:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00