Commit graph

209 commits

Author SHA1 Message Date
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
Sam Atkins
608bfac2a9 LibWeb: Implement CSS Time class
This corresponds to `<time>` in the grammar.
2022-02-24 08:04:25 +01:00
Sam Atkins
0465abcfec LibWeb: Implement CSS Resolution class
This corresponds to `<resolution>` in the grammar.
2022-02-24 08:04:25 +01:00
Sam Atkins
bd79c303f6 LibWeb: Implement CSS Frequency class
This corresponds to `<frequency>` in the grammar.
2022-02-24 08:04:25 +01:00
Sam Atkins
355d1936f2 LibWeb: Implement CSS Angle class
This corresponds to `<angle>` in the grammar.
2022-02-24 08:04:25 +01:00
Andreas Kling
bfe69e9d0d LibWeb: Cache and reuse some very common StyleValue objects
Length values: auto, 0px, 1px
Color values: black, white, transparent
2022-02-19 14:45:59 +01:00
Sam Atkins
356d8bcfe8 LibWeb: Remove Length::Type::Undefined! :^) 2022-02-18 19:04:37 +01:00
Sam Atkins
1093d6e2c3 LibWeb: Use a Variant for calc() percentage_basis
Depending on the type of the calc() expression, the percentage_basis has
to be the same dimension type. Several places were already passing `
{}` for this, so let's make that an empty Variant instead of an
undefined Length. :^)
2022-02-18 19:04:37 +01:00
Sam Atkins
e5b0369dfd LibWeb: Parse spread-distance and inset parts of box-shadow
We do not actually use these when rendering the shadow yet.
2022-02-08 17:45:51 +01:00
Sam Atkins
cbdbe0c5a2 LibWeb: Implement CalculatedStyleValue::to_string() 2022-02-04 13:52:02 +01:00
Sam Atkins
714832e705 LibWeb: Distinguish between Integer and Number calc() values 2022-02-04 13:52:02 +01:00
Sam Atkins
2407a03fd9 LibWeb: Add resolving calc() to a number/integer/percentage
None of these require any outside metrics, which is nice! I believe the
Values-4 spec would have us simplify them down into a single value at
parse time, but that's a yak for another day.
2022-02-04 13:52:02 +01:00
Sam Atkins
b54cd17c1e LibWeb: Allow percentage tokens again when parsing calc()
I unintentionally broke this in my LengthPercentage PR, but it was not
convenient to fix until now.
2022-02-04 13:52:02 +01:00
Sam Atkins
f0fb84dfcb LibWeb: Refactor calc() resolution logic using CalculationResult
The previous static functions are now methods of their respective
CalcFoo structs, but the logic has not changed, only that they work
with CalculationResults instead of converting everything to floats.
2022-02-04 13:52:02 +01:00
Sam Atkins
35f64af3a4 LibWeb: Implement CalculationResult type for calc() results
calc() sub-expressions can return a variety of different types, which
then can be combined using the basic arithmetic operators. This class
should make that easier to deal with, instead of having to handle all
the possible combinations at each call site. :^)

We take the Layout::Node as a pointer not a reference, since later we'll
need to call these functions when resolving to `<number>` or `<integer>`
which don't use those, and we don't want to force users to pass them in
unnecessarily.
2022-02-04 13:52:02 +01:00
Sam Atkins
b69f6097de LibWeb: Resolve type of calc() expressions at parse-time
See https://www.w3.org/TR/css-values-3/#calc-type-checking

If the sub-expressions' types are incompatible, we discard the calc() as
invalid.

Had to do some minor rearranging/renaming of the Calc structs to make
the `resolve_foo_type()` templates work too.
2022-02-04 13:52:02 +01:00
Sam Atkins
b818d952d1 LibWeb: Combine the two sets of calc() operator enums 2022-02-04 13:52:02 +01:00
Sam Atkins
db04b5687d LibWeb: Move calc()-resolution code from Length to CalculatedStyleValue
The code is unchanged, just moved.
2022-02-04 13:52:02 +01:00
Sam Atkins
181d1e2dd6 LibWeb: Implement TransformationStyleValue::to_string() 2022-02-03 00:45:49 +01:00
Sam Atkins
5826fe094f LibWeb: Allow comma- or space-separated StyleValueLists
This lets us produce valid CSS in its to_string() method, instead of
always adding commas as before. :^)

Also, finally added a Formatter for StyleValues.
2022-02-03 00:45:49 +01:00
Sam Atkins
f71db4afd8 LibWeb: Make StyleValue::to_string() output valid CSS
Having clear debug output was useful, but most places that use to_string
() expect to get valid CSS, so let's do that. :^)
2022-02-03 00:45:49 +01:00
Sam Atkins
f22d8c8f77 LibWeb: Move non-trivial StyleValue to_string() methods to cpp file
Many of these will need to change in the future in order to include
features we don't yet support, and touching StyleValue.h is a great way
to have to wait for all of LibWeb to rebuild. I'm hoping this saves me
time in the long run. :^)
2022-02-03 00:45:49 +01:00
Sam Atkins
ea0f6b42f0 LibWeb: Add PercentageStyleValue, and parse it
This is in a slightly weird state, where Percentages are sometimes
Lengths and sometimes not, which I will be cleaning up in subsequent
commits, in an attempt not to change all of LibWeb in one go. :^)
2022-01-20 00:04:10 +01:00
Sam Atkins
c9062b4ed5 LibWeb: Remove now-unused CustomStyleValue 2021-12-09 21:30:31 +01:00
Sam Atkins
000fb5a70d LibWeb: Add new UnresolvedStyleValue class
This represents a property value that hasn't been converted to a
"proper" StyleValue yet. That is, it's either a custom property's value,
or a value that includes `var()` references, (or both!) since neither of
those can be fully resolved at parse time.
2021-12-09 21:30:31 +01:00
Andreas Kling
7c57961c61 LibWeb: Move BrowsingContext into HTML/
Browsing contexts are defined by the HTML specification, so let's move
them into the HTML directory. :^)
2021-11-18 21:11:30 +01:00
Sam Atkins
c052457498 LibWeb: Bring BackgroundStyleValue::to_string() to spec
This now outputs valid CSS representing the background, instead of
confusing debug info.

We can't guarantee that all the longhands have the same number of
values, since while that's always the case when parsing, we also create
BackgroundStyleValues when producing the resolved style, which just
combines the longhands together.
2021-11-17 22:20:01 +01:00
Sam Atkins
ae2a3bf185 LibWeb: Add BackgroundSizeStyleValue
There's nothing really background-size-specific about this, but since
there is no `<size>` value type defined in the CSS spec at this time,
and background-size is the only user of it, I think this name makes more
sense. But I'm not 100% convinced.
2021-11-10 14:38:49 +01:00
Sam Atkins
988a8ed3d8 LibWeb: Parse CSS background-position property
This is done a bit differently from other properties: using a
TokenStream instead of just a Vector of ComponentValues. The reason for
this is, we can then use call the same function when parsing the
`background` shorthand. Otherwise, we would have to know in advance how
many values to pass down, which basically would involve duplicating the
`background-position` parsing code inside `background`.

The StyleValue is PositionStyleValue, since it represents a
`<position>`: https://www.w3.org/TR/css-values-4/#typedef-position
Unfortunately, background-position's parsing is a bit different from
`<position>`'s, (background-position allows 3-value syntax and
`<position>` doesn't) so we'll need to come back and write a different
parsing function for that later.
2021-11-10 14:38:49 +01:00
Sam Atkins
0f393771b7 LibWeb: Move image resource request out of ImageStyleValue constructor
This always felt awkward to me, and required a few other hacks to make
it work. Now, the request is only started when `load_bitmap()` is
called, which we do inside `NodeWithStyle::apply_style()`.
2021-10-23 11:42:24 +02:00
Sam Atkins
58a0ca41a7 LibWeb: Use east const in StyleValue.{h,cpp} 2021-10-18 19:01:41 +02:00
Ben Wiederhake
c602db1620 LibWeb: Add missing headers 2021-10-06 23:52:40 +01:00
Andreas Kling
956968d4b2 LibWeb: Make ColorStyleValue serialization spec compliant
[CSS Color 4] tells us to use either rgb() or rgba() notation, depending
on the color's alpha value.
2021-10-03 17:59:15 +02:00
Andreas Kling
198bb322ef LibWeb: Fix null dereference when assigning an ImageStyleValue via JS
When parsing a CSS value in the context of a CSSStyleDeclaration
camelCase property setter, we don't necessarily have a Document to
provide the CSS parser for context.

So the parser can't go assuming that there's always a Document in the
ParsingContext. And ImageStyleValue can't go assuming that there's
always a Document either. This will require some more work to get things
right, I'm just patching up the null dereference for now.
2021-09-30 02:18:30 +02:00
Sam Atkins
4b554ba92a LibWeb: Clarify StyleValue API with new naming scheme
This does a few things, that are hard to separate. For a while now, it's
been confuzing what `StyleValue::is_foo()` actually means. It sometimes
was used to check the type, and sometimes to see if it could return a
certain value type. The new naming scheme is:

- `is_length()` - is it a LengthStyleValue?
- `as_length()` - casts it to LengthStyleValue
- `has_length()` - can it return a Length?
- `to_length()` - gets the internal value out (eg, Length)

This also means, no more `static_cast<LengthStyleValue const&>(*this)`
stuff when dealing with StyleValues. :^)

Hopefully this will be a bit clearer going forward. There are lots of
places using the original methods, so I'll be going through them to
hopefully catch any issues.
2021-09-24 15:01:43 +02:00
Sam Atkins
b927972da7 LibWeb: Add range-checking to property_accepts_value()
For `number` and `integer` types, you can add a range afterwards to add
a range check, using similar syntax to that used in the CSS specs. For
example:

```json
"font-weight": {
  ...
  "valid-types": [
    "number [1,1000]"
  ],
  ...
}
```

This limits any numbers to the range `1 <= n <= 1000`.
2021-09-23 17:47:40 +02:00
Sam Atkins
4a1dbb4f36 LibWeb: Move color identifier checking to StyleValue::is_color()
This allows us to perform this check outside of the CSS Parser.
2021-09-23 17:47:40 +02:00
Sam Atkins
17bb913625 LibWeb: Implement currentcolor special value
The `currentcolor` identifier represents the current value of the
`color` property. This is the default value for `border-color` and
`text-decoration-color`, and is generally useful to have. :^)
2021-09-17 23:06:45 +02:00
Sam Atkins
86f78bff2a LibWeb: Make StyleValue::to_color() take a Node instead of the Document
This is in preparation for the `currentcolor` value, which needs to know
what Node it's on so it can check the `color`.
2021-09-17 23:06:45 +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
dfa9dcca98 LibWeb+Browser: Remove unnecessary InProcessWebView.h includes 2021-08-24 16:37:28 +02:00