Commit graph

1753 commits

Author SHA1 Message Date
Sam Atkins
a8096d33ec LibWeb: Serialize @namespace using spec algorithms 2023-08-08 20:49:45 +01:00
MacDue
5f0d3c083f LibWeb: Allow (explicitly) converting CSSPixels to float and int
...and remove some unnecessary cast chains.
2023-08-08 14:58:26 +02:00
Andreas Kling
18c54d8d40 LibJS: Make Cell::initialize() return void
Stop worrying about tiny OOMs.

Work towards #20405
2023-08-08 07:39:11 +02:00
Lucas CHOLLET
3f35ffb648 Userland: Prefer _string over _short_string
As `_string` can't fail anymore (since 3434412), there are no real
benefits to use the short variant in most cases.
2023-08-08 07:37:21 +02:00
Andreas Kling
9f6ceff7cf LibWeb: Implement basic version of CSSOM View's VisualViewport
We got some errors while loading https://twinings.co.uk/ about this
interface missing, and it looked fairly simple so I sketched it out.
Note that I did leave some FIXMEs where it's not clear exactly which
metrics we should be returning.
2023-08-06 16:29:24 +02:00
Aliaksandr Kalenik
c72a2f9e46 LibWeb/CSS: Serialize short version if possible for "place-" properties
Output short version when both parts of place-content, place-items,
place-self are the same.
2023-08-06 08:26:36 +02:00
Aliaksandr Kalenik
da2cd73bcf LibWeb: Add place-self css property support 2023-08-06 08:26:36 +02:00
Andreas Kling
64c06c345e LibWeb: Parse :host() selector
We were already parsing non-function-syntax :host, so let's also do
the :host(...) variant. Note that we don't have matching for these yet.

This fixes many issues on sites generated by Wix, as they often have
selector lists that include some :host() selector, and we'd reject the
entire rule after failing to parse it.
2023-08-05 13:23:12 +02:00
Andreas Kling
cf9565551a LibWeb: Don't filter CSS rules into separate list based on @namespace
Instead, perform the filtering for each rule as we go. This avoids
creating a separate list of rules, which was ~5% of runtime when
mousing around on the Discord web interface.
2023-08-04 05:28:41 +02:00
Andreas Kling
37a618b7ad LibWeb: Add missing visit in CSSStyleSheet::visit_edges()
Gotta visit m_default_namespace_rule.
2023-08-04 05:28:41 +02:00
Sam Atkins
73fa58da34 LibWeb: Implement the CSS outline-offset property
This allows you to push the outline a certain distance away from the
border (or inside it, if the offset is negative).
2023-08-03 05:25:48 +02:00
Sam Atkins
fe7e797483 LibWeb: Implement the CSS outline property :^)
...along with `outline-color`, `outline-style`, and `outline-width`.

This re-uses the existing border-painting code, which seems to work well
enough!

This replaces the previous code for drawing focus-outlines, with generic
outline painting for any elements that want it. Focus outlines are now
instead supported by this code in Default.css:

```css
:focus-visible {
    outline: auto;
}
```
2023-08-03 05:25:48 +02:00
Sam Atkins
5640779838 LibWeb: Allow single-value shorthand properties to parse as CompositeSV
Don't give up if we can't parse that single value for the property
directly, but let the parsing code carry on and see if we can produce a
CompositeStyleValue.
2023-08-03 05:25:48 +02:00
Sam Atkins
14e6bae593 LibWeb: Implement the :focus-visible pseudo-class
This is very naive for now, and matches whenever `:focus` does.
2023-08-03 05:25:48 +02:00
Sam Atkins
5cf6d51753 LibWeb: Reformat inconsistent CSS JSON files
Mostly this is about 2-space indentation, but we now also only have one
key:value pair per line.
2023-08-02 12:49:46 +01:00
Tobias Christiansen
aabdb6a801 LibWeb: Make the linter happy in Properties.json
There was a space missing and the linter complained.
2023-08-02 11:35:57 +01:00
Tobias Christiansen
5fc6bff582 LibWeb: Add 'object-fit' property
This patch adds support for the 'object-fit' CSS property. :^)
2023-08-02 11:35:57 +01:00
Sam Atkins
f6e4caf197 LibWeb: Implement the :buffering and :stalled pseudo-classes
Currently, HTMLMediaElement doesn't implement the stall timeout, so
`:stalled` always returns false.
2023-08-01 12:50:40 -04:00
Sam Atkins
eb7cda1172 LibWeb: Implement the :volume-locked pseudo-class 2023-08-01 12:50:40 -04:00
Sam Atkins
c8a51f232d LibWeb: Implement the :muted pseudo-class 2023-08-01 12:50:40 -04:00
Sam Atkins
7b4ae43b91 LibWeb: Implement the :seeking pseudo-class
This matches while a media element is seeking.
2023-08-01 12:50:40 -04:00
Sam Atkins
4df5e24926 LibWeb: Implement the :playing and :paused pseudo-classes
These match media elements (`<video>` and `<audio>`) which are playing
or paused, respectively.
2023-08-01 12:50:40 -04:00
Sam Atkins
a336fe4fc4 LibWeb: Include all pseudo-classes in SimpleSelector::serialize
Rather than logging ones that are missed, just rely on the compiler to
complain if one is missing. `:indeterminate` was. :^)
2023-08-01 12:50:40 -04:00
Karol Kosek
16836e7e62 LibWeb: Remove checking for AllowedDataUrlType
CSS shouldn't probably check if a MIME type in the 'data:' URL is
correct or not. Every URL gets sent to a ResourceLoader so a client can
just validate if got file with correct media type.

This also makes loading 'data:' URLs in @import work now, as we didn't
have AllowedDataUrlType for stylesheets.
2023-08-01 14:19:05 +02:00
Sam Atkins
0805060e5e LibWeb: Speed up CSS namespace checking
CSSStyleSheet now caches the CSSNamespaceRule for the default namespace,
which is the only one we currently care about. This saves us from
iterating over its list of rules every time we want to know what that
default namespace is.

The spec dictates that `@namespace` rules are only valid near the start
of a stylesheet, so we also take advantage of that to quit searching
for namespaces as soon as we see a non-import rule.

Also renamed `namespace_filter()` to `default_namespace()` since that's
what it actually returns.

This makes github.com/serenityos/serenity snappy again. :^)
2023-08-01 07:41:06 +02:00
Sam Atkins
496db17c2d LibWeb: Add callback for when a CSSRuleList's rules change 2023-08-01 07:41:06 +02:00
Sam Atkins
5ee1b7db7c LibWeb: Convert BorderData::width to CSSPixels
The `clip_shrink` optimization in `paint_background()` now also
correctly uses DevicePixels, instead of reducing a DevicePixel rect by
a CSSPixels amount.
2023-07-30 22:18:26 +01:00
Jonah
60e35f2a97 LibWeb: Rough implementation of CSS namespace rule
This provides a rough implementation of the CSS @namespace rule.
Currently we just support default namespaces, namespace prefixes
are still to come.
2023-07-30 20:27:19 +01:00
MacDue
109ea418ab LibWeb: Parse and ignore SVG paint fallback color 2023-07-30 16:06:03 +02:00
Sam Atkins
06eb4a7557 LibWeb: Match math function values to properties in correct order
If a math function resolves to `<length>` or `<percentage>`, then it
will by definition also resolve to `<length-percentage>`. (Same for any
other basic types.) Since we were checking `<length-percentage>` first
and then bailing if no given properties could accept that, math
functions would always fail to match a property that just accepts a non
`-percentage` type.
2023-07-30 14:18:13 +02:00
Andreas Kling
8f29bdb62c LibWeb: Implement the CSS revert keyword
This is a universal value like `initial` and `inherit` and works by
reverting the current value to whatever we had at the start of the
current cascade origin.

The implementation is somewhat inefficient as we make a copy of all
current values at the start of each origin. I'm sure we can come up with
a way to make this faster eventually.
2023-07-29 19:16:08 +02:00
Andreas Kling
13d5d47b56 LibWeb: Implement the CSS all property
This sets all longhand values to one of initial, inherit, unset or
revert. Note that revert is not supported yet, but will be soon.
2023-07-29 19:16:08 +02:00
Andreas Kling
95097e47a7 LibWeb: Allow calc() values in image sizes attribute
Note that we currently can't resolve calc() values without a layout
node, so when normalizing an image's source set, we'll flush any pending
layout updates and hope that gives us an up-to-date layout node.

I've left a FIXME about implementing this in a more elegant and less
layout-thrashy way, as that will require more architectural work.
2023-07-29 11:58:51 +02:00
MacDue
9997f46593 LibWeb: Resolve currentColor when used for SVG gradient <stop>s
A small workaround is needed here as <stop> elements don't create a
layout node, so we can't get the current color from value->to_color().

This fixes the gradients in the Atlassian logo and icons.
2023-07-29 08:26:04 +01:00
Aliaksandr Kalenik
0e8a0a8191 LibWeb: Add support for "display: contents"
This change makes tree builder omit elements with "display: contents"
from the layout tree during construction. Their child elements are
instead directly appended to the parent element in layout tree.
2023-07-28 05:29:43 +02:00
Andreas Kling
9caa0bda7d LibWeb: Don't relayout whenever a CSS transform changes
Transforms are a paint-level concept for us, so we should be okay to
only update the stacking context tree and repaint.

This makes a lot of CSS animations use way less CPU.
2023-07-27 12:39:44 +02:00
Andreas Kling
902e76baff LibWeb: Ignore whitespace around easing function argument values
This makes our css-animations.html test file actually parse :^)
2023-07-25 07:20:29 +02:00
Dominique Liberda
4dc98af419 LibWeb: Make table headings centered by default 2023-07-24 02:28:21 +02:00
MacDue
30277f385c LibWeb: Add an initial implementation of SVG text-anchor
This only handles very simple <text> elements, but this is enough (with
the font-size changes) to improve the badges on the GitHub README a fair
bit.
2023-07-21 11:42:30 +02:00
Sam Atkins
dd1156fb17 LibWeb: Update spec comments for math function determined types
The spec was corrected here:
de4119a6e3
2023-07-19 11:12:53 +01:00
Aliaksandr Kalenik
a8587fe54e LibWeb: Add support for "place-items" CSS property
Adds support for place-items property which allows to specify both
align-items and justify-items in a single declaration.
2023-07-17 18:58:05 +02:00
Alan Kemp
3fd870a429 LibWeb: Create EdgeStyleValue for BackgroundPositionXY with no offset
When specifying either `background-position-x: right` or
`background-position-y: bottom` without an offset value no
EdgeStyleValue was created.

However, the spec says the offset should be optional.

Now, if you do not provide an offset, it creates the EdgeStyleValue
with a default offset of 0 pixels.
2023-07-17 14:53:52 +01:00
Andreas Kling
3ec9fd0aae LibWeb: Resolve calc() values in CSS transform
There are two parts to this fix:

- First, StyleProperties::transformations() would previously omit calc()
  values entirely when returning the list of transformations. This was
  very confusing to StackingContext which then tried to index into the
  list based on faulty assumptions. Fix this by emitting calc values.

- Second, StackingContext::get_transformation_matrix() now always calls
  resolve() on length-percentages. This takes care of actually resolving
  calc() values. If no reference value for percentages is provided, we
  default to 0px.

This stops LibWeb from asserting on websites with calc() in transform
values, such as https://qt.io/ :^)
2023-07-15 11:35:16 +02:00
Sam Atkins
8fc545992d LibWeb: Use generated math-function-parsing code 2023-07-15 10:23:33 +02:00
Sam Atkins
618c0402a7 LibWeb: Generate parsing code for CSS math functions 2023-07-15 10:23:33 +02:00
Sam Atkins
780998b3d5 LibWeb: Add CSSNumericType::matches_dimension()
This isn't a spec algorithm, but is useful when type-checking parameters
to math functions.
2023-07-15 10:23:33 +02:00
Sam Atkins
136dc7a1c3 LibWeb: Extract CalculationNode::constant_type_from_string() function
This is needed by some upcoming generated code. Renamed "PI" member to
"Pi" while I was at it.
2023-07-15 10:23:33 +02:00
Sam Atkins
e4a2bd7a44 LibWeb: Move RoundingMode to Enums.json
In the spec this is a `<rounding-strategy>`, so let's use that name.
This also fixes a bug where we were serializing `to-zero` as
`toward-zero`.
2023-07-15 10:23:33 +02:00
Andreas Kling
3194f10ad0 LibWeb: Explicitly instantiate a CSS parser template function
We're gonna call parse_a_comma_separated_list_of_component_values from
another cpp file soon, so let's prepare for that by instantiating the
specific version we need.
2023-07-15 10:23:33 +02:00
Aliaksandr Kalenik
f060f89220 LibWeb: Add support for justify-items property in CSS parser 2023-07-15 05:50:51 +02:00