2020-07-31 23:04:26 -03:00
|
|
|
/*
|
2021-04-28 17:46:44 -03:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2020-07-31 23:04:26 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-31 23:04:26 -03:00
|
|
|
*/
|
|
|
|
|
|
2024-04-26 21:09:58 -03:00
|
|
|
#include <LibWeb/Bindings/HTMLEmbedElementPrototype.h>
|
2022-09-30 20:16:16 -03:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-10-01 13:26:01 -03:00
|
|
|
#include <LibWeb/CSS/StyleProperties.h>
|
|
|
|
|
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
|
2020-07-31 23:04:26 -03:00
|
|
|
#include <LibWeb/HTML/HTMLEmbedElement.h>
|
2024-10-01 13:26:01 -03:00
|
|
|
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
2020-07-31 23:04:26 -03:00
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2023-11-19 15:47:52 -03:00
|
|
|
JS_DEFINE_ALLOCATOR(HTMLEmbedElement);
|
|
|
|
|
|
2022-02-18 17:00:52 -03:00
|
|
|
HTMLEmbedElement::HTMLEmbedElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 07:20:15 -03:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
2020-07-31 23:04:26 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
HTMLEmbedElement::~HTMLEmbedElement() = default;
|
2023-01-10 08:28:20 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
void HTMLEmbedElement::initialize(JS::Realm& realm)
|
2023-01-10 08:28:20 -03:00
|
|
|
{
|
2023-08-07 03:41:28 -03:00
|
|
|
Base::initialize(realm);
|
2024-03-16 09:13:08 -03:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLEmbedElement);
|
2023-01-10 08:28:20 -03:00
|
|
|
}
|
|
|
|
|
|
2024-10-01 13:26:01 -03:00
|
|
|
void HTMLEmbedElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
|
|
|
|
{
|
|
|
|
|
for_each_attribute([&](auto& name, auto& value) {
|
|
|
|
|
if (name == HTML::AttributeNames::align) {
|
|
|
|
|
if (value.equals_ignoring_ascii_case("center"sv))
|
|
|
|
|
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center));
|
|
|
|
|
else if (value.equals_ignoring_ascii_case("middle"sv))
|
|
|
|
|
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Middle));
|
|
|
|
|
} else if (name == HTML::AttributeNames::height) {
|
|
|
|
|
if (auto parsed_value = parse_dimension_value(value))
|
|
|
|
|
style.set_property(CSS::PropertyID::Height, *parsed_value);
|
|
|
|
|
}
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images:maps-to-the-dimension-property
|
|
|
|
|
else if (name == HTML::AttributeNames::hspace) {
|
|
|
|
|
if (auto parsed_value = parse_dimension_value(value)) {
|
|
|
|
|
style.set_property(CSS::PropertyID::MarginLeft, *parsed_value);
|
|
|
|
|
style.set_property(CSS::PropertyID::MarginRight, *parsed_value);
|
|
|
|
|
}
|
|
|
|
|
} else if (name == HTML::AttributeNames::vspace) {
|
|
|
|
|
if (auto parsed_value = parse_dimension_value(value)) {
|
|
|
|
|
style.set_property(CSS::PropertyID::MarginTop, *parsed_value);
|
|
|
|
|
style.set_property(CSS::PropertyID::MarginBottom, *parsed_value);
|
|
|
|
|
}
|
|
|
|
|
} else if (name == HTML::AttributeNames::width) {
|
|
|
|
|
if (auto parsed_value = parse_dimension_value(value)) {
|
|
|
|
|
style.set_property(CSS::PropertyID::Width, *parsed_value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 23:04:26 -03:00
|
|
|
}
|