Commit graph

100 commits

Author SHA1 Message Date
Moustafa Raafat
6ff9a88c3b LibWeb: Support animated backgrounds 2022-11-13 16:53:22 -07:00
MacDue
2c2b9fb1d7 LibWeb: Parse repeating-conic-gradient()s 2022-11-07 13:13:22 +00:00
MacDue
fdcc73d4b1 LibWeb: Paint conic-gradient()s
This is a first pass at painting conic-gradient()s, I've yet to try to
optimize this much, but I feel like you could do better than atan2
in a loop.
2022-11-01 23:07:05 +00:00
MacDue
e568c93404 LibWeb: Add PositionValue class to represent CSS <position>s
This class represents a <position> and handles resolving it to a
Gfx::FloatPoint relative to some rectangle.

It can handle all forms of <position>:

- Two presets:
  left center
- A preset + a length percentage:
  10% bottom
- Or relative to some edges:
  right 20% bottom 30px
2022-11-01 23:07:05 +00:00
MacDue
067759c0e9 LibWeb: Add ConicGradientStyleValue
This commit adds a simple style value (which is an abstract image)
to represent conic-gradient()s.

This commit also starts to factor out some reusable parts of the
linear-gradient() style value for other gradient types.
2022-11-01 23:07:05 +00:00
martinfalisse
b2b677e984 LibWeb: Refactor GridTrackSize classes
Refactor various classes in the GridTrackSize file for the incoming
named_tracks feature.

Previously the ExplicitTrackSizing had mixed responsiblities with the
newly-named GridRepeat class. This made it so it was not possible to
have multiple repeats within a single 'GridTrackSizeList' definition.

The MetaGridTrackSize class had both the responsibilities of being a
container for minmax values as well as for simple GridSizes. By uniting
the different possible values (repeat, minmax, default) into the
ExplicitGridTrack class are able to be more expressive as to the
different grid size modalities.

The GridTrackSizeList will be useful as compared to a
Vector<ExplicitGridTrack> since this way can keep track of the declared
line names. These same line names are able to be declared within the
values of a repeat function, hence the presence of a GridTrackSizeList
inside the GridRepeat class.
2022-11-01 11:19:41 +01:00
martinfalisse
f7af190de0 LibWeb: Add parent classes for managing GridTrackSizes
Add classes ExplicitTrackSizing and MetaGridTrackSize which will allow
for managing properties like auto-fill and minmax.

In the following CSS example there are 3 classes that will be used:
grid-template-column: repeat(auto-fill, minmax(50px, 1fr) 75px);

ExplicitTrackSizing - will contain the entire value. e.g.
repeat(auto-fill, minmax(50px, 1fr) 75px)

With a flag if it's a repeat, as well as references to the
MetaGridTrackSizes which is the next step down.

MetaGridTrackSize:
Contain the individual grid track sizes. Here there are two:
minmax(50px, 1fr) as well as 75px.

This way can keep track if it's a minmax function or not, and the
references to both GridTrackSizes in the case it is, or in just the one
if it is not.

GridTrackSize:
Is the most basic element, in this case there are three in total; two of
which are held by the first MetaGridTrackSize, and the third is held by
the second MetaGridTrackSize.
Examples: 50px, 1fr and 75px.
2022-10-15 16:04:01 +02:00
martinfalisse
86ce1b64f0 LibWeb: Fix bug in checking if GridTrackPlacement is auto-positioned
This fixes something I thought I had already fixed everywhere, where
previously there wasn't the possibility to have an Auto
GridTrackPlacement and so the Auto "implementation" was simply checking
if the position of the track was 0.
2022-10-06 21:16:01 +02:00
Andreas Kling
7abb512a86 LibWeb: Make PercentageOr<T>::contains_percentage() handle more cases 2022-09-29 20:09:44 +02:00
MacDue
980c92e9b5 LibWeb: Add FilterValueListStyleValue
This style value holds a list of CSS filter function calls e.g.

blur(10px) invert() grayscale()

It will be used to implement backdrop-filter, but the same style value
can be used for the image filter property.

(The name is a little awkward but it's referenced to as
filter-value-list in the spec too).
2022-09-16 10:50:48 +01:00
MacDue
b219931dfc LibWeb: Pass values by reference in style value operator== functions 2022-09-16 10:50:48 +01:00
Andreas Kling
55ad9591df LibWeb: Add a way to ask if a PercentageOr<T> value contains percentages
Values that contain percentages require special treatment in various
parts of layout. Previously we had no way of peeking into calc() values
to see if their expression contains one or more percentages. That's the
bulk of what we're adding here.
2022-09-14 14:43:17 +02:00
Andreas Kling
9018b58875 LibWeb: Only schedule ImageStyleValue resource load once
load_any_resources() may get called multiple times during layout, but
once we've started a resource load, we don't need to do it again.
2022-09-07 17:47:33 +02:00
martinfalisse
c40dd9ee78 LibWeb: Add GridTrackPlacementShorthandStyleValue
Add GridTrackPlacementShorthandStyleValue for the use of grid-column and
grid-row.
2022-08-25 13:47:48 +02:00
martinfalisse
08b832eb69 LibWeb: Add GridTrackPlacementStyleValue
Add GridTrackPlacementStyleValue for the use of CSS properties
grid-column-start, grid-column-end, grid-row-start, grid-row-end.
2022-08-25 13:47:48 +02:00
martinfalisse
0148260b5f LibWeb: Add GridTrackSizeStyleValue
Add GridTrackSizeStyleValue for the use of CSS properties
grid-template-columns, grid-template-rows.
2022-08-25 13:47:48 +02:00
MacDue
fa5c2183df LibWeb: Don't regenerate linear gradient data unless size changes
This is an easy check to add and seems like it makes things a
tiny bit smoother.
2022-08-23 01:02:49 +02:00
MacDue
de5d25ee44 LibWeb: Add missing checks to LinearGradientStyleValue::equals() 2022-08-23 01:02:49 +02:00
MacDue
3a1f8d714a LibWeb: Parse double-position linear-gradient() color stops
The only accepted syntax for these seems to be
<color> <length percentage> <length percentage>, no other order.

But that's just gathered from looking at other browsers as though
these are supported by all major browsers, they don't appear in
the W3C spec.
2022-08-23 01:02:49 +02:00
MacDue
f9a685437f LibWeb: Parse repeating-linear-gradient()
Including `-webkit-repeating-linear-gradient()`
2022-08-18 15:58:05 +02:00
MacDue
1473842b56 LibWeb: Follow image-rendering when painting image style values 2022-08-10 19:39:07 +02:00
MacDue
6a6475673f LibWeb: Convert images to common AbstractImageStyleValue base
This commit moves both the ImageStyleValue and LinearGradientStyleValue
to a common base class of AbstractImageStyleValue. This abstracts
getting the natural_width/height, loading/resolving, and painting
the image.

Now for 'free' you get:

 - Linear gradients working with the various background sizing/repeat
   properties.
 - Linear gradients working as list-markers :^) -- best feature ever!

P.s. This commit is a little large as it's tricky to make this change
incrementally without breaking things.
2022-08-08 22:39:06 +02:00
MacDue
9c8aa5b777 LibWeb: Fix resolution of CSS clip rect
Previously the clip rect was not relative to the top/left egdes
of the element, which lead to it being positioned incorrectly.

This fixes the clip-rect-auto-004 and clip-rect-auto-005 web
platform tests.
2022-08-08 14:03:29 +02:00
Tom
6b2e93eb7c LibWeb: Fix RectStyleValue to_string() implementation
Fix implementation of to_string() for RectStyleValue so that it can be
used by JS.
2022-08-08 12:16:36 +02:00
Tom
5049a56d96 LibWeb: Implement clip property
Implement clip when it is defined in the css property 'clip' as a rect
according to spec; only when the div is absolutely positioned.
2022-08-07 22:40:11 +02:00
Tom
b4dd477644 LibWeb: Parse rect style value
Add ability to parse a rect when it is used as the value of a style
property.
2022-08-07 22:40:11 +02:00
MacDue
ca2e345cdc LibWeb: Support -webkit-linear-gradient() correctly
The -webkit version of linear-gradient does not include the `to`
before a <side or corner>. The angles of the <side or corner>
for the webkit version are also opposite that of the standard one.

So for the standard: linear-gradient(to left, red, blue)
The webkit version is: -webkit-linear-gradient(right, red, blue)

Adding the `to` in the -webkit version is invalid, omitting it in
the standard one is also invalid.
2022-08-07 20:47:31 +02:00
Sam Atkins
3fce4f7c91 LibWeb: Resolve calc() FooPercentages that only contained percentages
Fixes #14697

Percentages inside `calc()` only got converted to the concrete type
(eg, Length) when added or subtracted with one. So if the `calc
()` doesn't contain any of that type, it would resolve to a
Percentage.

Now, we catch that returned Percentage and convert it to the proper
type. This fixes cases like `width: calc(100% / 2);`.
2022-07-27 17:03:55 +02:00
Sam Atkins
93c999ce00 LibWeb: Stop handling impossible Percentage return values
When a `calc()` is resolved, it can only return a Percentage value if
the requested type is Percentage. In all other cases, it returns a
concrete value.

eg, a `calc()` with Lengths and Percentages in will always resolve to a
Length, never a Percentage. This means we can just return Length
directly instead of LengthPercentage, which simplifies things in a few
places.
2022-07-21 16:36:08 +02:00
MacDue
4246d04e5a LibWeb: Calculate to <corner> angles for linear-gradients
This also renames LinearGradientStyleValue::angle() to
LinearGradientStyleValue::angle_degrees() to make the unit more
obvious.
2022-07-18 10:10:22 +01:00
MacDue
259bb30c35 LibWeb: Add LinearGradientStyleValue 2022-07-17 20:11:38 +01:00
MacDue
8603541e56 LibWeb: Add serialize_a_srgb_value()
This moves the logic from ColorStyleValue::to_string() to a standalone
function.
2022-07-17 20:11:38 +01:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
MacDue
a999b82882 LibWeb: Fix background images not showing till scrolling/repaint
Previously, set_needs_display() was passed an empty rectangle in
ImageStyleValue::resource_did_load(). This led to the browser not
doing a repaint when the image loaded.

Fixes #14435
2022-06-30 20:11:40 +01:00
Linus Groh
26fc01eecb LibWeb/CSS: Fix incorrect calc(<percentage> - <value>) computations
When swapping both values to perform the actual calculation, we need to
consider that `A + B == B + A`, but `A - B != B - A`, so turn it into
`-B + A`.

Co-Authored-By: Sam Atkins <atkinssj@serenityos.org>
2022-06-30 12:11:57 +01:00
stelar7
4359d4eb5d LibWeb: Note and fix Gfx related quirk in ColorStyleValue::to_string 2022-05-08 16:29:18 +02:00
Sam Atkins
9272c3283b LibWeb: Add missing StyleValue::equals() methods
Every StyleValue type now has its own `equals()` method, rather than
relying on the default "compare the to_string() output" method, which
has now been removed. This logic is still used by UnresolvedSV and
CalculatedSV, because it's probably the best option for them unless
performance becomes a real issue.

Also took this opportunity to move all the `equals()` implementations
into the .cpp file, which may or may not actually help with compile
times but StyleValue.h is huge and included everywhere, so it can't
hurt.
2022-04-18 21:30:51 +02:00
Sam Atkins
025ee02144 LibWeb: Add missing [as/is]_border_radius_shorthand() methods 2022-04-18 21:30:51 +02:00
Sam Atkins
d9afc2d6f2 LibWeb: Rename CombinedBorderRadiusSV -> BorderRadiusShorthandSV 2022-04-18 21:30:51 +02:00
Sam Atkins
61ad39b110 LibWeb: Use generated TransformFunction enum and functions 2022-04-18 14:16:28 +02:00
Igor Pissolati
7ae116b81b LibWeb: Bring BorderRadiusStyleValue::to_string() closer to spec 2022-04-04 00:03:15 +02:00
Andreas Kling
344374588b LibGfx: Rename FontMetrics => FontPixelMetrics
Let's make it clear in the type name that this contains pixel metrics.
Also rename Font::metrics() => Font::pixel_metrics().
2022-03-30 00:57:15 +02:00
Sam Atkins
1094654adc LbWeb: Rename BoxShadowFoo => ShadowFoo
The `text-shadow` property is almost identical to `box-shadow`:
> Values are interpreted as for box-shadow [CSS-BACKGROUNDS-3].
> (But note that the inset keyword are not allowed.)

So, let's use the same data structures and parsing code for both. :^)
2022-03-24 18:08:34 +01:00
Sam Atkins
c0d3f1a5e4 LibWeb: Use CSS::Number for CalculatedStyleValue numbers 2022-03-22 15:47:36 +01:00
Andreas Kling
f87edd4c14 LibWeb: Don't crash when detached document tries to use system palette
If the current Document is not attached to a Web::Page for whatever
reason, but we're trying to look up a color from the system palette,
let's just fail the lookup instead of crashing the process.
2022-03-19 22:04:43 +01:00
Simon Wanner
c4f46893f6 LibWeb: Add parsing support for the remaining transform functions 2022-03-18 18:51:42 +01:00
Lenny Maiorani
c37820b898 Libraries: Use default constructors/destructors in LibWeb
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-17 17:23:49 +00:00
Karol Kosek
0f7156ed81 LibWeb: Parse CSS text-decoration-thickness property 2022-03-06 22:04:41 +01:00
Andreas Kling
c59ab7cc8b LibWeb: Make StyleValue absolutization non-destructive
Instead of awkwardly visiting and mutating lengths inside StyleValues,
we now simply create a new StyleValue instead.

This fixes an issue where inherited relative lengths could get
absolutized using a parent as reference, and then not having the correct
values when used in a child context.
2022-02-26 01:35:25 +01:00
Sam Atkins
adaab23149 LibWeb: Parse the content property
For now, we only understand `none`, `normal`, `<image>` and `<string>`.
The various other functions and identifiers can be added later.

We can *almost* use a StyleValueList for this, except it's divided into
two parts - the content, and the optional "alt text". So, I've added a
new StyleValue for it.
2022-02-25 19:35:34 +01:00