Commit Graph

123 Commits

Author SHA1 Message Date
Andreas Kling
a4625e3943 LibWeb: Only react to link element attribute changes when BC connected
Link elements that aren't "browsing-context connected" should not
trigger a resource fetch when their attributes change.

This fixes an issue where we'd waste time by loading every style sheet
twice! :^)
2024-04-26 10:40:43 +02:00
Andreas Kling
870a954e11 LibWeb: Implement Element.outerHTML
This piggybacks on the same fragment serialization code that innerHTML
uses, but instead of constructing an imaginary parent element like the
spec asks us to, we just add a separate serialization mode that includes
the context element in the serialized markup.

This makes the image carousel on https://utah.edu/ show up :^)
2024-04-09 18:17:14 -04:00
Tim Ledbetter
521a1be97f LibWeb: Don't crash when querying the CDataSection.assignedSlot property 2024-03-23 20:56:26 +01:00
Aliaksandr Kalenik
036cd9b2dd LibWeb: Null layout and paintable pointers of removed DOM::Node
When a node is removed from the DOM tree, its paintable needs to be
removed to ensure that it is not used to obtain sizes that are no
longer valid.

This change enables the ResizeObserver to send a notification if a node
is removed, as it should, because a removed node now has a size of zero

It should be okay to nullify pointers without concerning
parent/sibling/child relationships because the layout and paintable
trees will be rebuilt following any DOM mutation anyway.
2024-02-20 10:55:10 +01:00
Andreas Kling
75d5429d66 LibWeb: Add fast_is<T> for form, embed, image, and object elements
These are used by Window::supported_property_names(), which can get
very hot.
2023-12-24 22:49:19 +01:00
Shannon Booth
a8f5ebeddd LibWeb: Port DOM::Node from DeprecatedString 2023-12-02 22:54:53 +01:00
Sam Atkins
cc633123ca LibWeb: Extract shared lazy-loading behavior into a base class
`<iframe>` and `<img>` tags share the same spec for several aspects of
lazy-loading: how the `loading` attribute works, the "will lazy load
element" steps, and a member for storing the lazy-load resumption
steps. So let's share the implementation by using a base class.

This mostly involves moving things around. However, we also change the
`start_intersection_observing_a_lazy_loading_element()` method to take
a LazyLoadingElement, and operate on one, instead of always casting to
HTMLImageElement.

We do unfortunately have to do some shenanigans to make the cast work,
by adding a virtual function stub in DOM::Element.
2023-12-01 10:28:02 +01:00
Shannon Booth
6c42de3e8b LibWeb: Port XMLSerializer from DeprecatedString to String 2023-11-20 15:00:19 +01:00
Andreas Kling
9edfd5e360 LibWeb: Only allocate DOM::Node registered observer list on demand
Most DOM nodes don't have registered mutation observers, so let's put
the metadata about them behind an OwnPtr to save space in the common
case.

Saves 16 bytes per DOM node that doesn't have registered observers.
2023-11-20 00:39:42 +01:00
Shannon Booth
eca9874e56 LibWeb: Port Element::attribute_changed from DeprecatedString to String
Which as you would expect has a bunch of fallout, but also results in a
whole lot of awkward conversions falling away.
2023-11-19 08:16:34 +00:00
Andreas Kling
6b580d68a3 LibWeb: Rename DOM::Node::id() to unique_id()
The old name was pretty confusing, since it had nothing to do with the
common "id" content attribute.

This makes way for using id() to return the "id" attribute instead. :^)
2023-11-02 17:09:34 +01:00
Ali Mohammad Pur
aeee98b3a1 AK+Everywhere: Remove the null state of DeprecatedString
This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
2023-10-13 18:33:21 +03:30
Shannon Booth
e4f8c59210 LibWeb: Port AttributeNames to FlyString 2023-10-08 08:11:48 -04:00
Andreas Kling
a6131634f1 LibWeb: Add fast_is<T>() for HTMLSlotElement
2.4x speed-up on StyleBench :^)
2023-09-23 13:04:38 +02:00
Shannon Booth
07b332e17c LibWeb: Add IDL definition for SVGScriptElement
It does not currently handle any of the actual scripting, but this
should at least allow us to create an instance of the element.

The test being added here isn't actually testing much, but before the
previous commit we used to crash parsing the page due to a TODO().
2023-09-23 11:41:57 +02:00
Shannon Booth
8ce9e51c97 LibWeb: Port Node interface from DeprecatedString to String
Which is fortunately quite straight forward :^)
2023-09-17 20:29:18 +02:00
Timothy Flynn
45b36bd08a LibWeb: Introduce the slottable concept for DOM elements and text nodes
A slottable is either a DOM element or a DOM text node. They may be
assigned to slots (HTMLSlotElement) either automatically or manually.
Automatic assignment occurs by matching a slot's `name` attribute to
a slottable's `slot` attribute. Manual assignment occurs by using the
slot's (not yet implemented) `assign` API.

This commit does not perform the above assignments. It just sets up the
slottable concept via IDL and hooks the slottable mixin into the element
and text nodes.
2023-09-13 13:45:47 +02:00
Aliaksandr Kalenik
63939445b1 LibWeb: Use fit-content width if button's computed width is "auto"
Implements following line from the spec:
"If the computed value of 'inline-size' is 'auto', then the used value
is the fit-content inline size."
2023-09-12 17:26:30 +02:00
Andreas Kling
d54cd23615 LibWeb: Never blockify HTML <br> elements
This is a bit iffy, but since <br> elements can't be implemented in
"just CSS" today, we should also exclude them from the blockification
algorithm. This is important, since <br> is expected to always have
inline-like behavior.
2023-09-01 12:45:38 +02:00
Andreas Kling
354d2ccc3c LibWeb: Support fast_is<T>() for table, table sections, rows and cells
3.2x speed-up on WebKit/PerformanceTests/DOM/GridSort.html
2023-08-23 08:06:25 +02:00
Andreas Kling
3d7c880a42 LibWeb: Give DOM::Node a direct pointer to its Paintable
Instead of going via the layout tree.
2023-08-20 05:02:59 +02:00
Andreas Kling
25375bf1d5 LibWeb: Make Document::paintable() return a ViewportPaintable 2023-08-20 05:02:59 +02:00
Aliaksandr Kalenik
c985a1b2af LibWeb: Add non-const version of paintable_box() in DOM::Node 2023-08-07 05:23:31 +02:00
Andreas Kling
bb39ca9b4a LibWeb: Add fast_is<SVGGraphicsElement>()
This dynamic_cast was ~6% of runtime when mousing around on Discord.
2023-08-04 05:28:41 +02:00
Andreas Kling
28fdc7af05 LibWeb: Detach stale layout nodes from DOM during layout tree build
When toggling `display: none` on an element, it can go from having a
layout subtree to not having one. In the `none` case, we were previously
leaving stale layout nodes hanging off DOM nodes in the subtree.

These layout nodes could be queried for outdated information and
probably other things that we shouldn't allow.

Fix this by having TreeBuilder prune any old layout nodes hanging off
nodes in a subtree after its subtree root doesn't produce a layout node.
2023-08-01 09:19:41 +02:00
Aliaksandr Kalenik
6b191ab73d LibJS+LibWeb: Add fast_is<DOM::Node> for JS::Object
Solves problem that is<DOM::Node, JS::Object>() is quite hot in
profiles while loading https://www.postgresql.org/about/featurematrix/.
2023-07-14 05:55:41 +02:00
Aliaksandr Kalenik
04a5196a5d LibWeb: Add fast_is<T>() for SVGUseElement
is<SVGUseElement> quite hot in profiles
2023-06-23 06:23:42 +02:00
PrestonLTaylor
31d536912c LibWeb: Allow SVG painting to escape out of a shadow tree
The spec for the `<use>` element requires a shadow tree for the
rendered content, so we need to be able to escape shadow trees when
rendering svg content.
2023-06-03 05:58:00 +02:00
Andreas Kling
dd19f61538 LibWeb: Add fast way to check if a DOM node is an SVG element 2023-05-24 06:43:21 +02:00
Andreas Kling
80d6330a26 LibWeb: Don't create mutation record node lists if nobody is interested
By deferring allocation of StaticNodeList objects until we know somebody
actually wants the MutationRecord, we avoid a *lot* of allocation work.

This shaves several seconds off of loading https://tc39.es/ecma262/

At least one other engine (WebKit) skips creating mutation records if
nobody is interested, so even if this is observable somehow, we would
at least match the behavior of a major engine.
2023-05-23 06:31:37 +02:00
Andreas Kling
4637d020c3 LibWeb: Add fast_is<T>() helper for HTMLScriptElement
This makes loading Google Groups quite a bit faster, as 20% of runtime
while loading was spent asking if DOM nodes are HTMLScriptElement.
2023-05-07 10:47:30 +02:00
Aliaksandr Kalenik
22572c39e0 LibWeb: Implement Node::navigable()
https://html.spec.whatwg.org/multipage/document-sequences.html#node-navigable
2023-04-23 15:41:05 +02:00
Linus Groh
d58b671ff6 LibWeb/DOM: Rename Node::{paint => paintable}_box()
It returns a PaintableBox, not a 'PaintBox'.
2023-04-20 20:43:30 +02:00
Andreas Kling
d8ccc2d54e LibWeb: Rename BrowsingContextContainer => NavigableContainer
The "browsing context container" concept in the HTML spec has been
replaced with "navigable container". Renaming this is the first step of
many towards implementing the new world.

Co-authored-by: Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
2023-04-19 18:26:45 +02:00
Luke Wilde
034aaf3f51 LibWeb: Introduce CustomElementRegistry and creating custom elements
The main missing feature here is form associated custom elements.
2023-04-06 11:36:56 +02:00
Andreas Kling
d4b2544dc5 LibWeb: Make the Node.compareDocumentPosition() return value enum public
This will allow other parts of LibWeb to understand these values.
2023-03-30 14:12:07 +02:00
Timothy Flynn
8a8340b3cd LibWeb: Port MutationRecord types to FlyString
Co-authored-by: Luke Wilde <lukew@serenityos.org>
2023-03-18 19:50:45 +01:00
Matthew Olsson
7c0c1c8f49 LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Andreas Kling
1cf5737e9e LibWeb: Add fast_is<T>() for various types stood out in a profile 2023-03-11 10:46:26 +01:00
Matthew Olsson
c0b2fa74ac LibWeb: Fix a few const-ness issues 2023-03-06 13:05:43 +00:00
Jonah
da5c9189b2 LibWeb: Implement Accessible Name and Description Calculation
This is an initial implementation of the accname standard. There is
still some of the algorithm left unimplemented that we will need
to implement in the future. However, as is, this implementation is
sufficient for basic pages.
2023-02-19 15:58:20 +01:00
Linus Groh
8556d47240 LibWeb: Move ARIA-related code into the Web::ARIA namespace
ARIA has its own spec and is not part of the DOM spec, which is what the
Web::DOM namespace is for (https://www.w3.org/TR/wai-aria-1.2/).

This allows us to stay closer to the spec with function names and don't
have to add the word "ARIA" to identifiers constantly - the namespace
now provides that clarity.
2023-01-29 00:02:55 +00:00
MacDue
890b4d7980 LibWeb: Replace ARIA role static FlyStrings with an enum
This replaces the FlyStrings for ARIA roles that were constructed in
a [[gnu::constructor]] with a single enum. I came across this as the
DOM inspector was crashing due to a null FlyString for an ARIA role.

After fixing that, I was confused as to why these roles were not an
enum. Looking at the spec there's a fixed list of roles and switching
from references to static strings to an enum was pretty much an
exercise in find and replace :).

No functional changes (outside of fixing the mentioned crash).
2023-01-28 22:09:18 +00:00
Sam Atkins
7891ad2a28 LibWeb: Remove declarations for non-existent methods 2023-01-27 20:33:18 +00:00
Andreas Kling
35ba13802d LibWeb: Remove unused declaration Node::removed_last_ref() 2023-01-11 12:55:00 +01:00
Timothy Flynn
f3db548a3d AK+Everywhere: Rename FlyString to DeprecatedFlyString
DeprecatedFlyString relies heavily on DeprecatedString's StringImpl, so
let's rename it to A) match the name of DeprecatedString, B) write a new
FlyString class that is tied to String.
2023-01-09 23:00:24 +00:00
Jonah
a469bbd178 LibWeb: Add Functionality to Dump to Accessibility Tree
This will be used to display the accessibility tree in the inspector.
2023-01-07 10:51:53 +00:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Andreas Kling
87b0ddb354 LibWeb: Add DOM::Node::parent_or_shadow_host_element()
This will be used in style computation to inherit style across shadow
tree boundaries.
2022-11-05 18:54:39 +01:00
Timothy Flynn
13b8eeff54 LibWeb: Fully implement the fragment serializing algorithm
Rather than assuming the node's node document is an HTML document,
handle XML documents as well.
2022-11-03 14:48:04 +00:00