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>
|
2023-05-08 07:51:03 +02:00
|
|
|
#include <LibWeb/CSS/StyleProperties.h>
|
2023-03-23 21:12:15 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
2023-03-24 15:04:24 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/IdentifierStyleValue.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-03-14 13:21:51 -06:00
|
|
|
HTMLTableCellElement::~HTMLTableCellElement() = default;
|
2020-06-07 23:10:45 +02:00
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
JS::ThrowCompletionOr<void> HTMLTableCellElement::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2023-01-28 12:33:35 -05:00
|
|
|
MUST_OR_THROW_OOM(Base::initialize(realm));
|
2023-01-10 06:28:20 -05:00
|
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLTableCellElementPrototype>(realm, "HTMLTableCellElement"));
|
2023-01-28 12:33:35 -05:00
|
|
|
|
|
|
|
return {};
|
2023-01-10 06:28:20 -05: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) {
|
2023-05-28 15:06:12 +12:00
|
|
|
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
|
|
|
|
auto color = parse_legacy_color_value(value);
|
2020-06-12 22:47:51 +02:00
|
|
|
if (color.has_value())
|
2023-05-05 15:02:03 +01:00
|
|
|
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
|
2020-06-13 15:16:56 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-07-04 12:57:12 +02:00
|
|
|
if (name == HTML::AttributeNames::valign) {
|
|
|
|
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value.view(), CSS::PropertyID::VerticalAlign).release_value_but_fixme_should_propagate_errors())
|
|
|
|
style.set_property(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull());
|
|
|
|
return;
|
|
|
|
}
|
2020-06-13 15:16:56 +02:00
|
|
|
if (name == HTML::AttributeNames::align) {
|
2023-03-10 08:48:54 +01:00
|
|
|
if (value.equals_ignoring_ascii_case("center"sv) || value.equals_ignoring_ascii_case("middle"sv)) {
|
2023-05-05 15:02:03 +01:00
|
|
|
style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::LibwebCenter).release_value_but_fixme_should_propagate_errors());
|
2021-10-28 01:50:19 +02:00
|
|
|
} else {
|
2023-05-02 15:09:46 +01:00
|
|
|
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value.view(), CSS::PropertyID::TextAlign).release_value_but_fixme_should_propagate_errors())
|
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);
|
|
|
|
}
|
|
|
|
|
2023-05-25 20:37:57 +01:00
|
|
|
WebIDL::ExceptionOr<void> HTMLTableCellElement::set_col_span(unsigned int value)
|
2022-03-28 23:27:56 +02:00
|
|
|
{
|
2023-05-25 20:37:57 +01:00
|
|
|
return 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);
|
|
|
|
}
|
|
|
|
|
2023-05-25 20:37:57 +01:00
|
|
|
WebIDL::ExceptionOr<void> HTMLTableCellElement::set_row_span(unsigned int value)
|
2022-03-28 23:36:10 +02:00
|
|
|
{
|
2023-05-25 20:37:57 +01:00
|
|
|
return set_attribute(HTML::AttributeNames::rowspan, DeprecatedString::number(value));
|
2022-03-28 23:36:10 +02:00
|
|
|
}
|
|
|
|
|
2023-01-28 22:23:16 +00:00
|
|
|
Optional<ARIA::Role> HTMLTableCellElement::default_role() const
|
2022-11-28 17:58:13 -06:00
|
|
|
{
|
|
|
|
// TODO: For td:
|
|
|
|
// role=cell if the ancestor table element is exposed as a role=table
|
|
|
|
// role=gridcell if the ancestor table element is exposed as a role=grid or treegrid
|
|
|
|
// No corresponding role if the ancestor table element is not exposed as a role=table, grid or treegrid
|
|
|
|
// For th:
|
|
|
|
// role=columnheader, rowheader or cell if the ancestor table element is exposed as a role=table
|
|
|
|
// role=columnheader, rowheader or gridcell if the ancestor table element is exposed as a role=grid or treegrid
|
|
|
|
// No corresponding role if the ancestor table element is not exposed as a role=table, grid or treegrid
|
|
|
|
// https://www.w3.org/TR/html-aria/#el-td
|
|
|
|
// https://www.w3.org/TR/html-aria/#el-th
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-06-07 23:10:45 +02:00
|
|
|
}
|