Commit graph

216 commits

Author SHA1 Message Date
Andreas Kling
9888e29c14 LibWeb: Streamline Node::enclosing_link_element() somewhat
No need to verify_cast repeatedly once we've confirmed the type.
2022-03-02 17:40:18 +01:00
Idan Horowitz
feb00b7105 Everywhere: Make JSON serialization fallible
This allows us to eliminate a major source of infallible allocation in
the Kernel, as well as lay down the groundwork for OOM fallibility in
userland.
2022-02-27 20:37:57 +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
Andreas Kling
784dbdef8e LibWeb: Make DOM inspector overlay rects a little nicer
Instead of just the outline, fill them with some semi-transparent color.
Also add tag name, ID, classes and coordinates to the little tooltip.
Finally, use the border box instead of the context box for metrics,
same as other browsers.
2022-02-26 08:25:46 +01:00
Andreas Kling
19b5033dc4 LibWeb: Implement Node.removeChild() in terms of "pre-remove"
This is what the spec wants us to do.
2022-02-21 22:21:59 +01:00
Adam Hodgen
c6dd8a1f66 LibWeb: Implement Node.nodeValue DOM attribute 2022-02-21 16:31:45 +01:00
Andreas Kling
e76e8e22b5 LibWeb: Separate "event listener" from "EventListener"
I can't imagine how this happened, but it seems we've managed to
conflate the "event listener" and "EventListener" concepts from the DOM
specification in some parts of the code.

We previously had two things:

    - DOM::EventListener
    - DOM::EventTarget::EventListenerRegistration

DOM::EventListener was roughly the "EventListener" IDL type,
and DOM::EventTarget::EventListenerRegistration was roughly the "event
listener" concept. However, they were used interchangeably (and
incorrectly!) in many places.

After this patch, we now have:

    - DOM::IDLEventListener
    - DOM::DOMEventListener

DOM::IDLEventListener is the "EventListener" IDL type,
and DOM::DOMEventListener is the "event listener" concept.

This patch also updates the addEventListener() and removeEventListener()
functions to follow the spec more closely, along with the "inner invoke"
function in our EventDispatcher.
2022-02-16 22:21:45 +01:00
Luke Wilde
5aacec65ab LibWeb: Rewrite EventTarget to more closely match the spec
This isn't perfect (especially the global object situation in
activate_event_handler), but I believe it's in a much more complete
state now :^)

This fixes the issue of crashing in prepare_for_ordinary_call with the
`i < m_size` crash, as it now uses the IDL callback functions which
requires the Environment Settings Object. The environment settings
object for the callback is fetched at the time the callback is created,
for example, WrapperGenerator gets the incumbent settings object for
the callback at the time of wrapping. This allows us to remove passing
in ScriptExecutionContext into EventTarget's constructor.

With this, we can now drop ScriptExecutionContext.
2022-02-08 17:47:44 +00:00
Andreas Kling
7e1bf4d300 LibWeb: Compute element style in Layout::TreeBuilder
Instead of making each Layout::Node compute style for itself, we now
compute it in TreeBuilder before even calling create_layout_node().

For non-element DOM nodes, we create the style and layout tree node
in TreeBuilder. This allows us to move create_layout_node() from
DOM::Node to DOM::Element.
2022-02-05 22:50:39 +01:00
Vyacheslav Pukhanov
3f006d81fe LibWeb: Add JSON serialization for nested browsing contexts
This changes allows for nested browser contexts to be embedded in the
serialized JSON of their container element (like `iframe`) and enables
their inspection in the DOM Inspector.
2021-11-24 19:07:48 +01:00
Andreas Kling
5088846606 LibWeb: Show DOM comment contents in DOM inspector 2021-11-02 22:30:06 +01:00
Andreas Kling
5db51d85a3 LibWeb: Hide uninteresting whitespace text nodes from DOM inspector
Use a simple heuristic to exclude uninteresting whitespace and
de-clutter the inspector's DOM tree.

Uninteresting whitespace is currently one of these:
- Non-rendered whitespace-only text nodes
- Rendered whitespace-only text nodes between block-level elements
2021-11-02 22:30:06 +01:00
Luke Wilde
1ea3f34823 LibWeb: Implement Node.getRootNode 2021-10-16 10:51:23 +02:00
Andreas Kling
1b6f0f857e LibWeb: Re-mark nodes as needing style after moving between documents
Since style update is driven by Document, moving a node with dirty style
from one document to another means that we have to schedule a style
update in the new document.
2021-10-12 17:53:38 +02:00
Andreas Kling
0264ae23bc LibWeb: Make CSS layout lazier
Instead of doing layout synchronously whenever something changes,
we now use a basic event loop timer to defer and coalesce relayouts.

If you did something that requires a relayout of the page, make sure
to call Document::set_needs_layout() and it will get coalesced with all
the other layout updates.

There's lots of room for improvement here, but this already makes many
web pages significantly snappier. :^)

Also, note that this exposes a number of layout bugs where we have been
relying on multiple relayouts to calculate the correct dimensions for
things. Now that we only do a single layout in many cases, these kind of
problems are much more noticeable. That should also make them easier to
figure out and fix. :^)
2021-10-06 17:14:22 +02:00
Luke Wilde
6a7739c645 LibWeb: Convert Node.childNodes to NodeList
This changes the old child_nodes implementation to children_as_vector
so that can still be used in insert_before.
2021-10-03 00:18:52 +02:00
Andreas Kling
71087422f6 LibWeb: Add Node::in_a_document_tree()
This is "in a document tree" from the DOM spec.
2021-09-30 00:00:55 +02:00
Andreas Kling
f67648f872 LibWeb: Rename HTMLDocumentParser => HTMLParser 2021-09-25 23:36:43 +02:00
Andreas Kling
0ee457dfdf LibWeb: Provide a default DOM::EventTarget::dispatch_event()
All EventTarget subclasses except Window do the same exact thing in
their overrides, so let's just share an implementation in the base.
2021-09-25 23:36:43 +02:00
Luke Wilde
f62477c093 LibWeb: Implement HTML fragment serialisation and use it in innerHTML
The previous implementation was about a half implementation and was
tied to Element::innerHTML. This separates it and puts it into
HTMLDocumentParser, as this is in the parsing section of the spec.

This provides a near finished HTML fragment serialisation algorithm,
bar namespaces in attributes and the `is` value.
2021-09-14 02:09:18 +02:00
Andreas Kling
449cbd5ecc LibWeb: Implement Node.isEqualNode(Node? otherNode) 2021-09-13 12:54:24 +02:00
Andreas Kling
a0528598b5 LibWeb: Implement Node.isSameNode(Node? otherNode) 2021-09-13 12:49:23 +02:00
Andreas Kling
e91edcaa28 LibWeb: Rename InitialContainingBlockBox => InitialContainingBlock
The "Box" suffix added nothing here.
2021-09-08 11:27:46 +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
Luke Wilde
5e61382849 LibWeb: Make Node.textContent more spec compliant
The current implementation felt a bit ad-hoc and notably allowed
textContent to operate on all node types. It also only returned the
child text content of the Node instead of the descendant text content.
2021-09-06 02:36:04 +02:00
Luke Wilde
d36838d050 LibWeb: Implement the (string) replace all operations for Node 2021-09-06 02:36:04 +02:00
Luke Wilde
f7f37eaa0f LibWeb: Make Node::root return a reference
The root of a node can never be null, as "the root of an object is
itself, if its parent is null, or else it is the root of its parent."

https://dom.spec.whatwg.org/#concept-tree-root
2021-09-02 22:53:19 +02:00
Sam Atkins
1159eefff3 LibWeb: Include DOM Node ID in serialized JSON
This will be used in the DOM Inspector to communicate which node is
being inspected.
2021-09-02 22:16:41 +02:00
Sam Atkins
d7485df928 LibWeb: Give each Node a unique ID
We maintain a directory of ID -> Node. Nodes add themselves to this
directory when they are created, receiving a random ID. When a Node is
destroyed, it removes itself from this directory. Anyone can request a
Node from the directory by its ID using `Node::from_id()`.

We reserve the `0` ID to mean "none".

These IDs allow different processes to communicate about a given Node
over IPC, for example the DOM Inspector.
2021-09-02 22:16:41 +02:00
Sam Atkins
48a2239f60 LibWeb: Remove commented-out dbgln
This is unrelated to the PR I'm working on, but keeps getting
reformatted because clang-format wants comments to start with a space.
2021-09-02 22:16:41 +02:00
Luke Wilde
bd55f0ad64 LibWeb: Add shadow including ancestor/descendant checks 2021-09-02 09:11:24 +02:00
Luke
9cae827f07 LibWeb: Implement Node.contains
Used by Web Components Polyfills.
2021-07-05 12:39:46 +02:00
Luke
f3f2170ac6 LibWeb: Add the cloning steps in clone_node
This will be used in HTMLTemplateElement later to clone template
contents.

This makes the clone functions non-const in the process, as the cloning
steps can have side effects.
2021-07-05 12:39:46 +02:00
Luke
e4ae1cdd1f LibWeb: Use the element factory in clone_node
It was directly creating a new Element object instead of creating the
appropriate element.

For example, document.body.cloneNode(true) would return an Element
instead of an HTMLBodyElement.
2021-07-05 12:39:46 +02:00
Luke
5430bc8963 LibWeb: Make clone_node capable of cloning document fragments
Used by Web Components Polyfills.
2021-07-05 12:39:46 +02:00
Luke
0ea50d44bf LibWeb: Check if scripting is disabled before running script
This is not a full check, it's just enough to prevent script execution
in DOMParser.
2021-07-05 12:39:46 +02:00
Timothy Flynn
1bbf3f1d09 LibWeb: Do not encode "internal_id" in DOM JSON
This is now unused.
2021-07-01 19:19:46 +02:00
Andreas Kling
384cffaa04 LibWeb: Fix build breakage after merging the oldish DOM inspector PR 2021-06-29 23:11:09 +02:00
Adam Hodgen
4affe052b8 LibWeb: Add JSON serialization method to DOM::Node
This method builds a JSON object representing the full state of the
DOM tree.

The JSON that is built will be used for building the DOM Inspector
widget for the OutOfProcessWebView.
2021-06-29 23:06:48 +02:00
Andreas Kling
ba9d5c4d54 LibJS: Rename Function => FunctionObject 2021-06-27 22:36:04 +02:00
Ali Mohammad Pur
fd72597999 LibWeb: Make ExceptionOr capable of holding all error types in the spec
The WebIDL spec specifies a few "simple" exception types in addition to
the DOMException type, let's support all of those.
This allows functions returning ExceptionOr<T> to throw regular
javascript exceptions (as limited by the webidl spec) by returning a
`DOM::SimpleException { DOM::SimpleExceptionType::T, "error message" }`
which is pretty damn cool :^)
2021-06-27 12:49:49 +01: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
Luke
46f2c278b0 LibWeb: Implement Node.replaceChild
The `if (child->parent())` check seems to be redundant, but I'm keeping
it just to match the spec.
2021-05-07 08:53:37 +02:00
Luke
8b5ea01cfb LibWeb: Use node_to_insert instead of node in Node::insert_before
It was using the passed in node instead of the node from the vector.
Fixes a crash I found while testing jQuery.
2021-05-03 08:20:02 +02:00
Luke
8bafbdddc6 LibWeb: Expose Node.ownerDocument
Required by jQuery.
2021-05-02 22:51:46 +02:00
Andreas Kling
b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Linus Groh
ebdeed087c Everywhere: Use linusg@serenityos.org for my copyright headers 2021-04-22 22:51:19 +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
Linus Groh
5da4c9bf1e LibWeb: Implement Node.cloneNode()
With this we can now successfully run a Vue.js 2 hello world! :^)
2021-04-14 09:30:29 +02:00
AnotherTest
9c201767a0 LibWeb: Fix some FIXMEs related to ExceptionOr<T>
This fixes a few FIXMEs mentioned in 5beacf08a2,
which depended on #6075 being fixed.
2021-04-13 22:31:06 +02:00