summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS
AgeCommit message (Collapse)Author
2021-10-03LibWeb: Remove pointless brackets from Length::to_string()Andreas Kling
Since we expose these strings to web content via LengthStyleValue, let's not have non-standard brackets in there to confuse anyone trying to parse these values. :^)
2021-10-03LibWeb: Make ColorStyleValue serialization spec compliantAndreas Kling
[CSS Color 4] tells us to use either rgb() or rgba() notation, depending on the color's alpha value.
2021-10-03LibWeb: Have CSSStyleRule inherit from CSSRule in IDLLuke Wilde
This also allows removing the cssText attribute being on CSSStyleRule.
2021-10-01LibWeb: Implement CSSRule and CSSStyleDeclaration serializationAndreas Kling
There are a handful of FIXME's here, but this seems generally good. Note that CSS *values* don't get serialized in a spec-compliant way since we currently rely on StyleValue::to_string() which is ad-hoc.
2021-10-01LibWeb: Add missing virtual/override/final in CSSStyleRuleAndreas Kling
2021-10-01LibWeb: Parse media queries! :^)Sam Atkins
While not complete by any means, we are now compatible with the [level 3 spec](https://www.w3.org/TR/css3-mediaqueries/#syntax) and some parts of [level 4.](https://www.w3.org/TR/mediaqueries-4#mq-syntax) Compatibility with level 4+ requires: - Implementing the range syntax: `(800px <= width <= 1200px)` - Parsing `<general-enclosed>`, which represents syntax that is not yet used but they may use in the future.
2021-10-01LibWeb: Add TokenStream::rewind_to_position()Sam Atkins
Parsing media queries sometimes requires significant back-tracking, so `reconsume_current_input_token()` was not good enough. `rewind_to_position()` lets you reconsume an erbitrary number of tokens to return to an earlier point in the stream, which you previously saved from `TokenStream::position()`.
2021-10-01LibWeb: Parse `@media` rules into CSSMediaRule objectsSam Atkins
This is not yet actually useful, since we only have a stub for parsing the query part, but now I have a nice way to test that things are working. :^)
2021-10-01LibWeb: Make consume_a_qualified_rule() understand block tokensSam Atkins
This now matches the spec, and fixes the situation where if it was given a TokenStream of StyleComponentValueRules, it would drop any Blocks on the floor instead of adding them to the result StyleRule.
2021-10-01LibWeb: Make MediaQueryList store MediaQueries instead of a StringSam Atkins
2021-10-01LibWeb: Sketch out media-query parsingSam Atkins
This does everything except actually parse the individual media queries.
2021-10-01LibWeb: Add CSSMediaRuleSam Atkins
This is the class corresponding to a `@media` rule. It contains a list of media queries and a list of child css rules.
2021-10-01LibWeb: Add MediaListSam Atkins
This is a list of MediaQuery objects. Not to be confused with `MediaQueryList`, which is concerned with firing events when a media query's match-state changes.
2021-10-01LibWeb: Partially implement MediaQuery class :^)Sam Atkins
The main thing that's missing is the actual matching, but this is enough to get started.
2021-10-01LibWeb: Implement MediaQueryList.onchangeLuke Wilde
2021-10-01Userland: Fix typosNico Weber
2021-09-30LibWeb: Fix null dereference when assigning an ImageStyleValue via JSAndreas Kling
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-30LibWeb: Reimplement the <style> element following the specAndreas Kling
We now follow the "update a style block" algorithm from the HTML spec instead of using the ad-hoc CSSLoader mechanism. This necessitated improving our StyleSheet and CSSStyleSheet classes as well, so that's baked into this commit.
2021-09-30LibWeb: Add the CSSStyleRule interface with some limited functionalityAndreas Kling
2021-09-29LibWeb: Implement most of CSSStyleRule.insertRule()Andreas Kling
2021-09-29LibWeb: Add CSSStyleSheet.{insert,delete,remove}Rule() APIsAndreas Kling
Note that insertRule() is really just a big TODO right now.
2021-09-29LibWeb: Make CSSRule and CSSRuleList available to JavaScript :^)Andreas Kling
This patch makes both of these classes inherit from RefCounted and Bindings::Wrappable, plus some minimal rejigging to allow us to keep using them internally while also exposing them to web content.
2021-09-29LibWeb: Add CSSConditionRuleSam Atkins
https://www.w3.org/TR/css-conditional-3/#the-cssconditionrule-interface This simply exposes a condition string, which is implemented differently in each sub-class.
2021-09-29LibWeb: Add CSSGroupingRuleSam Atkins
This is an abstract base class for CSSRules that hold a CSSRuleList.
2021-09-29LibWeb: Use a CSSRuleList inside CSSStyleSheetSam Atkins
This better matches the spec. :^)
2021-09-29LibWeb: Add CSSRuleListSam Atkins
"The CSSRuleList interface represents an ordered collection of CSS style rules." - https://www.w3.org/TR/cssom-1/#the-cssrulelist-interface
2021-09-29LibWeb: Make StyleSheetList.item an IDL getterLuke Wilde
2021-09-26LibWeb: Support simplest form of CSSStyleDeclaration.setProperty()Andreas Kling
This patch adds the setProperty(name, value) API to CSSStyleDeclaration. Setting an invalid or empty value will cause the property to be removed from the declaration. Note that this only works on mutable declarations (i.e element.style) and not on resolved declarations (i.e window.getComputedStyle(element)).
2021-09-25LibWeb: Provide a default DOM::EventTarget::dispatch_event()Andreas Kling
All EventTarget subclasses except Window do the same exact thing in their overrides, so let's just share an implementation in the base.
2021-09-24LibWeb: Ignore `font-size: calc(...)` for nowAndreas Kling
This doesn't work correctly in the new world where fonts are resolved during the CSS cascade. Let's patch it out with a FIXME and get back to it once everything has fallen into place.
2021-09-24LibWeb: Rename CSS::StyleResolver => StyleComputerAndreas Kling
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-24LibWeb: Absolutize internal lengths in all StyleValuesAndreas Kling
StyleValue now has a virtual visit_lengths() that allows us to update all CSS lengths during the absolutization phase.
2021-09-24LibWeb: Remove on-demand font resolutionAndreas Kling
Fonts are now resolved as part of the CSS cascade.
2021-09-24LibWeb: Give DOM::Document some default style propertiesAndreas Kling
Add StyleResolver::create_document_style() to help in creating an "empty" style with nothing but default values.
2021-09-24LibWeb: Start absolutizing lengths after performing the CSS cascadeAndreas Kling
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-24LibWeb: Rename "Computed" CSSStyleDeclaration => "Resolved"Andreas Kling
The original name was based on the window.getComputedStyle() API. However, "Computed" in "getComputedStyle" is actually a misnomer that the platform is stuck with due to backwards compatibility. What getComputedStyle() returns is actually a mix of computed and used values. The spec calls it the "resolved" values. So let's call this declaration subclass "ResolvedCSSStyleDeclaration" to match.
2021-09-24LibWeb: Replace last couple of StyleValue casts with `as_foo()`Sam Atkins
2021-09-24LibWeb: Use new StyleValue API in StyleResolverSam Atkins
Less casts, more readable. :^)
2021-09-24LibWeb: Use new StyleValue API in StyleProperties.cppSam Atkins
This replaces a bunch of casts with `.as_foo()` calls, and adjusts calls to the old `is_foo()` methods that now are better as `has_foo()`. Also tidied up some whitespace to be more consistent.
2021-09-24LibWeb: Use new StyleValue API in ComputedCSSStyleDeclarationSam Atkins
Why manually cast things when a method can do it for you safely?
2021-09-24LibWeb: Clarify StyleValue API with new naming schemeSam Atkins
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-24LibWeb: Alphabetically sort StyleValuesSam Atkins
The random order keeps confuzing me!
2021-09-23LibWeb: Remove type checking from set_property_expanding_shorthands()Sam Atkins
Now that the Parser checks that StyleValues are valid, we don't need to do the checks here, since any value here is guaranteed to be acceptable.
2021-09-23LibWeb: Use property_accepts_value() for parsing text-decorationSam Atkins
2021-09-23LibWeb: Use property_accepts_value() for overflow parsingSam Atkins
2021-09-23LibWeb: Fix `auto` conversion to identifierSam Atkins
Calling `is_identifier()` here was wrong, since it just means you can get an Identifier from it. This meant that an `auto` LengthStyleValue would return true, then it would get `static_cast` to the wrong class, and return a garbage value. Basically, I really need to tidy up the API for StyleValue, so it's clear whether `is_foo()` means the object is a `FooStyleValue`, or it can just return a `foo` value.
2021-09-23LibWeb: Use property_accepts_value() for list style parsingSam Atkins
2021-09-23LibWeb: Use property_accepts_value() for font parsingSam Atkins
2021-09-23LibWeb: Add range-checking to property_accepts_value()Sam Atkins
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-23LibWeb: Use property_accepts_value() for parsing flexbox propertiesSam Atkins