Forráskód Böngészése

LibWeb: Parse the <svg viewBox> attribute

Just parse it into an SVG::ViewBox object for now, we don't actually use
it for anything yet.
Andreas Kling 3 éve
szülő
commit
7de23aede2

+ 9 - 0
Userland/Libraries/LibWeb/SVG/SVGSVGElement.cpp

@@ -9,6 +9,7 @@
 #include <LibWeb/DOM/Document.h>
 #include <LibWeb/DOM/Document.h>
 #include <LibWeb/DOM/Event.h>
 #include <LibWeb/DOM/Event.h>
 #include <LibWeb/Layout/SVGSVGBox.h>
 #include <LibWeb/Layout/SVGSVGBox.h>
+#include <LibWeb/SVG/AttributeNames.h>
 #include <LibWeb/SVG/SVGSVGElement.h>
 #include <LibWeb/SVG/SVGSVGElement.h>
 
 
 namespace Web::SVG {
 namespace Web::SVG {
@@ -36,4 +37,12 @@ unsigned SVGSVGElement::height() const
     return attribute(HTML::AttributeNames::height).to_uint().value_or(150);
     return attribute(HTML::AttributeNames::height).to_uint().value_or(150);
 }
 }
 
 
+void SVGSVGElement::parse_attribute(FlyString const& name, String const& value)
+{
+    SVGGraphicsElement::parse_attribute(name, value);
+
+    if (name.equals_ignoring_case(SVG::AttributeNames::viewBox))
+        m_view_box = try_parse_view_box(value);
+}
+
 }
 }

+ 6 - 0
Userland/Libraries/LibWeb/SVG/SVGSVGElement.h

@@ -8,6 +8,7 @@
 
 
 #include <LibGfx/Bitmap.h>
 #include <LibGfx/Bitmap.h>
 #include <LibWeb/SVG/SVGGraphicsElement.h>
 #include <LibWeb/SVG/SVGGraphicsElement.h>
+#include <LibWeb/SVG/ViewBox.h>
 
 
 namespace Web::SVG {
 namespace Web::SVG {
 
 
@@ -25,8 +26,13 @@ public:
     virtual bool requires_svg_container() const override { return false; }
     virtual bool requires_svg_container() const override { return false; }
     virtual bool is_svg_container() const override { return true; }
     virtual bool is_svg_container() const override { return true; }
 
 
+    Optional<ViewBox> const& view_box() { return m_view_box; }
+
 private:
 private:
+    virtual void parse_attribute(FlyString const& name, String const& value) override;
+
     RefPtr<Gfx::Bitmap> m_bitmap;
     RefPtr<Gfx::Bitmap> m_bitmap;
+    Optional<ViewBox> m_view_box;
 };
 };
 
 
 }
 }