2020-06-07 23:10:45 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-07 23:10:45 +02:00
|
|
|
*/
|
|
|
|
|
2021-07-30 19:31:46 +01:00
|
|
|
#include <LibWeb/CSS/Parser/Parser.h>
|
2020-07-26 15:08:16 +02:00
|
|
|
#include <LibWeb/HTML/HTMLTableCellElement.h>
|
2020-06-07 23:10:45 +02:00
|
|
|
|
2020-07-28 18:20:36 +02:00
|
|
|
namespace Web::HTML {
|
2020-06-07 23:10:45 +02:00
|
|
|
|
2022-02-18 21:00:52 +01:00
|
|
|
HTMLTableCellElement::HTMLTableCellElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 11:20:15 +01:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
2020-06-07 23:10:45 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
HTMLTableCellElement::~HTMLTableCellElement() = default;
|
2020-06-07 23:10:45 +02:00
|
|
|
|
2020-07-26 20:01:35 +02:00
|
|
|
void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
2020-06-12 22:47:51 +02:00
|
|
|
{
|
|
|
|
for_each_attribute([&](auto& name, auto& value) {
|
|
|
|
if (name == HTML::AttributeNames::bgcolor) {
|
|
|
|
auto color = Color::from_string(value);
|
|
|
|
if (color.has_value())
|
2020-07-26 20:01:35 +02:00
|
|
|
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()));
|
2020-06-13 15:16:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (name == HTML::AttributeNames::align) {
|
2021-10-28 01:50:19 +02:00
|
|
|
if (value.equals_ignoring_case("center"sv) || value.equals_ignoring_case("middle"sv)) {
|
|
|
|
style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::LibwebCenter));
|
|
|
|
} else {
|
|
|
|
CSS::Parser parser(CSS::ParsingContext(document()), value.view());
|
|
|
|
if (auto parsed_value = parser.parse_as_css_value(CSS::PropertyID::TextAlign))
|
|
|
|
style.set_property(CSS::PropertyID::TextAlign, parsed_value.release_nonnull());
|
|
|
|
}
|
2020-06-13 15:16:56 +02:00
|
|
|
return;
|
2020-06-12 22:47:51 +02:00
|
|
|
}
|
2020-06-28 14:30:03 +02:00
|
|
|
if (name == HTML::AttributeNames::width) {
|
2022-03-26 14:19:00 +01:00
|
|
|
if (auto parsed_value = parse_nonzero_dimension_value(value))
|
2020-06-28 14:30:03 +02:00
|
|
|
style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull());
|
|
|
|
return;
|
2022-03-26 14:19:00 +01:00
|
|
|
} else if (name == HTML::AttributeNames::height) {
|
|
|
|
if (auto parsed_value = parse_nonzero_dimension_value(value))
|
|
|
|
style.set_property(CSS::PropertyID::Height, parsed_value.release_nonnull());
|
|
|
|
return;
|
2020-06-28 14:30:03 +02:00
|
|
|
}
|
2020-06-12 22:47:51 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-07 23:10:45 +02:00
|
|
|
}
|