Commit Graph

162 Commits

Author SHA1 Message Date
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
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
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
Simon Wanner
b5ba479d65 LibWeb: Render svg-as-image with 1:1 scaling factor
We're passing the SVGDecodedImageData a size in device pixels, so it's
incorrect to apply the host page's device_pixels_per_css_pixels on top
of that.
2023-05-30 21:28:18 +02:00
MacDue
6f8c2dc322 LibWeb: Make SVG transform parser less crashy
Previously, this would blindly use parse_number() without checking if
there was a number to parse. This meant we would crash on transforms
like:
	rotate(BAD 32 0)

Now the attribute just gracefully fails to parse.
2023-05-27 18:40:41 +02:00
Cameron Youell
0afdde0eef LibWeb: Consume sign in SVG::parse_elliptical_arg_argument
This was crashing on google.com with the linux chrome user agent,
interestingly it seems like this behavior may have been accidental as
only two of the three `parse_number()` were changed in f7dbcb6
2023-05-26 14:54:00 +02:00
Andreas Kling
655d9d1462 LibWeb: Make CSSPixels and Length use 64-bit (double) floating point
This fixes a plethora of rounding problems on many websites.
In the future, we may want to replace this with fixed-point arithmetic
(bug #18566) for performance (and consistency with other engines),
but in the meantime this makes the web look a bit better. :^)

There's a lot more things that could be converted to doubles, which
would reduce the amount of casting necessary in this patch.
We can do that incrementally, however.
2023-05-24 14:40:35 +02:00
Andreas Kling
dd19f61538 LibWeb: Add fast way to check if a DOM node is an SVG element 2023-05-24 06:43:21 +02:00
Andreas Kling
0f4b82bdea LibWeb: Move SVGElement's dataset construction to initialize()
It's not safe to allocate new cells while in a cell constructor.
2023-05-21 16:01:19 +02:00
Andreas Kling
94a26e2715 LibWeb: Include SVG-as-image isolated contexts in layout/DOM tree dumps
This allows us to see the inside of SVG-as-image in layout tests. :^)
2023-05-21 07:44:29 +02:00
Andreas Kling
dcc561aa60 LibWeb: Calculate intrinsic size and aspect ratio for SVG-as-image
This finally makes SVG-as-image show up visually! :^)

We should find a way to share this logic with Layout::SVGSVGBox, but
that will require some finesse since they have to work at different
points in the layout/paint timeline.
2023-05-21 07:44:29 +02:00
Andreas Kling
41ab0837fa LibWeb: Render SVG-as-image into an isolated top-level browsing context
In order to separate the SVG content from the rest of the engine, it
gets its very own Page, PageClient, top-level browsing context, etc.

Unfortunately, we do have to get the palette and CSS/device pixel ratios
from the host Page for now, maybe that's something we could refactor in
the future.

Note that this doesn't work visually yet, since we don't calculate the
intrinsic sizes & ratio for SVG images. That comes next. :^)
2023-05-21 07:44:29 +02:00
Andreas Kling
e63f68661f LibWeb: Have ImageProvider bitmap getter take optional size argument
This allows the painting subsystem to request a bitmap with the exact
size needed for painting, instead of being limited to "just give me a
bitmap" (which was perfectly enough for raster images, but not for
vector graphics).
2023-05-21 07:44:29 +02:00
Andreas Kling
6f46bff4df LibWeb: Stub out a new SVGDecodedImageData class
This class will implement isolated SVG layout and rendering.
2023-05-21 07:44:29 +02:00
MacDue
00cda96e2d LibWeb: Implement SVG opacity properties
This implements the stop-opacity, fill-opacity, and stroke-opacity
properties (in CSS). This replaces the existing more ad-hoc
fill-opacity attribute handling.
2023-05-20 08:52:19 +02:00
Andreas Kling
6f204f8c32 LibWeb: Fix null dereference on SVG element with bogus fill URL
Fixes a crash seen on YouTube channel pages.
2023-05-19 15:41:34 +02:00
Andreas Kling
70db40c9b0 LibWeb: Don't include Layout/Node.h from DOM/Element.h
This required moving the CSS::StyleProperty destruct out of line.
2023-05-08 09:29:44 +02:00
Andreas Kling
e43027091d LibWeb: Don't include HTML/Window.h from DOM/Element.h
This required moving HTML::ScrollOptions to its own header file.
2023-05-08 09:29:44 +02:00
Andreas Kling
ca1fa5f748 LibWeb: Use the new to_px() helpers in CSS, SVG and layout code
There should be no behavior change from this, only slightly less
verbosity. :^)
2023-05-06 18:41:34 +02:00
Sam Atkins
f4d8a24fe4 LibWeb: Propagate errors from parse_css_value and property_initial_value 2023-05-06 08:07:28 +02:00
Sam Atkins
d16600a48b LibWeb: Propagate errors from StyleValue construction
Turns out we create a lot of these, mostly from places that don't return
ErrorOr. The yak stack grows.
2023-05-06 08:07:28 +02:00
MacDue
9b652842e4 LibWeb: Add an initial implementation of SVG <radialGradient>
This follows on from the SVG linear gradients. It supports the same
features (xlink:href, gradientUnits, gradientTransform).

With this commit I have now implemented all web gradients :^)

(Though we are still missing a few parameters for SVG gradients,
e.g. spreadMethod).
2023-05-04 16:50:01 +02:00
MacDue
2826bd2b45 LibWeb: Move some common SVG gradient functions into SVGGradientElement
These functions will also be used by SVG radial gradients.
2023-05-04 16:50:01 +02:00
MacDue
eda429111e LibWeb: Don't inherit SVG color stops if current gradient has stops
The previous behaviour was incorrect, the template's stops should only
be used if the current gradient does not have any stops.
2023-05-04 16:50:01 +02:00
MacDue
9ecc5413de LibWeb: Add tag and attribute names for SVG linear gradients 2023-05-04 16:50:01 +02:00
MacDue
3d54b9ffa3 LibWeb: Mark SVG::NumberPercentage accessors as const 2023-05-04 16:50:01 +02:00
Andreas Kling
4ad12f3cb2 LibWeb: Honor fill, stroke and stroke-width attribute on SVGSVGElement
These are presentational hints and are handled by SVGGraphicsElement (a
superclass of SVGSVGElement) so we just need to call up to it. :^)
2023-05-04 15:40:34 +02:00
MacDue
afd355c135 LibWeb: Resolve and paint SVG gradient fills
This bit is mostly ad-hoc for now. This simply turns fill: url(#grad1)
into document().get_element_by_id('grad1') then resolves the gradient.
This seems to do the trick for most use cases, but this is not
attempting to follow the spec yet to keep things simple.
2023-04-28 09:42:28 +02:00
MacDue
aa3464466e LibWeb: Implement SVGLinearGradientElement (<linearGradient>)
This represents the SVG <linearGradient>. The actual gradient is
converted to a Gfx::PaintStyle for use in SVG fills... There is a little
guesswork in the implementation, but it seems to match Chrome/Firefox.

Note: Still not hooked up to actual painting in this commit.
2023-04-28 09:42:28 +02:00
MacDue
71938550fa LibWeb: Implement SVGGradientElement
This is the base class for all SVG gradient types. This supports:

- The `gradientUnits` attribute
- The `gradientTransform` attribute
- And following `xlink:hrefs` for inheriting <stops>/attributes
2023-04-28 09:42:28 +02:00
MacDue
b19d2634f6 LibWeb: Implement SVGStopElement (<stop>)
This is used to specify the color/position of color stops for SVG
gradients.
2023-04-28 09:42:28 +02:00
MacDue
297d8eebcd LibWeb: Add stop-color as a CSS property
(This is to set the color of a stop for an SVG gradient)
2023-04-28 09:42:28 +02:00
MacDue
2013761feb LibWeb: Add SVG tag names for <linearGradient>s 2023-04-28 09:42:28 +02:00
MacDue
66d1b78348 LibWeb: Implement SVGAnimatedNumber
See https://www.w3.org/TR/2013/WD-SVG2-20130409/types.html#InterfaceSVGAnimatedNumber
2023-04-28 09:42:28 +02:00
Andreas Kling
7f79208759 LibWeb: Support implicit lineto commands after moveto in SVG paths
Per SVG2, any coordinate pairs following a moveto command should be
treated as implicit lineto commands with the same absoluteness as the
moveto command.
2023-04-17 14:18:45 +02:00
MacDue
5df4e64eb7 LibWeb: Implement SVG preserveAspectRatio attribute
This attribute is used to define how the viewBox should be scaled.
Previously the behaviour implemented was that of "xMidYMid meet", now
all of them work (expect none :P).

With this the Discord login backend is now correctly scaled/positioned.

This also brings our SVG code a little closer to the spec! With spec
comments and all :^)

(Minor non-visible update to layout tests)
2023-04-17 07:32:31 +02:00
MacDue
f9c61e3ba7 LibWeb: Scale SVG stroke-width based on viewbox
This fixes the clipping of strokes in quite a few cases and now fixes
the Gartic Phone logo :^)

(Layout test updated but no visible changes there)
2023-04-15 19:28:13 +02:00
Nico Weber
f56b897622 Everywhere: Fix a few typos
Some even user-visible!
2023-04-12 19:37:35 +02:00
MacDue
ba7383d28f LibWeb: Allow floating point values when parsing SVG viewboxes 2023-04-12 07:40:22 +02:00
MacDue
f753a4f640 LibWeb: Always use quirks mode when parsing SVG width/height attributes
This is a bit if a hack, but without this unitless values for these
attributes fail to parse with <!DOCTYPE html>.
2023-04-12 07:40:22 +02:00
MacDue
d0496ae9b8 LibWeb: Apply CSS scaling to SVG elements
Not sure why this was not done before, not now it works easily :^)
2023-04-12 07:40:22 +02:00
MacDue
570d71f869 LibWeb: Parse the transform attribute when set on SVGGraphicsElements
This uses the new attribute parser functionality, and then resolves the
transform list into a single Gfx::AffineTransform.

This also adds a .get_transform() function which resolves the final
transform, by applying all parent transforms.
2023-04-12 07:40:22 +02:00
MacDue
6482c306f1 LibWeb: Parse and apply fill-opacity attribute to SVG paths
This is needed to fix the rendering of the Street View directional
controls (which have paths with various levels of opacity set by
this attribute).
2023-04-12 07:40:22 +02:00
MacDue
62f087bd56 LibWeb: Add SVG transform parsing
This parses SVG transforms using the syntax from CSS Transforms
Module Level 1. Note: This looks very similar to CSS tranforms, but
the syntax is not compatible. For example, SVG rotate() is
rotate(<a> <x> <y>) where all parameters are unitless numbers whereas
CSS rotate() is rotate(<angle> unit) along with separate rotateX/Y/Z().

(At the same time AttributeParser is updated to use GenericLexer which
makes for easier string matching).

There is work needed for error handling (which AttributeParser does not
deal with very gracefully right now).
2023-04-12 07:40:22 +02:00
Ben Wiederhake
560133a0c6 Everywhere: Remove unused DeprecatedString includes 2023-04-09 22:00:54 +02:00
Sam Atkins
4b711932cc LibWeb: Split PercentageStyleValue out of StyleValue.{h,cpp} 2023-03-25 16:56:04 +00:00
Simon Wanner
03c225b023 LibWeb: Move Element.prototype.style to ElementCSSInlineStyle mixin
Also adds the `PutForwards` extended attribute allowing setting the
style property.
2023-03-20 20:37:40 -04:00
Michiel
2480b94ae7 LibWeb: Support more length types in SVG width/height attributes
Previously we were using the HTML parse_dimension_value method for the
height and width attributes of an SVG element. These attributes should
however be treated as css properties instead and thus also support
calc() and absolute units so we use the css parser for this instead.
2023-03-20 23:45:01 +01:00
Timothy Flynn
db2ba5f1d9 LibWeb: Initialize static web strings during main-thread VM creation
These are currently initialized in a [[gnu::constructor]], which has a
weird initialization order. These constructors are invoked before main()
and, incidentally, before any user-defined default constructors of the
static strings they are initializing.

This will become an issue when these strings are ported to FlyString,
which has a user-defined default constructor. In that scenario, when the
FlyString constructor is executed after the [[gnu::constructor]], the
strings will be "reset" to the empty string.

Instead of relying on a non-standard compiler extension here, let's just
initialize these strings explicitly during main-thread VM creation, as
this now happens in WebContent's main().
2023-03-18 19:50:45 +01:00