SVGForeignObjectElement.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/ExceptionOrUtils.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/CSS/Parser/Parser.h>
  9. #include <LibWeb/Layout/BlockContainer.h>
  10. #include <LibWeb/SVG/AttributeNames.h>
  11. #include <LibWeb/SVG/SVGAnimatedLength.h>
  12. #include <LibWeb/SVG/SVGForeignObjectElement.h>
  13. #include <LibWeb/SVG/SVGLength.h>
  14. namespace Web::SVG {
  15. SVGForeignObjectElement::SVGForeignObjectElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  16. : SVGGraphicsElement(document, move(qualified_name))
  17. {
  18. }
  19. SVGForeignObjectElement::~SVGForeignObjectElement() = default;
  20. void SVGForeignObjectElement::initialize(JS::Realm& realm)
  21. {
  22. Base::initialize(realm);
  23. set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGForeignObjectElementPrototype>(realm, "SVGForeignObjectElement"));
  24. // FIXME: These never actually get updated!
  25. m_x = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
  26. m_y = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
  27. m_width = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
  28. m_height = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
  29. }
  30. void SVGForeignObjectElement::visit_edges(Cell::Visitor& visitor)
  31. {
  32. Base::visit_edges(visitor);
  33. visitor.visit(m_x);
  34. visitor.visit(m_y);
  35. visitor.visit(m_width);
  36. visitor.visit(m_height);
  37. }
  38. JS::GCPtr<Layout::Node> SVGForeignObjectElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
  39. {
  40. return heap().allocate_without_realm<Layout::BlockContainer>(document(), this, move(style));
  41. }
  42. void SVGForeignObjectElement::apply_presentational_hints(CSS::StyleProperties& style) const
  43. {
  44. Base::apply_presentational_hints(style);
  45. auto parsing_context = CSS::Parser::ParsingContext { document() };
  46. if (auto width_value = parse_css_value(parsing_context, attribute(Web::HTML::AttributeNames::width), CSS::PropertyID::Width))
  47. style.set_property(CSS::PropertyID::Width, width_value.release_nonnull());
  48. if (auto height_value = parse_css_value(parsing_context, attribute(Web::HTML::AttributeNames::height), CSS::PropertyID::Height))
  49. style.set_property(CSS::PropertyID::Height, height_value.release_nonnull());
  50. }
  51. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::x()
  52. {
  53. return *m_x;
  54. }
  55. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::y()
  56. {
  57. return *m_y;
  58. }
  59. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::width()
  60. {
  61. return *m_width;
  62. }
  63. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::height()
  64. {
  65. return *m_height;
  66. }
  67. }