Commit Graph

650 Commits

Author SHA1 Message Date
Timothy Flynn
bb8b24eef7 LibWeb: Move initial creation of Unicode segmenters to the Document
The expensive part of creating a segmenter is doing the locale and UCD
data lookups at creation time. Instead of doing this once per text node,
cache the segmenters on the document, and clone them as needed (cloning
is much, much cheaper).

On a profile loading Ladybird's GitHub repo, the following hot methods
changed as follows:

    ChunkIterator ctor: 6.08% -> 0.21%
    Segmenter factory:  5.86% ->    0%
    Segmenter clone:    N/A   -> 0.09%

(cherry picked from commit 5d7175874258f00763adcced230149dd1379e4a6;
mended as usual for Unicode::Segmenter -> Locale::Segmenter, and also
to resolve minor conflicts due to serenity not yet having
LadybirdBrowser/ladybird#1106. Also, due to serenity not using ICU,
this doesn't have a big performance effect over here, but it still
makes future cherry-picks easier)
2024-11-27 12:57:15 -05:00
Sam Atkins
6026e4b2e7 LibWeb: Fill-in some fixmes around sandboxing flag sets
...Including a couple of steps in
obtain_a_browsing_context_to_use_for_a_navigation_response() which
didn't have FIXMEs.

No apparent changes on WPT.

(cherry picked from commit 310cdc35f05946be15cb16ccc2f32e4f1e43efe3)
2024-11-26 22:37:15 -05:00
Timothy Flynn
d89c41e4ad LibWeb: Add Document helpers to move its cursor to word boundaries
This implementation is based on the same feature I added to Serenity's
TextEditor:

https://github.com/SerenityOS/serenity/pull/17477

(cherry picked from commit ecf2cc600bea8f8396061f5fe6aba8358a033bbb;
amended to change Unicode::Segmenter to Locale::Segmenter due to
LibLocale and LibUnicode being separate libraries in serenity)
2024-11-26 16:03:32 -05:00
Sam Atkins
dad75576d3 LibWeb: Match spec changes to "apply the history step"
Corresponds to https://github.com/whatwg/html/pull/10704

(cherry picked from commit c5c5d97544cd49425d057028964e7c7af4cae3cf)
2024-11-25 12:19:48 -05:00
thislooksfun
271f3c9bdd LibWeb/CSS: Evaluate media queries in shadow roots
This fixes a rendering issue on https://prodengi.kz/ that someone on
Discord reported. :^)

(cherry picked from commit 0b775da7c72a85c099f35d8caf2e7b66721a4483)
2024-11-25 08:50:54 -05:00
ronak69
72c61c0cf0 LibWeb: Only return HTML elements from getElementsByName()
Fixes two WPT tests:
document.getElementsByName-namespace-xhtml.xhtml and
document.getElementsByName-namespace.html

(cherry picked from commit 917a2a3c8625b1d78d3f8d597f32a304d5996740)
2024-11-25 08:50:54 -05:00
Timothy Flynn
6cbfce87bd LibWeb+LibWebView: Set the default path for invalid cookie Path values
We were missing this spec step when parsing the Path attribute.

(cherry picked from commit e74d2b17620b1d68d66d51a13831ee1657154a1c)
2024-11-24 21:30:22 -05:00
Tim Ledbetter
f6ef0a2c5d LibWeb: Rename Window::open_impl() to Window::window_open_steps()
This is the same name used in the specification.

(cherry picked from commit f3c6326f27e4427b549f7d88c99580cb356b5c3c)
2024-11-24 17:29:26 -05:00
Timothy Flynn
f581ef97b0 LibWeb: Log when document.execCommand and family are called
These are used by WPT. Log the commands so we know what we need to
implement.

(cherry picked from commit 96fbb33b13cb65a3a4ce721dd1531911b33db610)
2024-11-24 17:29:26 -05:00
Aliaksandr Kalenik
a23a2061a8 LibWeb: Save layout mode inside formatting context object
FormattingContext::run() does not allow reentrancy, so it's safe to
save and access layout mode from FC object. This avoids need to drill it
through methods of a formatting context and makes it clear that this
value could never be changed after FC construction.

(cherry picked from commit 90b8bfc04ce47a555e8426e82a82003c518063d7)
2024-11-23 20:41:57 -05:00
Aliaksandr Kalenik
2090947600 LibWeb: Remove box argument from FormattingContext::run()
Root formatting context box is passed into constructor and saved in FC,
so it's possible to access it from there instead of passing the same
box into run().

(cherry picked from commit 623e358d7a6a8b9bce6a93b2975655149adbf149)
2024-11-23 20:41:57 -05:00
Andreas Kling
9b4db4a0e0 LibWeb: Make DOMException take error message as a String
There was no need to use FlyString for error messages, and it just
caused a bunch of churn since these strings typically only existed
during the lifetime of the error.

(cherry picked from commit 175f3febb8037a440d4ead7347d3266ee3d345e1;
minorly amended to fix conflict in WebSocket.cpp due to serenity
not having the adapter class removal in LadybirdBrowser/ladybird#1671)
2024-11-22 11:13:42 -05:00
Shannon Booth
485150860a LibURL: Define Origin methods depending on URL::Parser out of line
This is also in an effort towards resolving a future circular dependency
between Origin.h and URL.h

(cherry picked from commit 43973f2d0a32aedf4405f246b5f2806f61016384;
amended to fix tiny include conflict in Document.cpp)
2024-11-21 22:16:27 -05:00
Shannon Booth
2855880f8a LibWeb+LibURL: Move HTML::Origin to URL::Origin
While Origin is defined in the HTML spec - this leaves us with quite an
awkward relationship as the URL spec makes use of AO's from what is
defined in the HTML spec.

To simplify this factoring, relocate Origin into LibURL.

(cherry picked from commit dc401f49ea7e861064484e79594e35c3d93000ae;
amended to fix minor conflicts due to serenity not (yet?) having a
LibUnicode/Segmenter.h include in Document.cpp, and due to
BrowsingContext already having LadybirdBrowser/ladybird#2358 in
serenity)
2024-11-21 22:16:27 -05:00
Timothy Flynn
94af8840a4 LibWeb: Disentangle associated MessagePorts when a document is destroyed
(cherry picked from commit ba1b26cdc2f5012e8c9ac705854f621a83eeda4c)
2024-11-21 09:41:42 -05:00
Timothy Flynn
fb4e032c8f LibWeb: Update spec steps for destroying a DOM document
This just updates our copied spec steps - new steps are not implemented
here. This is mostly just to highlight new steps we are missing around
MessagePorts.

No behavior change, but this does resolve an outstanding FIXME around
spec step ordering.

(cherry picked from commit 83be2606dba7ac430bab4d61a70e926d12d452ee)
2024-11-21 09:41:42 -05:00
Julius Elshoff
15e1590def LibWeb: Rename 'cross-origin opener policy' to 'opener policy'
(cherry picked from commit de31ea5852e3fc0aca1e86e06c6bc019f27824de)
2024-11-21 07:32:56 -05:00
Andreas Kling
e1ba881587 AK+LibWeb: Add {Fly,}String::to_ascii_{upper,lower}_case()
These don't have to worry about the input not being valid UTF-8 and
so can be infallible (and can even return self if no changes needed.)

We use this instead of Infra::to_ascii_{upper,lower}_case in LibWeb.

(cherry picked from commit 073bcfd3866852a4c4bcca2bd131bd65ae53541f)
2024-11-18 20:22:45 -05:00
Andrew Kaster
38f93f5e18 LibWeb: Remove uses of obsolete PlatformObject::global_object()
This API is a relic from the time when it was important for objects to
have easy access to the Window, and to know it was the global object.

We now have more spec-related concepts like relevant_global_object and
current_global_object to pull the Window out of thin air.

(cherry picked from commit 02a56f648000517f191eeaea2abc68783c097486)
2024-11-16 14:12:55 -05:00
Sam Atkins
d6c79e8349 LibWeb: Add Document::get_style_sheet_source()
This returns the source text of the specified style sheet. StyleComputer
now exposes user agent style sheets so that these can also be requested.

(cherry picked from commit 49b2eb5f51be2ddfd2c6009e7d8064b58d665af3)
2024-11-15 23:10:03 -05:00
Sam Atkins
23959eeb6f LibWeb: Rename Document::for_each_css_style_sheet for clarity
This only iterates style sheets that are in use, so make this clear by
renaming it to `for_each_active_css_style_sheet()`.

(cherry picked from commit c29f4f69ef9a16bd63a4bf133618120068e96bf3)
2024-11-15 23:10:03 -05:00
Shannon Booth
8e6d036dc5 LibWeb: Factor out AO for 'try to scroll to the fragment'
I had made a stab at implementing this to determine whether it could
assist in fixing an issue where scroll_to_the_fragment was not getting
called at the appropriate time. It did not fix that issue, and actually
ended up breaking one of our in tree tests. In the meantime, factor out
this method into a standalone function.

(cherry picked from commit 41f574155df89bb5122646a0978fa8821c35fc16)
2024-11-14 17:46:06 -05:00
ronak69
8fbecc096d LibWeb: Insert title as first child on setting title of svg document
Before, the new title element got appended instead of prepended, as
nullptr was passed as the "child" argument to the insert_before()
function.

This change makes two WPT tests pass in:
http://wpt.live/html/dom/documents/dom-tree-accessors/document.title-09.html

(cherry picked from commit 3ff613712132bd3d03f44f27986f7ca5aaea8eb5)
2024-11-14 17:46:06 -05:00
Andreas Kling
bff196be31 LibWeb: Avoid unnecessary style recomputation during traversal
While traversing the DOM tree, looking for nodes that need a style
update, we were recomputing style for every node visited along the way,
even nodes that didn't themselves need a style update (but one of their
descendants did).

This avoids a bunch of completely unnecessary style recomputation on
basically every website.

(cherry picked from commit 5431db8c1c9d366d0a27959cfbf0f146bf4be20d)
2024-11-13 10:17:34 -05:00
Andreas Kling
337b113e68 LibWeb: Use the correct document URL in DOMParser.parseFromString()
We were hard-coding "about:blank" as the document URL for parsed HTML
documents, which was definitely not correct.

This fixes a bunch of WPT tests under /domparsing/ :^)

(cherry picked from commit 55f58eea99c0429dcc39cd0430fafa60eecf5542)
2024-11-13 10:17:34 -05:00
Jamie Mansfield
5ef8538d38 LibWeb/UIEvents: Implement TextEvent
(cherry picked from commit f610a12671cccc5bf96c7ce8f7773c02412b8d81)
2024-11-12 22:26:21 -05:00
Jamie Mansfield
ad93d00ed2 LibWeb/UIEvents: Implement CompositionEvent
(cherry picked from commit 86e20ea2469c0defb6fca40de3cbb339c168b543)
2024-11-12 22:26:21 -05:00
ronak69
9ee02fc952 LibWeb: Frameset should be the body element if it comes before body
Fixes one WPT test: "Frameset followed by body inside the html element"
http://wpt.live/html/dom/documents/dom-tree-accessors/Document.body.html

(cherry picked from commit 5f9a36feacede04cd51c1a286bc5fb87b60fb5e2)
2024-11-12 19:57:55 -05:00
Shannon Booth
57cec9ba63 LibWeb: Avoid potential infinite recursion in Document::update_layout
(cherry picked from commit aa585c4182b8755f01118062c6ea54f5739fffcd)
2024-11-12 04:24:21 -05:00
Shannon Booth
78651dda36 LibWeb: Avoid possible infinite recursion in Document::is_fully_active
(cherry picked from commit bfc28bd62157507db711ffab7ae2683cd466da51)
2024-11-12 04:24:21 -05:00
Tim Ledbetter
f9158f4210 LibWeb: Fire iframe load event on document close
This matches the behavior of other browsers.

(cherry picked from commit e1eeb93cc6095a47371d23db0bbf55eb30215cee)
2024-11-11 19:54:09 -05:00
Edwin Hoksberg
94d2315a59 LibWeb: Handle Refresh header
Fixes a bunch of tests in:
- https://staging.wpt.fyi/results/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh

(cherry picked from commit cbe4ba7f8c825d9732346964c8f1f1f8eec00eac)
2024-11-11 19:54:09 -05:00
Andreas Kling
3479bf0470 LibWeb: Make Document::m_intersection_observers a weak mapping
These registrations are not meant to keep the observers alive.
This fixes a handful of world leaks on Speedometer.

(cherry picked from commit b397a0d5350fad04f43e3e5d9bdb9c801a4e712a)
2024-11-11 17:22:05 -05:00
Andreas Kling
c2d89a02c7 LibWeb: Check for active document in descendant_navigables()
This is not in the spec, but I did see a null pointer dereference here
while browsing the web, and it seems completely harmless for this
function to skip over navigables without an active document.

(cherry picked from commit 56e1c0e7eec813c311c41696063a3a31b4b14f0d)
2024-11-10 20:06:23 -05:00
Andreas Kling
1bf3aeaab4 LibWeb: Sync with spec in "destroy a document and its descendants"
The only real change here is that we make the document unsalvageable.
Everything else is fixing up spec comments.

(cherry picked from commit faf097bb4168208a7c0250280ff07e638be8058a)
2024-11-10 10:46:01 -05:00
Tim Ledbetter
5272446a09 LibWeb: Return a WindowProxy from document.defaultView
This aligns our implementation with the most recent specification steps.

(cherry picked from commit 089139f09dbc78455c5c09916cbc97e33f823ca0)
2024-11-10 10:46:01 -05:00
Annya
a371e02c5f LibWeb: Implement Range's extension method
This patch implements `Range::getClientRects` and
`Range::getBoundingClientRect`. Since the rects returned by invoking
getClientRects can be accessed without adding them to the Selection,
`ViewportPaintable::recompute_selection_states` has been updated to
accept a Range as a parameter, rather than acquiring it through the
Document's Selection.

With this change, the following tests now pass:

- wpt[css/cssom-view/range-bounding-client-rect-with-nested-text.html]
- wpt[css/cssom-view/DOMRectList.html]

Note: The test
"css/cssom-view/range-bounding-client-rect-with-display-contents.html"
still fails due to an issue with Element::getClientRects, which will
be addressed in a future commit.

(cherry picked from commit 75c7dbc5d2dd045733a4c319aeab6644b5b7b36d)
2024-11-10 10:46:01 -05:00
bbb651
3e710465ca HTML: BrowsingContext: Remove m_parent and fix is_ancestor_of
`BrowsingContext::m_parent` has been removed from the spec,
and previously `m_parent` was always null.

`BrowsingContext::is_top_level` was already always returning
true before because of that, and the updated spec algorithm
causes assertions to fail.

This fixes the following example:
```html
<a href="about:blank" target="test">a
<iframe name="test">
```
clicking the link twice no longer causes it to open in a new tab.

(cherry picked from commit e6a668ad913f0755840954c188c255fc5fc66606)
2024-11-07 22:42:20 -05:00
Andreas Kling
5c4c048195 LibWeb: Rename invalidate_layout() => invalidate_layout_tree()
I believe this is slightly less confusing, since what the function does
is trigger a full layout tree *rebuild*, not just a relayout.

(cherry picked from commit aa8f17aea4d1aa1950a66969fc8b5c431fbc1b7c)
2024-11-04 13:17:01 -05:00
Tim Ledbetter
716bf5cb7a LibWeb: Elide boundary checks when constructing find in page ranges
Previously, unnecessary boundary checks were being done when
constructing the range objects used to represent find in page matches.
These checks are no longer performed leading to a significant speedup
when performing find in page queries on pages containing a lot of text.

(cherry picked from commit e76ad9492e0992f9a6d821240bea2b62f27a03c8)
2024-11-01 09:38:01 -04:00
Tim Ledbetter
7d472b5bc7 LibWeb: Cache text blocks used by find in page
The first step of the find in page algorithm is to walk the layout tree
of each document on the page and construct a list of strings against
which to search for matches.

Previously, this was being done for each new query, even when the
page content hadn't been updated. The output of this process is now
cached in the viewport node of the associated document. This ensures
that this process is no longer repeated unnceessarily.

(cherry picked from commit 156c1083e9de23a93075ec9e3c55cd5f93c48896)
2024-11-01 09:38:01 -04:00
Tim Ledbetter
b9fb8c7972 LibWeb: Ensure layout is up to date before performing find in page query
(cherry picked from commit fee7b4147c97e5c775e17fac30667d02bf01c3c4)
2024-11-01 09:38:01 -04:00
Tim Ledbetter
5a5eda3356 LibWeb: Don't search non-visible text for find in page results
Elements which are `display: none` or `visibility: hidden` are no
longer included in find in page results.

(cherry picked from commit a3a7a65b1c89af5631436c06d2847fe7ad5c51cb)
2024-11-01 09:38:01 -04:00
Tim Ledbetter
6a3170fa09 LibWeb: Don't match text across block elements for find in page queries
Find in page will no longer match text that spans across block elements.
Previously, given the markup `WH<div>F</div>`, the query `WHF` would
find a match. We would now match `WH` and `F` separately, but not `WHF`.

(cherry picked from commit 23166b85d2443cccbdd8fcb1e9d99c9f3f9d04a3)
2024-11-01 09:38:01 -04:00
Tim Ledbetter
7c5f5e62f2 LibWeb: Support finding text split across multiple text nodes
Previously, the find in page function would fail to find text which was
split across multiple text nodes. For example, given the following
markup: `WH<span>F` the query `WHF` would previously fail to be
matched.

This is done by traversing all of the document's text nodes -
constructing a complete string to query against and keeping track of
the locations where that string is split across multiple nodes.

(cherry picked from commit ec4d29849dc1d0357c73690722aea1a7802dd0bc)
2024-11-01 05:15:17 -04:00
Andreas Kling
b8037403d2 LibWeb: Cache the Document's node navigable when possible
To avoid expensive lookups, we now cache a weak pointer from document to
the last known node navigable. Before using the cache, we validate that
the document is still the navigable's active document.

(cherry picked from commit e746b2b133758b3552ae07941cc6d14332c64d59)
2024-10-31 20:24:54 -04:00
Andreas Kling
1b73445f55 LibWeb: Note what's causing a style invalidation to happen
You can now build with STYLE_INVALIDATION_DEBUG and get a debug stream
of reasons why style invalidations are happening and where.

I've rewritten this code many times, so instead of throwing it away once
again, I figured we should at least have it behind a flag.

(cherry picked from commit ddbfac38b0074819470766846fca08fd78630eb0;
minorly amended for conflicts in AK/Debug.h.in and
Meta/CMake/all_the_debug_macros.cmake due to us having more debug
macros. Also, downstream got alphabetical order for
STYLE_INVALIDATION_DEBUG wrong.)
2024-10-20 01:32:53 -04:00
Timothy Flynn
c62dd41874 LibWeb: Move the navigable's cursor position to be owned by the document
Navigables are re-used for navigations within the same tab. Its current
ownership of the cursor position is a bit ad-hoc, so nothing in the spec
indicates when to reset the cursor, nor do we manually do so. So when a
cursor update happens on one page, that cursor is retained on the next
page.

Instead, let's have the document own the cursor. Each navigation results
in a new document, thus we don't need to worry about resetting cursors.

This also makes many of the callsites feel nicer. We were previously
often going from the node, to the document, to the navigable, to the
cursor. This patch removes the navigable hop.

(cherry picked from commit faebbbc281d1267062770b02fc6d962d92a3bd62)
2024-10-18 21:58:17 -04:00
BenJilks
26facdeecc LibWeb: Use text encoding from DOM when parsing URLs
This passes the DOM encoding down to the URL parser, so the correct
encoder can be used.

(cherry picked from commit c1958437f983bb9761661534da34934c8dddcf6f)
2024-10-15 22:54:51 -04:00
Shannon Booth
9d729e19bf LibWeb: Rename SharedImageRequest to SharedResourceRequest
For the SVG <use> element, we want to support loading HTML documents
that have a SVG element inside of it pointed to by the URL fragment.

In this situation we would need to fetch and parse the entire document
in SharedImageRequest (so that we can still cache the SVGs). Rename
SharedImageRequest to SharedResourceRequest to make the class a little
more generic for future usecases.

(cherry picked from commit a342370dfb4f1eeabc7dcb8fbe6f8e4eb6f6b1f4)
2024-09-27 22:27:02 -04:00