Commit graph

2034 commits

Author SHA1 Message Date
MacDue
43177fd2a1 Tests/LibWeb: Add a ref test for SVG mask with maskUnits=userSpaceOnUse 2023-10-09 07:28:18 +02:00
MacDue
e9fd7c96af Tests/LibWeb: Add ref test for an SVG mask with mask-type: alpha 2023-10-09 07:28:18 +02:00
MacDue
479451498b LibWeb: Implement mask-type CSS property
This property allows specifying if a mask is an alpha or luminance mask.

See: https://drafts.fxtf.org/css-masking/#the-mask-type
2023-10-09 07:28:18 +02:00
Shannon Booth
e4f8c59210 LibWeb: Port AttributeNames to FlyString 2023-10-08 08:11:48 -04:00
Andreas Kling
3250a424f0 LibWeb: Don't offset abspos children of flex container by padding twice
We were incorrectly offsetting the static position of abspos children of
flex containers by the padding twice. This was a misguided attempt to
adjust to the abspos containing block being the padding box, not the
content box.

Fixes #21344.
2023-10-08 09:06:30 +02:00
Ali Mohammad Pur
ebe254a6d3 LibWeb/XML: Avoid placing all elements missing an ns in the HTML ns
Also remove the hack for SVG documents, a well-formed SVG document has
the correct xmlns attribute set, which should be automatically picked up
by the builder now.
2023-10-07 20:02:10 +02:00
Andreas Kling
0762388709 LibWeb: Make XHR.response an actual XMLDocument for XML documents
Before this change, we were producing a generic DOM::Document, which
was not distinguishable from an XMLDocument by IDL interface type.
2023-10-07 10:19:18 +02:00
Andreas Kling
2b343c9508 LibWeb: Don't crash in XHR.response{,XML} for empty XML document
There were some unhandled paths due to the liberally typed XHR response
object. This patch flushes out those issues by using a tighter type set
in the Variant. (NonnullGCPtr<Object> instead of Value)
2023-10-07 10:19:18 +02:00
Andreas Kling
65717e3b75 LibJS: Inline fast case for Value::to_{boolean,number,numeric,primitive}
These functions all have a very common case that can be dealt with a
very simple inline check, often avoiding the need to call an out-of-line
function. This patch moves the common case to inline functions in a new
ValueInlines.h header (necessary due to header dependency issues..)

8% speed-up on the entire Kraken benchmark :^)
2023-10-07 07:13:52 +02:00
Tim Ledbetter
80238f29d2 LibIMAP: Handle invalid escape sequences in Quoted-Printable parser
When an invalid escape sequence is encountered, we now output the
characters unaltered instead of crashing.
2023-10-06 22:31:43 +02:00
Tim Ledbetter
b25efa219b LibGfx/DDSLoader: Allow image dimensions that are not divisible by 4 2023-10-06 22:18:27 +02:00
Tim Ledbetter
bf75ecdcf7 Tests/AK: Add FuzzyMatch tests 2023-10-06 22:09:18 +02:00
Aliaksandr Kalenik
28c9015bd8 LibWeb: Resolve percentages in calc() for font-size
Fixes crashing on https://react.dev/
2023-10-06 08:23:03 +02:00
Tim Schumacher
87bcaa6151 AK: Implement printf's "period without precision value" correctly 2023-10-06 08:21:18 +02:00
Bastiaan van der Plaat
3c27843cfe LibWeb: Add DOMMatrix fromFloat32Array and fromFloat64Array 2023-10-03 16:15:14 -06:00
Bastiaan van der Plaat
2e122b16e4 LibWeb: Add DOMMatrix toFloat32Array and toFloat64Array 2023-10-03 16:15:14 -06:00
kleines Filmröllchen
9a026fc8d5 AK: Implement SipHash as the default hash algorithm for most use cases
SipHash is highly HashDoS-resistent, initialized with a random seed at
startup (i.e. non-deterministic) and usable for security-critical use
cases with large enough parameters. We just use it because it's
reasonably secure with parameters 1-3 while having excellent properties
and not being significantly slower than before.
2023-10-01 11:06:36 +03:30
Sam Atkins
b8ede72107 LibWeb: Add a test for getComputedStyle()
Print out the value of each property in the computed-style of the body
element. This is by no means a thorough test that we're serializing
every property's value correctly in every configuration, (and in fact,
some are definitely wrong,) but it does give us a nice baseline.
2023-09-29 20:20:55 +02:00
Sam Atkins
9e99368694 LibWeb: Track quote-nesting level while building the layout tree
This makes multiple levels of quote actually use different quotation
marks, instead of always the first available pair of them.

Each Layout::Node remembers what the quote-nesting level was before its
content was evaluated, so that we can re-use this number in
`apply_style()`. This is a bit hacky, since we end up converting the
`content` value into a string twice.

`StyleProperties::content()` now takes an initial quote-nesting level,
and returns the final level after that content.
2023-09-28 14:49:10 +02:00
Bastiaan van der Plaat
5e7a82a853 LibWeb: Create canvas bitmap when not existing in toDataURL and toBlob 2023-09-28 13:09:25 +02:00
kleines Filmröllchen
d6571f54d8 LibCore: Make MappedFile a Stream
The internal reuse of FixedMemoryStream makes this straightforward.
There alread is one user of the new API, demonstrating the need for this
change beyond what I said out to use it for :^)
2023-09-27 03:22:56 +02:00
kleines Filmröllchen
5b2496e522 AK: Make writability violation of FixedMemoryStream non-fatal
Writing to a read-only file is not a program-crashing error either, so
we just return the standard EBADFD (see write(2)) here.
2023-09-27 03:22:56 +02:00
Aliaksandr Kalenik
fe3a824ad4 Tests/LibWeb: Add basic tests for setTimeout and setInterval
It is useful to have at least very basic tests for those APIs :)
2023-09-26 19:42:59 +02:00
stelar7
73ef102b01 LibCrypto: Add Chacha20Poly1305 2023-09-26 13:22:04 +03:30
Bastiaan van der Plaat
6265c544f9 LibWeb: Add DOMMatrix rotate, rotateFromVector and rotateAxisAngle 2023-09-24 20:02:38 -06:00
Bastiaan van der Plaat
42c2a67c83 LibWeb: Add DOMMatrix scale and scale3d 2023-09-24 20:02:38 -06:00
Bastiaan van der Plaat
67f6a9ee12 LibWeb: Fix DOMMatrix fromMatrix to use complete DOMMatrixInit struct
DOMMatrix fromMatrix was using create_from_dom_matrix_2d_init to make
a DOMMatrix for it's init struct this is wrong because only the 2D
params of the DOMMatrix are put into the new matrix. I have added
a non 2D version of that function that takes the full DOMMatrixInit
so now fromMatrix works correctly again. I also have added some
text tests to test if it works correctly.

I split the dommatrix.html text tests into multiple files because that
file was becoming to big so now every sub function is a seperate file.
2023-09-24 20:02:38 -06:00
Daniel Bertalan
4d2af7c3d6 AK: Implement reverse iterators for OrderedHashTable 2023-09-24 23:36:43 +02:00
Aliaksandr Kalenik
7cdbd59e92 LibWeb: Update session history when History entry is pushed/replaced
With this change `shared_history_push_replace_state()` starts to
actually add/replace session history entry.
2023-09-23 17:59:10 -06:00
Sam Atkins
ae4b8d86df LibWeb: Include standard SVG user agent style sheet
For now, part of this is commented-out. Our current implementations of
`<mask>` and `<symbol>` rely on creating layout nodes, so they can't be
`display: none`.
2023-09-23 16:27:14 +02:00
Shannon Booth
07b332e17c LibWeb: Add IDL definition for SVGScriptElement
It does not currently handle any of the actual scripting, but this
should at least allow us to create an instance of the element.

The test being added here isn't actually testing much, but before the
previous commit we used to crash parsing the page due to a TODO().
2023-09-23 11:41:57 +02:00
Andrew Kaster
5949e3c3e8 LibWeb: Implement named property access AOs on Window
These allow accessing embeds, forms, images and objects with a given
name attribute, and any element with a given id attribute, as top level
properties on the global object.

It also allows accessing NavigableContainers by target name as top level
properties on the global object.

The current implementation feels very expensive. It's likely that
these values will need smarter caching in the future.
2023-09-22 19:55:59 -06:00
Andrew Kaster
247f12d7b0 LibWeb: Insert WindowProperties object into Window's prototype chain
And implement WindowProperties, the "named properties object" for Window
according to the spec.

This involves moving an AO out of LegacyPlatformObject and into a common
place that the WindowProperties class can access.

This doesn't implement the AOs on Window that actually name lookup for
the unenumerable named properties on the window yet, just the
scaffolding.
2023-09-22 19:55:59 -06:00
Andrew Kaster
64899dba44 LibWeb: Implement document-tree child navigable target name property set
This AO allows accessing child navigables by their name as named
properties on the WindowProxy object.
2023-09-22 19:55:59 -06:00
Aliaksandr Kalenik
06d05b3c55 LibWeb: Boxes that establish FFC or GFC should avoid overlapping floats
Before, we only ensured that boxes establishing BFC did not overlap
with floats because that is what CSS 2.2 specification says. However,
we should also apply the same for boxes establishing FFC or GFC as this
aligns with the behavior of other browsers.

Fixes https://github.com/SerenityOS/serenity/issues/21095
2023-09-22 16:48:28 +02:00
Sam Atkins
0634d11318 LibWeb: Stop adding extra whitespace when serializing CSS Functions
Otherwise `attr(|name, "fallback")` becomes `attr(| name ,  "fallback")`

The test here is slightly aspirational. There are other rules for
serialization we don't follow (like stripping whitespace entirely from
many places) so these are marked with FIXMEs.
2023-09-20 18:29:37 +02:00
Aliaksandr Kalenik
693d602b2f LibWeb: Fix infinite loop in GFC growth limit distribution
This change is bd85e1b30b ported from
base size to growth limit distribution.

Fixes https://github.com/SerenityOS/serenity/issues/21056
2023-09-20 18:28:11 +02:00
MacDue
8270b9ab7e LibWeb: Add simple ref test for SVG masking 2023-09-19 10:46:05 +02:00
MacDue
0af8d81f48 LibWeb: Layout SVG <mask> elements (but don't paint them)
This allows SVG mask elements to have layout computed, but not connected
to the main paint tree. They should only be reachable if (and painted)
if referenced by the "mask" attribute of another element.

This is controlled by the forms_unconnected_subtree() function on the
paintable, which (if it returns true) prevents the paintable from being
added as a child to what would be its parent.
2023-09-19 10:46:05 +02:00
Bastiaan van der Plaat
9939b028c6 LibWeb: Add basic Navigator send beacon support 2023-09-18 11:08:26 -06:00
Hendiadyoin1
d262670729 LibWeb: Use more CSSPixelFractions in GFC::expand_flexible_tracks
Also contains a drive-by expression simplification, and accidental
double truncation fix.
2023-09-18 18:02:51 +02:00
Andreas Kling
1f69e9cddf LibWeb: Remove Layout::Node::m_visible and compute it on the fly
This fixes an issue where the value would be out of sync with reality
in anonymous wrapper block boxes, since we forgot to compute m_visible
after assigning the computed values to them.

Fixes #21106
2023-09-18 14:45:20 +02:00
kleines Filmröllchen
8bcf25561b AK: Fix MemoryStream seek from end
The seek offset is still applied positively when seeking from the end;
see the Kernel's seek implementation.
2023-09-17 17:13:52 -06:00
Bastiaan van der Plaat
8e7d3a6acc LibWeb: Add missing Canvas Context2D transform functions 2023-09-17 16:48:54 -06:00
Shannon Booth
77d32fcb5f LibWeb: Add an initial implementation for Web::FileAPI::FileReader
Some steps are still to be implemented, namely:
 * Properly aborting the read algorithm
 * Handling BinaryString type properly
 * Setting error on any error

But as it stands, this is enough functionality for the basic case of
reading the contents of a blob using the FileReader API.
2023-09-17 16:37:31 -06:00
Sam Atkins
f0a4baabc7 LibWeb: Support quotes in content values
This adds initial support for `open-quote`, `close-quote`,
`no-open-quote` and `no-close-quote`. We don't yet track the "nesting
level" so we always use the first pair of quotes from the `quotes`
property.
2023-09-17 15:45:52 -06:00
implicitfield
1b3ad1c721 LibCrypto: Add support for BLAKE2b 2023-09-17 16:49:35 +03:30
Aliaksandr Kalenik
351567a01f Tests/LibWeb: Add text tests for navigation 2023-09-16 16:53:32 +02:00
Andreas Kling
39f16ecd41 LibWeb: Don't break for atomic inline elements in white-space: nowrap 2023-09-16 15:21:16 +02:00
Kemal Zebari
824c54acaf LibWeb/URL: Add strip_trailing_spaces_from_an_opaque_path()
Also remove 2 FIXMEs by including this function.
2023-09-15 11:15:43 -06:00
Timothy Flynn
139c575cc9 LibUnicode: Update to Unicode version 15.1.0
https://unicode.org/versions/Unicode15.1.0/

This update includes a new set of code point properties, Indic Conjunct
Break. These may have the values Consonant, Linker, or Extend. These are
used in text segmentation to prevent breaking on some extended grapheme
cluster sequences.
2023-09-15 18:30:26 +02:00
Andreas Kling
23569f8690 LibWeb: Allow fractional font sizes in CSS
Fixes an issue where relative font sizes would "snap" to integer sizes
in an unpleasant-looking way while resizing on some websites.
2023-09-15 18:26:37 +02:00
Ali Mohammad Pur
4d71f4edc4 LibRegex: Don't add the Repeat instruction size to its jump target
This was causing the calculated jump target to become invalid, leading
to possibly invalid optimisations and (more likely) crashes.
Fixes #21047.
2023-09-15 18:07:23 +03:30
Luke Wilde
56f0b10d14 LibWeb: Fix setTimeout() when there's no active script
Implements https://github.com/whatwg/html/pull/9712
Fixes https://github.com/SerenityOS/serenity/issues/20970
2023-09-15 08:53:21 +02:00
Aliaksandr Kalenik
6f8be44c0e LibWeb+WebContent+headless-browser: Support async text tests
Previously, we used `on_load_finish` to determine when the text test
was completed. This method did not allow testing of async functions
because there was no way to indicate that the runner should wait for
the async call to end.

This change introduces a function in the `internals` object that is
intended to be called when the text test execution is completed. The
text test runner will now ignore `on_load_finish` which means a test
will timeout if this new function is never called.

`test(f)` function in `include.js` has been modified to automatically
terminate a test once `load` event is fired on `window`.
new `asyncTest(f)` function has been introduces. `f` receives function
that will terminate a test as a first argument.

Every test is expected to call either `test()` or `asyncTest()` to
complete. If not, it will remain hanging until a timeout occurs.
2023-09-15 08:52:25 +02:00
Zaggy1024
4cc3c41269 LibWeb: Allow calculated values for background-size dimensions
This fixes the sizing of the arrow icons displayed to the left of
parent sections on a table of contents on Wikipedia articles, which
are sized using the equation `calc(max(0.75em, 12px))`. Now, the icon
will not expand past the edges of the box they are within, avoiding
clipping the edges of the arrows.
2023-09-15 08:40:10 +02:00
Nicolas Ramz
b8f8b22aa5 LibGfx/ILBM: Add support for uncompressed files 2023-09-14 21:00:54 +01:00
Andreas Kling
80a78c4deb LibWeb: Don't generate ::before/::after for BR elements
We shouldn't be putting generated pseudo elements inside elements that
can't have children in the first place.

This patch fixes two issues:
- We stop generating pseudo elements for layout nodes that can't have
  children anyway.
- We mark Layout::BreakNode as not being able to have children.
2023-09-14 21:46:28 +02:00
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
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
Andrew Kaster
5ae9b2fdaf LibWeb: Add {de}serialization steps for TypedArrayBuffers and DataViews 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
Andrew Kaster
642802d339 LibWeb: Add {de}serialization steps for ArrayBuffers 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
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
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
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
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
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
3b0980c89f LibWeb: Stop allowing invalid tokens in display values
Previously we were overly generous in what we accepted for `display`.
For example, we accepted:
- Multiple outside or inside identifiers
- Unrecognized identifiers
- Non-identifier tokens

Now, we reject all these cases. This makes us stop accepting the
`display: block math;` declaration in `MathML/Default.css`, and so the
one layout test we have containing MathML elements has changed to
reflect that.
2023-09-11 17:03:22 +01:00
Aliaksandr Kalenik
40dea272d2 LibWeb: Add boxes for before/after pseudos post button layout tweak
When a button should use flex for alignment and also has ::before
and/or ::after, we previously did the following:
1. Prepended/appended the button's children with boxes for
   pseudo-elements.
2. Replaced the button's direct children with a flex container that
   contains its children.
As a result, the generated boxes for ::before/::after ended up as
children of the generated flex item, instead of being direct children
of the button layout box as they were supposed to be.

This change reverses these steps, ensuring that boxes for
pseudo-elements are generated only after modifications inside the
button layout are completed.
2023-09-11 15:19:56 +02:00
Aliaksandr Kalenik
0160d921e9 LibWeb: Set children of button layout box to be non-inline
When modifying the button layout during tree building to use flex for
vertical alignment, let's explicitly set the button box's children to
be non-inline. It doesn't make sense to layout the button as an IFC
when its only child is a flex container.
2023-09-11 15:19:56 +02:00
Shannon Booth
b738929195 LibDiff: Fix wrong index used when prepending context lines
`i` is used as the index for 'old lines' in diff generation, not 'new
lines'. Using the wrong index would mean that for certain diffs the
prefixed context information would have wrong content, and could even
result in a crash.

Fix this, and add a test for an input which was previously crashing.
2023-09-11 12:10:50 +01:00
Timothy Flynn
759e07579e LibAudio: Implement PlaybackStream for macOS using Audio Unit framework
https://developer.apple.com/documentation/audiounit

Apple has a number of audio frameworks we could use. This uses the Audio
Unit framework, as it gives us most control over the rendering of the
audio frames (such as being able to quickly pause / discard buffers).
From some reading, we could implement niceties such as fading playback
in and out while seeking over a short (10ms) period. This patch does not
implement such fancy features though.

Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2023-09-09 13:03:36 -04:00
Timothy Flynn
02a8683266 LibUnicode+LibJS: Stop propagating small OOM errors from normalization
This API only perform small allocations, and is only used by LibJS.
2023-09-09 13:03:25 -04:00
Aliaksandr Kalenik
df2bc8187c LibWeb: Use actual line height to calculate float y in IFC
Before, we were using the line height from NodeWithStyle::line_height()
 to calculate the y offset for floats inside the IFC. However, this
value doesn't always correspond to the actual height of a line box. For
instance, adding a fragment for an inline-block might change the height
of the line box. With this change, we recalculate the height of the
line box after adding a new fragment and use this recalculated height
value to determine the y position for floats.

Fixes https://github.com/SerenityOS/serenity/issues/20982
2023-09-09 17:05:22 +02:00
Sam Atkins
b1a569c1c5 LibWeb: Stop crashing when textarea element is modified before insertion
If an element is created from JS, it might have its contents modified
before it is inserted into the document. In this case, we don't have a
shadow tree yet and so trying to set m_text_node's text content would
cause a null dereference. So let's not do that. :^)

That case also means that by the time we do create the shadow tree, we
have the text content already, so we can set it there.

Added a test to verify that we don't crash, and that the text content
appears in the textarea whether it was inserted by JS or by the HTML
parser.
2023-09-09 13:52:01 +01:00
Sergey Bugaev
bba193d6a0 Tests, LibTest: Implement disabling core dumps on GNU Hurd 2023-09-06 11:41:16 -06:00
Andreas Kling
13db3c5ce0 LibGfx: Convert FontDatabase APIs to use FlyString 2023-09-06 11:29:03 -04:00
Andreas Kling
545d8336b8 LibGfx: Convert Font APIs to return String instead of DeprecatedString 2023-09-06 11:29:03 -04:00
Sergey Bugaev
e97c2538b6 Tests: Fix building TestSIMD on non-SSE ABIs 2023-09-06 07:21:07 -06:00
Sergey Bugaev
7bce0e5d1a Tests: Fix TestDuration build with 32-bit time_t
There are a bunch of tests that check for time_t handling 64-bit values
properly. This makes sense, but also obviously doesn't work when time_t
is 32-bit, and causes compile-time errors. Compile these tests out in
that case.

Since there's no straightforward way to check sizeof(time_t) inside the
proprocessor, only do this when glibc's __TIMESIZE is defined.
2023-09-06 07:21:07 -06:00
Shannon Booth
f991e40d7f LibWeb: Support [Reflect] on IDL String attributes that may return null
This change allows IDL interfaces to be compiled using new AK String
which have a attribute in the interface that may return null.

Without this change we would run into a compile error from code such as
the following example:

```
auto retval = impl->deprecated_attribute(HTML::AttributeNames::ref);

if (!retval.has_value()) {
    return JS::js_null();
 }
 return JS::PrimitiveString::create(vm, retval.release_value());
```

As `deprecated_attribute` returns a `DeprecatedString` instead of an
`Optional<String>`. Fix that by using the non-deprecated attribute
implementation, and falling back to the empty string for where we cannot
return null.

Also add a test here to cover a regression I almost introduced here
which was not previously covered by our test suite.

Ideally, all of this should actually just be calling
Element::get_attribute_value, but I'm not entirely sure at this stage
what the behavioral change would be to test for here. Since this
implementation preserves the previous behavior, stick with it, and add a
FIXME for now.
2023-09-05 20:36:09 -04:00
Bastiaan van der Plaat
f1742ae1b9 LibWeb: Add DOMMatrix flipX and flipY 2023-09-05 20:30:36 +02:00
Bastiaan van der Plaat
fc380bf516 LibWeb: Add DOMMatrix skewX and skewY 2023-09-05 20:30:36 +02:00
Zaggy1024
98926b487c LibWeb: Perform rounding when dividing CSSPixels
This should allow us to produce results that more closely match old
layouts when divisions were done in floating-point.
2023-09-05 14:50:45 +02:00
Zaggy1024
bd85e1b30b LibWeb: Entirely and exactly distribute grids' extra space to tracks
Previously, the code assumed that in dividing up the space in the
affected tracks there would never be an overshoot. Instead, we can
check for each track how much extra space is left and never consume any
extra.

In the same way, we can ensure that all extra space is consumed by
distributing all remaining extra space starting from the first track.
Thus, if there is no growth limit, the space distribution should always
consume all the extra space.
2023-09-05 14:50:45 +02:00
Zaggy1024
eb7c2ee307 LibWeb: Limit affected size of grid tracks instead of only increase
The spec says that the sum of affected size + item-incurred increase
should reach the limit, rather than just the item-incurred increase.

This seems to improve layout on the testcase `row-span-2-with-gaps`.
The extra line of space at the bottom of the left div
(`div.grid-item.item-span-two`) is not present anymore, matching other
browsers' layout much more closely.
2023-09-05 14:50:45 +02:00
Sam Atkins
07039af982 LibWeb: Implement attr() types :^)
Support the optional `<attr-type>` parameter to the `attr()` function,
which allows parsing the attribute's value as a variety of types,
instead of always as a string.
2023-09-05 14:27:23 +02:00
Sam Atkins
bf8aa33b68 LibWeb: Add tests for basic attr() behavior and fallback values 2023-09-05 14:27:23 +02:00
Andreas Kling
e013306df8 LibWeb: Allow font-size: 0
Zero is a valid font-size value, and should result in no text being
visible. We now match the behavior of other engines.
2023-09-05 14:23:35 +02:00
Andreas Kling
589a1e9325 LibWeb: Propagate font-size & line-height into generated table boxes
The final used values for these properties is stored in the layout node,
so we need to make sure they are propagated there as well when doing
table box fixup.
2023-09-05 14:23:35 +02:00
Zaggy1024
e3f693ca7c LibWeb: Resolve replaced element size constraints using aspect ratios
Some replaced elements can have intrinsic aspect ratios but no
intrinsic size. In these cases, the tentative sizes are undefined, and
can therefore sometimes be zero. However, when resolving the size
constraints, we are already guaranteed to have an intrinsic aspect
ratio, so let's use that instead to calculate the resolved sizes.
2023-09-04 12:40:17 +02:00
Zaggy1024
34c5043cbe LibWeb: Use CSSPixelFraction to represent aspect ratios
This allows us to retain perfect precision for aspect ratios derived
from either the intrinsic sizes of replaced elements, or the
`aspect-ratio` CSS property.
2023-09-04 12:40:17 +02:00
Andreas Kling
50d72f0d8c LibWeb: Handle case where abspos flex child position depends on height
There's a particularly awkward case where the static position of an
abspos child of a flex container is dependent on its height. This can
happen when `align-items: center` is in effect, as we have to adjust
the abspos child's Y position by half of its height.

This patch solves the issue by reordering operations in the abspos
height resolution algorithm, to make sure that height is resolved
before the static position is calculated.
2023-09-03 15:44:47 +02:00
Bastiaan van der Plaat
5cd35b633a LibWeb: Add DOMMatrix translate 2023-09-03 15:05:41 +02:00
Bastiaan van der Plaat
61c063f7b3 LibWeb: Add DOMMatrix multiply 2023-09-03 15:05:41 +02:00
Bastiaan van der Plaat
ff1bcc694d LibWeb: Add DOMMatrix and DOMMatrixReadOnly fromMatrix 2023-09-03 15:05:41 +02:00
Aliaksandr Kalenik
ed0dc2ff72 LibWeb: Use flex layout for button content alignment
Using flex layout inside button solves the issue with wrongly calculated
height when it has: pseudo element and whitespaces inside.

Also using flex instead of a table layout allows for the same vertical
alignment but with fewer layout nodes: a flex container and anonymous
wrapper for content instead of a table wrapper, table, row, and cell.
2023-09-03 12:33:10 +02:00
Bastiaan van der Plaat
b4ae719664 LibWeb: Add DOMPoint matrixTransform and DOMMatrix transformPoint 2023-09-01 20:58:13 +02:00
Andrew Kaster
1cd3826ad6 Userland+Tests: Don't use MAP_FILE when mmap-ing
MAP_FILE is not in POSIX, and is simply in most LibCs as a "default"
mode. Our own LibC defines it as 0, meaning "no flags". It is also not
defined in some OS's, such as Haiku. Let's be more portable and not use
the unnecessary flag.
2023-09-01 19:50:35 +02:00
Andreas Kling
ef9b6c25fa LibWeb: Consolidate consecutive inlines in a single anonymous flex item
Before this change, we were creating a new anonymous flex item for every
inline-level child of a flex container, even when we had a sequence of
inline-level children.

The fix here is to simply keep putting things in the last child of the
flex container, if that child is already an anonymous flex item.
2023-09-01 12:45:38 +02:00
Zaggy1024
50bb785306 Tests/LibWeb: Add a test for clipping text with CSS clip 2023-09-01 09:40:14 +02:00
Aliaksandr Kalenik
a482166087 LibWeb: Bring html element height calculation closer to the spec
Previously we always set the height of the HTML element equal to the
viewport height but now this will only happen in quirks mode as it is
intended. Otherwise the html element height will be computed as auto.
2023-08-31 21:43:58 +02:00
MacDue
720c27efbd LibWeb: Ensure transform of SVG <use> updates with x and y attributes
Rather than modify the transform of the parent (which could change
independently), this adds a new override element_transform() where
element specific tranfroms can be applied. This will always stay in
sync with the attributes.

A ref test comparing a .svg and .html version of the same file is
added as due to differences in attribute parsing order, the .svg version
was previously drawn incorrectly.

Fixes #20859
2023-08-31 11:10:30 +02:00
Karol Kosek
51fefb57fc LibCore: Check if a promise is already resolved in Promise::map() 2023-08-31 11:10:09 +02:00
Shannon Booth
cb4c279e90 AK: Percent encode URL fragments when parsed
This fixes URL fragments containing characters in the fragment encoding
set that were not being correctly percent encoded.
2023-08-31 11:02:18 +02:00
Shannon Booth
4eab37f391 LibWeb/Tests: Also include URL hash in test results
None of the existing tests contain a URL which has a fragment in them,
but this does verify that the URL parser does not actually find any!
Also, this should let us verify the correctness of URLs which actually
do contain fragments.
2023-08-31 11:02:18 +02:00
Shannon Booth
23e82114b4 AK: Do not consider port of 0 as a null port
This fixes an issue where if a port number of 0 was given for a non
special scheme the port number was being dropped.
2023-08-31 11:02:18 +02:00
MacDue
e8342a5b79 Tests/LibWeb: Add ref test for border-radius shrink of zero sized box 2023-08-30 20:36:27 +02:00
Aliaksandr Kalenik
0fb571c1c2 LibWeb: Add Length::resolved() overload for CSSPixels
Since we always pass the px value as an argument to resolved(), we can
pass it directly as CSSPixels instead of wrapping it in Length. This
approach allows us to avoid converting to a double, resulting in fewer
precision issues.
2023-08-30 20:09:15 +02:00
Andi Gallo
fab4d543f6 LibWeb: Set line height for table boxes generated during fixup 2023-08-30 07:57:56 +02:00
Andreas Kling
6d7a2f5cc9 LibWeb: Prune old paintable pointers from layout tree after relayout
When text paintables shift around in the tree due to line wrapping,
we may end up in a situation where some text node does not generate
a paintable (due to being all whitespace, for example), even though
in the previous layout pass, it *did* generate a paintable.

To prevent holding on to old paintables in such cases, we now do a
pass in LayoutState::commit() where we explicitly detach all old
paintables from the layout tree.
2023-08-29 17:05:16 +02:00
Aliaksandr Kalenik
2495302991 LibWeb: Reset auto_placement_cursor_x after adding new column in GFC
We need to start looking from the beginning of current row if adding
new implicit column track made enough space to accomodate spanning item

This fixes placement for spanning grid items when `grid-auto-flow` is
specified to `column`.
2023-08-29 12:35:21 +02:00
Zaggy1024
bb156f8133 LibAudio: Add a Serenity implementation of PlaybackStream
This implementation is very naive compared to the PulseAudio one.

Instead of using a callback implemented by the audio server connection
to push audio to the buffer, we have to poll on a timer to check when
we need to push the audio buffers. Implementing cross-process condition
variables into the audio queue class could allow us to avoid polling,
which may prove beneficial to CPU usage.

Audio timestamps will be accurate to the number of samples available,
but will count in increments of about 100ms and run ahead of the actual
audio being pushed to the device by the server.

Buffer underruns are completely ignored for now as well, since the
`AudioServer` has no way to know how many samples are actually written
in a single audio buffer.
2023-08-29 11:31:10 +02:00
ronak69
2caf68fd03 AK: Add binary and octal mode formatting for FixedPoint 2023-08-29 11:10:45 +02:00
ronak69
352480338e AK: Refactor FixedPoint's formatter
The main change is the simplification of the expression
`(10^precision * fraction) / 2^precision` to `5^precision * fraction`.

Those expressions overflow or not depends on the value of `precision`
and `fraction`. For the maximum value of `fraction`, the following table
shows for which value of `precision` overflow will occur.

            Old   New
    u32      08    10
    u64      15    20
    u128     30    39

As of now `u64` type is used to calculate the result of the expression.
Meaning that before, only FixedPoints with `precision` less than 15
could be accurately rendered (for every value of fraction) in decimal.
Now, this limit gets increased to 20.

This refactor also fixes, broken decimal render for explicitly specified
precision width in format string, and broken hexadecimal render.
2023-08-29 11:10:45 +02:00
ronak69
4c6ea4a963 AK: Fix off-by-one error in round-to-even logic of FixedPoint
Because of the off-by-one error, the second bit of the fraction was
getting ignored in differentiating between fractions equal to 0.5 or
greater than 0.5. This resulted in numbers like 2.75 being considered
as having fraction equal to 0.5 and getting rounded incorrectly (to 2).
2023-08-29 11:10:45 +02:00
Marcus Nilsson
e2ca144cf9 Tests: Add tests for getaddrinfo() 2023-08-29 11:04:48 +02:00
Marcus Nilsson
db2f96e4ed Tests: Add tests for gethostbyname() 2023-08-29 11:04:48 +02:00
Marcus Nilsson
5c4b71ac67 Tests: Add tests for gethostbyname_r() 2023-08-29 11:04:48 +02:00
Andi Gallo
4a124333c8 LibWeb: Add back undistributable space when adjusting table width
If the table used width has to be adjusted because of a cell with
percentage width, add back the undistributable space due to border
spacing. This is consistent with the width distribution algorithm, which
sets aside the undistributable space and the behavior of other browsers.
2023-08-29 09:19:55 +02:00
Andreas Kling
2a86bd8c91 LibWeb: Fire the fail callback on SharedImageRequest when they fail
This fixes an issue where failed image loads would delay the document
load event forever.
2023-08-28 10:19:46 +02:00
Andi Gallo
8e0320626d LibWeb: Move line breaking test 2023-08-28 10:09:07 +02:00
Aliaksandr Kalenik
b66f65dc9e LibWeb: Define if identifier represent area or line during layout [GFC]
This fixes regression introduced in
c03e025a32 by assuming that it is
possible to determine whether identifier stands for line or area
during parsing.
2023-08-28 09:19:41 +02:00
Luke Wilde
af2886449a LibWeb: Implement PerformanceObserver 2023-08-27 23:27:44 +02:00
Aliaksandr Kalenik
e4dd4808c4 Tests/LibWeb: Split "grid/named-tracks.html" into smaller layout tests
The file grid/named-tracks.html contained multiple subtests. Splitting
them into individual files will make it simpler to identify where is
the issue.
2023-08-27 14:51:44 +02:00
Aliaksandr Kalenik
d3d67857b2 LibWeb: Use containing block width to measure fit-content width in GFC
When the grid layout gets to
`resolve_items_box_metrics(GridDimension::Column)`, we've already
determined the width of each column. However, the widths of the
individual grid items themselves haven't been set. Rather than using
`get_available_space_for_item()`, which returns an indefinite size if
an item's width/height hasn't been set, we should use the already
known track width as the available size to calculate the fit-content
width.
2023-08-27 05:11:55 +02:00
MacDue
360c0eb509 LibWeb: Remove implicit conversion from float and double to CSSPixels
In general it is not safe to convert any arbitrary floating-point value
to CSSPixels. CSSPixels has a resolution of 0.015625, which for small
values (e.g. scale factors between 0 and 1), can produce bad results
if converted to CSSPixels then scaled back up. In the worst case values
can underflow to zero and produce incorrect results.
2023-08-26 23:53:45 +02:00
Aliaksandr Kalenik
0060fe3095 LibWeb: Account for float intrusions in list marker x offset 2023-08-26 19:07:56 +02:00
Sam Atkins
240ec9aeed LibWeb: Treat invalid StyleValues that included var() as unset
This means StyleComputer::resolve_unresolved_style_value() always
returns a value, so we can change its return type.

However, it does still return an UnresolvedStyleValue sometimes, so we
can't remove those checks from the user code.
2023-08-26 15:33:45 +01:00
Sam Atkins
6b66e80fb8 LibWeb: Sort Ref/mainfest.json entries 2023-08-26 15:33:45 +01:00
Shannon Booth
f115e44066 LibWeb: Implement value attribute of RadioNodeList 2023-08-26 13:51:18 +02:00
Shannon Booth
fc4fd6cb02 LibWeb: Fix empty value attribute for 'file' input returning fakepath
It should be returning the empty string for this case.
2023-08-26 13:51:18 +02:00
Aliaksandr Kalenik
c03e025a32 LibWeb: Disambiguate GridTrackPlacement API
- Ambiguous `raw_value()` method is replaced with `line_number()` and
  `span()`.
- `line_name()` that before returned either line name or area name is
  replaced with `line_name()` and `area_name()`.
- `Position` type is replaced with `Line` and `Area` type so we don't
   have to guess while doing layout.

Affected test expectations:
- `template-lines-and-areas` - improvement over what we had before.
- `named-tracks` - rebaseline a giant test. will have to split it into
  smaller tests in the future.
2023-08-26 13:16:17 +02:00
Andi Gallo
29352f570a LibWeb: Fix table column constrainedness
Adjust implementation to reflect the CSS 2.1 definition of width.
2023-08-26 13:10:45 +02:00
Andrew Kaster
587cfa7739 LibWeb: Don't assert when calling navigation properties
The invariants for these property getters are supposed to be checked by
the has_entries_and_events_disabled AO, but we don't have all the
plumbing hooked up between Navigables and Navigation yet.

Add a test to make sure that these methods don't assert when calling
them on a fresh page.
2023-08-26 07:35:50 +01:00
Andreas Kling
da8692572a LibWeb: Support media queries with the resolution feature
The resolution is simply 1dppx * device pixel ratio.

This makes high resolution images show up on https://apple.com/
when running on a high-DPI display. :^)
2023-08-25 20:10:47 +02:00
Andreas Kling
b63e393cef LibWeb: Fix broken conversion of CSS <resolution> dpi/dpcm to dppx
Also add a basic test that documents how these media features currently
get serialized, even if they're not identical to other browsers yet.
2023-08-25 20:10:47 +02:00
Andreas Kling
b256e52586 AK: Make Formatter for NonnullOwnPtr<T> format the T
This mirrors the behavior of NonnullRefPtr<T>. If you want to format
the pointer address, call .ptr() on it.
2023-08-25 20:10:47 +02:00
Liav A
1c0aa51684 Kernel+Userland: Remove the {get,set}_thread_name syscalls
These syscalls are not necessary on their own, and they give the false
impression that a caller could set or get the thread name of any process
in the system, which is not true.

Therefore, move the functionality of these syscalls to be options in the
prctl syscall, which makes it abundantly clear that these operations
could only occur from a running thread in a process that sees other
threads in that process only.
2023-08-25 11:51:52 +02:00
Andreas Kling
13e2ca6b59 LibWeb: Parse src: local(...) in CSS @font-face rules
Note that we don't load the local font as specified, but at least we no
longer reject such src properties in the CSS parser.

This makes the custom fonts used on http://apple.com/ actually load. :^)
2023-08-25 11:51:28 +02:00
Timothy Flynn
5a2bf7fdd1 LibWeb: Set the correct end position of HTML attribute names
We were previously setting the end position of attribute names in self-
closing HTML tags to the end of the attribute value. To illustrate the
previous behavior, consider this tag and its attribute's start and end
positions (shown inclusively below):

    <meta charset="UTF-8" />
          ^ name start
                  ^ value start
                        ^ value end
                        ^ name end

Rather than setting the end position of the attribute name when we parse
the closing slash, ensure the end position is already set while we are
in the AttributeName state. We now have:

    <meta charset="UTF-8" />
          ^ name start
                ^ name end
                  ^ value start
                        ^ value end

The tokenizer unit test has been extended to test these positions.
2023-08-25 08:22:24 +02:00
Timothy Flynn
5b2bc90b50 LibWeb: Set consistent positions for the start and end of HTML tags
To illustrate the previous behavior, consider these tags and their start
and end positions (shown inclusively below):

    Start tag:    End tag:
    <span>        </span>
     ^ start       ^ start
         ^end           ^end

The start position of a tag is the first ASCII-alpha code point after
the opening brace. The start position of a close tag is the slash just
before the first ASCII-alpha code point. And the end position of both
is the closing brace. So the opening brace is not included in the
emitted tag, but the closing brace is. And the end tag including the
slash is an oddity that had to be worked around in its only use case
(syntax highlighting).

We now consistently exclude the braces from the emitted tag, and also
exclude the slash from the end tag, so that it does not need to be
accounted for in syntax highlighting. That is, we now have:

    Start tag:    End tag:
    <span>        </span>
     ^ start        ^ start
        ^end           ^end

The tokenizer unit test has been extended to test these positions.
2023-08-25 08:22:24 +02:00
Jonatan Klemets
04bc9b14d0 LibWeb: Use parse_non_negative_integer for colspan and rowspan parsing
`DeprecatedString::to_int` calls `StringUtils::convert_to_int`
internally. However, the integer parsing is not done in an HTML
spec-compliant way. For example, `colspan="2;"` is valid according to
the spec. But, with the current implementation, we will fail to parse
"2;", and instead fall back to using 1 as the colspan value.

This patch changes the `HTMLTableCellElement::col_span` and
`HTMLTableCellElement::row_span` methods to use the
`Web::HTML::parse_non_negative_integer` function that will parse the
attribute value in an HTML spec-compliant way.
2023-08-24 22:26:53 +01:00
Jonatan Klemets
9812031a02 LibWeb: Implement spec-compliant integer parsing
We have code inside LibWeb that uses the
`AK::StringUtils::convert_to_uint`and `AK::StringUtils::convert_to_int`
methods for parsing integers. This works well for the most part, but
according to the spec, trailing characters are allowed and should be
ignored, but this is not how the `StringUtil` methods are implemented.

This patch adds two new methods named `parse_integer` and
`parse_non_negative_integer` inside the `Web::HTML` namespace that uses
`StringUtils` under the hood but adds a bit more logic to make it spec
compliant.
2023-08-24 22:26:53 +01:00
Aliaksandr Kalenik
6267037a74 Tests/LibWeb: Split grid/positions-and-spans.html into smaller tests
This giant grid test has been a source of problems while iterating on
GFC for a long time. Let's split it into smaller tests to make it
easier to identify issues without needing further reductions on the
test.
2023-08-24 20:18:00 +02:00
Aliaksandr Kalenik
c3f38c6cb8 Tests/LibWeb: Adjust "clip-abspos-children" ref-test to actually pass
Fixed the "clip-abspos-children" test which previously passed due to
black backgrounds on CI blending with the test's black borders.
2023-08-24 15:48:34 +02:00