Commit Graph

50 Commits

Author SHA1 Message Date
Shannon Booth
97c1722ebd LibWeb: Remove resolved FIXME about implementing more methods in Range
We are not missing a whole bunch of IDL methods any more :^)
2024-05-12 07:28:09 +01:00
Andreas Kling
bbb96d65b1 LibWeb: Don't crash on live range offset update during node insertion
When inserting a node into a parent, any live DOM ranges that reference
the parent may need to be updated. The spec does this by increasing or
decreasing the start/end offsets of each live range *before* actually
performing the insertion.

This caused us to crash with a verification failure, since it was
possible to set the range offset to an invalid value (that would go on
to immediately become valid after the insertion was finished).

This patch fixes the issue by adding special badged helpers on Range for
Node to reach into it and increase/decrease the offsets during node
insertion. This skips the offset validity check and actually makes our
code read slightly more like the spec.

Found by Domato :^)
2024-03-12 16:30:39 +01:00
Aliaksandr Kalenik
02d5ed44cb LibWeb: Stub Range::get_client_rects()
Fixes "Application error: a client-side exception has occurred (see
the browser console for more information)." on https://kotlinlang.org/
2024-01-20 08:56:52 +01:00
Shannon Booth
ee431e6911 LibWeb: Use WebIDL typedefs in Range/AbstractRange
In the public APIs which have their types exposed through IDL.
2024-01-04 10:10:44 +01:00
Andreas Kling
bfd354492e LibWeb: Put most LibWeb GC objects in type-specific heap blocks
With this change, we now have ~1200 CellAllocators across both LibJS and
LibWeb in a normal WebContent instance.

This gives us a minimum heap size of 4.7 MiB in the scenario where we
only have one cell allocated per type. Of course, in practice there will
be many more of each type, so the effective overhead is quite a bit
smaller than that in practice.

I left a few types unconverted to this mechanism because I got tired of
doing this. :^)
2023-11-19 22:00:48 +01:00
Shannon Booth
7b79324548 LibWeb: Port Range interface from DeprecatedString to String 2023-08-29 10:05:02 +02:00
Andreas Kling
72c9f56c66 LibJS: Make Heap::allocate<T>() infallible
Stop worrying about tiny OOMs. Work towards #20449.

While going through these, I also changed the function signature in many
places where returning ThrowCompletionOr<T> is no longer necessary.
2023-08-13 15:38:42 +02:00
Andreas Kling
18c54d8d40 LibJS: Make Cell::initialize() return void
Stop worrying about tiny OOMs.

Work towards #20405
2023-08-08 07:39:11 +02:00
Andreas Kling
e8f5085669 LibWeb: Implement Range.createContextualFragment() 2023-03-10 14:58:55 +01:00
Matthew Olsson
c0b2fa74ac LibWeb: Fix a few const-ness issues 2023-03-06 13:05:43 +00:00
Kenneth Myhra
0791195843 LibWeb: Make factory methods of DOM::Range fallible 2023-02-18 00:52:47 +01:00
Timothy Flynn
2692db8699 LibJS+Everywhere: Allow Cell::initialize overrides to throw OOM errors
Note that as of this commit, there aren't any such throwers, and the
call site in Heap::allocate will drop exceptions on the floor. This
commit only serves to change the declaration of the overrides, make sure
they return an empty value, and to propagate OOM errors frm their base
initialize invocations.
2023-01-29 00:02:45 +00:00
Andreas Kling
b79bc25a1f LibWeb: Use DOM Selection instead of ad-hoc layout tree selection
Before this patch, we were expressing the current selection as a range
between two points in the layout tree. This was a made-up concept I
called LayoutRange (2x LayoutPosition) and as it turns out, we don't
actually need it!

Instead, we can just use the Selection API from the Selection API spec.
This API expresses selection in terms of the DOM, and we already had
many of the building blocks implemented.

To ensure that selections get visually updated when the underlying Range
of an active Selection is programmatically manipulated, Range now has
an "associated Selection". If a range is updated while associated with
a selection, we recompute layout tree selection states and repaint the
page to make it user-visible.
2023-01-12 19:55:10 +01:00
Andreas Kling
bf69f4370e LibWeb: Implement BrowsingContext::selected_text() in terms of Selection
Instead of sifting through the layout tree to extract the selected text,
look at the DOM selection instead.

Note that we can't just stringify the DOM Range, as that would include
non-visible things (like the content of <style> elements, etc.) so we
run it through an ad-hoc variant of the range stringification algorithm.
This can probably be factored better, but it's a start. :^)
2023-01-12 19:55:10 +01:00
Timothy Flynn
834202aeb9 LibWeb: Move setting of Web object prototypes to initialize()
This needs to happen before prototype/constructor intitialization can be
made lazy. Otherwise, GC could run during the C++ constructor and try to
collect the object currently being created.
2023-01-10 16:08:14 +01:00
Luke Wilde
34c130b336 LibWeb: Stub Range.getBoundingClientRect
This seems to be used by Discord around the chat message box, but
didn't explore very far.
2022-12-10 00:21:10 +00:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01: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
317ab7a04b LibWeb: Make Range's boundary point comparison a public function
We'll need this in the Selection API implementation as well.
2022-10-11 21:49:48 +02:00
Andrew Kaster
8de7e49a56 LibWeb: Remove unecessary dependence on Window from DOM and WebIDL
These classes only needed Window to get at its realm. Pass a realm
directly to construct DOM and WebIDL classes.

This change importantly removes the guarantee that a Document will
always have a non-null Window object. Only Documents created by a
BrowsingContext will have a non-null Window object. Documents created by
for example, DocumentFragment, will not have a Window (soon).

This incremental commit leaves some workarounds in place to keep other
parts of the code building.
2022-10-01 21:05:32 +01:00
Linus Groh
ad04d7ac9b LibWeb: Move ExceptionOr from DOM/ to WebIDL/
This is a concept fully defined in the Web IDL spec and doesn't belong
in the DOM directory/namespace - not even DOMException, despite the name
:^)
2022-09-25 19:13:31 +01:00
Linus Groh
4270ede7c4 LibWeb: Remove WRAPPER_HACK() macro
We no longer access Bindings::FooWrapper anywhere for a Foo platform
object, so these can be removed :^)
2022-09-21 21:12:24 +01:00
Andreas Kling
45425de849 LibWeb: Use the WRAPPER_HACK() macro instead of hand-coding wrap()
This macro will soon go away, but let's start by replacing all the
hand-coded versions of wrap() with this macro that expands to the same
exact thing.
2022-09-06 00:27:09 +02:00
Andreas Kling
6f433c8656 LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
2022-09-06 00:27:09 +02:00
Andreas Kling
bb547ce1c4 LibWeb: Make AbstractRange and subclasses GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
2fb9eb5257 LibWeb: Implement Range.deleteContents()
And here's another point on Acid3. :^)
2022-03-22 20:17:52 +01:00
Andreas Kling
e1c71b3f91 LibWeb: Implement Range.cloneContents() 2022-03-22 20:03:09 +01:00
Andreas Kling
8ab25f8d8c LibWeb: Implement Range.surroundContents(newParent)
Here goes another Acid3 point :^)
2022-03-21 23:28:46 +01:00
Andreas Kling
1254758b00 LibWeb: Update live DOM ranges on Text and CharacterData mutations
Taking care of the FIXMEs I added in earlier patches. :^)
2022-03-21 20:06:59 +01:00
Andreas Kling
c74b1b6d65 LibWeb: Implement Range.insertNode(node) 2022-03-21 19:14:50 +01:00
Andreas Kling
16f4c76da6 LibWeb: Implement Range.extractContents()
Another point on Acid3 coming through! :^)
2022-03-21 18:06:28 +01:00
Andreas Kling
394cd77467 LibWeb: Implement stringifier for DOM Range :^) 2022-03-21 16:29:19 +01:00
Lenny Maiorani
c37820b898 Libraries: Use default constructors/destructors in LibWeb
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-17 17:23:49 +00:00
Linus Groh
1422bd45eb LibWeb: Move Window from DOM directory & namespace to HTML
The Window object is part of the HTML spec. :^)
https://html.spec.whatwg.org/multipage/window-object.html
2022-03-08 00:30:30 +01:00
Luke Wilde
ad5fb1fd7e LibWeb: Implement Range.comparePoint 2022-02-26 12:53:32 +01:00
Luke Wilde
62b76e0658 LibWeb: Implement Range.isPointInRange 2022-02-26 12:53:32 +01:00
Luke Wilde
386ee5ab17 LibWeb: Implement Range.intersectsNode 2022-02-26 12:53:32 +01:00
Luke Wilde
4c08757ff9 LibWeb: Add Range.detach 2022-02-26 12:53:32 +01:00
Luke Wilde
8a755726ad LibWeb: Implement Range.selectNodeContents 2022-02-26 12:53:32 +01:00
Luke Wilde
2b2dbdc74f LibWeb: Implement Range.collapse 2022-02-26 12:53:32 +01:00
Luke Wilde
dfdc2ddb9e LibWeb: Implement Range.selectNode 2022-02-26 12:53:32 +01:00
Luke Wilde
a26f1b2ff9 LibWeb: Implement Range.compareBoundaryPoints 2022-02-26 12:53:32 +01:00
Luke Wilde
d73fb7e10f LibWeb: Implement Range.set{Start,End}{Before,After} 2022-02-26 12:53:32 +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
a2acda5669 LibWeb: Abstract Range's members into AbstractRange
Range's member variables are stored in AbstractRange as per the spec,
as they are also shared with StaticRange.
2022-02-26 12:53:32 +01:00
Andreas Kling
c25d653c31 LibWeb: Implement Range.commonAncestorContainer 2022-02-25 20:45:03 +01: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
Andreas Kling
9194a97cbe LibWeb: Add Document.createRange()
Also tidy up DOM::Range a little bit while we're here, and unify the
way we create them to use a delegating constructors.
2021-02-21 23:48:01 +01:00
Linus Groh
8f8f7bfd0f LibWeb: Add constructor to Range IDL interface 2021-02-17 23:45:07 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00