Commit Graph

771 Commits

Author SHA1 Message Date
Andreas Kling
4c665c3749 LibWeb: Remove some unnecessary use of the internal realm in EventTarget
Now that EventTarget is GC-allocated, it can find the GC heap by just
calling heap() on itself, no need to get this via the internal realm.
2022-09-06 01:07:59 +02:00
Andreas Kling
8f110e0fb1 LibWeb: Remove the NoInstanceWrapper extended IDL attribute
No interfaces require wrappers anymore, so we can just make this the
default mode.
2022-09-06 00:27:09 +02:00
Andreas Kling
9176a0de99 LibWeb: Stop using Bindings::wrap() in a bunch of places
wrap() is now basically a no-op so we should stop using it everywhere
and eventually remove it. This patch removes uses of wrap() in
non-generated code.
2022-09-06 00:27:09 +02: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
3768743a0a LibWeb: Remove now-unused Bindings::Wrappable class 2022-09-06 00:27:09 +02:00
Andreas Kling
497ead37bc LibWeb: Make DOMException GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
57db2529cf LibWeb: Make DOMRect, DOMRectReadOnly and DOMRectList GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
b30e95eb27 LibWeb: Don't allocate NamedNodeMap in Element constructor
Allocations should happen in the initialize() virtual, so move it there.
2022-09-06 00:27:09 +02:00
Andreas Kling
ffad902c07 LibWeb: Use cached_web_prototype() as much as possible
Unlike ensure_web_prototype<T>(), the cached version doesn't require the
prototype type to be fully formed, so we can use it without including
the FooPrototype.h header. It's also a bit less verbose. :^)
2022-09-06 00:27:09 +02:00
Andreas Kling
dd9cd3050b LibWeb: Use correct Window object when dispatching Document load event 2022-09-06 00:27:09 +02:00
Andreas Kling
1029ea4b32 LibWeb: Use correct relevant settings object in Document initialization
The code was not in line with the spec comment right above it.
2022-09-06 00:27:09 +02:00
Andreas Kling
a835f313f7 LibWeb: Make Document::is_fully_active() more robust
We were missing a check for null browsing context container documents.
2022-09-06 00:27:09 +02:00
Andreas Kling
4901f69345 LibWeb: Don't capture raw ptr in Document::completely_finish_loading()
It's not safe to capture a raw pointer in a HTML task, as the garbage
collector doesn't have visibility into the task captures.
2022-09-06 00:27:09 +02:00
Andreas Kling
b8d485e6f0 LibWeb: Make AbortController GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
16fbb91aa1 LibWeb: Make History GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
2bba97964b LibWeb: Make HTMLCollection and subclasses GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
4c887bf6c3 LibWeb: Remove Document::interpreter()
Nobody needs this anymore, so we can finally remove it. :^)
2022-09-06 00:27:09 +02:00
Andreas Kling
2d72abc3d4 LibWeb+WebContent: Store Realm instead of Interpreter in ConsoleClient 2022-09-06 00:27:09 +02:00
Andreas Kling
905eb8cb4d LibWeb: Make MutationObserver GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
43ec0f734f LibWeb: Make MutationRecord GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
48e0066371 LibWeb: Make NodeList GC-allocated 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
7c3db526b0 LibWeb: Make DOM::Event and all its subclasses GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
a4ddb0ef87 LibWeb: Make TreeWalker GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
bd629c45b5 LibWeb: Make NodeIterator GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
8cda70c892 LibWeb: Move event listeners, handlers and callbacks to the GC heap
This patch moves the following things to being GC-allocated:
- Bindings::CallbackType
- HTML::EventHandler
- DOM::IDLEventListener
- DOM::DOMEventListener
- DOM::NodeFilter

Note that we only use PlatformObject for things that might be exposed
to web content. Anything that is only used internally inherits directly
from JS::Cell instead, making them a bit more lightweight.
2022-09-06 00:27:09 +02:00
Andreas Kling
967a3e5a45 LibWeb: Make DOMImplementation GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
0176d42f49 LibWeb: Make DOMTokenList GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
a56b3f9862 LibWeb: Make NamedNodeMap GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
72bacba97b LibWeb: Make CSSStyleDeclaration GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
5d6cb9cbdb LibWeb: Make CSSRuleList GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
5366924f11 LibWeb: Make StyleSheetList GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
5d60212076 LibWeb: Make StyleSheet and CSSStyleSheet GC-allocated 2022-09-06 00:27:09 +02:00
Linus Groh
61bd9fef7d LibJS+LibWeb: Remove last uses of GlobalObject::associated_realm() 2022-08-27 11:29:10 +01:00
MacDue
8d2c2f7c52 LibWeb: Determine the origin when navigating across documents 2022-08-26 00:21:10 +02:00
martinfalisse
e4c5799026 LibWeb: Add GridFormattingContext 2022-08-25 13:47:48 +02:00
Linus Groh
61e18c681b LibWeb: Restore realm retrieval from 'this' in activate_event_handler()
Removing the FIXME'd code in b99cc7d was a bit too eager, and relying on
the main thread VM's current realm only works when JS is being executed.

Restore a simplified version of the old code to determine the realm this
time instead of the global object, following the assumptions already
made in get_current_value_of_event_handler() regarding what kind of
event target 'this' can be.
2022-08-23 17:44:39 +01:00
Linus Groh
b465f46e00 LibJS: Remove GlobalObject parameter from native functions 2022-08-23 13:58:30 +01:00
Linus Groh
40a70461a0 LibWeb: Replace GlobalObject with Realm in wrapper functions
Similar to create() in LibJS, wrap() et al. are on a low enough level to
warrant passing a Realm directly instead of relying on the current realm
from the VM, as a wrapper may need to be allocated while no JS is being
executed.
2022-08-23 13:58:30 +01:00
Linus Groh
a022e548b8 LibJS: Replace GlobalObject with VM in Value AOs [Part 4/19]
This is where the fun begins. :^)
2022-08-23 13:58:30 +01:00
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
stelar7
8055b0a9b9 LibWeb: Add spec comments to Event 2022-04-20 14:07:38 +02:00
stelar7
6b859db2e0 LibWeb: Add spec comments to EventDispatcher 2022-04-20 14:07:38 +02:00
Andreas Kling
32bff52c25 LibWeb: Use Vector::in_reverse() in DOM::EventDispatcher 2022-04-13 19:52:25 +02:00
Sam Atkins
c449cabae3 LibWeb: Move CSS Parser into new Web::CSS::Parser namespace
The goal here is to move the parser-internal classes into this namespace
so they can have more convenient names without causing collisions. The
Parser itself won't collide, and would be more convenient to just
remain `CSS::Parser`, but having a namespace and a class with the same
name makes C++ unhappy.
2022-04-12 23:03:46 +02:00
Igor Pissolati
682a4a347a LibWeb: Bring Node closer to spec
Node::base_uri() correct implementation was left as a FIXME.
2022-04-12 19:42:16 +02:00
Igor Pissolati
e2fa5c0cda LibWeb: Bring Document closer to spec 2022-04-12 19:42:16 +02:00
Andreas Kling
a8afb883c1 LibWeb: Implement CSS declaration block's "updating flag"
This flag is used to prevent reparsing the style attribute after it is
automatically updated after using the CSSOM API to mutate style.
2022-04-11 21:10:07 +02:00
Simon Danner
bd90498332 LibWeb: Add SVGDefsElement
* Similarly to clipPath, this doesn't need to get rendered, so return no
  LayoutNode.
2022-04-11 20:19:10 +02:00
Andreas Kling
07a3002d39 LibWeb: Bring Element.client{Left,Top} closer to spec
These are supposed to return values based on the computed border size
of the element. Not the X/Y position values of the principal box.
2022-04-10 21:35:55 +02:00
Andreas Kling
e81594d9a1 LibWeb: Sketch out a very basic SVG <clipPath> element
This element doesn't actually support anything at the moment, but it
still massively speeds up painting performance on Wikipedia! :^)

How? Because we no longer paint SVG <path> elements found inside
<clipPath> elements. SVGClipPathElement::create_layout_node() returns
nullptr which stops the layout tree builder from recursing further into
the subtree, and so the <path> element never gets a layout or paint box.

Mousing over Wikipedia now barely break 50% CPU usage on my machine :^)
2022-04-10 21:35:55 +02:00
Andreas Kling
25f6d2e2ab LibWeb: Update layout in Element.getBoundingClientRect() 2022-04-10 20:44:29 +02:00
Andreas Kling
bb17f74fb1 LibWeb: Bring Element.client{Width,Height} closer to spec
There were two main issues with these functions:

1. They were not updating layout before inspecting metrics.
2. They were not returning viewport metrics for the root and body
   elements when appropriate.
2022-04-10 20:30:19 +02:00
Anthony Van de Gejuchte
69ca27d3d7 LibWeb: Show correct favicon when default favicon is loaded
Block the replacement of the favicon by the default favicon loader
when a favicon that is loaded through a link tag is already active.

This way, the favicon in the link tags will be prioritized against
the default favicons from `/favicon.ico` or the seranity default icon.
2022-04-10 12:10:59 +02:00
Anthony Van de Gejuchte
06d9853a8b LibWeb: Update displayed favicon when a favicon is loaded
When a favicon has been loaded, trigger a favicon update on
document level. Of all the link tags in the header, the last
favicon that is load should be shown.

When the favicon could not be loaded, load the next icon in reverse tree
order.
2022-04-10 12:10:59 +02:00
Simon Wanner
b19e134999 LibWeb: Invalidate layout after the computed font changes
If the font resource finishes loading we need to make sure the element
using it gets a chance to re-layout, even if the font-family property
didn't change.
2022-04-09 23:48:18 +02:00
Igor Pissolati
1b94b4c593 LibWeb: Bring MouseEvent a bit closer to spec 2022-04-09 18:27:24 +02:00
Idan Horowitz
d25bd2dbd8 LibWeb: Add the GlobalEventHandlers IDL mixin 2022-04-02 12:22:48 +04:30
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Linus Groh
7bdbac7fd9 LibWeb: Add 'is scripting enabled' concept to EnvironmentSettingsObject
This is now the source of truth for 'user enabled/disabled scripting',
but it has to ask the window's page, which actually stores the setting.

Also use this new functionality in two places where it was previously
marked as a FIXME.
2022-03-31 17:08:38 +02:00
Linus Groh
f60a2a1d80 LibWeb: Remove Document::is_scripting_enabled() and use Node's
There's no need to have a custom is_scripting_enabled() for the
Document class, as it (indirectly) inherits from Node.
Also, let's not hardcode false here :^)
2022-03-31 17:08:38 +02:00
Idan Horowitz
f45d361f03 LibWeb: Replace ad-hoc EventHandler type with callback function typedef 2022-03-31 01:10:47 +02:00
Elisée Maurer
34db0dab41 LibWeb: Implement Element.toggleAttribute() 2022-03-30 18:30:29 +02:00
Andreas Kling
b0955fd269 LibWeb: Add fast_is<T>() for some common DOM Node subclasses 2022-03-30 00:52:02 +02:00
Andreas Kling
427beb97b5 LibWeb: Streamline how inline CSS style declarations are constructed
When parsing the "style" attribute on elements, we'd previously ask the
CSS parser for a PropertyOwningCSSStyleDeclaration. Then we'd create a
new ElementCSSInlineStyleDeclaration and transfer the properties from
the first object to the second object.

This patch teaches the parser to make ElementCSSInlineStyleDeclaration
objects directly.
2022-03-29 16:35:46 +02:00
Sam Atkins
da1a819858 LibWeb: Rename parse_css_declaration() -> parse_css_style_attribute() 2022-03-28 22:25:25 +02:00
Linus Groh
192f4b0258 LibWeb: Ensure lazy WindowObject creation when activating event handler 2022-03-27 20:14:25 +01:00
Timothy Flynn
5608bc4eaf LibWeb: Remove inheritance of FormAssociatedElement from HTMLElement
HTMLObjectElement will need to be both a FormAssociatedElement and a
BrowsingContextContainer. Currently, both of these classes inherit from
HTMLElement. This can work in C++, but is generally frowned upon, and
doesn't play particularly well with the rest of LibWeb.

Instead, we can essentially revert commit 3bb5c62 to remove HTMLElement
from FormAssociatedElement's hierarchy. This means that objects such as
HTMLObjectElement individually inherit from FormAssociatedElement and
HTMLElement now.

Some caveats are:

* FormAssociatedElement still needs to know when the HTMLElement is
  inserted into and removed from the DOM. This hook is automatically
  injected via a macro now, while still allowing classes like
  HTMLInputElement to also know when the element is inserted.

* Casting from a DOM::Element to a FormAssociatedElement is now a
  sideways cast, rather than directly following an inheritance chain.
  This means static_cast cannot be used here; but we can safely use
  dynamic_cast since the only 2 instances of this already use RTTI to
  verify the cast.
2022-03-24 03:35:11 +01:00
Andreas Kling
e0c7727934 LibWeb: Fill the whole viewport with the correct background color
CSS2 tells us to use the HTML element's background color if not
transparent. Otherwise, the BODY element's background color.
2022-03-23 17:38:00 +01:00
Andreas Kling
fd7a059e09 LibWeb: Make NodeIterator behave like other browser engines
If invoking a NodeFilter ends up deleting a node from the DOM, it's not
enough to only adjust the NodeIterator reference nodes in the
pre-removing steps. We must also adjust the current traversal pointer.

This is not in the spec, but it's how other engines behave, so let's do
the same.

I've encapsulated the Node + before-or-after-flag in a struct called
NodePointer so that we can use the same pre-removing steps for both the
traversal pointer and for the NodeIterator's reference node.

Note that when invoking the NodeFilter, we have to remember the node we
passed to the filter function, so that we can return it if accepted by
the filter.

This gets us another point on Acid3. :^)
2022-03-23 00:22:36 +01:00
Andreas Kling
a0b0b29fa1 LibWeb: Minor cleanups in NodeIterator and TreeWalker
- Use TRY() when invoking the NodeFilter
- Say "nullptr" instead of "RefPtr<Node> {}"
2022-03-23 00:19:57 +01: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
Linus Groh
2219eef250 LibWeb: Convert Text to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
46bb547dd6 LibWeb: Convert ShadowRoot to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
a68d31debd LibWeb: Convert ParentNode to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
8d20fb1e94 LibWeb: Convert NodeOperations to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
3861396fe4 LibWeb: Convert Node to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
3cb7c463a7 LibWeb: Convert Element to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
b6f09aaef2 LibWeb: Convert DOMTokenList to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
91d0088a5b LibWeb: Convert DOMImplementation to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
e758bd303f LibWeb: Convert Document to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
ab0a354bb4 LibWeb: Convert ChildNode to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
70b1f18e58 LibWeb: Explicitly ignore [[nodiscard]] values returned from TRY()
This broke the clang build.
2022-03-22 13:20:06 +00:00
Timothy Flynn
c3f9cd6dbd LibWeb: Convert Range to use TRY for error propagation 2022-03-22 12:09:27 +00:00
Timothy Flynn
2d34216628 LibWeb: Make DOM::ExceptionOr compatible with the TRY macro
This will help reduce the quite repetitive pattern of:

    auto result_or_error = dom_node->do_something();
    if (result_or_error.is_exception())
        return result_or_error.exception();
    auto result = result_or_error.release_value();

Similar to LibJS completions, this adds an alias to the error accessors.
This also removes the requirement on release_value() for ValueType to
not be Empty, which we also had to do for TRY compatibility in LibJS.
2022-03-22 12:09:27 +00:00
Jamie Mansfield
9b9d32dfb2 LibWeb: Fix crash when removing event listeners 2022-03-22 02:35:07 +01:00
Timothy Flynn
5133491714 LibWeb: Expose HTMLCollection's root element to its subclasses
For example, HTMLOptionsCollection will need to access its root
HTMLSelectElement.
2022-03-22 02:08:15 +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
68f3feb1d1 LibWeb: Fix two spec transcription mistakes in live range updating
This scores us another point on Acid3. :^)
2022-03-21 21:11:38 +01:00
Andreas Kling
4d49c607f8 LibWeb: Fix spec transcription mistake in Range.extractContents()
The spec text and code didn't match up.

Thanks to Tim for spotting this! :^)
2022-03-21 21:01:47 +01:00
Andreas Kling
ac8a8459d0 LibWeb: Don't allow setting Range start/end to document being destroyed 2022-03-21 20:37:49 +01:00
Andreas Kling
3b6323340a LibWeb: Update live ranges on Node insertion and removal
Taking care of some old FIXMEs :^)
2022-03-21 20:26:35 +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
d2f9f8bd4f LibWeb: Implement Text.splitText(offset)
With FIXMEs about updating live ranges, but still.
2022-03-21 19:14:50 +01:00
Andreas Kling
8bc3f4c186 LibWeb: Fix logic mistakes in Range stringification
We were passing the wrong length argument to substring() when
stringifying a range where start and end are the same text node.

Also, make sure we visit all the contained text nodes when appending
them to the output.

This was caught by an Acid3 subtest.
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
24e25fe3d0 LibWeb: Add CharacterData.replaceData(offset, count, data)
Note that we don't queue mutation records or update live ranges yet,
I've left those as FIXMEs.
2022-03-21 18:05:20 +01:00
Andreas Kling
e50c7de1b2 LibWeb: Add CharacterData.substringData(offset, count) 2022-03-21 17:20:42 +01:00
Andreas Kling
394cd77467 LibWeb: Implement stringifier for DOM Range :^) 2022-03-21 16:29:19 +01:00
Andreas Kling
8c88ee1165 LibWeb: Only invalidate stacking context tree for opacity/z-index change
I came across some websites that change an elements CSS "opacity" in
their :hover selectors. That caused us to relayout on hover, which we'd
like to avoid.

With this patch, we now check if a property only affects the stacking
context tree, and if nothing layout-affecting has changed, we only
invalidate the stacking context tree, causing it to be rebuilt on next
paint or hit test.

This makes :hover { opacity: ... } rules much faster. :^)
2022-03-21 13:03:33 +01:00
Andreas Kling
59afdb959f LibWeb: Build stacking context tree lazily
There's no actual need to build the stacking context tree before
performing layout. Instead, make it lazy and build the tree when it's
actually needed for something.

This avoids a bunch of work in situations where multiple synchronous
layouts are forced (typically by JavaScript) without painting or hit
testing taking place in between.

It also opens up for style invalidations that only target the stacking
context tree.
2022-03-21 13:03:33 +01:00
Simon Wanner
69fc7009bf LibWeb: Grey out invisible nodes in the DOM inspector
This makes it easier to navigate large DOM trees where
some nodes have display: none
2022-03-20 19:57:09 +01:00
Andreas Kling
07a4d590dd LibWeb: Layout browsing context parent before its children
When updating layout inside a nested browsing context, try first to
perform layout in the parent document (the nested browsing context's
container's document).

This ensures that nested browsing contexts have the right viewport
dimensions in case the parent layout changes them somehow.
2022-03-20 19:03:43 +01:00
Andreas Kling
2b7775118d LibWeb: Clear element.style when the "style" attribute is removed
We were hanging on to element inline style, even after the style
attribute was removed. This made inline style sticky and impossible to
remove. This patch fixes that. :^)
2022-03-20 16:31:40 +01:00
Andreas Kling
618b857457 LibWeb: Evaluate @media CSS rules when updating style
In case we have new @media rules, we need to make sure we've evaluated
them before actually recomputing styles for the document.
2022-03-20 16:19:47 +01:00
Andreas Kling
5d672717aa LibWeb: Add a barebones SVGTextContentElement with getNumberOfChars() 2022-03-20 13:36:45 +01:00
Andreas Kling
0b861e0c9d LibWeb: Make document-level style invalidation fast
Add a flag to DOM::Document that means the whole document needs a style
update. This saves us the trouble of traversing the entire DOM to mark
all nodes as needing a style update.
2022-03-19 22:04:43 +01:00
Andreas Kling
c1f0d21bbe LibWeb: Rename the LayoutMode enum values and explain them
The old mode names, while mechanically accurate, didn't really reflect
their relationship to the CSS specifications.

This patch renames them as follows:

    Default => Normal
    AllPossibleLineBreaks => MinContent
    OnlyRequiredLineBreaks => MaxContent

There's also now an explainer comment with the LayoutMode enum about the
specific implications of layout in each mode.
2022-03-19 15:46:15 +01:00
Andreas Kling
3b037726e9 LibWeb: Invalidate layout after setting Element.innerHTML
It's not enough to only relayout here, since the API can substantially
change the DOM. We have to rebuild the layout tree.
2022-03-18 19:54:46 +01:00
Linus Groh
9422ae9bb2 LibJS: Add infallible variant of VM::push_execution_context()
It makes no sense to require passing a global object and doing a stack
space check in some cases where running out of stack is highly unlikely,
we can't recover from errors, and currently ignore the result anyway.

This is most commonly in constructors and when setting things up, rather
than regular function calls.
2022-03-18 01:12:12 +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
Andreas Kling
d71b0e4638 LibWeb: Don't discard update_style_recursively() return value
This was causing us to miss layout invalidations. With this fixed, we
can remove the invalidation from Element::recompute_style() along with
the associated FIXME.

Thanks to Idan for spotting this! :^)
2022-03-16 21:30:39 +01:00
Andreas Kling
0e8b538e0a LibWeb: Invalidate less style when moving between hovered nodes
Instead of invalidating style for the entire document, we now locate the
nearest common ancestor between the old and new innermost hovered node,
and only invalidate that ancestor and its descendants.

This drastically reduces the amount of style update work when mousing
around on GitHub (and any other pages, really.) It's actually really
really snappy now. Very cool! :^)
2022-03-16 18:06:45 +01:00
Andreas Kling
f1711a562a LibWeb: Avoid layout invalidation for some CSS property changes
Use the new CSS::property_affects_layout() helper to figure out if we
actually need to perform a full relayout after recomputing style.

There are three tiers of required invalidation after an element receives
new style: none, repaint only, or full relayout.

This avoids the need to rebuild the layout tree (and perform layout on
it) when trivial properties like "color" etc are changed.
2022-03-16 18:06:45 +01:00
Andreas Kling
df5c123d8c LibWeb: Schedule a relayout after setting CharacterData.data 2022-03-16 18:06:45 +01:00
Andreas Kling
28721874e8 LibWeb: Schedule a relayout after setting Element.innerHTML 2022-03-16 18:06:45 +01:00
Andreas Kling
b1096c2ae4 LibWeb: Make Element::set_shadow_root() disconnect any previous root 2022-03-16 00:38:44 +01:00
sin-ack
29583104d2 LibWeb: Refactor all LabelableNode subclasses + input event handling :^)
This commit is messy due to the Paintable and Layout classes being
tangled together.

The RadioButton, CheckBox and ButtonBox classes are now subclasses of
FormAssociatedLabelableNode. This subclass separates these layout nodes
from LabelableNode, which is also the superclass of non-form associated
labelable nodes (Progress).

ButtonPaintable, CheckBoxPaintable and RadioButtonPaintable no longer
call events on DOM nodes directly from their mouse event handlers;
instead, all the functionality is now directly in EventHandler, which
dispatches the related events. handle_mousedown and related methods
return a bool indicating whether the event handling should proceed.

Paintable classes can now return an alternative DOM::Node which should
be the target of the mouse event. Labels use this to indicate that the
labeled control should be the target of the mouse events.

HTMLInputElement put its activation behavior on run_activation_behavior,
which wasn't actually called anywhere and had to be manually called by
other places. We now use activation_behavior which is used by
EventDispatcher.

This commit also brings HTMLInputElement closer to spec by removing the
did_foo functions that did ad-hoc event dispatching and unifies the
behavior under run_input_activation_behavior.
2022-03-16 00:38:31 +01:00
Andreas Kling
1881761d0f LibWeb: Fix mistake in Node::invalidate_style()
We were not actually walking past the first ancestor when setting
child-needs-update bit upwards.

Also, let's walk all the way to the root, even if there's a
child-needs-update bit already set. This ensures that we always leave
this function with the ancestor chain in a sane state.
2022-03-15 22:43:44 +01:00
Andreas Kling
b4bda4cdf3 LibWeb: Make invalidate_style() set child-needs-update on shadow hosts 2022-03-15 22:43:44 +01:00
Andreas Kling
03d6e1953f LibWeb: Improvements to Node::invalidate_style()
- Access members directly instead of going through accessors,
  avoiding a lot of redundant traversal done by accessors.

- Cross shadow boundaries and make sure that shadow trees get their
  dirty bits updated as well.

- Do the minimum amount of traversal needed when setting the "child
  needs style update" bit upwards through ancestors.
2022-03-15 20:02:30 +01:00
Andreas Kling
e31fe3eeb8 LibWeb: Rename Element::specified_css_values() => computed_css_values()
Let's make it very clear that these are *computed* values, and not at
all the specified values. The specified values are currently discarded
by the CSS cascade algorithm.
2022-03-15 19:48:19 +01:00
Andreas Kling
43ef813f3d LibWeb: Rename Element::computed_style() to resolved_css_values()
This more accurately reflects what's actually being returned.
2022-03-15 19:48:19 +01:00
Andreas Kling
5b8290dfa3 LibWeb: Invalidate document style after Node.insertBefore() 2022-03-15 19:48:19 +01:00
Andreas Kling
cf49e93b04 LibWeb: Invalidate style on media query evaluation change 2022-03-15 19:48:19 +01:00
Andreas Kling
a033dfc885 LibWeb: Actually connect ShadowRoot to its host element
This way we can traverse from inside a shadow root across the boundary
to the outside. :^)
2022-03-15 19:48:19 +01:00
Andreas Kling
2be4064ca8 LibWeb: Add fast_is<ParentNode>() 2022-03-15 19:48:19 +01:00
Andreas Kling
32dd4bf1b9 LibWeb: Recurse into shadow trees when updating style
The style update mechanism was happily ignoring shadow subtrees.
Fix this by checking if an element has a shadow root, and recursing into
it if needed.
2022-03-15 19:48:19 +01:00
Andreas Kling
5d941ddf3a LibWeb: Make style invalidation cross shadow boundaries
Before this change, style invalidation didn't propagate upwards across
shadow boundaries, so our shadow trees were sitting there with invalid
style, never actually getting updated.
2022-03-15 19:48:19 +01:00
Andreas Kling
fdb647c097 LibWeb: Use a WeakPtr for DocumentFragment's "host" field
We had a reference cycle between fragments and their hosts.
2022-03-15 19:48:19 +01:00
Andreas Kling
afc5fade05 LibWeb: Add some fast_is<T> helpers for hot classes on GitHub :^) 2022-03-13 18:09:43 +01:00
Andreas Kling
201afb50c7 LibWeb: Make Element::recompute_style() really compare properties
It's not enough to compare StyleProperties pointers to see if something
changed, we have to do a deep compare.
2022-03-13 00:04:51 +01:00
Andreas Kling
b6097cf724 LibWeb: Add fast_is<SVG::SVGSVGElement>() 2022-03-13 00:04:51 +01:00
Andreas Kling
ba606d9057 LibWeb: Move PaintingBox to its own .cpp and .h files 2022-03-11 00:21:49 +01:00
Andreas Kling
cb0c5390ff LibWeb: Move mouse event and label logic from layout to painting tree
Input events have nothing to do with layout, so let's not send them to
layout nodes.

The job of Paintable starts to become clear. It represents a paintable
item that can be rendered into the viewport, which means it can also
be targeted by the mouse cursor.
2022-03-11 00:21:49 +01:00
Andreas Kling
053766d79c LibWeb: Split Paintable into Paintable and PaintableBox
To prepare for paintable inline content, we take the basic painting
functionality and hoist it into a base class.
2022-03-11 00:21:49 +01:00
Andreas Kling
9461e44afa LibWeb: Use Layout::Box::paint_box() accessor in more places 2022-03-11 00:21:49 +01:00
Andreas Kling
f6497b64ac LibWeb: Rename Painting::Box => Paintable
Calling this "Box" made it very confusing to look at code that used both
Layout::Box and Painting::Box. Let's try calling it Paintable instead.
2022-03-11 00:21:49 +01:00
Andreas Kling
9f5cbcaad3 LibWeb: Hang StackingContext off of the paint boxes
Stacking contexts have nothing to do with layout and everything with
painting, so let's keep them in Painting::Box.
2022-03-11 00:21:49 +01:00
Andreas Kling
a4d51b3dc2 LibWeb: Add Painting::Box and move things from Layout::Box into it
The "paintable" state in Layout::Box was actually not safe to access
until after layout had been performed.

As a first step towards making this harder to mess up accidentally,
this patch moves painting information from Layout::Box to a new class:
Painting::Box. Every layout can have a corresponding paint box, and
it holds the final used metrics determined by layout.

The paint box is created and populated by FormattingState::commit().

I've also added DOM::Node::paint_box() as a convenient way to access
the paint box (if available) of a given DOM node.

Going forward, I believe this will allow us to better separate data
that belongs to layout vs painting, and also open up opportunities
for naturally invalidating caches in the paint box (since it's
reconstituted by every layout.)
2022-03-11 00:21:49 +01:00
Sam Atkins
6de2b62906 LibWeb: Display pseudo-elements in the DOM inspector
This patch only makes them appear in the tree - they are not yet
inspectable themselves.
2022-03-10 17:30:09 +01:00
Ben Abraham
7594350376 Browser: Show currently loading host and remaining resource count 2022-03-10 00:51:05 +01:00
Andreas Kling
6499cf4d28 LibWeb: Always relayout document on element style change
Let's get this right before trying to make it fast. This patch removes
the code that tried to do less work when an element's style changes,
and instead simply invalidates the entire document.

Note that invalidations are still coalesced, and will not be
synchronized until update_style() and/or update_layout() is used.
2022-03-09 18:14:24 +01:00
Andreas Kling
bca3c2a443 LibWeb: Always call update_style() in update_layout()
If the style is dirty, update_style() may cause layout to become dirty.
Therefore we must always update style when updating layout, to ensure
up-to-date results.
2022-03-09 18:14:24 +01:00
Andreas Kling
c988cbb8b1 LibWeb: Invalidate document style when a node is removed
This forces us to recompute style everywhere, since all kinds of
selectors may produce different results now.

In the future, we should look at narrowing down the invalidation that
occurs here, but for now let's just invalidate everything and make the
results correct before worrying about performance.
2022-03-09 18:14:24 +01:00
Andreas Kling
9c6999ecf2 LibWeb: Implement "NodeIterator pre-removing steps"
These steps run when a node is about to be removed from its parent,
and adjust the position of any live NodeIterators so that they don't
point at a now-removed node.

Note that while this commit implements what's in the DOM specification,
the specification doesn't fully match what other browsers do.

Spec bug: https://github.com/whatwg/dom/issues/907
2022-03-09 16:43:56 +01:00
Andreas Kling
acbdb95b0a LibWeb: Add support for DOM's TreeWalker
This patch adds TreeWalker (created via Document.createTreeWalker())
which allows you to traverse a filtered view of the DOM in all
directions.
2022-03-09 16:43:55 +01:00
Andreas Kling
fabcee016f LibWeb: Add basic support for DOM's NodeIterator and NodeFilter
This patch adds NodeIterator (created via Document.createNodeIterator())
which allows you to iterate through all the nodes in a subtree while
filtering with a provided NodeFilter callback along the way.

This first cut implements the full API, but does not yet handle nodes
being removed from the document while referenced by the iterator. That
will be done in a subsequent patch.
2022-03-09 16:43:00 +01:00