SVGSVGElement.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/Parser/Parser.h>
  8. #include <LibWeb/CSS/StyleComputer.h>
  9. #include <LibWeb/DOM/Document.h>
  10. #include <LibWeb/DOM/Event.h>
  11. #include <LibWeb/Layout/SVGSVGBox.h>
  12. #include <LibWeb/SVG/AttributeNames.h>
  13. #include <LibWeb/SVG/SVGSVGElement.h>
  14. namespace Web::SVG {
  15. SVGSVGElement::SVGSVGElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  16. : SVGGraphicsElement(document, qualified_name)
  17. {
  18. }
  19. RefPtr<Layout::Node> SVGSVGElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
  20. {
  21. return adopt_ref(*new Layout::SVGSVGBox(document(), *this, move(style)));
  22. }
  23. void SVGSVGElement::apply_presentational_hints(CSS::StyleProperties& style) const
  24. {
  25. // Width defaults to 100%
  26. if (auto width_value = parse_html_length(document(), attribute("width"))) {
  27. style.set_property(CSS::PropertyID::Width, width_value.release_nonnull());
  28. } else {
  29. style.set_property(CSS::PropertyID::Width, CSS::PercentageStyleValue::create(CSS::Percentage { 100 }));
  30. }
  31. // Height defaults to 100%
  32. if (auto height_value = parse_html_length(document(), attribute("height"))) {
  33. style.set_property(CSS::PropertyID::Height, height_value.release_nonnull());
  34. } else {
  35. style.set_property(CSS::PropertyID::Height, CSS::PercentageStyleValue::create(CSS::Percentage { 100 }));
  36. }
  37. }
  38. void SVGSVGElement::parse_attribute(FlyString const& name, String const& value)
  39. {
  40. SVGGraphicsElement::parse_attribute(name, value);
  41. if (name.equals_ignoring_case(SVG::AttributeNames::viewBox))
  42. m_view_box = try_parse_view_box(value);
  43. }
  44. }