2020-08-01 03:07:00 +01:00
|
|
|
/*
|
2021-04-28 22:46:44 +02:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2020-08-01 03:07:00 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 03:07:00 +01:00
|
|
|
*/
|
|
|
|
|
2024-04-27 12:09:58 +12:00
|
|
|
#include <LibWeb/Bindings/HTMLTableColElementPrototype.h>
|
2022-09-30 17:16:16 -06:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-10-01 17:45:10 +01:00
|
|
|
#include <LibWeb/CSS/StyleProperties.h>
|
2020-08-01 03:07:00 +01:00
|
|
|
#include <LibWeb/HTML/HTMLTableColElement.h>
|
2023-11-24 17:40:05 +01:00
|
|
|
#include <LibWeb/HTML/Numbers.h>
|
2024-10-01 17:45:10 +01:00
|
|
|
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
2020-08-01 03:07:00 +01:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(HTMLTableColElement);
|
2023-11-19 19:47:52 +01:00
|
|
|
|
2022-02-18 21:00:52 +01:00
|
|
|
HTMLTableColElement::HTMLTableColElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 11:20:15 +01:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
2020-08-01 03:07:00 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
HTMLTableColElement::~HTMLTableColElement() = default;
|
2020-08-01 03:07:00 +01:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void HTMLTableColElement::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2023-08-07 08:41:28 +02:00
|
|
|
Base::initialize(realm);
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTableColElement);
|
2023-01-10 06:28:20 -05:00
|
|
|
}
|
|
|
|
|
2023-11-24 17:40:05 +01:00
|
|
|
// https://html.spec.whatwg.org/multipage/tables.html#dom-colgroup-span
|
2024-11-30 22:56:41 +00:00
|
|
|
WebIDL::UnsignedLong HTMLTableColElement::span() const
|
2023-11-24 17:40:05 +01:00
|
|
|
{
|
|
|
|
// The span IDL attribute must reflect the content attribute of the same name. It is clamped to the range [1, 1000], and its default value is 1.
|
2023-12-07 18:40:54 +01:00
|
|
|
if (auto span_string = get_attribute(HTML::AttributeNames::span); span_string.has_value()) {
|
2024-11-30 22:56:41 +00:00
|
|
|
if (auto span_digits = parse_non_negative_integer_digits(*span_string); span_digits.has_value()) {
|
|
|
|
auto span = AK::StringUtils::convert_to_int<i64>(*span_digits);
|
|
|
|
// NOTE: If span has no value at this point, the value must be larger than NumericLimits<i64>::max(), so return the maximum value of 1000.
|
|
|
|
if (!span.has_value())
|
|
|
|
return 1000;
|
2023-12-07 18:40:54 +01:00
|
|
|
return clamp(*span, 1, 1000);
|
2024-11-30 22:56:41 +00:00
|
|
|
}
|
2023-11-24 17:40:05 +01:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> HTMLTableColElement::set_span(unsigned int value)
|
|
|
|
{
|
2024-11-30 22:56:41 +00:00
|
|
|
if (value > 2147483647)
|
|
|
|
value = 1;
|
2024-10-14 10:05:01 +02:00
|
|
|
return set_attribute(HTML::AttributeNames::span, String::number(value));
|
2023-11-24 17:40:05 +01:00
|
|
|
}
|
|
|
|
|
LibWeb: Split StyleComputer work into two phases with separate outputs
Before this change, StyleComputer would essentially take a DOM element,
find all the CSS rules that apply to it, and resolve the computed value
for each CSS property for that element.
This worked great, but it meant we had to do all the work of selector
matching and cascading every time.
To enable new optimizations, this change introduces a break in the
middle of this process where we've produced a "CascadedProperties".
This object contains the result of the cascade, before we've begun
turning cascaded values into computed values.
The cascaded properties are now stored with each element, which will
later allow us to do partial updates without re-running the full
StyleComputer machine. This will be particularly valuable for
re-implementing CSS inheritance, which is extremely heavy today.
Note that CSS animations and CSS transitions operate entirely on the
computed values, even though the cascade order would have you believe
they happen earlier. I'm not confident we have the right architecture
for this, but that's a separate issue.
2024-12-12 10:06:29 +01:00
|
|
|
void HTMLTableColElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
2024-10-01 17:45:10 +01:00
|
|
|
{
|
|
|
|
for_each_attribute([&](auto& name, auto& value) {
|
|
|
|
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:maps-to-the-dimension-property-2
|
|
|
|
if (name == HTML::AttributeNames::width) {
|
|
|
|
if (auto parsed_value = parse_dimension_value(value)) {
|
LibWeb: Split StyleComputer work into two phases with separate outputs
Before this change, StyleComputer would essentially take a DOM element,
find all the CSS rules that apply to it, and resolve the computed value
for each CSS property for that element.
This worked great, but it meant we had to do all the work of selector
matching and cascading every time.
To enable new optimizations, this change introduces a break in the
middle of this process where we've produced a "CascadedProperties".
This object contains the result of the cascade, before we've begun
turning cascaded values into computed values.
The cascaded properties are now stored with each element, which will
later allow us to do partial updates without re-running the full
StyleComputer machine. This will be particularly valuable for
re-implementing CSS inheritance, which is extremely heavy today.
Note that CSS animations and CSS transitions operate entirely on the
computed values, even though the cascade order would have you believe
they happen earlier. I'm not confident we have the right architecture
for this, but that's a separate issue.
2024-12-12 10:06:29 +01:00
|
|
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, *parsed_value);
|
2024-10-01 17:45:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-01 03:07:00 +01:00
|
|
|
}
|