Commit Graph

6020 Commits

Author SHA1 Message Date
Andreas Kling
43e1343abf LibWeb: Treat % max-height as none when containing block size indefinite
Fixes #19371
2023-06-14 17:08:15 +02:00
Andreas Kling
b6f3369b66 LibWeb: Fix spelling of non_anonymous_containing_block() 2023-06-14 17:08:15 +02:00
Andreas Kling
34591ff3d9 LibWeb: Use a separate class for shared image requests
As it turns out, making everyone piggyback on HTML::ImageRequest had
some major flaws, as HTMLImageElement may decide to abort an ongoing
fetch or wipe out image data, even when someone else is using the same
image request.

To avoid this issue, this patch introduces SharedImageRequest, and then
implements ImageRequest on top of that.

Other clients of the ImageRequest API are moved to SharedImageRequest
as well, and ImageRequest is now only used by HTMLImageElement.

This fixes an issue with image data disappearing and leading to asserts
and/or visually absent images.
2023-06-14 14:23:17 +02:00
Andi Gallo
ce186dca70 LibWeb: Fix the x coordinate of a block after a float
The margin from the containing blocks shouldn't be included in the
amount by which we increment x after a float was places. That coordinate
should be relative to the containing block.

Fixes the comments layout on https://lobste.rs.
2023-06-14 08:30:22 +02:00
Shannon Booth
bd26d022ac LibWeb: Implement FileAPI::Blob::stream() 2023-06-14 06:27:04 +02:00
Shannon Booth
9f39be6e23 LibWeb: Implement FileAPI::Blob::get_stream()
This is used internally in many Blob algorithms, such as Blob::stream(),
Blob::text() and Blob::array_buffer().
2023-06-14 06:27:04 +02:00
Shannon Booth
94883866f5 LibWeb: Implement Web::Streams::readable_stream_enqueue AO
This AO will be used in the Web::FileAPI::Blob::get_stream()
implementation to enqueue all data in the blob to the stream.

There are still plenty of cases to handle, but this appears to be enough
for the basic case of reading all chunks from a readable stream until it
is done.
2023-06-14 06:27:04 +02:00
Shannon Booth
b7b5b5763e LibWeb: Add support to set up stream with byte reading support
This is used by Blobs to set up their stream in their get stream
algorithm.
2023-06-14 06:27:04 +02:00
Shannon Booth
666e413cd2 LibWeb: Add missing forward of Web::Streams::PullIntoDescriptor 2023-06-14 06:27:04 +02:00
Shannon Booth
79fc7d7c7c LibWeb: Add HTML::Task::Source::FileReading 2023-06-14 06:27:04 +02:00
Andreas Kling
41da9a4231 LibWeb: Resolve auto margins on abspos elements in more cases
Specifically, we now handle cases where all three of `left`, `width`
and `right` are non-`auto`.
2023-06-13 17:47:50 +02:00
Andreas Kling
434df52b91 LibWeb: Make stretch-fit return 0 when the available size is indefinite
The spec says the result of this algorithm is undefined in such cases,
and it appears that other engines yield a zero size.

More importantly, this prevents us from leaking a non-finite value into
the layout tree.
2023-06-13 16:14:45 +02:00
Valtteri Koskivuori
2c5a062c8f LibWeb: Teach CSS transformed StackingContexts about image-rendering
Previously, all StackingContexts which were scaled using CSS transforms
were hard-coded to use BilinearBlend. This fix maps specified
image-rendering properties to reasonable ScalingModes for painting.
2023-06-13 06:14:17 +02:00
Timothy Flynn
ac2238ee70 LibWeb: Begin implementing the HTMLAudioElement for audio playback
This uses LibAudio to attempt to decode resoures downloaded with <audio>
elements, and draws some basic media controls for the element.
2023-06-13 06:14:01 +02:00
Timothy Flynn
c89fd6dff0 LibWeb: Implement the AudioTrack and AudioTrackList interfaces
These are used to own and manage the playing of audio data.
2023-06-13 06:14:01 +02:00
Timothy Flynn
a34e369252 Ladybird+LibWeb+WebContent: Create a platform plugin for playing audio
This creates (and installs upon WebContent startup) a platform plugin to
play audio data.

On Serenity, we use AudioServer to play audio over IPC. Unfortunately,
AudioServer is currently coupled with Serenity's audio devices, and thus
cannot be used in Ladybird on Lagom. Instead, we use a Qt audio device
to play the audio, which requires the Qt multimedia package.

While we use Qt to play the audio, note that we can still use LibAudio
to decode the audio data and retrieve samples - we simply send Qt the
raw PCM signals.
2023-06-13 06:14:01 +02:00
Timothy Flynn
ee48d7514f LibWeb: Extract media element timeline painting to a base class
This moves the painting of the media timeout out of VideoPaintable into
a base MediaPaintable. This is to allow re-using the same timeline logic
and controls for audio elements.
2023-06-13 06:14:01 +02:00
Aliaksandr Kalenik
147c3b3d97 LibWeb+WebContent: Forbid access to underlying type of CSSPixels
Although DistinctNumeric, which is supposed to abstract the underlying
type, was used to represent CSSPixels, we have a whole bunch of places
in the layout code that assume CSSPixels::value() returns a
floating-point type. This assumption makes it difficult to replace the
underlying type in CSSPixels with a non-floating type.

To make it easier to transition CSSPixels to fixed-point math, one step
we can take is to prevent access to the underlying type using value()
and instead use explicit conversions with the to_float(), to_double(),
and to_int() methods.
2023-06-13 06:08:27 +02:00
Aliaksandr Kalenik
5a54c686a7 LibWeb: Transform GridItem from a class to a struct in GFC
GridItem is simple enough to be a struct. No behavior change.
2023-06-13 06:05:26 +02:00
Hendiadyoin1
eeb15fc10b LibWeb: Stop lying about string types 2023-06-13 01:49:02 +02:00
Andreas Kling
867e04768e LibWeb: Use grid item *outer* size when calculating minimum contribution
Previously we used the border box, which meant that tracks did not grow
to accommodate item margins.
2023-06-12 17:51:08 +02:00
Andreas Kling
741c7aef21 LibWeb: Support more CSS functions in grid track size lists
Instead of hard-coding a check for "calc", we now call out to
parse_dynamic_value() which allows use of other functions like min(),
max(), clamp(), etc.
2023-06-12 17:51:08 +02:00
Andi Gallo
6a7a7e2337 LibWeb: Some row span fixes when combined with nested tables
Add logic to compute {min, max}-height and use min-height when
calculating table height, per specifications.

Fixes some issues with phylogenetic tree visualizations on Wikipedia.
2023-06-12 17:51:00 +02:00
Andi Gallo
75e87c32f2 LibWeb: Fix table width algorithm when available space is a constraint
Handle available space more carefully when computing a table width, in
order to avoid creating a definite infinite width when available space
width is max-content, as it's the case in calculate_max_content_width.
The constraint is thus correctly propagated by the time we cache the
computed value, which was previously rejected by the hash function due
to being definite but infinite instead of max-content.
2023-06-12 17:51:00 +02:00
Aliaksandr Kalenik
5925e6f196 LibWeb: Use static factory methods to construct GridTrack in GFC
This allows to be more explicit in layout code about whether a track is
going to be created from definition or be auto-sized or a gap.
2023-06-12 06:33:51 +02:00
Aliaksandr Kalenik
3fba0a944a LibWeb: Expand minmax in grid tracks defined by grid-auto-rows/columns
Use GridTrack::create_from_definition() that takes care of minmax().
2023-06-12 06:33:51 +02:00
Aliaksandr Kalenik
57581735b7 LibWeb: Add GridTrack::create_from_definition() in GFC
Introducing method to construct grid track from definition allows to
reduce duplication in layout code.
2023-06-12 06:33:51 +02:00
Andreas Kling
2ebb3639aa LibWeb: Remove ImageLoader and ImageResource
The old image loading mechanism is no longer used, as everything has
been moved on top of HTML::ImageRequest! :^)
2023-06-11 20:37:12 +02:00
Andreas Kling
a553fe055b LibWeb: Piggyback on HTML::ImageRequest in HTMLObjectElement
Like the piggybacking in CSS, this is also totally ad-hoc, since there's
no spec to follow.

The code here is weird and definitely sub-optimal as we do a second load
if it turns out the loaded resource is an image, but given that object
elements are rarely used nowadays, I doubt we'll even notice.

That said, we should of course improve this code as we move forward.
2023-06-11 20:37:12 +02:00
Andreas Kling
680fc3f90a LibWeb: Piggyback on HTML::ImageRequest in CSS ImageStyleValue
This is all ad-hoc since no spec currently exists for this behavior.
Basically, ImageStyleValue now uses ImageRequest for fetching and
decoding of images.

This already leads to visible improvements on many websites.
2023-06-11 20:37:12 +02:00
Andreas Kling
f70d3faa0f LibWeb: Move image fetching & decoding into ImageRequest
This forces us to diverge from the spec, but it's for a good cause:
by moving it into ImageRequest, we'll be able to reuse fetching and
decoding logic from CSS and other places.

This patch also makes ImageRequests shareable, currently keyed by
the URL (this part needs improvement!)
2023-06-11 20:37:12 +02:00
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
Aliaksandr Kalenik
0f1f95da46 LibWeb: Add support for grid items with negative column-start in GFC
This changes grid items position storage type from unsigned to signed
integer so it can represent negative offsets and also updates placement
for grid items with specified column to correctly handle negative
offsets.
2023-06-07 11:37:11 +02:00
Andreas Kling
2c16e8371f LibWeb: Add naive support for {margin,padding}-{block,inline}
Like other logical properties, we just alias these to the LTR TB default
properties for now.
2023-06-07 11:20:42 +02:00
Andi Gallo
af1798dd04 LibWeb: Add support for inset shadows
Also move code for outer shadows to a helper.
2023-06-07 10:14:21 +02:00
Andreas Kling
0c2fcffba3 LibWeb: Make text-shadow inherited in CSS::ComputedValues
CSS text-shadow is an inherited property, so we have to make sure it's
part of the inherited substructure in ComputedValues, otherwise it gets
incorrectly reset in children.
2023-06-07 06:29:59 +02:00
Luke Wilde
42a183720b LibWeb/SVG: Support url() in the stroke attribute
This allows you to draw gradients in strokes, for example.
2023-06-07 06:29:46 +02:00
Andreas Kling
9e807d7c6a LibWeb: Support start and end alignment values in flex layout
These should just behave the same as `flex-start` and `flex-end`.
2023-06-06 21:02:04 +02:00
Andreas Kling
abd6380cce LibWeb: Add CSS logical property aliases for margin and padding sides
These just map to the LTR+TB defaults for now, as we don't yet resolve
any of the inputs to the logical property selection algorithm.
2023-06-06 21:02:04 +02:00
Andreas Kling
941092e3ad LibWeb: Make CSS/Properties.json "logical-aliases-for" an array
This allows us to specify all aliases properties instead of just one.
2023-06-06 21:02:04 +02:00
PrestonLTaylor
080b4e5e27 LibWeb: Allow loading of SVGs in ImageResource
This will allow for SVGs to be loaded when used in CSS rules.
2023-06-06 11:04:14 +02:00
Andreas Kling
c50ce2030d LibWeb: Allow event handler attributes on HTMLLinkElement
We were neglecting to set up event handlers for these due to a missing
call to the base class in HTMLLinkElement::parse_attribute().
2023-06-06 09:06:27 +02:00
Andreas Kling
b97004ea4a LibWeb: Fire "load" and "error" events for rel=preload link loads 2023-06-06 09:06:27 +02:00
Andreas Kling
3cea86632d LibWeb: Invalidate the layout tree on DOM node insertion 2023-06-06 09:06:27 +02:00
Andreas Kling
c197fb4037 LibWeb: Take box-sizing into account when sizing replaced elements
This fixes an issue where images with padding and/or border did not have
their size adjusted for `border-box`, thereby becoming larger than
intended by the author.
2023-06-05 09:00:00 +02:00
Shannon Booth
7f6a49c085 LibWeb: Ensure that contentType in Blob::slice is basic latin 2023-06-05 06:55:18 +02:00
Andreas Kling
89ba00304c LibWeb: Account for negative margins when calculating float intrusion
If a box has a negative margin-left, it may have a negative effective
offset within its parent BFC root coordinate system.

We can account for this when calculating the amount of left-side float
intrusion by flooring the X offset at 0.
2023-06-04 18:14:12 +02:00
Sam Atkins
874202045d LibWeb: Rewind TokenStream if we reject a parsed value as out-of-bounds
Wrap the parsing of numbers, integers, and dimensions in a transaction,
which we only commit if that parsed value was actually accepted by the
property.

This fixes `font: 0/0 a;` failing to parse.
2023-06-03 16:04:46 +02:00
Sam Atkins
c48347f0cb LibWeb: Exit parse_font_family_value() when hitting an illegal token
...instead of looping forever. Oops! :^)
2023-06-03 16:04:46 +02:00
Zhiyuan Guo
83345ba698 LibWeb: Don't crash when document.write a script with src attr
To abort the processing of any nested invocations of the tokenizer,
just return is enough in this case.
During the process of pending parsing blocking script, the
is_ready_to_be_parser_executed() check should be applied on the
blocking script, not the original script.
2023-06-03 12:22:01 +02:00
Sam Atkins
052ca0a246 LibWeb: Detect and reject math functions with no resolved type
... instead of crashing :^)
2023-06-03 06:14:53 +02:00
stelar7
a5f2024afa LibWeb: Resolve the transition-delay property 2023-06-03 05:59:19 +02:00
PrestonLTaylor
aa691c22d4 LibWeb: Implement the <symbol> SVG element 2023-06-03 05:58:00 +02:00
PrestonLTaylor
c7c3043aa2 LibWeb: Implement the <use> SVG element
The SVG <use> element is used to be able to reuse other SVG graphics
without having to re-write the svg element.

We now support this feature! :^)
2023-06-03 05:58:00 +02:00
PrestonLTaylor
b322abd8d0 LibWeb: Add document_fully_loaded event to DocumentObserver
SVGUseElement needs to be able to query the fully loaded document for
its referenced element.
2023-06-03 05:58:00 +02:00
PrestonLTaylor
31d536912c LibWeb: Allow SVG painting to escape out of a shadow tree
The spec for the `<use>` element requires a shadow tree for the
rendered content, so we need to be able to escape shadow trees when
rendering svg content.
2023-06-03 05:58:00 +02:00
stelar7
fd360ba171 LibWeb: Implement details_notification_task_steps for <details> 2023-06-03 05:56:00 +02:00
stelar7
8773122f6b LibWeb: Implement the <summary> element 2023-06-03 05:56:00 +02:00
Simon Wanner
870bcd56df LibWeb: Make disclosure marker bounds square
This makes sure we actually render an equilateral triangle
inside a square.
2023-06-03 05:54:49 +02:00
Simon Wanner
293ece2292 LibWeb: Support list-style-position
This moves the ::marker inside of <summary> actually inside. :^)
2023-06-03 05:54:49 +02:00
Simon Wanner
ee7282cbe4 LibWeb: Make pseudo-elements inspectable
This makes it possible to set a pseudo-element as the inspected node
using Document::set_inspected_node(), Document then provides
inspected_layout_node() for the painting related functions.
2023-06-03 05:54:49 +02:00
Simon Wanner
5e3e9b2f61 LibWeb: Add list-style-type: disclosure-{closed,open}
These markers are rendered as equilateral triangles pointing right and
down respectively. As we currently don't implement writing-mode the
closed marker does not respect it.
2023-06-03 05:54:49 +02:00
Sam Atkins
76611790e9 LibWeb: Fix order/formatting of Properties.json 2023-06-02 20:04:23 +02:00
Sam Atkins
d3009bd568 LibWeb: Add missing value ranges to CSS properties
...except those related to `grid`, because I can't figure out how the 17
different properties interact with each other, and what values apply to
which ones. 😅

All but 1 of these are the infinite range `[-∞,∞]`. As such, specifying
that range does not change anything, but it does make it explicit that
we've looked at what the range should be, instead of just not having
added it.
2023-06-02 20:04:23 +02:00
Andreas Kling
7115446995 LibWeb: Support font-size: calc()
Now that we have a way to resolve calc() lengths without a layout node,
we can finally support calc() values in font-size.

This wasn't possible before because font-related properties have to be
resolved eagerly in StyleComputer due to font-relative CSS length units
depending on the computed font being known.
2023-06-02 20:03:28 +02:00
Andreas Kling
df8a96ee00 LibWeb: Add a way to resolve calc() values without a layout node
Instead of a layout node, you can pass a new Length::ResolutionContext
struct which contains everything needed to resolve calc() lengths.
2023-06-02 20:03:28 +02:00
Aliaksandr Kalenik
2ade229f27 LibWeb: Fix crashing when grid track size is calc() with percentage
Use contains_percentage() that works for calc() values instead of
is_percentage().

This fixes issue when tracks with calc() that has percentages where
considered as "fixed" tracks with resolvable size which led to
incorrectly resolved infinite final track sizes.
2023-06-02 19:02:31 +02:00
Sam Atkins
1f2629f132 LibWeb: Bounds-check parsed CSS types
This reintroduces bounds-checking for the CSS `<angle>`, `<frequency>`,
`<integer>`, `<length>`, `<number>`, `<percentage>`, `<resolution>`,
and `<time>` types.

I regressed this around 6b8f484114 when
changing how we parsed StyleValues.

This is an improvement from before though, since we now allow the bounds
of a dimension type to have units.

Added a test to make sure we don't regress this again. :^)
2023-06-02 17:46:35 +02:00
Sam Atkins
fbfce2e73e LibWeb: Add comparison operators to CSS numeric types (except Length)
This is to make it easier to bounds-check their values during parsing.
Length is left out because many length units are relative to the
context in which they are used, and so we cannot easily compare `10px`
and `1em`, for example.
2023-06-02 17:46:35 +02:00
Andreas Kling
06617a982e LibWeb: Support flex items with calc() main size containing percentages
If a flex item's main size is a CSS calc() value that resolves to a
length and contains a percentage, we can only resolve it when we have
the corresponding reference size for the containing block.
2023-06-02 17:17:45 +02:00
Andreas Kling
d6c3cbd958 LibWeb: Make StackingContext sorting a lot faster
Stacking contexts are sorted after building a tree of them. They are
sorted by z-index first, DOM tree order second.

Sorting was previously *very* slow on pages with many stacking contexts.
That was because the sort() function used Node::is_before() in the
quick_sort comparator to see if one StackingContext was before another.
is_before() does tree traversal and can take quite a long time per call.

This patch avoids all that by letting StackingContext know its index
among all StackingContexts within the same document in tree order.
There's a noticeable snappiness increase on the CSS-FLEXBOX-1 spec page,
for instance. :^)
2023-06-02 15:00:38 +02:00
stelar7
2ef6aa5f3d LibWeb: Parse clamp() css math function 2023-06-02 05:22:12 +02:00
stelar7
eaee0ecd88 LibWeb: Parse max() css math function 2023-06-02 05:22:12 +02:00
stelar7
6a10821bfd LibWeb: Parse min() css math function 2023-06-02 05:22:12 +02:00
stelar7
570e43a66a LibWeb: Move function parsing to separate method 2023-06-02 05:22:12 +02:00
MacDue
47fc91ed43 LibWeb: Remove per path clipping for SVGGeometryPaintable
Somewhere the path bounding box in the layout and the actual draw path
are getting slightly mismatched. This results in partly clipped bits of
SVGs. The paths are already clipped to the containing SVG, and the size
of the path in the layout is computed from the bounding box, so it is
probably safe just to remove this clipping for now.
2023-06-02 05:21:48 +02:00
FalseHonesty
de9604212f LibWeb: Avoid text-aligning content that is too long for its line box
Previously, we would always respect the `text-align` property, even if
the text being aligned was too long for its line box and would be
clipped. This led to seeing the clipped middle/end of strings when we
should instead always see the beginning of the text.
2023-06-02 05:21:22 +02:00
Sam Atkins
7ce4cbfe1d LibWeb: Convert NumberStyleValue from float to double
We have double precision in the parser, and currently use doubles for
most of layout, so we might as well keep that extra precision inside
NumberStyleValue too.
2023-06-01 21:04:21 +02:00
Sam Atkins
8889635ba7 LibWeb: Remove int usage of NumberStyleValues
Use IntegerStyleValue where we should; remove the ability of
NumberStyleValue to hold integers, and add integer interpolation for
animations.
2023-06-01 21:04:21 +02:00
Sam Atkins
1160d8186b LibWeb: Implement IntegerStyleValue, for holding <integer>
Having one StyleValue for `<number>` and `<integer>` is making user code
more complicated than it needs to be. We know based on the property
being parsed, whether it wants a `<number>` or an `<integer>`, so we
can use separate StyleValue types for these.
2023-06-01 21:04:21 +02:00
Sam Atkins
ad8565011c LibWeb: Rename NumericStyleValue -> NumberStyleValue
This is in preparation of splitting off a separate IntegerStyleValue.
2023-06-01 21:04:21 +02:00
Andreas Kling
1a6a4ca7d4 LibWeb: Round lengths to 3 decimals after resolving from percentage
This is a hack to emulate the behavior of other engines that use
fixed-point math. By rounding to 3 decimals, we retain a fair amount of
detail, while still allowing overshooting 100% without breaking lines.

This is both gross and slow, but it fixes real sites. Notably, the
popular Bootstrap library uses overshooting percentages in their
12-column grid system.

This hack can be removed when CSSPixels is made a fixed-point type.
2023-06-01 18:13:42 +02:00
Andreas Kling
3f9cfa144c LibWeb: Allow infinitely long flex lines when sizing under max-content
If the flex container is being sized under a max-content main size
constraint, there is effectively infinite space available for flex
items. Thus, flex lines should be allowed to be infinitely long.

This is a little awkward, because the spec doesn't mention specifics
about how to resolve flexible lengths during intrninsic sizing.
I've marked the spec deviations with big "AD-HOC" comments.
2023-06-01 15:11:48 +02:00
stelar7
9c74f49b1d LibWeb: Implement has_transient_activation 2023-06-01 14:28:52 +02:00
stelar7
29029de839 LibWeb: Set last activation timestamp on the window 2023-06-01 14:28:52 +02:00
stelar7
266d4a3553 LibWeb: Implement step 7 of choose_a_browsing_context 2023-06-01 14:28:52 +02:00
Andreas Kling
caa491b72a LibWeb: Measure the overflow for all scroll containers
Instead of just measuring the layout viewport, we now measure overflow
in every box that is a scroll container.

This has the side effect of no longer creating paintables for layout
boxes that didn't participate in layout. (For example, empty/anonymous
boxes that were ignored by flex itemization.)

Such boxes are now marked as "(not painted)" in the layout tree dumps,
as they have no paintable to dump geometry from.
2023-06-01 13:33:35 +02:00
Andreas Kling
b7d2f6fa88 LibWeb: Clip overflow in descendant boxes for non-visible CSS overflow
We were only clipping for hidden, when we should be clipping for hidden,
clip, scroll and auto. Basically everything but visible. :^)
2023-06-01 13:33:35 +02:00
Andreas Kling
4ff52cebc4 LibWeb: Let's say that layout viewports are always scroll containers
This will allow us to have a shared code path for overflow calculation.
2023-06-01 13:33:35 +02:00
Andreas Kling
571c05bb47 LibWeb: Include scrollable overflow in paint tree dumps 2023-06-01 13:33:35 +02:00
Andreas Kling
966058d693 LibWeb: Support line-height: calc(...) values that resolve to number
This is used on GitHub and many other websites.
2023-06-01 09:20:05 +02:00
FalseHonesty
dcead6f5eb LibWeb: Add support for parsing place-content shorthand CSS property 2023-06-01 09:06:13 +02:00
Andreas Kling
fde86350e3 LibWeb: Put debug spam about indefinitely sized SVGs behind a flag 2023-06-01 07:34:37 +02:00
Andreas Kling
c62c714764 LibWeb: Put debug spam about negative content sizes behind a flag
We already clamp these values to zero, so it's actually pretty harmless
when this happens. If someone wants to investigate these issues deeper
and see if they can be fixed earlier in the layout pipeline, they can
enable the spam locally.
2023-06-01 07:34:37 +02:00
Andi Gallo
827936cf7b LibWeb: Invalidate layout tree in textContent setter
The textContent setter changes the structure of the DOM, therefore the
layout tree becomes invalid.
2023-06-01 07:22:50 +02:00
Andreas Kling
4fed7beb7b LibWeb: Make solve_replaced_size_constraint() into FormattingContext 2023-05-31 11:38:05 +02:00
Andreas Kling
42470d837e LibWeb: Move layout box rect helpers into FormattingContext
These are only used during layout, and always within formatting context
code, so we might as well put them in FormattingContext and avoid having
to pass the LayoutState around all the time.
2023-05-31 11:38:05 +02:00
Andreas Kling
4f08fcde29 LibWeb: Remove unnecessary static formatting context functions
At one point in the past, we had some functions that were called across
different formatting context types, which necessitated making them
static and taking the LayoutState as a parameter.

In all cases, those functions were used to do incorrect hacks, all of
which we've replaced with more correct solutions. :^)
2023-05-31 11:38:05 +02:00
stelar7
421559d725 LibWeb: Change calc node representation from float to double 2023-05-31 10:56:32 +02:00
stelar7
344f37986f LibWeb: Allow calculated values in transform 2023-05-31 05:57:53 +02:00
stelar7
e23d31ae83 LibWeb: Lazy evaluate optional to avoid crash 2023-05-31 05:56:46 +02:00