SVGForeignObjectElement.cpp 2.9 KB

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