Commit graph

1753 commits

Author SHA1 Message Date
Andreas Kling
d54cd23615 LibWeb: Never blockify HTML <br> elements
This is a bit iffy, but since <br> elements can't be implemented in
"just CSS" today, we should also exclude them from the blockification
algorithm. This is important, since <br> is expected to always have
inline-like behavior.
2023-09-01 12:45:38 +02:00
Zaggy1024
709767cc4b LibWeb: Don't convert to floating point in CSS::EdgeRect 2023-09-01 09:40:14 +02:00
Andrew Kaster
da060eedb1 LibWeb: Create IdentifierStyleValue for fit-content size declarations
This doesn't quite resolve the FIXME, because we still don't support the
fit-content(percentage) syntax.
2023-08-31 10:57:44 +02:00
Aliaksandr Kalenik
0fb571c1c2 LibWeb: Add Length::resolved() overload for CSSPixels
Since we always pass the px value as an argument to resolved(), we can
pass it directly as CSSPixels instead of wrapping it in Length. This
approach allows us to avoid converting to a double, resulting in fewer
precision issues.
2023-08-30 20:09:15 +02:00
Ali Mohammad Pur
ba4db899d4 LibSyntax+Userland: Make LibSyntax not depend on LibGUI
This moves some stuff around to make LibGUI depend on LibSyntax instead
of the other way around, as not every application that wishes to do
syntax highlighting is necessarily a LibGUI (or even a GUI) application.
2023-08-29 07:57:39 -04:00
Shannon Booth
f3e5335096 LibWeb: Port CSSKeyframeRules interface from DeprecatedString to String 2023-08-29 10:05:02 +02:00
Shannon Booth
15334a68df LibWeb: Port CSSKeyframesRules interface from DeprecatedString to String 2023-08-29 10:05:02 +02:00
Shannon Booth
cf733d309e LibWeb: Port CSSConditionRule interface from DeprecatedString to String 2023-08-29 10:05:02 +02:00
Shannon Booth
ff45874d4e LibWeb: Port MediaList interface from DeprecatedString to String 2023-08-29 10:05:02 +02:00
Aliaksandr Kalenik
b66f65dc9e LibWeb: Define if identifier represent area or line during layout [GFC]
This fixes regression introduced in
c03e025a32 by assuming that it is
possible to determine whether identifier stands for line or area
during parsing.
2023-08-28 09:19:41 +02:00
MacDue
71baa8c31a LibWeb: Add CSSPixels::nearest_value_for(FloatingPoint)
This is intended to annotate conversions from unknown floating-point
values to CSSPixels, and make it more obvious the fp value will be
rounded to the nearest fixed-point value.
2023-08-26 23:53:45 +02:00
MacDue
360c0eb509 LibWeb: Remove implicit conversion from float and double to CSSPixels
In general it is not safe to convert any arbitrary floating-point value
to CSSPixels. CSSPixels has a resolution of 0.015625, which for small
values (e.g. scale factors between 0 and 1), can produce bad results
if converted to CSSPixels then scaled back up. In the worst case values
can underflow to zero and produce incorrect results.
2023-08-26 23:53:45 +02:00
Timothy Flynn
7df48756d6 LibWeb: Use SystemColor::button_text for ButtonText CSS values 2023-08-26 19:24:22 +02:00
Sam Atkins
240ec9aeed LibWeb: Treat invalid StyleValues that included var() as unset
This means StyleComputer::resolve_unresolved_style_value() always
returns a value, so we can change its return type.

However, it does still return an UnresolvedStyleValue sometimes, so we
can't remove those checks from the user code.
2023-08-26 15:33:45 +01:00
Aliaksandr Kalenik
c03e025a32 LibWeb: Disambiguate GridTrackPlacement API
- Ambiguous `raw_value()` method is replaced with `line_number()` and
  `span()`.
- `line_name()` that before returned either line name or area name is
  replaced with `line_name()` and `area_name()`.
- `Position` type is replaced with `Line` and `Area` type so we don't
   have to guess while doing layout.

Affected test expectations:
- `template-lines-and-areas` - improvement over what we had before.
- `named-tracks` - rebaseline a giant test. will have to split it into
  smaller tests in the future.
2023-08-26 13:16:17 +02:00
Andreas Kling
c6cb876851 LibWeb: Use a serif font in the default UA style sheet
This matches how most/all other browsers behave today.
2023-08-26 12:13:00 +02:00
Sam Atkins
cd273f2312 LibWeb: Use system-color keywords in Default.css 2023-08-25 20:30:20 +01:00
Sam Atkins
848ec538c6 LibWeb: Implement <system-color> and <deprecated-color> keywords
The spec allows for these either to be based on the OS, or to be defined
by the browser. Looking at the other browser engines, there's a mix of
the two options. Since we've had issues with using OS colors as
defaults, let's use hard-coded colors for now. Some of these are based
on the definitions in
https://html.spec.whatwg.org/multipage/rendering.html
2023-08-25 20:30:20 +01:00
Sam Atkins
1dcd63be05 LibWeb: Deduplicate "ident is color" check
Reuse the check from IdentifierStyleValue in the CSS Parser, instead of
duplicating it. This might not be the ideal place to put it, but it
works for now.
2023-08-25 20:30:20 +01:00
Andreas Kling
b63e393cef LibWeb: Fix broken conversion of CSS <resolution> dpi/dpcm to dppx
Also add a basic test that documents how these media features currently
get serialized, even if they're not identical to other browsers yet.
2023-08-25 20:10:47 +02:00
Andreas Kling
13e2ca6b59 LibWeb: Parse src: local(...) in CSS @font-face rules
Note that we don't load the local font as specified, but at least we no
longer reject such src properties in the CSS parser.

This makes the custom fonts used on http://apple.com/ actually load. :^)
2023-08-25 11:51:28 +02:00
Andreas Kling
e924ea002f LibWeb: Add Referer HTTP header to CSS font requests
If we don't do this, we just get 404 Not Found for all fonts used by
https://apple.com/
2023-08-25 11:51:28 +02:00
Sam Atkins
565ed9b06c LibWeb: Comment out invalid display-outside rules from Default.css
This property was removed from the CSS specs, and efforts to correct the
HTML spec have stalled. For now, let's comment them out so that I don't
get spammed with the meaningless log warnings that they didn't parse,
every time I launch Ladybird. :^)
2023-08-24 22:51:11 +01:00
Andreas Kling
418f9ceadd LibWeb: Invalidate font cache when web fonts are downloaded
In case we've looked up the family name before and cached the result of
font fallback, we now invalidate any cached entries with the same family
name so that the next lookup may consider the newly downloaded font.
2023-08-24 22:07:00 +01:00
Andreas Kling
7cd975268c LibWeb: Use Gfx::FontDatabase::for_each_typeface_with_family_name()
This avoids looking at every single installed typeface to see if there's
a family name match.

Fixes a large performance regression introduced when making
StyleComputer consider system fonts in CSS font fallback.

Regressed with 69a81243f5.
2023-08-24 14:58:22 +02:00
Aliaksandr Kalenik
5896c0ed06 LibWeb/CSS: Set "inherited" to false for "clip" property
"clip" should not be inherited.
2023-08-23 15:49:06 +02:00
Sam Atkins
6dcd8d4a2c LibWeb: Add support for "User" CascadeOrigin
User styles are applied after the UserAgent's built-in styles, and
before the Author styles that are part of the web page.

Because they're neither part of the page, but can still be modified
while the page is open, caching is a little tricky. The approach here
is to piggy-back on the StyleComputer's rule caches, which already get
rebuilt whenever the styles change. This is not the smartest approach,
since it means re-parsing the style sheet more often than is necessary,
but it's simple and works. :^)
2023-08-23 05:32:10 +02:00
Sam Atkins
7bc5949e35 LibWeb: Implement the :placeholder-shown pseudo-class
This matches if the element has a placeholder, and that placeholder is
currently visible. This applies to `<input>` and `<textarea>` elements,
but our `<textarea>` is very limited so does not support placeholders.
2023-08-23 05:30:59 +02:00
Sam Atkins
9f5b1e6614 LibWeb: Implement the :read-only and :read-write pseudo-classes 2023-08-23 05:30:59 +02:00
Sam Atkins
3d10bf3ae7 LibWeb: Implement the :target-within pseudo-class selector
As noted in a9620d8784 we don't currently
set the target element so this does not function, so no tests. But it
should work once we have a fleshed out Navigables implementation. :^)
2023-08-23 05:30:59 +02:00
Sam Atkins
3af8b491b4 LibWeb: Implement :any-link and :local-link pseudo-class selectors
`:any-link` matches links, whether they have been visited or not.

`:local-link` matches links to the current URL.
2023-08-23 05:30:59 +02:00
Sam Atkins
c171810030 LibWeb: Make CalculatedStyleValue::dump() infallible 2023-08-22 17:51:48 +01:00
Sam Atkins
7fe97ee6c5 LibWeb: Make StyleValue::to_string() infallible 2023-08-22 17:51:48 +01:00
Sam Atkins
ccfe197e5a LibWeb: Make serializing CSS Parser types infallible 2023-08-22 17:51:48 +01:00
Sam Atkins
846c719e49 LibWeb: Make serializing Supports rules infallible 2023-08-22 17:51:48 +01:00
Sam Atkins
91114c157b LibWeb: Make serializing selectors infallible 2023-08-22 17:51:48 +01:00
Sam Atkins
afa27bad19 LibWeb: Make serializing media-queries infallible 2023-08-22 17:51:48 +01:00
Sam Atkins
2754c16e97 LibWeb: Make serializing GridTrack classes infallible 2023-08-22 17:51:48 +01:00
Sam Atkins
6bee81cfb6 LibWeb: Make serializing basic CSS types infallible 2023-08-22 17:51:48 +01:00
Sam Atkins
b5893ee115 LibWeb: Make Serialize functions infallible 2023-08-22 17:51:48 +01:00
Sam Atkins
b8e694c0f2 LibWeb: Implement the :dir() selector pseudo-class 2023-08-21 13:51:56 +02:00
Sam Atkins
5b125811f1 LibWeb: Add support for pseudo-class functions that take an ident param
This is prep work for `:dir()`, though other pseudo-classes may well use
it in the future too.
2023-08-21 13:51:56 +02:00
Sam Atkins
a48b2c1c66 LibWeb: Fill in missing kinds of calc() expansion in StyleComputer
This is all of them currently, except Length, because we lack the needed
information to be able to expand font-relative lengths.

The whole way `expand_unresolved_values()` works is awkward, but at some
point we'll be able to run the simplification algorithm on the
calculation, which will either return a single value, or a new
calculation that's simplified as much as possible.

Mostly I just wanted that FIXME log message to go away, because it's
overwhelming on certain sites.
2023-08-20 19:38:03 +02:00
Sam Atkins
2c7603f2ae LibWeb: Add helper for creating <dimension> CSS tokens 2023-08-20 19:38:03 +02:00
Andreas Kling
27ddfa84fa LibWeb: Accept height: {min,max,fit}-content
And treat them as "auto" for now, per CSS-SIZING-3, with a FIXME about
supporting more layout directions.

This fixes an issue on MDN where `height: max-content` was not
overriding height from non-CSS presentational hints.
2023-08-20 19:37:50 +02:00
Andreas Kling
90e95d38d7 LibWeb: Make align-items: normal behave like stretch on flex items
CSS-ALIGN-3 tells us that `normal` behavior inside flex containers is
simply to behave as `stretch` so this patch makes them behave the same
inside FFC.

Furthermore, we change the `align-items` initial value to `normal`,
matching other engines.
2023-08-20 19:37:50 +02:00
Sam Atkins
6367b6a3d0 LibWeb: Use x-macro for StyleValue::Type instead of manual boilerplate
This saves us from having to manually write these every time we add a
new type of StyleValue:

- bool is_foo() const;
- FooStyleValue const& as_foo() const;
- FooStyleValue& as_foo();
2023-08-20 17:59:36 +02:00
Sam Atkins
fae05faf7f LibWeb: Rename StyleValue::Type::Url -> URL
This matches the URLStyleValue name. (This will be important shortly.)
2023-08-20 17:59:36 +02:00
Andreas Kling
703c2bb06e LibWeb: Add support for parsing grid-auto-flow CSS property
Co-Authored-By: Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
2023-08-20 15:36:18 +02:00
Sam Atkins
1a5533e528 LibWeb: Tokenize CSS numbers as doubles
Every later stage uses doubles, so dropping that precision right at the
start of parsing is a little silly. :^)
2023-08-20 14:25:18 +01:00