mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-18 06:00:27 +00:00
From the SVG spec The value of the ‘viewBox’ attribute is a list of four numbers <min-x>, <min-y>, <width> and <height>, separated by whitespace and/or a comma... Currently try_parse_view_box will fail to parse the attribute if the values are separated by commas. This change replaces try_parse_view_box with a more correct implementation. It will reside in the AttributeParser.cpp. This new implementation correctly handles comma-separated viewBox values, and is also more robust against invalid inputs. Additionally, it adds a new test case to ensure viewBox values with various syntax are parsed correctly and invalid values are rejected.
34 lines
954 B
C++
34 lines
954 B
C++
/*
|
|
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibJS/Heap/Cell.h>
|
|
#include <LibWeb/SVG/AttributeParser.h>
|
|
#include <LibWeb/SVG/SVGAnimatedString.h>
|
|
|
|
namespace Web::SVG {
|
|
|
|
class SVGFitToViewBox {
|
|
public:
|
|
virtual ~SVGFitToViewBox() = default;
|
|
|
|
GC::Ref<SVGAnimatedRect> view_box_for_bindings() const { return *m_view_box_for_bindings; }
|
|
Optional<ViewBox> view_box() const { return m_view_box; }
|
|
Optional<PreserveAspectRatio> preserve_aspect_ratio() const { return m_preserve_aspect_ratio; }
|
|
|
|
protected:
|
|
void initialize(JS::Realm&);
|
|
void visit_edges(JS::Cell::Visitor&);
|
|
void attribute_changed(DOM::Element& element, FlyString const& name, Optional<String> const& value);
|
|
|
|
private:
|
|
Optional<ViewBox> m_view_box;
|
|
GC::Ptr<SVGAnimatedRect> m_view_box_for_bindings;
|
|
Optional<PreserveAspectRatio> m_preserve_aspect_ratio;
|
|
};
|
|
|
|
}
|