HTMLEmbedElement.cpp 2.5 KB

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