ladybird/Userland/Libraries/LibWeb/CSS/Parser/ParsingContext.cpp
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

62 lines
1.6 KiB
C++

/*
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2021, the SerenityOS developers.
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/DOM/Document.h>
namespace Web::CSS::Parser {
ParsingContext::ParsingContext(JS::Realm& realm, Mode mode)
: m_realm(realm)
, m_mode(mode)
{
}
ParsingContext::ParsingContext(DOM::Document const& document, AK::URL url, Mode mode)
: m_realm(const_cast<JS::Realm&>(document.realm()))
, m_document(&document)
, m_url(move(url))
, m_mode(mode)
{
}
ParsingContext::ParsingContext(DOM::Document const& document, Mode mode)
: m_realm(const_cast<JS::Realm&>(document.realm()))
, m_document(&document)
, m_url(document.url())
, m_mode(mode)
{
}
ParsingContext::ParsingContext(DOM::ParentNode& parent_node, Mode mode)
: m_realm(parent_node.realm())
, m_document(&parent_node.document())
, m_url(parent_node.document().url())
, m_mode(mode)
{
}
bool ParsingContext::in_quirks_mode() const
{
return m_document ? m_document->in_quirks_mode() : false;
}
// https://www.w3.org/TR/css-values-4/#relative-urls
AK::URL ParsingContext::complete_url(StringView relative_url) const
{
return m_url.complete_url(relative_url);
}
HTML::Window const* ParsingContext::window() const
{
return m_document ? &m_document->window() : nullptr;
}
}