summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS
AgeCommit message (Collapse)Author
2021-08-07LibWeb: Add auto as a recognized argument of flex-basisTobias Christiansen
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-04LibWeb: Fix EOF handling in CSS Tokenizer peek_{twin,triplet}()Sam Atkins
Previously, the loops would stop before reaching EOF, meaning that the values that should have been set to EOF were left with their 0 initial values. Now, we initialize to EOFs instead. The if/else inside the loops always ran the else branch so I have removed the if branches.
2021-08-02LibWeb: Switch to new CSS Parser :^)Sam Atkins
Change all the places that were including the deprecated parser, to include the new one instead, and then delete the old parser code. `ParentNode::query_selector[_all]()` now treat their input as a comma-separated list of selectors, instead of just one, and return elements that match any of the selectors in that list. This is according to these specs: - querySelector/querySelectorAll: https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselector%E2%91%A0 - selector matching algorithm: https://www.w3.org/TR/selectors-4/#match-against-tree
2021-08-02LibWeb: Implement CSS parsing convenience functionsSam Atkins
These mostly match the API in `DeprecatedCSSParser.h`. The exception is that `parse_selector()` returns a `SelectorList` instead of just one `Selector`. The only uses of that are in `ParentNode::query_selector[_all]()` which should be matching against a list, according to the spec. `parse_html_length()` is an odd case. It's used for `width="200"` cases in HTML, so is not really CSS related, but does produce a StyleValue. The values allowed in `width/height` in HTML vary per element, but they are a lot more restricted than in CSS, so it's slightly inappropriate to use the CSS parser for them, even though it's convenient. We also ignore a few functions: - `parse_line_width()` - `parse_line_style()` - `parse_color()` These are all only used in `StyleResolver`, when it is given a property value as a String. That won't happen once the old parser is removed.
2021-08-02LibWeb: Clarify naming and publicity of CSS Parser methodsSam Atkins
`parse_as_foo()` implies that the Parser's internal data is used, whereas `parse_a_foo()` implies that the passed-in data is used. Also, made all the `parse_a_foo()` methods private, as they are only required within the Parser, and this makes the API clearer to outsiders. The `parse_a(s)_foo()` naming is a little awkward, but it comes from section 5.3 of the spec, so seemed worth keeping: https://www.w3.org/TR/css-syntax-3/#parser-entry-points
2021-08-02LibWeb: Only dump parsed CSS stylesheet if logging is enabledSam Atkins
2021-08-01LibWeb: Remove unused header includesBrian Gianforcaro
2021-07-31LibWeb: Ignore unquoted data urls in CSSSam Atkins
Previously we were only ignoring quoted ones (eg `url("data:...")`), so now we ignore unquoted ones (eg `url(data:...)`) too.
2021-07-31LibWeb: Parse calc() values in new CSS ParserSam Atkins
This is a port of the code from DeprecatedCSSParser, to work with CSS Tokens and TokenStream. I've modified it as little as possible.
2021-07-31LibWeb: Treat CSS calc() values as "builtin_or_dynamic"Sam Atkins
2021-07-31LibWeb: Allow peeking more than 1 token ahead in CSS ParserSam Atkins
2021-07-31LibWeb: Parse box-shadow property in new CSS ParserSam Atkins
Previous multi-value properties use a ValueListStyleValue, which then gets parsed into its sub-properties in the StyleResolver. However, that is not ideal, especially as it exposes StyleResolver to the inner workings of the Parser and Tokenizer, which it should not need to know about. The way `box-shadow` was implemented as a StyleValue subclass means that the parsing can happen inside the Parser instead, which seems like a better solution. Converting the other complicated cases (background, font, list-style) is on my todo list for later.
2021-07-31LibWeb: Convert CSS parse_{color,length}() lambdas into methodsSam Atkins
This lets us get the Length and Color values directly, without having to create a StyleValue object and then throw it away again, when parsing the box-shadow property in the next commit.
2021-07-31LibWeb: Fix issues with CSS attribute selector handlingSam Atkins
This is three small, related changes: 1. Element::has_attribute() now returns true if the attribute exists but has no value. (eg, `<div foo />` -> `has_attribute("foo")`) 2. SelectorEngine::matches_attribute() now makes sure there is a first segment before comparing it, fixing a crash. 3. CSS::Parser now converts attribute names in attribute selectors to lowercase, to match the expectations of the rest of the system. Converting to lowercase is not always correct, depending on language, but since we only currently support HTML, and that expects them to be case-insensitive, it is fine for now.
2021-07-31LibWeb: Make CSS 'An+B' parsing spec-compliantSam Atkins
Parsing this pattern from CSS tokens turns out to be slightly crazy, but thankfully well documented in the spec. The spec lists the cases in order of simple -> complicated, but this would cause problems in code, since `<n-dimension> <signed-.integer>` would never by reached, as `<n-dimension>` comes before. Instead, I have grouped them by their first token. Also renamed the NthChildPattern class to ANPlusBPattern, to match spec terminology.
2021-07-31LibWeb: Parse CSS selectors according to the specSam Atkins
The spec does not directly tell us how to parse selectors, so there are likely some bugs here, but I've used the spec language where possible. This is very much based on the previous selector parsing code. Any parse error inside a selector makes the entire SelectorList invalid, so nothing is returned.
2021-07-31LibWeb: Bring Selector terminology in line with the CSS specSam Atkins
- CompoundSelector -> *deleted* - ComplexSelector -> CompoundSelector - Relation -> Combinator Our Selector is really a ComplexSelector, but only the Parser and SelectorEngine need to know that, so keeping it named Selector makes it more understandable for users. Our CompoundSelector is really a CompoundSelectorAndCombinator. Combining the two makes sense in our codebase, but the accurate name is so long that I think it makes the code less readable. Renamed some Combinators to also match the spec terminology: - AdjacentSibling -> NextSibling - GeneralSibling -> SubsequentSibling The previous names are somewhat ambiguous, so hopefully this is clearer.
2021-07-31LibWeb: Stop parsing integer CSS values as LengthsSam Atkins
This was a hack copied over from the old parser, but it was causing problems with flex-grow, and probably other properties that accept numbers. Removing it does not seem to break anything, so lets' remove it! :^)
2021-07-31LibWeb: Define proper debug symbols for CSS Parser and TokenizerSam Atkins
You can now turn debug logging for them on using `CSS_PARSER_DEBUG` and `CSS_TOKENIZER_DEBUG`.
2021-07-31LibWeb: Use references to CSS tokens instead of copying by valueSam Atkins
A couple of places required a logic change to make this work, but mostly it's a simple case of adding &.
2021-07-31LibWeb: Get CSS @import rules working in new parserSam Atkins
Also added css-import.html, which tests the 3 syntax variations on `@import` statements. Note that the optional media-query parameter to `@import` is not handled yet.
2021-07-29LibWeb: Remove unused enum value CSS::StyleValue::PositionAndreas Kling
CSS position values are just basic identifiers, they don't require a custom StyleValue type.
2021-07-29LibWeb: Handle comment blocks when skipping unknown @-rulesK-Adam
This css definition was parsed incorrectly before: ```css @media screen { /* Unclosed bracket in comment { */ body { background: red; } } ```
2021-07-26LibWeb: Add a CustomHasProperty trait to WrapperGeneratordavidot
We immediately use this in CSSStyleDeclaration to fix that "background" in element.style did not return true. This is the mechanism used in css3test.com for detecting support of features.
2021-07-24LibWeb: Parse box-shadow in the DeprecatedCSSParserTobias Christiansen
This adds support for box-shadows to the DeprecatedCSSParser. When it encounters a box-shadow property, the following syntaxes can get parsed: - box-shadow: <offset_x> <offset_y> <color> - box-shadow: <offset_x> <offset_y> <blur_radius> <color> There is other possible data following the property, but those aren't supported for now.
2021-07-24LibWeb: Make box-shadow known throughout the CSS subsystemTobias Christiansen
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-24LibWeb: Add box-shadow as a known ValueIDTobias Christiansen
2021-07-24LibWeb: Add BoxShadowStyleType as a CSS StyleTypeTobias Christiansen
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-24LibWeb: Parse and store the opacity propertyEgor Ananyin
2021-07-24LibWeb: Add calc() resolution to CSS::LengthTobias Christiansen
This patch finally adds the actual calculation that goes into calc() expressions. When the resolution of a Length that is a calculated value the parsed CalculatedStyleValue gets traversed and appropriate values get calculated.
2021-07-24LibWeb: Plumb calculated StyleValues into CSS::LengthTobias Christiansen
This is a bit hackish, but this way the existance of the calc() becomes transparent to the user who just wants a Length and doesn't care where it came from.
2021-07-24LibWeb: Add the parsing to the calc() handlingTobias Christiansen
This patch adds the parsing of previously tokenized calc() expressions into the CSS-Parser. The tokens are processed into a complete CalculatedStyleValue.
2021-07-24LibWeb: Move type derivation of CSS::Length into seperate functionTobias Christiansen
That way this can (and will) be used in other places.
2021-07-24LibWeb: Add tokenization of calc expressionTobias Christiansen
Here the first step in understanding a calc() expression is taken: Finding the start of an expression and tokenizong it.
2021-07-24LibWeb: Add CalculatedStyleValue to the CSS StyleValuesTobias Christiansen
This adds the CalculatedStyleValue and all the structs needed to work with the calc() expressions.
2021-07-23LibWeb: Dont try to parse "data" urls as linksstelar7
2021-07-22LibWeb: Resolve CSS text-decoration from value listSam Atkins
This detects and resolves these in the text-decoration property, in any order: - text-decoration-color - text-decoration-line - text-decoration-style Only the solid underline renders, but all three sub-properties are assigned correctly.
2021-07-22LibWeb: Resolve background properties from ValueListStyleValueSam Atkins
As before, there are several sub-properties that we do not support, and we ignore anything after the first comma.
2021-07-22LibWeb: Implement ImageStyleValue parsingSam Atkins
Later we will want to make a distinction between URL and Image values, but this works for now.
2021-07-22LibWeb: Resolve CSS font property from value listSam Atkins
The font property now resolves into its various parts: - font-family - font-weight - font-size - font-style - line-height The font-variant and font-stretch parts are left unparsed since LibWeb doesn't know how to render those. Added `fonts.html` as a test for various forms of `font` declarations, based on the examples in the spec.
2021-07-22LibWeb: Resolve CSS list-style from value listSam Atkins
This resolves the three sub-properties, appearing in any order: - list-style-image - list-style-position - list-style-type Added `list-style-position` values to support this, though they are not yet used in rendering.
2021-07-22LibWeb: Resolve CSS flex/flex-flow from value listSam Atkins
Also moved the 'flex' code in StyleResolver to be next to the 'flex-flow' code, because that seemed more reasonable.
2021-07-22LibWeb: Implement CSS color parsing from TokensSam Atkins
This was broken when we switched away from using StringStyleValues. While I was at it, I have implemented hsl/a() and the percentage syntax for rgb/a(). As a bonus, added `colors.html` as a test page for the various CSS color syntaxes, since nothing was testing rgb() or rgba() before. Much of the parsing code in LibGFX/Color.h seems to be centered around CSS color values, but this is not used by the new Parser. (And can't be used, because it requires a String value and we have a list of Tokens of some kind instead.) Maybe that should be removed from there when the new CSS parser is operational.
2021-07-22LibWeb: Handle ValueListStyleValues in StyleResolverSam Atkins
This implements a lot of cases, but not all of them. The following need more infrastructure first: - Flex - FlexFlow - Background - BackgroundImage - BackgroundRepeat - ListStyle and parts - Font Also, colors are not parsed correctly. This will be handled next.
2021-07-22LibWeb: Expose StyleValue parsing method in CSS ParserSam Atkins
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-22LibWeb: Convert StyleResolver.{h,cpp} to east constSam Atkins
2021-07-22LibWeb: Generate a ValueListStyleValue when parsing CSS valuesSam Atkins
We skip whitespace tokens while doing this. As far as I can tell, whitespace is not useful once we get to this point, and it legally may or may not appear between any two tokens. By not including it in the ValueListStyleValue, we make the "if it has 3 parts"-type checks a lot more straightforward.
2021-07-22LibWeb: Add CSS ValueListStyleValueSam Atkins
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-19LibWeb: Add parsing for the justify-content propertyTobias Christiansen
2021-07-14LibWeb: Use split_view() in attribute selector matchingAndreas Kling
Using split() creates a new String object for each of the split tokens. Use split_view() instead to avoid these unnecessary heap allocations.