Commit graph

304 commits

Author SHA1 Message Date
Andreas Kling
1c0fc75cb6 LibWeb: Fix bogus condition when checking CSS font file extensions
Thanks Idan for pointing this out! :^)
2022-09-15 01:20:35 +02:00
Andreas Kling
6d92c1d231 LibWeb: Be slightly better at @font-face rules with multiple sources
This patch improves @font-face loading when there are multiple src
values in two ways:

- Invalid/empty URLs are ignored
- Fonts with unsupported file extensions are ignored

This makes us load and display the emblem font on modern Reddit,
which is pretty neat! :^)
2022-09-14 21:46:34 +02:00
Andreas Kling
f64c175960 LibWeb: Invalidate layout whenever a CSS font is loaded
It's not enough to invalidate only the style, we have to do a full
layout invalidation since new fonts might mean new metrics, etc.
2022-09-14 21:24:31 +02:00
Andreas Kling
524ec95bcd LibWeb: Keep CSS sheets sorted in document tree order
This ensures that style is applied consistently, even if the document
has external CSS resources that don't always arrive in the same order.
2022-09-09 15:20:10 +02:00
Andreas Kling
8f0a48ef23 LibWeb: Make default CSS font settings match other browsers better
Let's make 16px the default font size instead of 10px. This makes our
layout results match those of other engines in many more cases.

Also make the h1-h6 element styles use relative (em) font sizes, also
matching other browsers.
2022-09-08 12:43:49 +02:00
Andreas Kling
5c2e3d1637 LibWeb+WebContent: Add abstraction layer for generic font families
Instead of hard-coding the names of system fonts to use for the CSS
generic fonts (like "sans-serif", "monospace", etc.) we now call out
to a Platform::FontPlugin and ask for the generic names.
2022-09-08 11:57:03 +02:00
Andreas Kling
12042f0757 LibWeb: Make CSSRule and all its subclasses GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
5366924f11 LibWeb: Make StyleSheetList GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
5d60212076 LibWeb: Make StyleSheet and CSSStyleSheet GC-allocated 2022-09-06 00:27:09 +02:00
martinfalisse
7bb3a8d646 LibWeb: Parse grid-column and grid-row CSS values 2022-08-25 13:47:48 +02:00
Andreas Kling
cf4b7e343a LibWeb: Blockify inline-flex to flex
Previously, `inline-flex` would blockify to `block` since blockification
didn't take the inner display type into account. This is still not
perfect, but it fixes a lot of situations where inline-level flex
containers would be demoted to regular block containers.
2022-07-19 15:40:41 +02: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
Sam Atkins
ce5914230f LibWeb: Actually use BorderRadiusShorthandStyleValue
Somehow we were never actually using this before, but parsing the
property as a StyleValueList instead.
2022-04-18 21:30:51 +02:00
Sam Atkins
e941f07931 LibWeb: Make StyleProperties::property() always return a value
By the time that property() gets called, we've already given every
single property a value, so we can just return it. This simplifies a
lot of places that were manually handling a lack of value
unnecessarily.
2022-04-14 14:54:06 +02:00
Sam Atkins
d67e817d8e LibWeb: Break friendship between CSS Function and Parser
Again, this means deviating from the spec by creating a complete
Function in one go instead of creating it empty and then poking at its
internals.
2022-04-12 23:03:46 +02:00
Sam Atkins
f235da27d9 LibWeb: Break friendship between CSS Block and Parser
This means deviating a little from the spec, so that we create a
complete Block in one go instead of creating an empty one and then
poking at its internals.
2022-04-12 23:03:46 +02:00
Sam Atkins
bf786d66b1 LibWeb: Move Token and Tokenizer into Parser namespace 2022-04-12 23:03:46 +02:00
Sam Atkins
3e49036edf LibWeb: Move/rename StyleBlockRule to Parser::Block 2022-04-12 23:03:46 +02:00
Sam Atkins
e0b2ebcc7b LibWeb: Move/rename StyleFunctionRule to Parser::Function 2022-04-12 23:03:46 +02:00
Sam Atkins
fff2c35f51 LibWeb: Move ComponentValue to CSS::Parser namespace 2022-04-12 23:03:46 +02:00
Sam Atkins
c449cabae3 LibWeb: Move CSS Parser into new Web::CSS::Parser namespace
The goal here is to move the parser-internal classes into this namespace
so they can have more convenient names without causing collisions. The
Parser itself won't collide, and would be more convenient to just
remain `CSS::Parser`, but having a namespace and a class with the same
name makes C++ unhappy.
2022-04-12 23:03:46 +02:00
Andreas Kling
751b605690 LibWeb: Cache scaled web fonts instead of recreating them every time
Previously, we would create a new Gfx::ScaledFont whenever we needed one
for an element's computed style. This worked fine on Acid3 since the use
of web fonts was extremely limited.

In the wild, web fonts obviously get used a lot more, so let's have a
per-point-size font cache for them.
2022-04-10 12:40:07 +02:00
Simon Wanner
539adf5b9c LibWeb: Support WOFF in font-face 2022-04-09 23:48:18 +02:00
Simon Wanner
f386b0d43c LibWeb: Migrate SC::FontLoader from TTF::Font to Gfx::VectorFont 2022-04-09 23:48:18 +02:00
Simon Wanner
5136c5ae1a LibGfx: Move ScaledFont and new base class VectorFont out of TTF 2022-04-09 23:48:18 +02:00
Simon Wanner
206d6ece55 LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
Simon Wanner
6f8fd91f22 LibGfx: Move TTF files from TrueTypeFont/ to Font/TrueType/ 2022-04-09 23:48:18 +02:00
Andreas Kling
6e70670e0b LibWeb: Load fonts from style sheet once when sheet is added
Previously, we were running the "load fonts if needed" machine at the
start of every style computation. That was a lot of unnecessary work,
especially on sites with lots of style rules, since we had to traverse
every style sheet to see if any @font-face rules needed loading.

With this patch, we now load fonts once per sheet, right after adding
it to a document's style sheet list.
2022-04-08 21:27:35 +02:00
Sam Atkins
8b538b1578 LibWeb: Rename StyleComponentValueRule -> ComponentValue
"Component value" is the term used in the spec, and it doesn't conflict
 with any other types, so let's use the shorter name. :^)

Also, this doesn't need to be friends with the Parser any more.
2022-04-07 21:20:14 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Sam Atkins
05bd0ca3ee LibWeb: Rename parse_css() -> parse_css_stylesheet() 2022-03-30 18:43:07 +02:00
Simon Wanner
6437f5da36 LibWeb: Add basic support for the attr() CSS function
CSS Values and Units Module Level 5 defines attr as:
  `attr(<q-name> <attr-type>?, <declaration-value>?)`

This implementation does not contain support for the type argument,
effectively supporting `attr(<q-name>, <declaration-value>?)`
2022-03-30 03:18:14 +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
Andreas Kling
2f7b6af87e LibGfx: Remove code point parameter from Gfx::Font::Metrics
Everyone was asking for the glyph width of 'M' anyway. We can just make
that request implicit and simplify the API.
2022-03-30 00:57:15 +02:00
Andreas Kling
1f9aed2617 LibWeb: Load and use fonts described by @font-face rules :^)
When encountering a @font-face rule, StyleComputer will now fire off
a resource request and download the first source URL specified.

Once downloaded, we try to parse it as a TrueType font file, and if it
works, it's added to a cache in StyleComputer. This effectively makes
fonts per-document since every document has its own StyleComputer.

This is very unoptimized and could definitely use some caching, etc.
But it does work on Acid3. :^)
2022-03-29 02:14:20 +02:00
Andreas Kling
d5bba91a16 LibWeb: Don't round font sizes when looking them up
We previously had a rounding error which sometimes led to asking LibGfx
for fonts with slightly wrong sizes.
2022-03-27 01:14:56 +01:00
Karol Kosek
44bfca369a LibWeb: Resolve style values from the element inline style
This will set the background color in the project header on GitHub! :^)
2022-03-26 17:30:49 +01:00
Karol Kosek
0934573deb LibWeb: Set CSS custom properties from the element inline style 2022-03-26 17:30:49 +01:00
Andreas Kling
632928a11e LibWeb: Pass font sizes in pt rather than px to Gfx::FontDatabase
Our font database uses point sizes for fonts, and we were passing it
px sizes. This caused all fonts to be 1.333x larger than they should
be on the web. Of course it wasn't always noticeable with bitmap fonts,
but noticeable everywhere with scalable fonts.
2022-03-23 14:13:15 +01:00
Sam Atkins
c0db19f63c LibWeb: Use a Variant for SimpleSelector's contents
This reduces SimpleSelector's size from 112 bytes to 80 bytes. :^)
2022-03-22 15:47:36 +01:00
Andreas Kling
aa45cdf71d LibWeb: Give StyleComputer a helper for getting the current viewport 2022-03-19 22:04:43 +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
Andreas Kling
6ad8330102 LibWeb: Make parent- and root-relative font-size work better
Relative font-sizes like "2em" were previously resolved against the
fallback value (10px) which led to incorrect layouts in many places.

Fix this by resolving relative font-sizes against the absolutized
font-size of the parent or root element as appropriate.
2022-03-16 12:52:46 +01:00
Andreas Kling
e31fe3eeb8 LibWeb: Rename Element::specified_css_values() => computed_css_values()
Let's make it very clear that these are *computed* values, and not at
all the specified values. The specified values are currently discarded
by the CSS cascade algorithm.
2022-03-15 19:48:19 +01:00
Andreas Kling
759bfbb572 LibWeb: Use StyleComputer::invalidate_rule_cache() directly everywhere
Get rid of the old, roundabout way of invalidating the rule cache by
incrementing the StyleSheetList "generation".

Instead, when something wants to invalidate the rule cache, just have it
directly invalidate the rule cache. This makes it much easier to see
what's happening anyway.
2022-03-15 19:48:19 +01:00
Andreas Kling
511d4951b0 LibWeb: Don't access layout nodes in StyleComputer
Style computation always happens *before* layout, so we can't rely on
things having (or not having) layout nodes, as that information will
always be one step behind.

Instead, we have to use the DOM to find all the information we need.
2022-03-15 19:48:19 +01:00
Andreas Kling
c1e6fc67a1 LibWeb: Add a Vector::ensure_capacity() in collect_matching_rules()
Avoid some incremental Vector growth by pre-allocating enough capacity
to cover the case where every single selector matches an element.
2022-03-13 19:55:08 +01:00
Andreas Kling
39389b5704 LibWeb: Don't make deep copy of custom properties for every element
Previously we were making a copy of the full set of custom properties
that applied to a DOM element. This was very costly and dominated the
profile when mousing around on GitHub.

Note that this may break custom properties on pseudo elements a little
bit, and that's something we'll have to look into.
2022-03-13 18:09:43 +01:00
Andreas Kling
4a14c4dae8 LibWeb: Support the CSS 'unset' value
This works as 'inherit' for inherited properties and 'initial' for
everything else.
2022-03-13 00:04:51 +01:00
Andreas Kling
d201378750 LibWeb: Apply non-CSS presentational hints before author styles
According to css-cascade-4, we should apply presentational hints from
content attributes *before* author styles.
2022-03-13 00:04:51 +01:00