SVGSVGElement.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/Painter.h>
  7. #include <LibWeb/CSS/StyleResolver.h>
  8. #include <LibWeb/DOM/Document.h>
  9. #include <LibWeb/DOM/Event.h>
  10. #include <LibWeb/Layout/SVGSVGBox.h>
  11. #include <LibWeb/SVG/AttributeNames.h>
  12. #include <LibWeb/SVG/SVGSVGElement.h>
  13. namespace Web::SVG {
  14. SVGSVGElement::SVGSVGElement(DOM::Document& document, QualifiedName qualified_name)
  15. : SVGGraphicsElement(document, qualified_name)
  16. {
  17. }
  18. RefPtr<Layout::Node> SVGSVGElement::create_layout_node()
  19. {
  20. auto style = document().style_resolver().resolve_style(*this);
  21. if (style->display() == CSS::Display::None)
  22. return nullptr;
  23. return adopt_ref(*new Layout::SVGSVGBox(document(), *this, move(style)));
  24. }
  25. unsigned SVGSVGElement::width() const
  26. {
  27. return attribute(HTML::AttributeNames::width).to_uint().value_or(300);
  28. }
  29. unsigned SVGSVGElement::height() const
  30. {
  31. return attribute(HTML::AttributeNames::height).to_uint().value_or(150);
  32. }
  33. void SVGSVGElement::parse_attribute(FlyString const& name, String const& value)
  34. {
  35. SVGGraphicsElement::parse_attribute(name, value);
  36. if (name.equals_ignoring_case(SVG::AttributeNames::viewBox))
  37. m_view_box = try_parse_view_box(value);
  38. }
  39. }