Commit Graph

50 Commits

Author SHA1 Message Date
Tobias Christiansen
307f90b675 LibWeb: Add proper parsing of the AlignItems property
This teaches all the relevant places about 'align-items'.
2021-09-15 22:28:28 +02:00
kleines Filmröllchen
047c013be0 LibWeb: Add several computed CSS styles
These are mostly combined styles such as background, as well as handling
the Invalid and Custom property IDs (which both make no sense).
2021-09-14 22:02:14 +02:00
kleines Filmröllchen
6865a5a447 LibWeb: Add CombinedBoderRadiusStyleValue for CSS border-radius
This style value can hold all four border radii and format them into
valid CSS for the `border-radius` property.
2021-09-14 22:02:14 +02:00
Idan Horowitz
4629f2e4ad LibWeb: Add the Web::URL namespace and move URLEncoder to it
This namespace will be used for all interfaces defined in the URL
specification, like URL and URLSearchParams.

This has the unfortunate side-effect of requiring us to use the fully
qualified AK::URL name whenever we want to refer to the AK class, so
this commit also fixes all such references.
2021-09-13 01:43:10 +02:00
Sam Atkins
e2c32a6c65 Everywhere: Use my shiny new serenityos.org email :^) 2021-09-03 12:22:36 +02:00
Andreas Kling
1fa5fba432 LibWeb: Make the base StyleValue::to_length() return an undefined length
Previously it was returning an "auto" length. This caused all the new
"initial" values to effectively turn into auto values long before layout
had a chance to resolve them.

This broke replaced elements with intrinsic size but no specified width
or height, and is the reason that Mr. ACID2 temporarily lost his eyes.
2021-08-26 13:25:52 +02:00
Sam Atkins
b92a6d6542 LibWeb: Implement CSS unset builtin value
This is equivalent to `initial` or `inherit`, depending on if the
property is inherited by default.
2021-08-25 12:14:34 +02:00
Sam Atkins
6d39f4342d LibWeb: Use single shared instance of Inherit/InitialStyleValue
These are always the same, so we can avoid allocating them repeatedly
and just use a single instance of each. :^)
2021-08-25 12:14:34 +02:00
Sam Atkins
afc434c416 LibWeb: Remove ValueListStyleValue :^)
This was the whole point of this PR. No more dealing with
ComponentValues in StyleResolver!
2021-08-14 12:45:01 +02:00
Sam Atkins
678760bd87 LibWeb: Parse multiple font-family values
Apart from now gathering comma-separated font-family names into a
StyleValueList, this also corrects the logic for parsing a single
font-family. Previously, we did not handle unquoted font names at all,
and now they are handled including when they are several words separated
by whitespace.

Modified the logic for `font` to use `parse_font_family_value()`.
`FontStyleValue.font_families()` is now a StyleValueList instead of a
vector, so that it can be better handled in StyleResolver.

We also finally remove the CSS::ParsingContext in
set_property_expanding_shorthands(). :^)
2021-08-14 12:45:01 +02:00
Sam Atkins
6f9263de04 LibWeb: Implement and use BackgroundRepeatStyleValue
This wraps an x and y background-repeat value. Potentially, we could use
this in place of the background-repeat-x and background-repeat-y
pseudo-properties, but for now StyleResolver splits it into those
properties, like it did before.
2021-08-14 12:45:01 +02:00
Sam Atkins
e6c0cb5a7f LibWeb: Implement and use OverflowStyleValue
Also added a test page for the `overflow` properties. They apparently
don't work, but at least they do parse.
2021-08-14 12:45:01 +02:00
Sam Atkins
168865dbdc LibWeb: Implement and use BorderRadiusStyleValue
This parses the elliptical border-radius values, though currently we
only support circular ones. So, to_length() is overloaded to return the
horizontal-radius. This means the code in Layout/Node.cpp does not need
to change for now.
2021-08-14 12:45:01 +02:00
Sam Atkins
cb3e097663 LibWeb: Implement and use BorderStyleValue 2021-08-14 12:45:01 +02:00
Sam Atkins
c27f99fc1d LibWeb: Implement and use FlexFlowStyleValue 2021-08-14 12:45:01 +02:00
Sam Atkins
2644d2c221 LibWeb: Implement and use FlexStyleValue
This is not just moving the code from StyleResolver to Parser. The logic
has changed to allow for the `flex-basis` to come before or after the
`flex-grow/shrink` values, as well as handle the special one-value
cases.

Also added test cases to flex.html to check the parsing. It does parse
correctly, but elements with `flex-basis: auto` do not calculate their
width correctly.
2021-08-14 12:45:01 +02:00
Sam Atkins
44a082391b LibWeb: Implement and use TextDecorationStyleValue
Modified text-decoration.html to better test that the values can be in
any order, and that it adopts the color from the `color` property if no
decoration color is specified. Right now, it always does because we do
not support a different decoration color. Later, we need to support the
`currentcolor` special CSS value for this purpose.
2021-08-14 12:45:01 +02:00
Sam Atkins
0e15561df0 LibWeb: Implement and use ListStyleStyleValue
Yes, the name is silly, but it's a StyleValue for list-style, so...
yeah. :^)

Since `list-style-type` and `list-style-image` can both have `none` as a
value, and can appear in any order, we have to handle it separately, and
then assign either or both of those to `none` depending on how many
`none`s there are, and whether those sub-properties already have values.

Added some extra test cases to lists.html to cover list-style-image and
list-style-position parts of the list-style shorthand, and the `none`
values.
2021-08-14 12:45:01 +02:00
Sam Atkins
dcbfb61816 LibWeb: Implement and use BackgroundStyleValue
This one represents one secton of a `background` property, since it can
have multiple background values separated by commas. Eventually, we will
represent that as a List of BackgroundStyleValues.

Also modified some background-foo properties in StyleResolver so that
the is_background_x() functions could be removed.

I realized that our handling of var() in shorthand properties is wrong,
so have been removing the is_builtin_or_dynamic() calls from the parsing
code for shorthands. This broke our var() test page, so I have replaced
the use of 'background' with 'background-color' there.
2021-08-14 12:45:01 +02:00
Sam Atkins
59501f1940 LibWeb: Implement and use FontStyleValue
After working with the code for a while, it makes more sense to put all
the parsing in Parser, instead of some of it living in StyleResolver.
That means our current ValueListStyleValue needs to be replaced with
specific StyleValue types for the properties that are shorthands or
otherwise combine several values together.

Here we implement FontStyleProperty, which represents a `font` CSS
property.

Also adjusted the fonts.html test page so that font-weights are featured
in test cases without things we do not yet support.
2021-08-14 12:45:01 +02:00
Sam Atkins
21c9825caf LibWeb: Implement new StyleValueList
StyleValueList is a list of StyleValues of the same type, for use in
properties like `margin` which accept a variable number of arguments.

I had originally hoped to simply swap the old ValueListStyleValue from
being a list of ComponentValues to one of StyleValues, but I can see now
that I will need to have both for a little while, so renamed the old
is_value_list() to is_component_value_list() temporarily.
2021-08-14 12:45:01 +02:00
Sam Atkins
81527f5eba LibWeb: Add StyleValue.is_builtin() convenience function 2021-08-14 12:45:01 +02:00
Sam Atkins
ed962be0fa LibWeb: Make 'auto' be both a Length and Identifier in CSS
I had accidentally parsed it in `parse_builtin_or_dynamic_value()`
instead of `parse_length()` before, which was confusing, so now it's
parsed along with other Lengths.

Whether it should be a Length is up for debate, and has been tripping me
up a few times, but a lot of code expects it to be one. For now, an
'auto' Length value (or any other value which overloads `is_auto()`)
also claims to be a `ValueID::Auto` identifier.
2021-08-14 12:45:01 +02:00
Sam Atkins
c8c2a8df56 LibWeb: Make '0' always be both a number and a length in CSS
A '0' token can be interpreted both as a Number, and as a Length. This
is problematic as in our CSS parser, we often call parse_css_value()
first, to figure out what something is, and then assign it. So we do not
know in advance whether we want a Length or not. Previously, it always
got parsed as a Length, and then every place that expected a
NumericStyleValue had to also check for a Length(0), which is easy to
forget to do.

In particular, this was causing issues with the `flex` property parsing.

To solve this, we now always parse 0 as a NumericStyleValue, and NSVs of
0 pretend to be a Length(0px) when asked. In two places, we were casting
to a LengthStyleValue* based on is_length(), which no longer works, so
those have been adjusted to use `StyleValue::to_length()` instead. They
also now check for `is_numeric()` first, to avoid the extra conversion
to a Length and back.

Possibly this opens up new issues elsewhere. In my testing it seems
fine, but until we can get CSS test suites running, it's hard to know
for certain.
2021-08-14 12:45:01 +02:00
Tobias Christiansen
2a77abf85e Everywhere: Use tobyase@serenityos.org for my copyright headers 2021-08-09 21:43:05 +02:00
Tobias Christiansen
833936f3ec LibWeb: Add auto as a recognized argument of flex-basis
There isn't actually any special treatment of this over 'content' in
the FlexFormattingContext, for now both are treated the same.
This fixes #9225
2021-08-07 15:21:34 +02:00
Sam Atkins
21c59efbb9 LibWeb: Treat CSS calc() values as "builtin_or_dynamic" 2021-07-31 00:18:11 +02:00
Andreas Kling
efa9627fc4 LibWeb: Remove unused enum value CSS::StyleValue::Position
CSS position values are just basic identifiers, they don't require
a custom StyleValue type.
2021-07-29 15:01:47 +02:00
Tobias Christiansen
2fdae3b0ca LibWeb: Add BoxShadowStyleType as a CSS StyleType
This new StyleType stores values related to box-shadows, since they
consist of multiple parts that isn't just a shorthand for other
properties.
2021-07-24 22:16:48 +02:00
Tobias Christiansen
f8bf6ae911 LibWeb: Add CalculatedStyleValue to the CSS StyleValues
This adds the CalculatedStyleValue and all the structs needed to work
with the calc() expressions.
2021-07-24 03:02:07 +04:30
Sam Atkins
6e0376361a LibWeb: Expose StyleValue parsing method in CSS Parser
Now that StyleResolver is going to deal with StyleComponentValueRules,
it will need to be able to parse those into StyleValues, using
`parse_css_value()`.

Also added StyleValue::is_builtin_or_dynamic(), which returns true for
values that are valid anywhere - things like `initial` and `inherit`,
along with `var()`, `attr()` and `calc()` - which we want to test for
easily.
2021-07-22 23:09:01 +02:00
Sam Atkins
4a03279539 LibWeb: Add CSS ValueListStyleValue
As the new CSS parser tokenizes its input, we can no longer easily
rely on a StringStyleValue for multi-value properties. (eg, border)
ValueListStyleValue lets us wrap all of the ComponentValues that
the Parser produced for one declaration, as a single StyleValue, to
then be parsed into StyleValues by the StyleResolver.

Originally, I wanted it to be a list of StyleValues, but several
properties use syntax that makes use of non-StyleValue tokens, eg:
```css
/* Syntax using a / */
font: 12px/14px sans-serif;
/* Multiple values separated by commas */
background: url(catdog.png), url(another-image.jpg), blue;
```
Passing the ComponentValue tokens themselves means that all that
information is carried over. The alternative might be to create a
StyleValue subclass for each property and parse them fully inside
the Parser. (eg, `FontStyleValue`)

I decided against `ListStyleValue` as a name, to avoid confusion
with list styles. It's not ideal, but names are hard.
2021-07-22 23:09:01 +02:00
Tobias Christiansen
80a44c3891 LibWeb: Add parsing for the justify-content property 2021-07-19 18:47:09 +04:30
Tobias Christiansen
e18e2af826 LibWeb: Add roman numerals as a list-style for ol's
This patch adds support for the identifiers upper-roman and lower-roman
of the list-style property.
2021-07-04 22:17:03 +02:00
Tobias Christiansen
af4d80af4d LibWeb: Add parsing for NumericStyleValue
This StyleValue can hold an arbitrary float value.
2021-06-06 01:46:06 +04:30
Tobias Christiansen
ae3e6510d6 LibWeb: Parse flex-basis
Flex-basis accepts either 'content' or a Length.
2021-06-06 01:46:06 +04:30
Tobias Christiansen
e6545d5259 LibWeb: Add parsing for flex-wrap property 2021-06-06 01:46:06 +04:30
Tobias Christiansen
f0c6160362 LibWeb: Add CustomStyleValue
This extends StyleValue and can hold the identifier of the custom
property.
2021-05-28 10:45:38 +01:00
Tobias Christiansen
889e1d3db9 LibWeb: Add list-style-type: upper-latin and upper-alpha support 2021-04-29 10:43:33 +02:00
Tobias Christiansen
cb34775c83 LibWeb: Add list-style-type: lower-alpha and lower-latin support
They achieve the same, a list which markers are lowercase (latin)
characters.
2021-04-29 10:43:33 +02:00
Tobias Christiansen
0983cd9243 LibWeb: Add list-style-type: decimal-leading-zero support
This doesn't exactly do what you would think from its name: It surely
adds an extra leading zero to the front of a number, but only if the
number is less than 10. CSS is weird sometimes.
2021-04-29 10:43:33 +02:00
Andreas Kling
b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Timothy Flynn
5de0e0068c LibWeb: Support two-value background-repeat
The background-repeat value may be specified as either one- or two-value
identifiers (to be interpreted as horizontal and vertical repeat). This
adds two pseudo-properties, background-repeat-x and background-repeat-y,
to handle this. One-value identifiers are mapped to two-value in
accordance with the spec.
2021-04-05 18:49:04 +02:00
Timothy Flynn
bd5a91269f LibWeb: Store computed CSS value of background-repeat 2021-04-03 11:24:33 +02:00
Adam Hodgen
e169e24104 LibWeb: Parese the CSS "cursor" property 2021-02-28 18:19:52 +01:00
Andreas Kling
21371bf6ee LibWeb: Add parsing and application of CSS "overflow" property
We don't actually do anything with the values yet, but now they are
available for layout nodes once we are ready to implement them.
2021-02-22 15:21:42 +01:00
Andreas Kling
149f10b0b9 LibWeb: Parse the CSS "flex-direction" property 2021-01-18 20:20:16 +01:00
Andreas Kling
140463e833 LibWeb: Parse "display: flex" and create BlockBox layout nodes for them
I'm not 100% sure that BlockBox is the right layout node for flex
containers, but it's the most obviously fitting one we already have.
2021-01-18 20:20:00 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00