SVGForeignObjectElement.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/Layout/SVGForeignObjectBox.h>
  11. #include <LibWeb/SVG/AttributeNames.h>
  12. #include <LibWeb/SVG/SVGAnimatedLength.h>
  13. #include <LibWeb/SVG/SVGForeignObjectElement.h>
  14. #include <LibWeb/SVG/SVGLength.h>
  15. namespace Web::SVG {
  16. JS_DEFINE_ALLOCATOR(SVGForeignObjectElement);
  17. SVGForeignObjectElement::SVGForeignObjectElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  18. : SVGGraphicsElement(document, move(qualified_name))
  19. {
  20. }
  21. SVGForeignObjectElement::~SVGForeignObjectElement() = default;
  22. void SVGForeignObjectElement::initialize(JS::Realm& realm)
  23. {
  24. Base::initialize(realm);
  25. WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGForeignObjectElement);
  26. // FIXME: These never actually get updated!
  27. m_x = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
  28. m_y = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
  29. m_width = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
  30. m_height = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
  31. }
  32. void SVGForeignObjectElement::visit_edges(Cell::Visitor& visitor)
  33. {
  34. Base::visit_edges(visitor);
  35. visitor.visit(m_x);
  36. visitor.visit(m_y);
  37. visitor.visit(m_width);
  38. visitor.visit(m_height);
  39. }
  40. JS::GCPtr<Layout::Node> SVGForeignObjectElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
  41. {
  42. return heap().allocate_without_realm<Layout::SVGForeignObjectBox>(document(), *this, move(style));
  43. }
  44. void SVGForeignObjectElement::apply_presentational_hints(CSS::StyleProperties& style) const
  45. {
  46. Base::apply_presentational_hints(style);
  47. auto parsing_context = CSS::Parser::ParsingContext { document() };
  48. if (auto width_value = parse_css_value(parsing_context, get_attribute_value(Web::HTML::AttributeNames::width), CSS::PropertyID::Width))
  49. style.set_property(CSS::PropertyID::Width, width_value.release_nonnull());
  50. if (auto height_value = parse_css_value(parsing_context, get_attribute_value(Web::HTML::AttributeNames::height), CSS::PropertyID::Height))
  51. style.set_property(CSS::PropertyID::Height, height_value.release_nonnull());
  52. }
  53. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::x()
  54. {
  55. return *m_x;
  56. }
  57. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::y()
  58. {
  59. return *m_y;
  60. }
  61. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::width()
  62. {
  63. return *m_width;
  64. }
  65. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::height()
  66. {
  67. return *m_height;
  68. }
  69. }