1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:17:34 +00:00

LibWeb: Enable quirks when parsing SVGGraphicsElement CSS attributes

This allows valid SVG attributes such as `font-size` with a unitless
value to be parsed successfully (in an admittedly hacky way).
This commit is contained in:
MacDue 2023-07-20 20:58:13 +01:00 committed by Andreas Kling
parent 48d03a68e9
commit 4cdb4de049
3 changed files with 26 additions and 5 deletions

View file

@ -6,10 +6,32 @@
#pragma once
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
namespace Web::SVG {
namespace FIXME {
class TemporarilyEnableQuirksMode {
public:
TemporarilyEnableQuirksMode(DOM::Document const& document)
: m_document(const_cast<DOM::Document&>(document))
, m_previous_quirks_mode(document.mode())
{
m_document.set_quirks_mode(DOM::QuirksMode::Yes);
}
~TemporarilyEnableQuirksMode()
{
m_document.set_quirks_mode(m_previous_quirks_mode);
}
private:
DOM::Document& m_document;
DOM::QuirksMode m_previous_quirks_mode {};
};
}
class SVGElement : public DOM::Element {
WEB_PLATFORM_OBJECT(SVGElement, DOM::Element);

View file

@ -117,6 +117,9 @@ Gfx::AffineTransform SVGGraphicsElement::get_transform() const
void SVGGraphicsElement::apply_presentational_hints(CSS::StyleProperties& style) const
{
// FIXME: Hack to ensure unitless SVG properties (such as font-size) are parsed.
FIXME::TemporarilyEnableQuirksMode enable_quirks(document());
CSS::Parser::ParsingContext parsing_context { document() };
for_each_attribute([&](auto& name, auto& value) {
if (name.equals_ignoring_ascii_case("fill"sv)) {

View file

@ -41,11 +41,7 @@ void SVGSVGElement::apply_presentational_hints(CSS::StyleProperties& style) cons
Base::apply_presentational_hints(style);
// NOTE: Hack to ensure SVG unitless widths/heights are parsed even with <!DOCTYPE html>
auto previous_quirks_mode = document().mode();
const_cast<DOM::Document&>(document()).set_quirks_mode(DOM::QuirksMode::Yes);
ScopeGuard reset_quirks_mode = [&] {
const_cast<DOM::Document&>(document()).set_quirks_mode(previous_quirks_mode);
};
FIXME::TemporarilyEnableQuirksMode enable_quirks(document());
auto width_attribute = attribute(SVG::AttributeNames::width);
auto parsing_context = CSS::Parser::ParsingContext { document() };