Commit graph

54434 commits

Author SHA1 Message Date
Sam Atkins
6bf107fc16 LibWeb: Implement the :open and :closed pseudo-classes
These apply to any elements that have some kind of open/closed state.
The spec suggests `<details>`, `<dialog>`, and `<select>`, so that's
what I've supported here. Only `<details>` is fleshed out right now,
but once the others are, these pseudo-classes should work
automatically. :^)
2023-09-13 19:55:22 +02:00
Sam Atkins
29bb0f0ae6 LibWeb: Stub out an "open" state on <select> elements
The CSS Selectors-4 spec suggests that `:open` and `:closed` should
apply to `<select>` elements, so let's add a way of storing and
exposing that state. We don't yet actually generate any layout for
`<select>` elements, so they will always report that they are closed.
2023-09-13 19:55:22 +02:00
Timothy Flynn
b1632c58bf LibWeb: Create a shadow tree for details elements with manual slots
The spec requires that details elements be assigned a shadow tree with
two slots. The first slot is assigned the first summary child element of
the details element. The second slot is assigned all other children.
2023-09-13 13:45:47 +02:00
Timothy Flynn
bdf2323b3f LibWeb: Perform layout of a slot's assigned nodes 2023-09-13 13:45:47 +02:00
Timothy Flynn
e4d3a9aa68 LibWeb: Ensure DOM events on slottables are properly propagated
Most events on a slottable are composed, meaning they propagate from the
slottable and through its shadow tree before bubbling up to the parent
of the slottable.
2023-09-13 13:45:47 +02:00
Timothy Flynn
d67d93f870 LibWeb: Handle reassigning slottables on node insertion and removal 2023-09-13 13:45:47 +02:00
Timothy Flynn
683ce8e615 LibWeb: Implement (most of) the assigned slot/slottable lookup APIs
This implements looking up a slottable's assigned slot, and a slot's
list of assigned slottables. For the latter, only unflattened lookups
are implemented so far.
2023-09-13 13:45:47 +02:00
Timothy Flynn
b602ee7ddd LibWeb: Implement automatic slottable assignment
This implements automatic slottable assignment by way of hooking into
the element attribute change steps. When the `name` attribute of a slot
or the `slot` attribute of a slottable changes, assignment is performed.
2023-09-13 13:45:47 +02:00
Timothy Flynn
e9da74ebe0 LibWeb: Implement manual slottable assignment
This implements manual slottable assignment by way of HTMLSlotElement's
`assign` API. This includes all of the slottable-related AOs needed to
perform the assignment.
2023-09-13 13:45:47 +02:00
Timothy Flynn
7870f10aa8 LibWeb: Introduce the slot concept for HTML slot elements
A slot is an HTMLSlotElement. It may have any number of slottable nodes
assigned to it.
2023-09-13 13:45:47 +02:00
Timothy Flynn
45b36bd08a LibWeb: Introduce the slottable concept for DOM elements and text nodes
A slottable is either a DOM element or a DOM text node. They may be
assigned to slots (HTMLSlotElement) either automatically or manually.
Automatic assignment occurs by matching a slot's `name` attribute to
a slottable's `slot` attribute. Manual assignment occurs by using the
slot's (not yet implemented) `assign` API.

This commit does not perform the above assignments. It just sets up the
slottable concept via IDL and hooks the slottable mixin into the element
and text nodes.
2023-09-13 13:45:47 +02:00
Timothy Flynn
b85a252753 LibWeb: Implement the attribute-change-steps extension
This is similar to the run activation behavior in that elements may
define these steps themselves. HTMLSlotElement is one such element. The
existing (ad-hoc) Element::attribute_changed() method is not sufficient
there as the steps require knowledge of the attribute's old value and
its namespace, which this extension provides.

Unlike the run activation behavior, we store these steps in a list. An
element may end up defining multiple attribute change steps. For example
all DOM elements must define steps to handle the "slot" attribute, and
HTMLSlotElement must define steps to handle the "name" attribute.
2023-09-13 13:45:47 +02:00
Timothy Flynn
54b5a431a3 LibWeb: Implement element slot-related attributes and settings
This implements the element's slot attribute itself, and setting the
slot assignment on the element's shadow root.
2023-09-13 13:45:47 +02:00
Timothy Flynn
4e32f0d39f LibWeb: Remove virtual specifier from Element::set/remove_attribute()
Only HTMLDetailsElement was overriding these methods, which has been
updated to use Element::attribute_changed() instead.
2023-09-13 13:45:47 +02:00
Timothy Flynn
8bb5652835 LibWeb: Implement HTMLDetailsElement's open attribute closer to the spec
The spec now has a "toggle task tracker" to coalesce rapid changes to
this attribute. It also now has an explicit ToggleEvent to encapsulate
the old and new state of the element.

This further handles the attribute being added/removed using a override
of Element::attribute_changed(), rather than being the only element to
instead override Element::set/remove__attribute().
2023-09-13 13:45:47 +02:00
Timothy Flynn
153ae93f9c LibWeb: Implement ToggleEvent for HTMLDetailsElement 2023-09-13 13:45:47 +02:00
Timothy Flynn
f598a357ad LibWeb: Assign a unique ID to each HTML task
And return that ID when queueing an element task. This is required for
some task tracking - specifically, the HTML ToggleTaskTracker struct.
2023-09-13 13:45:47 +02:00
Andrew Kaster
5ae9b2fdaf LibWeb: Add {de}serialization steps for TypedArrayBuffers and DataViews 2023-09-13 08:49:09 +02:00
Andrew Kaster
bddf3fbf2d LibWeb: Make StructuredSerialize/Deserialize friendlier to recursion
Make the internal calls take objects by reference, and take writable
spans into data rather than const& to the underlying vector type.
2023-09-13 08:49:09 +02:00
Sam Atkins
e0fe77d012 LibWeb+headless-browser: Replace ref-test manifest with link tags
Each ref test now links to its reference page with a link tag, in the
same format as WPT:

`<link rel="match" href="reference-page.html" />`

The reference pages have all been moved into a separate `reference/` dir
so that we can just treat every file in `ref/` as a test. There's no
filter to only look at .html files, because we also have a .svg file in
there, and there may be other formats we want to use too. But it's not
too hard to add one if we need it.
2023-09-13 08:48:19 +02:00
Sam Atkins
f3add3dd72 WebContent: Add "load-reference-page" debug request
This attempts to load the URL of the first `<link rel="match" href=""/>`
it finds. If that tag is missing, we load an error page to make sure
the ref-test fails. (And to provide some feedback if someone looks at
the screenshot somehow.) Wrong URLs will instead end up loading the
default 404 error page.
2023-09-13 08:48:19 +02:00
Sam Atkins
7ba686dcb3 LibWeb: Run on_load_start/finish callbacks when loading HTML directly
I need this for the upcoming "load-reference-page" debug request. But it
generally seems like the correct thing to do. :^)
2023-09-13 08:48:19 +02:00
Sam Atkins
cb8c4cd2e6 WebContent: Return once debug_request is handled
The request can only be one string, so once we've matched it, stop
checking all the other possible values. :^)
2023-09-13 08:48:19 +02:00
Tim Ledbetter
9a6927c575 GameOfLife: Ensure BoardWidget can always contain the board
Previously, when there were more rows or columns than the BoardWidget
could contain, nothing was displayed. The BoardWidget minimum size is
now set whenever the number of rows or columns changes.
2023-09-13 07:45:49 +01:00
Tim Ledbetter
871f5ba431 2048: Disable the undo and redo actions when unavailable
This change also ensures that the redo stack is cleared when a move is
made, so that it isn't possible to redo a previous move after having
made a new one.
2023-09-13 07:27:01 +02:00
Shannon Booth
c3e6077cfc LibWeb: Make Document::{visibility,read}_state return a StringView
Also using the visibility state enum to change strcmp to a simple
enum state check :^)
2023-09-13 07:26:35 +02:00
Shannon Booth
49eb3bfb1d LibWeb: Make Document::run_the_document_write_steps take a StringView
Which flows on down into HTMLTokenizer::insert_input_at_insertion_point.
2023-09-13 07:26:35 +02:00
Shannon Booth
827170f6e6 LibWeb: Take a StringView in Document::get_elements_by_class_name
We only ever use the view of the DeprecatedFlyString anyway, so let's
just use a StringView.
2023-09-13 07:26:35 +02:00
Shannon Booth
ec39a5a41a LibWeb: Const qualify Document::number_of_things_delaying_the_load_event 2023-09-13 07:26:35 +02:00
Shannon Booth
e42bda5f19 LibWeb: Make Document::open functions take a StringView
One of these functions doesn't make any use of the arguments at all, and
the other defers to an open helper which already takes a StringView.
2023-09-13 07:26:35 +02:00
Shannon Booth
8ad05fff4a LibWeb: Make Document::set_cookie take a StringView
Enabled by also making the same change to ParsedCookie::parse_cookie :^)
2023-09-13 07:26:35 +02:00
Andrew Kaster
642802d339 LibWeb: Add {de}serialization steps for ArrayBuffers 2023-09-12 22:14:39 +02:00
Andrew Kaster
a527f55768 LibWeb: Create StructuredSerialize helpers for Bytes
Call them from the helpers for strings. We'll have other object classes
soon that need to serialize ByteBuffers, so let's take advantage of the
encoding scheme we are already using for Strings.
2023-09-12 22:14:39 +02:00
Andrew Kaster
56d0a0ac0f LibJS: Make CreateDataByteBlock AO publicly available
At the same time, make CopyDataBlockBytes const-correct.
2023-09-12 22:14:39 +02:00
Andrew Kaster
267074cd81 LibWeb: Add {de}serialization steps for RegExpObjects
We skip serializing any of the internal state of the Regex<ECMA262>
object, because that state is all computable from the input pattern
and flags. If it turns out that this is really, really slow, we can add
some optimizations to serialize more of the regex parse result.
2023-09-12 22:14:39 +02:00
Andrew Kaster
3a74bd2509 LibWeb: Don't try to deserialize past length of strings
If we serialize a string followed by some other object, the deserialize
helper would just happily keep appending bytes to the string until the
end of the serialization buffer. Avoid doing that by checking the string
length for figuring out when the string actually ends.
2023-09-12 22:14:39 +02:00
Cubic Love
842b2a01e6 Base: Add manpage for pkg 2023-09-12 20:03:12 +02:00
Aliaksandr Kalenik
63939445b1 LibWeb: Use fit-content width if button's computed width is "auto"
Implements following line from the spec:
"If the computed value of 'inline-size' is 'auto', then the used value
is the fit-content inline size."
2023-09-12 17:26:30 +02:00
Aliaksandr Kalenik
7eee3f6952 LibWeb: Add mutable_computed_values() for NodeWithStyle
This fixes the issue that we previously had to use a gross static_cast
whenever we wanted to mutate computed values outside of the Node
methods.
2023-09-12 17:26:30 +02:00
Andreas Kling
44b2735b9e LibJS: Make line-and-column resolution fast for large minified JS
Instead of caching start-of-line offsets, we now cache byte offsets
at regular intervals. This fixes an issue where we had terrible
performance on large minified JS, since that often means one very,
VERY long line (with no line endings to cache).

My machine was spending ~35ms per stack frame when throwing errors
on some heavy minified websites, and after this patch, we now spend
<1ms per stack frame.
2023-09-12 17:21:42 +02:00
Sam Atkins
ff02de4ad0 LibWeb: Serialize StringStyleValue with quotes
In order to access the string's contents, use the new
`StringStyleValue::string_value()` method.

I think I found all the existing places that relied on
`StringStyleValue::to_string()` returning an unquoted string, but it's
hard to know for sure until things break.
2023-09-12 14:29:21 +01:00
Sam Atkins
77ae510319 LibWeb: Parse each unquoted font-family name as a single CustomIdentSV
Previously we made StringStyleValues from these, but once we start
actually quoting StringStyleValues when serializing them, this will
break the font-family serialization.
2023-09-12 14:29:21 +01:00
Aliaksandr Kalenik
d1e542999c LibWeb: Ensure preceding offset is non-negative in float_box()
When calculating the edge offset of the next floating item based on the
offset of the preceding floating item, we need to ensure that the
preceding offset is always > 0. This isn't explicitly written in the
spec, but all other popular engines do that.

Fixes https://github.com/SerenityOS/serenity/issues/21023
2023-09-12 12:11:53 +02:00
Aliaksandr Kalenik
81ddad3fcf LibWeb: Allow block level boxes to be floated and have clearance
Before, we completely ignored clearance for block-level boxes if they
were floated. This was incorrect because it is valid for a block-level
box to be floated and still have clearance. However, unlike clearance
on normal flow boxes, clearance on floating boxes does not affect the
y-position of subsequent normal flow boxes. Instead, it pushes the
box's position to the very beginning of an edge.

Work towards https://github.com/SerenityOS/serenity/issues/21023
2023-09-12 12:11:53 +02:00
Jelle Raaijmakers
9240233378 Revert "AK: Refill a BufferedStream when it has less than the
...requested size"

This reverts commit 13573a6c4b.

Some clients of `BufferedStream` expect a non-blocking read by
`read_some` which the commit above made impossible by potentially
performing a blocking read. For example, the following command hangs:

    pro http://ipecho.net/plain

This is caused by the HTTP job expecting to read the body of the
response which is included in the active buffer, but since the buffered
data size is less than the buffer passed into `read_some`, another
blocking read is performed before anything is returned.

By reverting this commit, all tests still pass and `pro` no longer
hangs. Note that because of another bug related to `stdout` / `stderr`
mixing and the absence of a line ending, there is no output to the
command above except a progress update.
2023-09-11 21:38:24 -04:00
Sam Atkins
489f9c3151 LibWeb: Implement text-transform: math-auto
This is a simple mapping of some code-points to others.

I was going to use a ref test for this, but without knowing that the
font contains the code-points (which SerenitySans does not) we'd be
comparing a series of replacement characters to a series of replacement
characters, which doesn't tell you if they're the right code-points
underneath.
2023-09-11 17:03:22 +01:00
Sam Atkins
ce775ea701 LibWeb: Use a switch to handle TextTransform values
This makes it more obvious that we're missing some of these. (And makes
it easier to find this code when searching for a specific value.)
2023-09-11 17:03:22 +01:00
Sam Atkins
f7209fb9d4 LibWeb: Implement font-size: math
This is a MathML extension, basically a big hack to make parts of
equations smaller, such as sub/superscripts. The important thing is, it
works. :^)
2023-09-11 17:03:22 +01:00
Sam Atkins
6476dea898 LibWeb: Implement the math-depth CSS property
This one is a bit fun because it can be `add(<integer>)` or `auto-add`,
but children have to inherit the computed value not the specified one.
We also have to compute it before computing the font-size, because of
`font-size: math` which will be implemented later.
2023-09-11 17:03:22 +01:00
Sam Atkins
53f3ed026a LibWeb: Mark CalculatedStyleValue::resolve_integer() as const 2023-09-11 17:03:22 +01:00