Commit graph

24 commits

Author SHA1 Message Date
Andreas Kling
f8dd3e14ba LibWeb: Rename CSS::StyleResolver => StyleComputer
Resolved style is a spec concept that refers to the weird mix of
computed style and used style reflected by getComputedStyle().

The purpose of this class is to produce the *computed* style for a given
element, so let's call it StyleComputer.
2021-09-24 15:12:15 +02:00
Andreas Kling
785ace4fc2 LibWeb: Remove on-demand font resolution
Fonts are now resolved as part of the CSS cascade.
2021-09-24 15:12:15 +02:00
Andreas Kling
23a08fd35a LibWeb: Start absolutizing lengths after performing the CSS cascade
Once we've performed the cascade on a set of values for an element,
we should have enough information to resolve/absolutize some lengths.

Basically, any CSS length that isn't "auto" or a percentage can be
turned into an absolute length (in pixels) as long as we have the
following information:

- The viewport rect
- The parent element's font
- The document element's font
- The element's own font

To ensure that we can absolutize lengths relative to the element's own
font, we now do a separate first pass where font-related properties are
defaulted (in the cascade spec sense of the word) and become usable.

There's a lot more work to do here, but this should open up a lot of
simplification in layout code, since it will no longer need to care
about relative lengths. Layout still needs to resolve percentages, since
we can't do that for some properties until the containing block
dimensions are known.
2021-09-24 15:01:49 +02:00
Andreas Kling
d965a9552f LibWeb: Start implementing the CSS cascade
The 'C' in "CSS" is for Cascade, so let's actually implement the cascade
in LibWeb. :^)

StyleResolver::resolve_style() now begins by collecting all the matching
CSS rules for the given DOM::Element. Rules are then processed in the
spec's cascade order (instead of in the order we encounter them.)

With this, "!important" is now honored on CSS properties.

After performing the cascade, we do another pass of what the spec calls
"defaulting" where we resolve "inherit" and "initial" values.
I've left a FIXME about supporting correct "initial" values for every
property, since we're currently lacking some coverage there.

Note that this mechanism now resolves every known CSS property. This is
*not* space-efficient and we'll eventually need to come up with some
strategies to reduce memory usage around this. However, this will do
fine until we have more of the engine working correctly. :^)
2021-09-21 12:49:28 +02:00
Tobias Christiansen
9ebfafafbe LibWeb: Add transform property to the system
This patch adds parsing support as well as all the needed stuctures all
over LibWeb to pass Transformations around.
2021-09-18 21:53:37 +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
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
Andreas Kling
cf8f1c5a5f LibWeb: Remove unused CSS::StyleProperties::string_or_fallback() 2021-08-26 13:25:52 +02:00
Sam Atkins
8c39fee34d LibWeb: Handle non-px font sizes
The previous code assumed all font sizes were in px, but now we perform
the conversion. There is an existing bug with em sizes returning 0,
which seems to affect other places too - see
`NodeWithStyle::apply_style()`.

This also implements 'larger', 'smaller' and calc() font-sizes.
2021-08-18 10:32:32 +02:00
Tobias Christiansen
f1bdaafcf6 LibWeb: Make box-shadow known throughout the CSS subsystem
This patch spreads box-shadows around:
- The Values important to box-shadows are stored in a BoxShadowData
  struct
- StyleProperties knows how to construct such a struct from a
  BoxShadowStyleValue and a Node knows how to ask for it
- CalculatedValues contain BoxShadowData and expose them
2021-07-24 22:16:48 +02:00
Egor Ananyin
0e6ba6e1d3 LibWeb: Parse and store the opacity property 2021-07-24 22:02:28 +04:30
Tobias Christiansen
80a44c3891 LibWeb: Add parsing for the justify-content property 2021-07-19 18:47:09 +04:30
Tobias Christiansen
ae61e9ded2 LibWeb: Add flex-grow and flex-shrink
They get parsed and are available to the programmer of Layouts :^)
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
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
Simon Danner
c8d56ee4f4
LibWeb: Improve fallback font selection
Try to find a font that has at least some of the requested properties.
This makes e.g. rfcs on tools.ietf.org easier to read since their
headers are now bold.
2021-04-22 20:47:47 +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
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Renamed from Libraries/LibWeb/CSS/StyleProperties.h (Browse further)