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
|
|
|
*/
|
|
|
|
|
|
2026-04-18 05:54:06 -03:00
|
|
|
#include <LibWeb/Bindings/HTMLEmbedElement.h>
|
2022-09-30 20:16:16 -03:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-12-20 07:32:17 -03:00
|
|
|
#include <LibWeb/CSS/ComputedProperties.h>
|
2024-11-08 09:14:37 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
2025-08-08 06:28:41 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.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 {
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DEFINE_ALLOCATOR(HTMLEmbedElement);
|
2023-11-19 15:47:52 -03:00
|
|
|
|
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
|
|
|
{
|
2024-03-16 09:13:08 -03:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLEmbedElement);
|
2025-04-20 11:22:57 -03:00
|
|
|
Base::initialize(realm);
|
2023-01-10 08:28:20 -03:00
|
|
|
}
|
|
|
|
|
|
2024-12-23 13:51:10 -03:00
|
|
|
bool HTMLEmbedElement::is_presentational_hint(FlyString const& name) const
|
|
|
|
|
{
|
|
|
|
|
if (Base::is_presentational_hint(name))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return first_is_one_of(name,
|
|
|
|
|
HTML::AttributeNames::align,
|
|
|
|
|
HTML::AttributeNames::height,
|
|
|
|
|
HTML::AttributeNames::hspace,
|
|
|
|
|
HTML::AttributeNames::vspace,
|
|
|
|
|
HTML::AttributeNames::width);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-30 06:44:26 -03:00
|
|
|
void HTMLEmbedElement::apply_presentational_hints(Vector<CSS::StyleProperty>& properties) const
|
2024-10-01 13:26:01 -03:00
|
|
|
{
|
2026-04-30 06:44:26 -03:00
|
|
|
Base::apply_presentational_hints(properties);
|
2024-10-01 13:26:01 -03:00
|
|
|
for_each_attribute([&](auto& name, auto& value) {
|
|
|
|
|
if (name == HTML::AttributeNames::align) {
|
|
|
|
|
if (value.equals_ignoring_ascii_case("center"sv))
|
2026-04-30 06:44:26 -03:00
|
|
|
properties.append({ .property_id = CSS::PropertyID::TextAlign, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Center) });
|
2024-10-01 13:26:01 -03:00
|
|
|
else if (value.equals_ignoring_ascii_case("middle"sv))
|
2026-04-30 06:44:26 -03:00
|
|
|
properties.append({ .property_id = CSS::PropertyID::TextAlign, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Middle) });
|
2024-10-01 13:26:01 -03:00
|
|
|
} else if (name == HTML::AttributeNames::height) {
|
|
|
|
|
if (auto parsed_value = parse_dimension_value(value))
|
2026-04-30 06:44:26 -03:00
|
|
|
properties.append({ .property_id = CSS::PropertyID::Height, .value = *parsed_value });
|
2024-10-01 13:26:01 -03:00
|
|
|
}
|
|
|
|
|
// 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)) {
|
2026-04-30 06:44:26 -03:00
|
|
|
properties.append({ .property_id = CSS::PropertyID::MarginLeft, .value = *parsed_value });
|
|
|
|
|
properties.append({ .property_id = CSS::PropertyID::MarginRight, .value = *parsed_value });
|
2024-10-01 13:26:01 -03:00
|
|
|
}
|
|
|
|
|
} else if (name == HTML::AttributeNames::vspace) {
|
|
|
|
|
if (auto parsed_value = parse_dimension_value(value)) {
|
2026-04-30 06:44:26 -03:00
|
|
|
properties.append({ .property_id = CSS::PropertyID::MarginTop, .value = *parsed_value });
|
|
|
|
|
properties.append({ .property_id = CSS::PropertyID::MarginBottom, .value = *parsed_value });
|
2024-10-01 13:26:01 -03:00
|
|
|
}
|
|
|
|
|
} else if (name == HTML::AttributeNames::width) {
|
|
|
|
|
if (auto parsed_value = parse_dimension_value(value)) {
|
2026-04-30 06:44:26 -03:00
|
|
|
properties.append({ .property_id = CSS::PropertyID::Width, .value = *parsed_value });
|
2024-10-01 13:26:01 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-20 07:32:17 -03:00
|
|
|
void HTMLEmbedElement::adjust_computed_style(CSS::ComputedProperties& style)
|
2024-11-08 09:14:37 -03:00
|
|
|
{
|
|
|
|
|
// https://drafts.csswg.org/css-display-3/#unbox
|
|
|
|
|
if (style.display().is_contents())
|
|
|
|
|
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::None)));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 23:04:26 -03:00
|
|
|
}
|