Commit Graph

664 Commits

Author SHA1 Message Date
Tim Ledbetter
30e505a630 LibWeb: Match attribute selectors case insensitively in XML documents
The values of attribute selectors are now compared case insensitively
by default if the attribute's document is not a HTML document, or the
element is not in the HTML namespace.

(cherry picked from commit 00f03f3e900d6f5c0196db9a9d7eb352ec516b44)
2024-11-07 22:42:20 -05:00
Tim Ledbetter
8537cd76f3 LibWeb: Limit HTMLProgressElement.max to positive values
Previously, 0 was returned if `HTMLProgressElement.max` was set to a
negative value.

(cherry picked from commit 353e3e75dcff05f05a65cfc3c70d1cff8db5d50c)
2024-11-07 22:42:20 -05:00
Shannon Booth
51b710bce1 LibWeb: Actually perform "update the href steps"
We completely missed this step, which made setters not actually do
anything!

Fixes 336 test failures on:

https://wpt.live/url/url-setters-a-area.window.html
(cherry picked from commit deff8df2c79af718f08f16bc47f5a22ac6add553)
2024-11-07 21:52:13 -05:00
Andreas Kling
1c8375f5df LibWeb: Don't extrapolate transition properties for unknown properties
If we don't recognize a given transition-property value as a known CSS
property (one that we know about, not necessarily an invalid one),
we should not extrapolate the other transition-foo values for it.

Fixes #1480

(cherry picked from commit 9765a733d0bc297815fc1a7fce562e3d8f69cd84)
2024-11-05 10:48:01 -05:00
Tim Ledbetter
01324df21e LibWeb: Implement setRangeText for input and textarea elements
This method replaces range of text in its respective element with a new
string

(cherry picked from commit 2f5b0707163db5df5ff2d25dc329e70d8f54a7f1)
2024-11-04 19:28:16 -05:00
Tim Ledbetter
95527fd7aa LibWeb: Implement cloning steps for HTMLTextAreaElement
(cherry picked from commit d3e076f963716222787903a9613e0678d909a7ab)
2024-11-04 13:39:53 -05:00
Tim Ledbetter
3710a5b1fb LibWeb: Implement cloning steps for HTMLInputElement
(cherry picked from commit 71cfa705d1eab052e773e6a695c438bab87ec8b0)
2024-11-04 13:39:53 -05:00
Jelle Raaijmakers
cb1edae2ca LibWeb: Implement input/textarea selection APIs
For both types of elements, `.selectionStart`, `.selectionEnd`,
`.selectionDirection`, `.setSelectionRange()`, `.select()` and the
`select` event are now implemented.

(cherry picked from commit 814ca3267ed73d7ad8492ef69ff87f95240cf922)
2024-11-04 13:17:37 -05:00
Timothy Flynn
b106429d4f LibWeb: Append attributes to the correct element
The spec indicates we should append attributes to the top element of the
stack of open elements. We were appending the attribute to the bottom.

(cherry picked from commit 657bbd1542ce8fcd3357e5b4dada895229faf834)
2024-11-04 13:17:19 -05:00
Timothy Flynn
7cb6a40e95 LibWeb: Use an infallible method to add attributes to nodes
In the HTML parser spec, there are 2 instances of the following text:

    add the attribute and its corresponding value to that element

The "add the attribute" text does not have a corresponding spec link to
actually specify what to do. We currently use `set_attribute`, which can
throw an exception if the attribute name contains an invalid character
(such as '<'). Instead, switch to `append_attribute`, which allows such
attribute names. This behavior matches Firefox.

Note we cannot yet make the unclosed-html-element.html test match the
expectations of the unclosed-body-element.html due to another bug that
would prevent checking if the expected element has the right attribute.
That will be fixed in an upcoming commit.

(cherry picked from commit 9fe35ddddf895b0835a347eab7b45b33d1638ce7)
2024-11-04 13:17:19 -05:00
Aliaksandr Kalenik
0a348c394c LibWeb: Make sure style is up-to-date in getAnimations()
StyleComputer is responsible for assigning animation targets, so we
have to make sure there are no pending style updates before querying
animations of an element.

This change also introduces a version of getAnimations() that does not
check style updates and used by StyleComputer to avoid mutual recursion.

(cherry picked from commit 94b3b84dd808b6607e8fd0aead1796709f3a8721)
2024-11-04 13:15:58 -05:00
Sam Atkins
87e74c6c0c LibWeb: Start transitions when affected properties change
Co-authored-by: Matthew Olsson <matthewcolsson@gmail.com>
(cherry picked from commit a1fca1a7f3f70e4acf15052014d5b180197df9fd)
2024-11-04 13:15:58 -05:00
Tim Ledbetter
3d130ee6ef LibWeb: Don't group radio buttons from different trees together
Previously, we were searching for other radio buttons from the document
root, rather than the element root.

(cherry picked from commit 67981af276cf55d69d51a872ec83e5b59d793b6c)
2024-11-04 12:29:19 -05:00
Tim Ledbetter
610873368a LibWeb: Don't crash when converting small CSS::Ratio to CSSPixelFraction
Previously, a crash would occur in the if `CSSPixelFraction` was given a
denominator value less than the resolution of `CSSPixels` (1/64).

We now divide both parts of the ratio by the denominator in this case.

(cherry picked from commit 2c5d626b2125ffea49e06735e2f93279d0dfa0e1)
2024-11-02 07:50:34 -04:00
Tim Ledbetter
b76de7e477 LibWeb: Don't crash when calling getBBox() on the outermost SVG element
(cherry picked from commit b140206a91e809426248f85a5471f734d8e86997)
2024-11-02 06:45:57 -04:00
Jamie Mansfield
c45292e1aa LibWeb: Don't crash with invalid import maps
See:
 - http://wpt.live/import-maps/multiple-import-maps/with-errors.html
(cherry picked from commit c891b83fc079ee0c34ea9ccc71cfed67e3b14cd2)
2024-11-02 06:45:48 -04:00
Andreas Kling
00e187e0a9 LibWeb: Fix crash when setting innerHTML inside iframe srcdoc document
In particular, there was an assertion failure due to the temporary
parser document's "about base URL" being empty when trying to "parse a
URL" during parsing.

We fix this by copying the context element's document's about base URL
to the temporary parsing document while parsing a fragment.

This fixes a crash when loading search results on https://amazon.com/

(cherry picked from commit b64df59cc61f31b8a0aab91abb4630b3ecb1dcee)
2024-11-02 06:45:38 -04:00
Andreas Kling
2be65856ae LibWeb: Don't crash on getClientRects() in document without navigable
I previously believed there was no way a detached document should have
layout information, but it turns out there is a way: getComputedStyle().

So we need to account for cases where we have a layout node, but no
navigable, since that is a state we can get into at this moment.

Fixes #354

(cherry picked from commit 1e7b17f15024d0618f1a1e17e3e927856febde28)
2024-11-02 06:45:28 -04:00
Timothy Flynn
cd69ebdecd LibWeb: Implement the DataTransferItem kind and type attributes
(cherry picked from commit 001d8384e5ea51e2a435517814d299174d65d786)
2024-11-01 22:04:14 -04:00
Timothy Flynn
a6d010c247 LibWeb: Implement the DataTransferItemList indexed getter
(cherry picked from commit ceb9e30d422425582ac1db857ff4c786fb7e212c)
2024-11-01 22:04:14 -04:00
Timothy Flynn
695771695d LibWeb: Implement the DataTransferItemList length attribute
(cherry picked from commit 843f8f04a518ec0968e4f39ce27264efe0546fa9)
2024-11-01 22:04:14 -04:00
Timothy Flynn
cf1bdd72ac LibWeb: Implement DataTransferItemList.prototype.add()
(cherry picked from commit 74d9cfbf2a2ef84e8634dafc78fc56e6cb153b6b)
2024-11-01 22:04:14 -04:00
Timothy Flynn
77a96886e2 LibWeb: Implement separate DataTransfer factories for IDL / internal use
The IDL constructor has to take separate steps than a DataTransfer that
is internally constructed. Notably, an IDL-created object has its own
drag data store, and that store is placed in a read-write mode.

(cherry picked from commit 5c9287aa99e52886a3d144c26de6a54980a53db6)
2024-11-01 22:04:14 -04:00
Jamie Mansfield
abe4acab3a LibWeb: Implement HTMLTrackElement.readyState
(cherry picked from commit 1d12cb69d46a46442de2baa2a316d5b004821352)
2024-11-01 21:11:17 -04:00
Timothy Flynn
a3050819d2 LibWeb: Implement the DataTransfer files attribute
(cherry picked from commit 4bb9168712d6e706465ded9e1b6764a039651ea0)
2024-11-01 19:58:08 -04:00
Timothy Flynn
7085b7f127 LibWeb: Implement the DataTransfer types attribute
(cherry picked from commit 9f4e3c7e25bbc94a479a2a96cdbe85c47f634627)
2024-11-01 19:58:08 -04:00
Timothy Flynn
a7133e5f31 LibWeb: Begin implementing the drag-and-drop processing model
The drag-and-drop processing model allows for users to drag around
either elements within the DOM or objects completely outside the DOM.
This drag event can either end without action (via cancellation or user
input), or in a drop event, where the dragged object is dropped onto
another element within the DOM.

The processing model is rather large. This implements enough of it to
allow the UI process to specifically handle dragging objects outside of
the DOM onto the DOM. For example, dragging an image from the OS file
manager onto a file-upload input element. This does not implement the
ability to drag DOM elements.

(cherry picked from commit e8a1b8944719e1e297453527fbe0a84cc2c33eb6)
2024-11-01 19:58:08 -04:00
Colin Reeder
96d8776eba LibWeb: Add stub implementation of performance.navigation
(cherry picked from commit 14267b5d631d69091c1e9a936e1fa0f9a28752c1)
2024-11-01 16:16:35 -04:00
Tim Ledbetter
ac68be994b LibWeb: Implement a minimal version of Window.find()
This is a non-standard API that other browsers implement, which
highlights matching text in the current window.

This is just a thin wrapper around our find in page functionality, the
main motivation for adding this API is that it allows us to write tests
for our find in page implementation.

(cherry picked from commit c4d5ae28ea40ae0a0c783f34d840fb94662780fb)
2024-11-01 09:38:01 -04:00
Annya
265c942698 LibWeb/CSS: Implement revert-layer
With the introduction of the cascade layer, the 5th CSS-wide keyword,
`revert-layer`, has been added.

(cherry picked from commit bea7eec5183a816a100d190e409a622f429d7405)
2024-10-31 21:51:50 -04:00
Tim Ledbetter
6b2891da01 LibWeb: Match class selectors case insensitively in quirks mode
This align our implementation with the CSSWG Selectors Level 4
specification.

(cherry picked from commit 82ed2534776406872337b34ddf2dfaa0b3332c32)
2024-10-31 19:59:29 -04:00
Tim Ledbetter
3a74d614db LibWeb: Ensure ParentNode.getElementsByClassName() matches all classes
(cherry picked from commit 96c0cbf584e99d5c1c9b894d0317d8c2887ade83)
2024-10-31 19:58:12 -04:00
Sam Atkins
9d869b3afc LibWeb: Add coverage test for calc() usage
Ignoring the fact that we should serialize a simplified form of calc()
expressions, the following are wrong:

- grid-auto-columns
- grid-auto-rows
- grid-template-columns
- grid-template-rows
- transform-origin

Generated in part with this python script (though I've since iterated on
the output repeatedly so it's quite different):

```py
import json
properties_file = open("./Userland/Libraries/LibWeb/CSS/Properties.json")
properties = json.load(properties_file)
for (key, value) in properties.items():
    if not 'valid-types' in value:
        continue
    if 'longhands' in value:
        continue
    valid_types = value['valid-types']
    for type_string in valid_types:
        name, *suffix = type_string.split(None, 1)
        match name:
            case 'integer' | 'number':
                print(f'{key}: calc(2 * var(--n));')
            case 'angle':
                print(f'{key}: calc(2deg * var(--n));')
            case 'flex':
                print(f'{key}: calc(2fr * var(--n));')
            case 'frequency':
                print(f'{key}: calc(2hz * var(--n));')
            case 'length':
                print(f'{key}: calc(2px * var(--n));')
            case 'percentage':
                print(f'{key}: calc(2% * var(--n));')
            case 'resolution':
                print(f'{key}: calc(2x * var(--n));')
            case 'time':
                print(f'{key}: calc(2s * var(--n));')
```

(cherry picked from commit 301502a3a12b86e218f477f06d2d5271aee8e017;
amended to include `Well, hello friends  ` in
expected/css/calc-coverage.txt because we don't have
LadybirdBrowser/ladybird#1603 yet)
2024-10-27 16:58:12 -04:00
Sam Atkins
d29d44951d LibWeb: Serialize more @font-face descriptors
Adapt the existing `font-face-src-local-serialization.html` test into a
more general test for these.

(cherry picked from commit c497e5f850a5c7f43d6f216d9fd74a58ddefd9a0)
2024-10-26 09:29:16 -04:00
Sam Atkins
536fb5a0bc LibWeb/CSS: Implement cascade layers (aka @layer)
This is done quite simply for now, there are certainly optimizations
that can and should be made later.

With this we now pass:
- http://wpt.live/css/css-cascade/layer-basic.html
- http://wpt.live/css/css-cascade/layer-important.html
- http://wpt.live/css/css-cascade/layer-statement-copy-crash.html
- http://wpt.live/css/css-cascade/layer-stylesheet-sharing-important.html
- http://wpt.live/css/css-cascade/layer-stylesheet-sharing.html
- http://wpt.live/css/css-cascade/layer-vs-inline-style.html

(cherry picked from commit a50da405e9c350266edfc89e5d27f7acddbee422)
2024-10-20 21:09:21 -04:00
Jelle Raaijmakers
004462c6e9 LibWeb: Implement history.scrollRestoration
(cherry picked from commit 2106617f5b97dd2e3c4aea11ef26685f43e75261)
2024-10-20 16:39:16 -04:00
Shannon Booth
3c4c45b13b LibWeb: Actually set empty serialized query to OptionalNone
Because the type returned by to_string is a String, _not_ an
Optional<String>, the following code:

if (serialized_query.is_empty())
    serialized_query = {};

Was achieving nothing at all! Make sure that the type is an
Optional<String> so that we're not just setting an empty string to an
empty string.

(cherry picked from commit d755a83c09a5fba82a91f9cc3f9e3b2e07880127)
2024-10-19 15:26:29 -04:00
Shannon Booth
f36e2779b2 LibWeb: Use a stable sort for searching URLSearchParams
Quick sort is not a stable sort. This meant we had a subtle issue
implementing this portion of the spec comment:

 > The relative order between name-value pairs with equal names must
 > be preserved.

Switch to insertion sort which is a stable sort, and properly handles
keys which are the same.

Fixes 8 tests on  https://wpt.live/url/urlsearchparams-sort.any.html

(cherry picked from commit 1ba6dbd86c0a94e5f068e6586199866f7de6354e)
2024-10-19 15:26:29 -04:00
Shannon Booth
4c181bdf7f LibWeb: Implement value argument of URLSearchParams.has
(cherry picked from commit 264b5160c2099f1aab6f06ece720de984ea994b2)
2024-10-19 15:26:29 -04:00
Shannon Booth
6f129a8e1f LibWeb: Implement value argument of URLSearchParams.delete
(cherry picked from commit 5637dc43b2d6faf0576e7844581d0ced882d007f)
2024-10-19 15:26:29 -04:00
Shannon Booth
8c62701f82 LibWeb/Tests: Relocate search params test into URL folder
This is where I have been trying to put all of the URL tests.

(cherry picked from commit e2fb24c9b8e973542e8313ddb9e0f9f85a71c0e8)
2024-10-19 15:26:29 -04:00
Bastiaan van der Plaat
f19a183fe0 LibWeb: Add URL reflection to obsolete HTMLImageElement lowsrc property
(cherry picked from commit f2034270f14a72ebf0ac09493837c21bae0b4adf)
2024-10-19 15:26:29 -04:00
Shannon Booth
b37d0b4bbb HTML: Partially implement HTMLInputElement's selection{Start,End}
Now that the implementation is in FormAssociatedElement, the
implementation in HTMLInputElement is effectively just a passthrough,
with some minor differences to handle small behavioural quirks between
the two (such as the difference in nullability of types).

(cherry picked from commit 9f24176cac862c42c9cf4d3ac0e757397a5f6ae1)
2024-10-18 21:58:17 -04:00
Tim Ledbetter
df8eec7786 LibWeb: Change attribute type to USVString where applicable
Also mark USVString attributes as containing a URL, where applicable.

(cherry picked from commit 1369fc5069598644842defabbfbf3d30d2f3e647)
2024-10-17 21:31:52 -04:00
Shannon Booth
fe2f85c5a0 LibWeb: Implement USVString scalar value handling
USVString is defined in the IDL spec as:

> The USVString type corresponds to scalar value strings. Depending on
> the context, these can be treated as sequences of either 16-bit
> unsigned integer code units or scalar values.

This means we need to account for surrogate code points by using the
replacement character.

This fixes the last test in https://wpt.live/url/url-constructor.any.html

(cherry picked from commit aa32bfa4481f6298c99846025394b7bc415ca621)
2024-10-17 20:28:06 -04:00
Alisson Lauffer
73bbe2b801 LibWeb: Replace "+" in value with a space while decoding search params
(cherry picked from commit d38b28b57b88e865b580f0d5e33310631f13e62c)
2024-10-16 23:56:40 -04:00
Shannon Booth
8f243cc632 LibWeb: Actually run UTF-8 decode without BOM
This fixes a crash using URLSearchParams when provided a percent encoded
string which does not percent decode to valid UTF-8.

Fixes a crash running https://wpt.live/url/urlencoded-parser.any.html

(cherry picked from commit 9c72fc9642266ac92dedbccac7d8c0bd238450cd)
2024-10-16 23:56:40 -04:00
Shannon Booth
decc664458 LibURL: Fail parsing IPV4 URLs starting with 0x that overflow
Parsing last as an IPV4 number was not returning true in "ends with a
number" as the parsing of that part was overflowing. This means that the
URL is not considered to be an IPv4 address, and is treated as a valid
domain.

Helpfully, the spec also points out in a note that this step is
equivalent to simply checking that the last part ends with 0x followed
by only hex digits - which doesn't suffer from any overflow problem!

Arguably this is an editorial issue in the spec where this should be
clarified a little bit. But for now, fixing this fixes 3 sub tests in
WPT for:

https://wpt.live/url/url-constructor.any.html
(cherry picked from commit 6cac2981fb45498f7e5b84ded2669fb62111da17)
2024-10-15 12:08:50 -04:00
Shannon Booth
e01e49e00d LibURL: Fix heuristic for URL domain parsing IDNA fast path
Our heuristic was a bit too simplistic and would not run through the
ToASCII unicode algorithm which performs some extra validation. This
would cause invalid URLs that should fail to be parsed be mistakenly
accepted.

This fixes 8 tests in: https://wpt.live/url/url-constructor.any.html

(cherry picked from commit db3f1180464eefc841d2eccc5a6b441398dd164d)
2024-10-15 12:08:50 -04:00
Shannon Booth
8467171260 LibWeb: Don't strip leading '?' in query initializing a URL
In our implementation of url-initialize, we were invoking the
constructor of URLSearchParams:

https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams

Instead of the 'initialize' AO:

https://url.spec.whatwg.org/#urlsearchparams-initialize

This has the small difference of stripping any leading '?' from the
query (which we are not meant to be doing!).

(cherry picked from commit fd4e943e12aa077f11a537164166fdfb82e29e8d)
2024-10-15 12:08:50 -04:00