mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 22:08:59 +00:00
`current_property_id()` is insufficient to determine if a quirk is allowed. For example, unitless lengths are allowed in certain properties, but NOT if they are inside a calc() or other function. It's also incorrect when we are parsing a longhand inside a shorthand. So instead, replace that with a stack of value-parsing contexts. For now, this is either properties or CSS functions, but in future can be expanded to include media features and other places. This lets us disallow quirks inside functions, like we're supposed to. It also lays the groundwork for being able to more easily determine what type a percentage inside a calculation should become, as this is based on the same stack of contexts.
50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2020-2021, the SerenityOS developers.
|
|
* Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.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(Mode = Mode::Normal);
|
|
explicit ParsingContext(JS::Realm&, Mode = Mode::Normal);
|
|
explicit ParsingContext(JS::Realm&, URL::URL, Mode = Mode::Normal);
|
|
explicit ParsingContext(DOM::Document const&, Mode = Mode::Normal);
|
|
explicit ParsingContext(DOM::Document const&, URL::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;
|
|
URL::URL complete_url(StringView) const;
|
|
|
|
JS::Realm& realm() const
|
|
{
|
|
VERIFY(m_realm);
|
|
return *m_realm;
|
|
}
|
|
|
|
private:
|
|
GC::Ptr<JS::Realm> m_realm;
|
|
GC::Ptr<DOM::Document const> m_document;
|
|
URL::URL m_url;
|
|
Mode m_mode { Mode::Normal };
|
|
};
|
|
|
|
}
|