/src/serenity/Userland/Libraries/LibWeb/HTML/HTMLEmbedElement.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2020, the SerenityOS developers. |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Bindings/HTMLEmbedElementPrototype.h> |
8 | | #include <LibWeb/Bindings/Intrinsics.h> |
9 | | #include <LibWeb/CSS/StyleProperties.h> |
10 | | #include <LibWeb/CSS/StyleValues/CSSKeywordValue.h> |
11 | | #include <LibWeb/HTML/HTMLEmbedElement.h> |
12 | | #include <LibWeb/HTML/Parser/HTMLParser.h> |
13 | | |
14 | | namespace Web::HTML { |
15 | | |
16 | | JS_DEFINE_ALLOCATOR(HTMLEmbedElement); |
17 | | |
18 | | HTMLEmbedElement::HTMLEmbedElement(DOM::Document& document, DOM::QualifiedName qualified_name) |
19 | 0 | : HTMLElement(document, move(qualified_name)) |
20 | 0 | { |
21 | 0 | } |
22 | | |
23 | 0 | HTMLEmbedElement::~HTMLEmbedElement() = default; |
24 | | |
25 | | void HTMLEmbedElement::initialize(JS::Realm& realm) |
26 | 0 | { |
27 | 0 | Base::initialize(realm); |
28 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLEmbedElement); |
29 | 0 | } |
30 | | |
31 | | void HTMLEmbedElement::apply_presentational_hints(CSS::StyleProperties& style) const |
32 | 0 | { |
33 | 0 | for_each_attribute([&](auto& name, auto& value) { |
34 | 0 | if (name == HTML::AttributeNames::align) { |
35 | 0 | if (value.equals_ignoring_ascii_case("center"sv)) |
36 | 0 | style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center)); |
37 | 0 | else if (value.equals_ignoring_ascii_case("middle"sv)) |
38 | 0 | style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Middle)); |
39 | 0 | } else if (name == HTML::AttributeNames::height) { |
40 | 0 | if (auto parsed_value = parse_dimension_value(value)) |
41 | 0 | style.set_property(CSS::PropertyID::Height, *parsed_value); |
42 | 0 | } |
43 | | // https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images:maps-to-the-dimension-property |
44 | 0 | else if (name == HTML::AttributeNames::hspace) { |
45 | 0 | if (auto parsed_value = parse_dimension_value(value)) { |
46 | 0 | style.set_property(CSS::PropertyID::MarginLeft, *parsed_value); |
47 | 0 | style.set_property(CSS::PropertyID::MarginRight, *parsed_value); |
48 | 0 | } |
49 | 0 | } else if (name == HTML::AttributeNames::vspace) { |
50 | 0 | if (auto parsed_value = parse_dimension_value(value)) { |
51 | 0 | style.set_property(CSS::PropertyID::MarginTop, *parsed_value); |
52 | 0 | style.set_property(CSS::PropertyID::MarginBottom, *parsed_value); |
53 | 0 | } |
54 | 0 | } else if (name == HTML::AttributeNames::width) { |
55 | 0 | if (auto parsed_value = parse_dimension_value(value)) { |
56 | 0 | style.set_property(CSS::PropertyID::Width, *parsed_value); |
57 | 0 | } |
58 | 0 | } |
59 | 0 | }); |
60 | 0 | } |
61 | | |
62 | | } |