SVGForeignObjectElement.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/HTML/Parser/HTMLParser.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. JS::ThrowCompletionOr<void> SVGForeignObjectElement::initialize(JS::Realm& realm)
  21. {
  22. auto& vm = realm.vm();
  23. MUST_OR_THROW_OOM(Base::initialize(realm));
  24. set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGForeignObjectElementPrototype>(realm, "SVGForeignObjectElement"));
  25. // FIXME: These never actually get updated!
  26. m_x = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGAnimatedLength>> {
  27. return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0)));
  28. }));
  29. m_y = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGAnimatedLength>> {
  30. return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0)));
  31. }));
  32. m_width = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGAnimatedLength>> {
  33. return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0)));
  34. }));
  35. m_height = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGAnimatedLength>> {
  36. return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0)));
  37. }));
  38. return {};
  39. }
  40. void SVGForeignObjectElement::visit_edges(Cell::Visitor& visitor)
  41. {
  42. Base::visit_edges(visitor);
  43. visitor.visit(m_x);
  44. visitor.visit(m_y);
  45. visitor.visit(m_width);
  46. visitor.visit(m_height);
  47. }
  48. JS::GCPtr<Layout::Node> SVGForeignObjectElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
  49. {
  50. return heap().allocate_without_realm<Layout::BlockContainer>(document(), this, move(style));
  51. }
  52. void SVGForeignObjectElement::apply_presentational_hints(CSS::StyleProperties& style) const
  53. {
  54. Base::apply_presentational_hints(style);
  55. if (auto width_value = HTML::parse_dimension_value(attribute(SVG::AttributeNames::width)))
  56. style.set_property(CSS::PropertyID::Width, width_value.release_nonnull());
  57. if (auto height_value = HTML::parse_dimension_value(attribute(SVG::AttributeNames::height)))
  58. style.set_property(CSS::PropertyID::Height, height_value.release_nonnull());
  59. }
  60. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::x()
  61. {
  62. return *m_x;
  63. }
  64. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::y()
  65. {
  66. return *m_y;
  67. }
  68. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::width()
  69. {
  70. return *m_width;
  71. }
  72. JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::height()
  73. {
  74. return *m_height;
  75. }
  76. }