ladybird/Userland/Libraries/LibWeb/CSS/Parser/ParsingContext.h
Sam Atkins 79a30c209d 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.
2023-09-26 20:01:55 +02:00

49 lines
1.5 KiB
C++

/*
* Copyright (c) 2020-2021, the SerenityOS developers.
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/DOM/Document.h>
namespace Web::CSS::Parser {
class ParsingContext {
public:
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; }
HTML::Window const* window() const;
AK::URL complete_url(StringView) const;
PropertyID current_property_id() const { return m_current_property_id; }
void set_current_property_id(PropertyID property_id) { m_current_property_id = property_id; }
JS::Realm& realm() const { return m_realm; }
private:
JS::NonnullGCPtr<JS::Realm> m_realm;
JS::GCPtr<DOM::Document const> m_document;
PropertyID m_current_property_id { PropertyID::Invalid };
AK::URL m_url;
Mode m_mode { Mode::Normal };
};
}