Commit Graph

580 Commits

Author SHA1 Message Date
Linus Groh
e992a9f469 LibJS+LibWeb: Replace GlobalObject with Realm in Heap::allocate<T>()
This is a continuation of the previous three commits.

Now that create() receives the allocating realm, we can simply forward
that to allocate(), which accounts for the majority of these changes.
Additionally, we can get rid of the realm_from_global_object() in one
place, with one more remaining in VM::throw_completion().
2022-08-23 13:58:30 +01:00
Linus Groh
b99cc7d050 LibJS+LibWeb: Replace GlobalObject with Realm in create() functions
This is a continuation of the previous two commits.

As allocating a JS cell already primarily involves a realm instead of a
global object, and we'll need to pass one to the allocate() function
itself eventually (it's bridged via the global object right now), the
create() functions need to receive a realm as well.
The plan is for this to be the highest-level function that actually
receives a realm and passes it around, AOs on an even higher level will
use the "current realm" concept via VM::current_realm() as that's what
the spec assumes; passing around realms (or global objects, for that
matter) on higher AO levels is pointless and unlike for allocating
individual objects, which may happen outside of regular JS execution, we
don't need control over the specific realm that is being used there.
2022-08-23 13:58:30 +01:00
Linus Groh
c8f1651761 LibJS+LibWeb: Restore type safety of Realm::set_global_object()
The changes from 8a03b17 to allow any JS::Value aren't a good fit, as
shown by the excessive amount of verify_cast needed :^)
2022-08-06 12:02:48 +02:00
Andreas Kling
2a7924f96c LibWeb: Bring browsing context creation closer to spec
This patch implements the "create a new browsing context" function from
the HTML spec and replaces our existing logic with it.

The big difference is that browsing contexts now initially navigate to
"about:blank" instead of starting out in a strange "empty" state.
This makes it possible for websites to create a new iframe and start
scripting inside it right away, without having to load an URL into it.
2022-08-05 12:46:42 +02:00
Andreas Kling
73f77969a6 LibWeb: Add API for setting a document's referrer 2022-08-05 12:46:42 +02:00
Andreas Kling
6e71e400e6 LibWeb: Store document origin as a HTML::Origin object
This will allow us to remember an arbitrary origin instead of deriving
it from the document's URL.
2022-08-05 12:46:42 +02:00
Andreas Kling
b6bd793ede LibWeb: Clear the "is initial about:blank" flag in Document.write() 2022-08-05 12:46:41 +02:00
Andreas Kling
c46a8194b4 LibWeb: Use Document::m_type to check for XML documents
...instead of doing a string compare on the DOCTYPE node.
2022-08-05 12:46:41 +02:00
Andreas Kling
602f927982 LibWeb: Start implementing "create and initialize a Document" from HTML
The way we've been creating DOM::Document has been pretty far from what
the spec tells us to do, and this is a first big step towards getting us
closer to spec.

The new Document::create_and_initialize() is called by FrameLoader after
loading a "text/html" resource.

We create the JS Realm and the Window object when creating the Document
(previously, we'd do it on first access to Document::interpreter().)

The realm execution context is owned by the Environment Settings Object.
2022-08-05 12:46:40 +02:00
Andreas Kling
b838f2029b LibWeb: Move DOM::Document factory functions out of line 2022-08-05 12:42:46 +02:00
Andreas Kling
29a4266367 LibWeb: Add the "is initial about:blank" flag to DOM::Document 2022-08-05 12:42:46 +02:00
MacDue
d4b2eb22e1 LibWeb: Resolve circular IDL imports
These circular imports led to the generator silently failing to
generate the required methods/properties.
2022-07-30 13:20:47 +02:00
Sam Atkins
200e111af0 LibWeb: Extract the InnerHTML IDL mixin 2022-07-29 17:15:49 +01:00
Sam Atkins
d4c40e3aad LibWeb: Extract the ParentNode IDL mixin 2022-07-29 17:15:49 +01:00
Sam Atkins
79fdc08de9 LibWeb: Correct typo in Document.idl
Makes me wonder how things were working when Document was never
including GlobalEventHandlers.
2022-07-29 17:15:49 +01:00
Sam Atkins
d6a5ddd3c0 LibWeb: Extract the ChildNode IDL mixin 2022-07-29 17:15:49 +01:00
Andreas Kling
2ad98fdf80 LibWeb: Add fast_is<HTMLElement>()
This avoids slow RTTI lookups in selector matching.
2022-07-27 17:29:48 +02:00
Andreas Kling
9f32da1dbc LibWeb: Add fast_is<HTMLBaseElement>()
This avoids slow RTTI lookups in Document::base_url().
2022-07-27 17:29:48 +02:00
Andreas Kling
71a707480c LibWeb: Move "has-definite-width/height" flags to UsedValues
This state is less static than we originally assumed, and there are
special formatting context-specific rules that say certain sizes are
definite in special circumstances.

To be able to support this, we move the has-definite-size flags from
the layout node to the UsedValues struct instead.
2022-07-26 01:53:41 +02:00
Andreas Kling
16c173de43 LibWeb: Destroy ICB formatting context before committing used values
Absolutely positioned boxes are handled by the BFC destructor, so we
need to make sure the ICB BFC is destroyed if we want these boxes
to get laid out.
2022-07-26 00:04:21 +02:00
Andreas Kling
ed8930fff5 LibWeb: Add accessors for UsedValues::computed_{width,height}
This is preparation for doing some more work when assigning to these
values.
2022-07-19 15:40:41 +02:00
Linus Groh
bc68539e26 LibWeb: Add & use TRY_OR_RETURN_OOM macro
This is a convenient way to return a DOM exception for operations that
return ErrorOr and only have an OOM failure path.
2022-07-17 21:08:10 +01:00
Luke Wilde
aa9f7cc597 LibWeb: Fix queuing mutation records for node removal
Step 19 of node removal was missing, which allows the mutations of the
descendants of the removed node to still be observed by the parent.

Step 20 of node removal queued the mutation record for the removed
node instead of it's parent. Since queuing takes place after the node
is removed from the tree, the mutation record would be lost as the only
inclusive ancestor of the node at this point is only the node itself.
2022-07-17 18:21:09 +01:00
Andreas Kling
9b46091f38 LibWeb: Rename LayoutState::NodeState => LayoutState::UsedValues
This object contains all the CSS "used values" as seen during the layout
process, so calling it "used values" seems appropriate. :^)
2022-07-17 14:11:37 +02:00
Andreas Kling
52862c72d0 LibWeb: Rename FormattingState to LayoutState
This seems a bit more descriptive (and also a bit shorter).
2022-07-17 14:11:36 +02:00
Linus Groh
22a627fc1a LibWeb: Move Origin into the HTML namespace
Origin is defined in the HTML Standard, and therefore belongs into the
HTML directory and namespace in LibWeb.
https://html.spec.whatwg.org/multipage/origin.html#origin
2022-07-14 00:42:26 +01:00
Andreas Kling
3ee5bdcfb7 LibWeb: Traverse shadow-including subtree when adopting DOM nodes
This takes care of two FIXMEs and fixes an issue on Google Docs where
we'd mix boxes from different documents in the same layout tree.
(This happened because shadow trees remained attached to their old
document when their host was adopted.)
2022-07-12 23:17:17 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
Luke Wilde
a718c62c01 LibWeb: Implement all "attributes" mutation records for MutationObserver 2022-07-11 22:35:08 +02:00
Luke Wilde
1ca8782c99 LibWeb: Implement "characterData" mutation record for MutationObserver 2022-07-11 22:35:08 +02:00
Luke Wilde
56cfd5ced8 LibWeb: Implement all "childList" mutation records for MutationObserver 2022-07-11 22:35:08 +02:00
Luke Wilde
c9ba5531e0 LibWeb: Introduce Mutation{Record,Observer} and observer microtasks 2022-07-11 22:35:08 +02:00
Luke Wilde
ee719870c8 LibWeb: Implement CharacterData.{append,insert,delete}Data 2022-07-11 22:35:08 +02:00
Luke Wilde
af5b4ae1c4 LibWeb: Implement CharacterData::set_data in terms of replace_data
This makes it so that it always queues a mutation record, even if
`data` is set to the same value. It also makes it follow the spec
steps.
2022-07-11 22:35:08 +02:00
Luke Wilde
f3650d08cb LibWeb: Allow creating a StaticNodeList without an r-value Vector
It must accept taking a copy for DocumentFragment mutation records and
empty vectors created in-place.
2022-07-11 22:35:08 +02:00
Andreas Kling
0cacaf025d LibWeb: Stop putting the FormattingState nodes in a slow hash map
Instead, put them in a Vector<OwnPtr<NodeState>>. Each layout node
has a unique index into the vector. It's a simple serial ID assigned
during layout tree construction. Every new layout restarts the sequence
at 0 for the next ICB.

This is a huge layout speed improvement on all content.
2022-07-11 18:57:45 +02:00
Itamar
9498555256 LibWeb: Trigger a relayout after setting Element.innerHTML
In addition to tearing down the layout tree, we also want to trigger a
relayout for the changes made by setting Element.innerHTML to take
effect.
2022-07-05 21:27:37 +02:00
Andreas Kling
7a7043f821 LibWeb: Simplify some WeakPtr assignments
We can assign a raw pointer directly to a WeakPtr without null-checking
it first.
2022-07-04 22:30:59 +02:00
networkException
6805baeedd LibWeb: Add the type field to DOM::Document
This patch adds the document type concept to documents and sets it in
various places.
2022-07-04 12:39:48 +02:00
Luke Wilde
3fe66bddf4 LibWeb: Implement WindowEventHandlers 2022-06-29 21:21:50 +01:00
Luke Wilde
ebf2184636 LibWeb: Only make certain <body> and <frameset> events apply to Window
Previously we forwarded all event handler attributes to Window from
these two elements, however, we are only supposed to forward blur,
error, focus, load, resize and scroll.
2022-06-29 21:21:50 +01:00
Luke Wilde
1ceba560f4 LibWeb: Add CDATASection
Not used for anything currently other than exposing it on the Window
object. This allows Web Components Polyfills to patch its prototype.
2022-06-27 22:53:04 +01:00
Luke Wilde
1f820f8840 LibWeb: Add support for the <base> element changing the base URL
Used by Google seemingly almost all around account sign in and
management. The modern sign in page has this near the beginning:
```html
<base href="https://accounts.google.com">
```
All of the XHRs performed by sign in are relative URLs to this
base URL. Previously we ignored this and did it relative to the
current URL, causing the XHRs to 404 and sign in to fall apart.

I presume they do this because you can access the sign in page
from multiple endpoints, such as `/ServiceLogin` and
`/o/oauth2/auth/identifier`
2022-06-19 16:35:43 +01:00
Luke Wilde
bae330d559 LibWeb: Rename Event.srcTarget to Event.srcElement
It's called srcElement instead of srcTarget.
Required by w3school's search focus handler.
2022-06-18 16:13:03 +01:00
stelar7
96caf3aed1 LibWeb: Adjust implementation of Document::create_event
With this change, it no longer calls TODO() and crashes WebContent
2022-06-06 22:20:30 +01:00
Idan Horowitz
56ec781aea LibWeb: Support DocumentFragments in Node.prototype.cloneNode
In this case, "Do nothing" means do nothing *extra* aside from creating
a new instance.
2022-06-03 17:24:24 +01:00
DexesTTP
1af7bfb3a6 LibWeb: Remove unneeded iteration filter on LiveNodeList
Since all items of the subtree are Nodes, the "of type" condition was
always true. This triggers a warning on Lagom builds.
2022-05-06 14:11:03 +02:00
Linus Groh
95541d7064 LibWeb: Fix various spec comment inconsistencies
- Don't add multiple numbers to nested steps, just the innermost one
  (as rendered in the HTML document)
- "Otherwise" comments go before the else, not after it
- "FIXME:" goes before step number, not between it and the comment text
- Always add a period between number and comment text

The majority of these were introduced in #13756, but some unrelated ones
have been updated as well.
2022-04-20 19:49:01 +02:00
stelar7
1c0d29b8da LibWeb: Add spec comments to Node
This also implements a few more steps of compare_document_position,
and removes an invalid step from clone_node
2022-04-20 14:07:38 +02:00
stelar7
62bd88dc14 LibWeb: Add spec comments to EventTarget 2022-04-20 14:07:38 +02:00