Commit Graph

64 Commits

Author SHA1 Message Date
Timothy Flynn
4b94b0b561 LibWeb: Begin implementing the Clipboard API
https://w3c.github.io/clipboard-apis/

This implements enough for navigator.clipboard.writeText(String).
2023-11-11 08:54:37 +01:00
Andreas Kling
93e4a0de16 LibWeb: Move has_a_rendering_opportunity() to Navigable 2023-09-20 18:29:17 +02:00
Timothy Flynn
f598a357ad LibWeb: Assign a unique ID to each HTML task
And return that ID when queueing an element task. This is required for
some task tracking - specifically, the HTML ToggleTaskTracker struct.
2023-09-13 13:45:47 +02:00
Zaggy1024
766cd852d3 LibWeb: Move the unique task source start to be last in Task::Source
This also adds some big text to draw attention to the fact that this
enum value must remain last.
2023-08-29 14:50:21 -04:00
Andrew Kaster
6e64bf5464 LibWeb: Remove outdated old_queue_global_event_with_document
The FIXME here describes an old constraint on JS Interpreters which no
longer holds. It hails from a time when we had the global object and
JS realm attached to the document.
2023-08-28 12:57:05 +02:00
Luke Wilde
af2886449a LibWeb: Implement PerformanceObserver 2023-08-27 23:27:44 +02:00
Karol Kosek
b731705fec LibWeb: Implement HTMLCanvasElement.toBlob() 2023-08-04 11:05:55 +02:00
Luke Wilde
165abafb80 LibWeb: Add initial implementation of IntersectionObserver
The main missing features are rootMargin, proper nested browsing
context support and content clip/clip-path support.

This makes images appear on some sites, such as YouTube and
howstuffworks.com.
2023-07-07 05:27:25 +02:00
Zaggy1024
8157bb601b LibWeb: Place the unique task source used by media elements last
In the merging of an extremely large navigables PR, a task queue source
was added after the unique task source start value that was supposed to
remain last in the enum.
2023-06-30 12:52:46 +02:00
Luke Wilde
a53486a073 LibWeb: Add method to get last added task to an EventLoop 2023-06-19 06:12:26 +02:00
Shannon Booth
79fc7d7c7c LibWeb: Add HTML::Task::Source::FileReading 2023-06-14 06:27:04 +02:00
Andreas Kling
2626e28bb6 LibWeb: Add HTML::Task::Source::NavigationAndTraversal 2023-04-25 12:54:01 +02:00
Sam Atkins
6d93e03211 LibWeb+Browser+Ladybird: Use JS::SafeFunction for EventLoop callbacks
This automatically protects captured objects from being GC'd before the
callback runs.
2023-04-21 20:44:47 +01:00
Timothy Flynn
9a370a5eed LibWeb: Support taking matching tasks out of a task queue
This will be needed for HTMLMediaElement.
2023-04-07 16:02:22 +02:00
Timothy Flynn
807891c0df LibWeb: Support unique task sources
Some elements, like HTMLMediaElement, must have a unique task sources
for every instance of that element that is created. Support this with a
simple wrapper around IDAllocator.
2023-04-07 16:02:22 +02:00
Andreas Kling
bc6e61adec LibWeb: Don't churn HTML::EventLoop while in microtask checkpoint
At the end of HTML::EventLoop::process(), the loop reschedules itself if
there are more runnable tasks available.

However, the condition was flawed: we would reschedule if there were any
microtasks queued, but those tasks will not be processed if we're
currently within the scope of a microtask checkpoint.

To fix this, we now only reschedule the HTML event loop for microtask
processing *if* we're not already in a microtask checkpoint.

This fixes the 100% CPU churn seen when looking at PRs on GitHub. :^)
2023-04-01 12:45:47 +01:00
Matthew Olsson
7c0c1c8f49 LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Linus Groh
7de9179a6d LibWeb/HTML: Port Window.performance to IDL 2023-03-07 23:33:34 +00:00
Matthew Olsson
c0b2fa74ac LibWeb: Fix a few const-ness issues 2023-03-06 13:05:43 +00:00
Linus Groh
2a66fc6cae LibJS: Add make_handle({Nonnull,}GCPtr<T>) overloads 2022-12-15 06:56:37 -05:00
Timothy Flynn
4b8729aea6 LibWeb: Add a flag to pause an HTML event loop's execution
This will be used to unblock the WebContent IPC event loop while waiting
for a dialog response.
2022-11-16 17:23:56 +00:00
Linus Groh
32ad939e44 LibWeb: Rename HighResolutionTime/{CoarsenTime => TimeOrigin}.cpp/h
This is being used for more than just time coarsening now, so let's use
the spec's section title for the name.
2022-10-05 09:12:59 +01:00
Linus Groh
4ea6cc56be LibWeb: Move unsafe_shared_current_time() to HighResolutionTime
This doesn't belong on the EventLoop at all, as far as I can tell.
2022-10-05 09:12:59 +01:00
Andrew Kaster
f0c5f77f99 LibWeb: Remove unecessary dependence on Window from HTML classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct HTML classes.
2022-10-01 21:05:32 +01:00
Andreas Kling
d505192014 LibWeb: Use JS::SafeFunction in the HTML task queues
This means that HTML tasks automatically protect anything in their
capture lists, and we no longer need to jump through hoops with
JS::Handle etc.
2022-09-24 12:23:29 +02:00
Linus Groh
6055b0e850 LibWeb: Remove no-op impl() methods from the WEB_PLATFORM_OBJECT macro
These are leftovers from when wrapper objects still had an internal
implementation, which is no longer the case.
2022-09-21 21:12:24 +01:00
Andreas Kling
0c7ab663c1 LibWeb: Flesh out most of the "unload" algorithm for documents
Yet another small steps towards spec-compliant document lifecycles.
2022-09-21 11:51:18 +02:00
Andreas Kling
4ee5dfbe4b LibWeb: Flesh out a chunk of the HTML spec's frame navigation algorithms 2022-09-20 10:32:13 +02:00
Andreas Kling
da451467b1 LibWeb: Implement basic "scroll" events at the document level 2022-09-17 18:53:26 +02:00
Andreas Kling
9567e211e7 LibWeb+WebContent: Add abstraction layer for event loop and timers
Instead of using Core::EventLoop and Core::Timer directly, LibWeb now
goes through a Web::Platform abstraction layer instead.

This will allow us to plug in Qt's event loop (and QTimer) over in
Ladybird, to avoid having to deal with multiple event loops.
2022-09-07 20:30:31 +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
Linus Groh
52543fc771 LibJS+LibWeb: Let Realm store a plain Object for [[GlobalObject]]
This removes the requirement of having a global object that actually
inherits from JS::GlobalObject, which is now a perfectly valid scenario.

With the upcoming removal of wrapper objects in LibWeb, the HTML::Window
object will inherit from DOM::EventTarget, which means it cannot also
inherit from JS::GlobalObject.
2022-08-28 16:36:56 +01:00
Linus Groh
173dcfb7cb Everywhere: Fix a bunch of typos 2022-05-29 15:22:00 +02:00
Simon Wanner
836d2ff259 LibWeb: Implement the infrastructure necessary for requestIdleCallback
This includes a bug fix for the event loop processing steps which has
not been merged yet: https://github.com/whatwg/html/pull/7768
2022-04-02 23:52:25 +01:00
Ali Mohammad Pur
c1649e3372 LibWeb: Define HTML::perform_a_microtask_checkpoint()
This was declared and not defined.
2022-03-28 23:11:48 +02: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
17aeb99e9e LibWeb: Implement the JS host hooks for promises, job callbacks and more
This overrides the JS host hooks to follow the spec for queuing
promises, making/calling job callbacks, unhandled promise rejection
handling and FinalizationRegistry queuing.

This also allows us to drop the on_call_stack_emptied hook in
Document::interpreter().
2022-02-08 17:47:44 +00:00
Luke Wilde
f71f404e0c LibWeb: Introduce the Environment Settings Object
The environment settings object is effectively the context a piece of
script is running under, for example, it contains the origin,
responsible document, realm, global object and event loop for the
current context. This effectively replaces ScriptExecutionContext, but
it cannot be removed in this commit as EventTarget still depends on it.

https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object
2022-02-08 17:47:44 +00:00
Andreas Kling
7c57961c61 LibWeb: Move BrowsingContext into HTML/
Browsing contexts are defined by the HTML specification, so let's move
them into the HTML directory. :^)
2021-11-18 21:11:30 +01:00
Sam Atkins
050823bea7 LibWeb: Fire MediaQueryListEvents when an MQL's match-state changes
The HTML event loop does a check for MQL match-state changes and
dispatches the events. This requires us to keep a list of MQLs on the
Document.
2021-10-05 18:51:39 +02:00
Andreas Kling
478b36c37b LibWeb: Only auto-reschedule HTML::EventLoop when there are runnables
HTML::EventLoop tries to reschedule itself when there are more tasks in
any of its queues, but let's not do it if none of them are runnable.
2021-10-03 18:25:15 +02:00
Andreas Kling
962298b040 LibWeb: Don't update rendering in BrowsingContexts without opportunity
This patch adds the "has a rendering opportunity" concept from the spec
to BrowsingContext and uses it to filter out contexts that are unable
to render right now when doing the event loop's rendering updates.

Note that we actually consider all contexts to have a rendering
opportunity at all times right now. Coming up with reasons to avoid
rendering is left as a FIXME. :^)
2021-10-03 17:39:13 +02:00
Andreas Kling
6e341cd696 LibWeb: Let HTML::EventLoop drive the firing of resize events 2021-10-03 16:42:34 +02:00
Andreas Kling
81ef2b646e LibWeb: Let HTML::EventLoop drive animation frame callbacks 2021-10-03 16:42:34 +02:00
Andreas Kling
ae71e5f99b LibWeb: Let HTML::EventLoop keep track of live DOM::Document objects
This will be used by the event loop processing model.
2021-10-03 16:42:34 +02:00
Andreas Kling
bbfde63f79 LibWeb: Only take runnable tasks from the HTML task queue
We were previously willing to execute tasks before they had become
runnable.
2021-10-03 16:42:34 +02:00
Andreas Kling
6283c098ad LibWeb: Improve HTML::EventLoop::spin_until()
This algorithm now saved and restores the JavaScript execution context
stack while performing a microtask checkpoint, as the spec mandates.
2021-10-03 16:42:34 +02:00
Andreas Kling
5cf439cce0 LibWeb: Run setTimeout() and setInterval() callbacks as HTML tasks
We now invoke DOM timer callbacks via HTML tasks. This brings callback
sequencing closer to the spec, although there are still many
imperfections in this area.
2021-10-03 13:36:40 +02:00
Andreas Kling
a248ec63e3 LibWeb: Implement window.queueMicrotask(callback)
This API allows authors to schedule a serialized JS callback that will
get invoked at the next spec-allowed opportunity.
2021-09-26 14:39:14 +02:00