1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibWeb: Add SVG-presentation-attribute-parsing mode to CSS parser

When parsing these, <number> is allowed anywhere that would usually
allow a <length>, <length-percentage>, or <angle>. The spec is not
clear on exactly how this should work
(see https://github.com/w3c/svgwg/issues/792 ) so I'm using some
artistic license until things are clearer:
- If we expected a <length>, treat the <number> as pixels.
- If we expected an <angle>, treat the <number> as degrees.
- Only allow direct <number> tokens, not calc() or other functions.

From what I can tell this is what the spec *intended* but I may be very
wrong. In any case, telling the ParsingContext whether we're parsing
one of these attributes is a cleaner approach and more correct than
temporarily enabling quirks mode, which we did previously.
This commit is contained in:
Sam Atkins 2023-09-25 15:26:33 +01:00 committed by Andreas Kling
parent c46ce53ce3
commit 79a30c209d
3 changed files with 43 additions and 8 deletions

View file

@ -14,10 +14,18 @@ namespace Web::CSS::Parser {
class ParsingContext {
public:
explicit ParsingContext(JS::Realm&);
explicit ParsingContext(DOM::Document const&);
explicit ParsingContext(DOM::Document const&, AK::URL);
explicit ParsingContext(DOM::ParentNode&);
enum class Mode {
Normal,
SVGPresentationAttribute, // See https://svgwg.org/svg2-draft/types.html#presentation-attribute-css-value
};
explicit ParsingContext(JS::Realm&, Mode = Mode::Normal);
explicit ParsingContext(DOM::Document const&, Mode = Mode::Normal);
explicit ParsingContext(DOM::Document const&, AK::URL, Mode = Mode::Normal);
explicit ParsingContext(DOM::ParentNode&, Mode = Mode::Normal);
Mode mode() const { return m_mode; }
bool is_parsing_svg_presentation_attribute() const { return m_mode == Mode::SVGPresentationAttribute; }
bool in_quirks_mode() const;
DOM::Document const* document() const { return m_document; }
@ -34,6 +42,7 @@ private:
JS::GCPtr<DOM::Document const> m_document;
PropertyID m_current_property_id { PropertyID::Invalid };
AK::URL m_url;
Mode m_mode { Mode::Normal };
};
}