SVGForeignObjectElement.cpp 2.8 KB

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