2020-06-07 23:10:45 +02:00
|
|
|
/*
|
2022-03-26 14:29:52 +01:00
|
|
|
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
2020-06-07 23:10:45 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-07 23:10:45 +02:00
|
|
|
*/
|
|
|
|
|
2022-09-30 17:16:16 -06:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
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>
|
2022-03-26 14:29:52 +01:00
|
|
|
#include <LibWeb/HTML/Parser/HTMLParser.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-09-25 16:38:21 -06:00
|
|
|
set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableCellElement"));
|
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 {
|
2022-04-12 12:00:07 +01:00
|
|
|
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value.view(), CSS::PropertyID::TextAlign))
|
2021-10-28 01:50:19 +02:00
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-28 23:27:56 +02:00
|
|
|
unsigned int HTMLTableCellElement::col_span() const
|
|
|
|
{
|
|
|
|
return attribute(HTML::AttributeNames::colspan).to_uint().value_or(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLTableCellElement::set_col_span(unsigned int value)
|
|
|
|
{
|
2022-12-04 18:02:33 +00:00
|
|
|
MUST(set_attribute(HTML::AttributeNames::colspan, DeprecatedString::number(value)));
|
2022-03-28 23:27:56 +02:00
|
|
|
}
|
|
|
|
|
2022-03-28 23:36:10 +02:00
|
|
|
unsigned int HTMLTableCellElement::row_span() const
|
|
|
|
{
|
|
|
|
return attribute(HTML::AttributeNames::rowspan).to_uint().value_or(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLTableCellElement::set_row_span(unsigned int value)
|
|
|
|
{
|
2022-12-04 18:02:33 +00:00
|
|
|
MUST(set_attribute(HTML::AttributeNames::rowspan, DeprecatedString::number(value)));
|
2022-03-28 23:36:10 +02:00
|
|
|
}
|
|
|
|
|
2020-06-07 23:10:45 +02:00
|
|
|
}
|