Serenity Operating System
at master 94 lines 3.4 kB view raw
1/* 2 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibWeb/Bindings/ExceptionOrUtils.h> 8#include <LibWeb/Bindings/Intrinsics.h> 9#include <LibWeb/HTML/Parser/HTMLParser.h> 10#include <LibWeb/Layout/BlockContainer.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 16namespace Web::SVG { 17 18SVGForeignObjectElement::SVGForeignObjectElement(DOM::Document& document, DOM::QualifiedName qualified_name) 19 : SVGGraphicsElement(document, move(qualified_name)) 20{ 21} 22 23SVGForeignObjectElement::~SVGForeignObjectElement() = default; 24 25JS::ThrowCompletionOr<void> SVGForeignObjectElement::initialize(JS::Realm& realm) 26{ 27 auto& vm = realm.vm(); 28 29 MUST_OR_THROW_OOM(Base::initialize(realm)); 30 set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGForeignObjectElementPrototype>(realm, "SVGForeignObjectElement")); 31 32 // FIXME: These never actually get updated! 33 m_x = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGAnimatedLength>> { 34 return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0))); 35 })); 36 m_y = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGAnimatedLength>> { 37 return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0))); 38 })); 39 m_width = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGAnimatedLength>> { 40 return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0))); 41 })); 42 m_height = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGAnimatedLength>> { 43 return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0))); 44 })); 45 46 return {}; 47} 48 49void SVGForeignObjectElement::visit_edges(Cell::Visitor& visitor) 50{ 51 Base::visit_edges(visitor); 52 visitor.visit(m_x); 53 visitor.visit(m_y); 54 visitor.visit(m_width); 55 visitor.visit(m_height); 56} 57 58JS::GCPtr<Layout::Node> SVGForeignObjectElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style) 59{ 60 return heap().allocate_without_realm<Layout::BlockContainer>(document(), this, move(style)); 61} 62 63void SVGForeignObjectElement::apply_presentational_hints(CSS::StyleProperties& style) const 64{ 65 Base::apply_presentational_hints(style); 66 67 if (auto width_value = HTML::parse_dimension_value(attribute(SVG::AttributeNames::width))) 68 style.set_property(CSS::PropertyID::Width, width_value.release_nonnull()); 69 70 if (auto height_value = HTML::parse_dimension_value(attribute(SVG::AttributeNames::height))) 71 style.set_property(CSS::PropertyID::Height, height_value.release_nonnull()); 72} 73 74JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::x() 75{ 76 return *m_x; 77} 78 79JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::y() 80{ 81 return *m_y; 82} 83 84JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::width() 85{ 86 return *m_width; 87} 88 89JS::NonnullGCPtr<SVG::SVGAnimatedLength> SVGForeignObjectElement::height() 90{ 91 return *m_height; 92} 93 94}