Commit Graph

5889 Commits

Author SHA1 Message Date
MacDue
377ff0ac26 LibWeb: Implement SVG fill-rule attribute
Previously, we did an evenodd fill for everything which while for most
SVGs works, it is not correct default (it should be nonzero), and broke
some SVGs. This fixes a few of the icons on https://shopify.com/.
2023-06-11 19:34:24 +02:00
Andi Gallo
ead56e88db LibWeb: Avoid crash for unsupported length unit in SVG elements
Acid3 sets 1em as the y coordinate of one of external SVG fonts, we
don't support that yet. Ignore unsupported unit instead of crashing.
2023-06-11 19:04:30 +02:00
MacDue
30c316a2bf LibWeb+LibGfx: Allow stroking with a paint style and opacity 2023-06-11 16:15:56 +02:00
MacDue
eb4a58528e LibWeb+LibGfx: Allow filling with a paint style and opacity 2023-06-11 16:15:56 +02:00
Andreas Kling
5c07aeb78e LibWeb: Update HTML image loading algorithm for recent spec changes
Changes: 8a2375aac2

Note that we don't support the full lazy loading machinery yet, so this
isn't actually hooked up.
2023-06-11 10:32:09 +02:00
Andreas Kling
2e9b12d327 LibWeb: Update HTML image loading algorithm with null checks from spec
The spec has been updated to fix the missing null checks we found:
8f3d1fc6d1
2023-06-11 10:32:09 +02:00
Andreas Kling
8a43f5a64a LibWeb: Forward media attribute from link element to loaded style sheet
Otherwise, we will treat the loaded style sheet as if it had media="all"
which is not always appropriate.
2023-06-11 06:05:03 +02:00
Andreas Kling
79d2c9f3e8 LibWeb: Don't justify text lines that end in a forced break
These are treated the same as the last line in a block, per CSS-TEXT-3.
2023-06-10 21:46:33 +02:00
Andi Gallo
8090adf268 LibWeb: Add partial implementation of border conflict resolution
Fix handling of border style specified per column as well.
2023-06-10 11:17:21 +02:00
Andi Gallo
6c2712764d LibWeb: Add table-column-group to layout tree dump 2023-06-10 11:17:21 +02:00
Andi Gallo
48706742d8 LibWeb: Fix remove_irrelevant_boxes
It's supposed to remove children of table-column-group which are *not*
table-column, we were doing the opposite.
2023-06-10 11:17:21 +02:00
Andi Gallo
4d49852454 LibWeb: Distribute cell contribution to all spanned columns
The specification isn't explicit about it, but the contribution we
compute should be distributed to all columns, not just the first one.

The first reason for it is symmetry, it doesn't make sense for the
increased width of the spanning column to only affect the first column
in the span.

The second reason is the formula for the cell contribution, which is
weighted by the non-spanning width of the cell relative to the total
width of the columns in the same row. This only covers a fraction of the
gap, in order to fully cover it we have to add it to all columns in the
span. For this to be exactly the case when the columns don't all have
the same width, we'd have to add additional weighting based on the width
ratios, but given that the specification doesn't suggest it at all we'll
leave it out for now.
2023-06-10 07:10:06 +02:00
Andi Gallo
50df78d2a2 LibWeb: Fix upper limit of span when computing column measures
The maximum span limit has to be inclusive, not exclusive.
2023-06-10 07:10:06 +02:00
Andi Gallo
940d9b98ae LibWeb: Add support for table caption
Adds layout support and the CSS caption-side property.
2023-06-10 07:09:11 +02:00
MacDue
656f72adc0 LibWeb: Use fill_path() to paint <video> play buttons
With this, the play button is nicely antialiased.
2023-06-10 07:08:14 +02:00
Aliaksandr Kalenik
23f6674301 LibWeb: Rename TemporaryTrack to GridTrack in GFC
The word "Temporary" seems to lack any meaningful connection when
applied to grid tracks.
2023-06-10 07:08:01 +02:00
Aliaksandr Kalenik
10cab5fbdb LibWeb: Include gaps in for_each_spanned_track_by_item in GFC
This fixes the issue when left free space is calculated incorrectly
because for_each_spanned_track_by_item does not include gap tracks.
2023-06-10 07:08:01 +02:00
Peter Brottveit Bock
fdfffe2d8c LibWeb: Use IPv6Address::loopback() instead of parsing "::1"
When comparing an ipv6 address against '::1', then compare against
the value object from `IPv6Address::loopback()`, instead of parsing the
string "::1" to an IPv6Address.
2023-06-09 19:38:14 +01:00
Sam Atkins
1051624084 LibWeb: Obey CSS aspect-ratio property during layout
Calculate a "preferred aspect ratio" based on the value of
`aspect-ratio` and the presence of a natural aspect ratio, and use that
in layout.

This is by no means complete or perfect, but we do now apply the given
aspect-ratio to things.

The spec is a bit vague, just saying to calculate sizes for
aspect-ratio'ed boxes the same as you would for replaced elements. My
naive solution here is to find everywhere we were checking for a
ReplacedBox, and then also accept a regular Box with a preferred aspect
ratio. This gets us pretty far. :^)

https://www.w3.org/TR/css-sizing-4/#aspect-ratio-minimum is not at all
implemented.
2023-06-09 20:37:51 +02:00
Sam Atkins
84e7216603 LibWeb: Move "natural size" concept into Layout::Box
Having this here instead of in ReplacedBox means we can access it when
figuring out what the "preferred aspect ratio" is.

There's some inconsistency between specs about what this is called, but
they're moving towards referring to this as "natural width/height/
aspect-ratio", so let's copy that terminology.
2023-06-09 20:37:51 +02:00
Sam Atkins
6fd3b39bef LibWeb: Parse aspect-ratio property
Parse it, store the result in the ComputedValues, and also expose it to
ResolvedCSSStyleDeclaration.
2023-06-09 20:37:51 +02:00
Sam Atkins
5e3da93f1a LibWeb: Add RatioStyleValue and parsing 2023-06-09 20:37:51 +02:00
Sam Atkins
b9f9d87bd0 LibWeb: Allow calc() and friends inside <ratio> values
Anywhere that `<number>` appears in the grammar, `calc()` that resolves
to a number is valid, including inside the `<ratio>` grammar.
Thankfully, a calculation that produces a number cannot rely on any
context information for the calculation, so we can resolve them
straight away and just pretend they were a `<number>` the whole
time. :^)
2023-06-09 20:37:51 +02:00
Sam Atkins
57a247530c LibWeb: Introduce and use ComponentValue::is_delim() helper
`foo.is(Token::Type::Delim) && foo.token().delim() == '!'` becomes
`foo.is_delim('!')`, which is a lot less verbose. I really should have
done this ages ago.
2023-06-09 20:37:51 +02:00
Aliaksandr Kalenik
0d8d7ae94e LibWeb: Implement painting for svg text
The implementation of painting for SVG text follows the same pattern
as the implementation of painting for SVG geometries. However, instead
of reusing the existing PaintableWithLines to draw text, a new class
called SVGTextPaintable is introduced. because everything that is
painted inside an SVG is expected to inherit from SVGGraphicsPaintable.
Therefore reusing the text painting from regular text nodes would
require significant refactoring.
2023-06-09 17:20:34 +02:00
PrestonLTaylor
e2a935b1dc LibWeb: Implement the <style> SVG element
The `<style>` element is allowed to be in the SVG namespace, so we now
support this element.

It has the same behaviour as the HTML namespace `<style>` element as
described in the spec.

"The semantics and processing of a ‘style’ and its attributes must be
the same as is defined for the HTML ‘style’ element."
2023-06-09 17:14:50 +02:00
PrestonLTaylor
7f7ebc4b8b LibWeb: Extract updating a style block into StyleElementUtils 2023-06-09 17:14:50 +02:00
Sam Atkins
7a2c8d30b9 LibWeb: Allow auto as animation-duration and make that the default
This is a spec change: 2a7cc4b58f
2023-06-09 17:13:19 +02:00
Sam Atkins
c4c35ce9b9 LibWeb: Alphabetize animation properties
I didn't notice this when they were added, whoops
2023-06-09 17:13:19 +02:00
Ali Mohammad Pur
141143a1c6 LibWeb: Serialize custom properties in CSSStyleDeclaration::serialized()
Prior to this commit, PropertyOwningCSSStyleDeclaration::serialized()
did not include custom properties, which lead to an incomplete
`cssRule.cssText` result.
This commit makes that class also serialize the custom properties and
place them before the regular properties in the rule text.
2023-06-09 11:17:44 +01:00
Timothy Flynn
f95ed9f373 LibWeb: Implement document.title for SVG documents 2023-06-09 01:12:48 +02:00
Timothy Flynn
e2e4e6da52 LibWeb: Implement the SVG title element 2023-06-09 01:12:48 +02:00
Timothy Flynn
3a28be2a98 LibWeb: Parse SVG document types as XML documents
We began parsing SVG documents as HTML years ago in commit 05be648. This
was long before we had an XML parser, and actually violates the spec.
Since SVG documents have a MIME type of "image/svg+xml", the spec
mandates the document should be parsed as XML.

One impact here is that the SVG document is no longer "fixed" to include
<html>, <head>, and <body> tags. This will have prevented document.title
from detecting the document element is an SVG element.
2023-06-09 01:12:48 +02:00
Timothy Flynn
c8d8640018 LibWeb: Detect when an XML document belongs in the SVG namespace
We currently parse all XML documents as belonging in the HTML namespace.
Switch to the SVG namespace when parsing an SVG document.
2023-06-09 01:12:48 +02:00
Andreas Kling
3365a1e034 LibWeb: Resolve cyclic % against 0 when available size is min-content
This fixes an issue where replaced elements with cyclic percentage width
would make an oversized min-content contribution to its container.
2023-06-08 13:54:11 +02:00
Andreas Kling
a5f8f8238f LibWeb: Fix a case of incorrect flex container max-content main size
We were incorrectly returning a "specified size suggestion" for flex
items with a definite main size where that main size was also automatic.

This led to us incorrectly choosing 0 as the automatic minimum size for
that flex item, instead of its min-content size.
2023-06-08 13:54:11 +02:00
Andreas Kling
102b8d717f LibWeb: Set flex-basis to 0% when omitted from flex shorthand
This doesn't match the spec, *but* matches what other engines do, and it
turns out this is required for web compat. (It fixes the menu on MDN.)
2023-06-08 10:05:56 +02:00
Andreas Kling
dd2080c55f LibWeb: Stub out Element.scroll() and Element.scrollTo()
With this, we stop throwing exceptions in a way that makes MDN disappear
and it's now possible to browse MDN in Ladybird. :^)
2023-06-08 10:05:56 +02:00
Timothy Flynn
f2a28e83de LibWeb: Implement the document title attribute closer to the spec
The main differences between our current implementation and the spec
are:

    * The title element need not be a child of the head element.

    * If the title element does not exist, the default value should be
      the empty string - we currently return a null string.

    * We've since added AOs for several of the spec steps here, so we
      do not need to implement those steps inline.
2023-06-08 07:21:08 +02:00
Timothy Flynn
43b3673198 LibWeb: Add an accessor for the document's title element 2023-06-08 07:21:08 +02:00
Timothy Flynn
e8fde316f6 LibWeb: Add spec comments to a couple of Document element getters
The implementations are correct as-is. The spec comments are mostly to
help point out that an upcoming getter (the title element) is currently
accessed incorrectly. It is currently implemented like the head element
and searches the "expected" parent head element for its first title
element; instead it should search the document itself. This incorrect
behavior becomes clearer if all of these elements have spec comments.
2023-06-08 07:21:08 +02:00
Timothy Flynn
efd8176ce3 LibWeb: Convert a couple west-const formattings to east-const 2023-06-08 07:21:08 +02:00
MacDue
7ff6d8d9e2 LibWeb: Remove rounding in CRC2D.stroke_rect()
The new rasterizer can now handle floating point positions nicely so
this rounding can be removed.
2023-06-08 07:17:43 +02:00
MacDue
d259421b69 LibWeb: Allow paint style fills for CRC2D strokes 2023-06-08 07:17:43 +02:00
MacDue
727ff6cf59 LibWeb: Don't use paint styles for solid color CRC2D fills
It is faster to avoid the extra overhead/indirection of paint styles if
possible.
2023-06-08 07:17:43 +02:00
MacDue
87c103e210 LibWeb: Fix typo and slightly tidy CRC2D.fill_rect() 2023-06-08 07:17:43 +02:00
Aliaksandr Kalenik
1c979e0ed7 LibWeb: Resolve percentage padding and margins for grid items in GFC
Adds a second pass to resolve percentage paddings and margins of grid
items after track sizes are known. If resolving percentage paddings
or margins affects tracks sizes then second pass to re-resolve track
sizes might also be needed but I cannot come up with an example to
reproduce that so we can leave it to improve in the future :)
2023-06-08 07:14:47 +02:00
Aliaksandr Kalenik
775742b35d LibWeb: Add support for horizontal margins of grid items in GFC 2023-06-08 07:14:47 +02:00
Aliaksandr Kalenik
0177e4e6ba LibWeb: Consider all spanned tracks while finding extra space in GFC
This fixes the issue when functions that distribute base_size
or growth_limit to tracks only considered *affected* spanned tracks
while calculating left extra that is available for distribution while
indeed it should be just *all* spanned track by specific item that
extra space size.
2023-06-07 19:44:47 +02:00
Aliaksandr Kalenik
3b3ade0b8d LibWeb: Use none as initial value for grid-template-column/rows
This fixes the issue that currently we use "auto" as initial value for
grid-template-column and grid-template-rows although spec says it
should be "none". This makes a lot of difference for these properties
because currently we represent "auto" as a list with one auto-sized
track which means initial value for grid-template-column defines one
"explicit" track while it should define none of them.

This change makes grid-auto-columns/rows be applied to the correct
tracks when initial values is used for grid-template-column/rows.
2023-06-07 14:13:07 +02:00