mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 10:09:14 +00: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.
This commit is contained in:
parent
4d9f17eddf
commit
ed7f4664c2
Notes:
github-actions[bot]
2024-12-22 09:14:00 +00:00
Author: https://github.com/awesomekling
Commit: ed7f4664c2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2995
60 changed files with 663 additions and 385 deletions
|
@ -41,22 +41,22 @@ void HTMLBodyElement::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLBodyElement);
|
||||
}
|
||||
|
||||
void HTMLBodyElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLBodyElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name.equals_ignoring_ascii_case("bgcolor"sv)) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value
|
||||
auto color = parse_legacy_color_value(value);
|
||||
if (color.has_value())
|
||||
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
} else if (name.equals_ignoring_ascii_case("text"sv)) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-2
|
||||
auto color = parse_legacy_color_value(value);
|
||||
if (color.has_value())
|
||||
style.set_property(CSS::PropertyID::Color, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Color, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
} else if (name.equals_ignoring_ascii_case("background"sv)) {
|
||||
VERIFY(m_background_style_value);
|
||||
style.set_property(CSS::PropertyID::BackgroundImage, *m_background_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundImage, *m_background_style_value);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -84,7 +84,7 @@ void HTMLBodyElement::apply_presentational_hints(CSS::StyleProperties& style) co
|
|||
if (!value.has_value())
|
||||
return;
|
||||
if (auto parsed_value = parse_non_negative_integer(value.value()); parsed_value.has_value())
|
||||
style.set_property(property_id, CSS::LengthStyleValue::create(CSS::Length::make_px(*parsed_value)));
|
||||
cascaded_properties->set_property_from_presentational_hint(property_id, CSS::LengthStyleValue::create(CSS::Length::make_px(*parsed_value)));
|
||||
};
|
||||
|
||||
apply_margin_value(CSS::PropertyID::MarginTop, margin_top_value);
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
virtual ~HTMLBodyElement() override;
|
||||
|
||||
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
|
||||
// https://www.w3.org/TR/html-aria/#el-body
|
||||
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::generic; }
|
||||
|
|
|
@ -65,7 +65,7 @@ void HTMLCanvasElement::visit_edges(Cell::Visitor& visitor)
|
|||
});
|
||||
}
|
||||
|
||||
void HTMLCanvasElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLCanvasElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images
|
||||
// The width and height attributes map to the aspect-ratio property on canvas elements.
|
||||
|
@ -79,7 +79,7 @@ void HTMLCanvasElement::apply_presentational_hints(CSS::StyleProperties& style)
|
|||
|
||||
if (w.has_value() && h.has_value())
|
||||
// then the user agent is expected to use the parsed integers as a presentational hint for the 'aspect-ratio' property of the form auto w / h.
|
||||
style.set_property(CSS::PropertyID::AspectRatio,
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::AspectRatio,
|
||||
CSS::StyleValueList::create(CSS::StyleValueVector {
|
||||
CSS::CSSKeywordValue::create(CSS::Keyword::Auto),
|
||||
CSS::RatioStyleValue::create(CSS::Ratio { static_cast<double>(w.value()), static_cast<double>(h.value()) }) },
|
||||
|
|
|
@ -52,7 +52,7 @@ private:
|
|||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
|
||||
virtual GC::Ptr<Layout::Node> create_layout_node(CSS::StyleProperties) override;
|
||||
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
||||
|
|
|
@ -22,18 +22,18 @@ HTMLDivElement::HTMLDivElement(DOM::Document& document, DOM::QualifiedName quali
|
|||
HTMLDivElement::~HTMLDivElement() = default;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3
|
||||
void HTMLDivElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLDivElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name.equals_ignoring_ascii_case("align"sv)) {
|
||||
if (value.equals_ignoring_ascii_case("left"sv))
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebLeft));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebLeft));
|
||||
else if (value.equals_ignoring_ascii_case("right"sv))
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebRight));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebRight));
|
||||
else if (value.equals_ignoring_ascii_case("center"sv))
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebCenter));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebCenter));
|
||||
else if (value.equals_ignoring_ascii_case("justify"sv))
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Justify));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Justify));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ protected:
|
|||
|
||||
private:
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -29,32 +29,32 @@ void HTMLEmbedElement::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLEmbedElement);
|
||||
}
|
||||
|
||||
void HTMLEmbedElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLEmbedElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name == HTML::AttributeNames::align) {
|
||||
if (value.equals_ignoring_ascii_case("center"sv))
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center));
|
||||
else if (value.equals_ignoring_ascii_case("middle"sv))
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Middle));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Middle));
|
||||
} else if (name == HTML::AttributeNames::height) {
|
||||
if (auto parsed_value = parse_dimension_value(value))
|
||||
style.set_property(CSS::PropertyID::Height, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, *parsed_value);
|
||||
}
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images:maps-to-the-dimension-property
|
||||
else if (name == HTML::AttributeNames::hspace) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::MarginLeft, *parsed_value);
|
||||
style.set_property(CSS::PropertyID::MarginRight, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginLeft, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginRight, *parsed_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::vspace) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::MarginTop, *parsed_value);
|
||||
style.set_property(CSS::PropertyID::MarginBottom, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginTop, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginBottom, *parsed_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::width) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::Width, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, *parsed_value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -22,7 +22,7 @@ private:
|
|||
|
||||
virtual bool is_html_embed_element() const override { return true; }
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
||||
};
|
||||
|
||||
|
|
|
@ -112,21 +112,21 @@ void HTMLFontElement::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLFontElement);
|
||||
}
|
||||
|
||||
void HTMLFontElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLFontElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name.equals_ignoring_ascii_case("color"sv)) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#phrasing-content-3:rules-for-parsing-a-legacy-colour-value
|
||||
auto color = parse_legacy_color_value(value);
|
||||
if (color.has_value())
|
||||
style.set_property(CSS::PropertyID::Color, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Color, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
} else if (name.equals_ignoring_ascii_case("size"sv)) {
|
||||
// When a font element has a size attribute, the user agent is expected to use the following steps, known as the rules for parsing a legacy font size, to treat the attribute as a presentational hint setting the element's 'font-size' property:
|
||||
auto font_size_or_empty = parse_legacy_font_size(value);
|
||||
if (font_size_or_empty.has_value()) {
|
||||
auto font_size = string_from_keyword(font_size_or_empty.release_value());
|
||||
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, font_size, CSS::PropertyID::FontSize))
|
||||
style.set_property(CSS::PropertyID::FontSize, parsed_value.release_nonnull());
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::FontSize, parsed_value.release_nonnull());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@ class HTMLFontElement final : public HTMLElement {
|
|||
public:
|
||||
virtual ~HTMLFontElement() override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
|
||||
private:
|
||||
HTMLFontElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
|
|
@ -28,13 +28,13 @@ void HTMLHRElement::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLHRElement);
|
||||
}
|
||||
|
||||
void HTMLHRElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLHRElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#the-hr-element-2:maps-to-the-dimension-property
|
||||
if (name == HTML::AttributeNames::width) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::Width, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, *parsed_value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -26,7 +26,7 @@ private:
|
|||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -28,19 +28,19 @@ void HTMLHeadingElement::initialize(JS::Realm& realm)
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2
|
||||
void HTMLHeadingElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLHeadingElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
HTMLElement::apply_presentational_hints(style);
|
||||
HTMLElement::apply_presentational_hints(cascaded_properties);
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name.equals_ignoring_ascii_case("align"sv)) {
|
||||
if (value == "left"sv)
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Left));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Left));
|
||||
else if (value == "right"sv)
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Right));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Right));
|
||||
else if (value == "center"sv)
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center));
|
||||
else if (value == "justify"sv)
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Justify));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Justify));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class HTMLHeadingElement final : public HTMLElement {
|
|||
public:
|
||||
virtual ~HTMLHeadingElement() override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
|
||||
// https://www.w3.org/TR/html-aria/#el-h1-h6
|
||||
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::heading; }
|
||||
|
|
|
@ -82,32 +82,32 @@ void HTMLImageElement::visit_edges(Cell::Visitor& visitor)
|
|||
visit_lazy_loading_element(visitor);
|
||||
}
|
||||
|
||||
void HTMLImageElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLImageElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name == HTML::AttributeNames::hspace) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::MarginLeft, *parsed_value);
|
||||
style.set_property(CSS::PropertyID::MarginRight, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginLeft, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginRight, *parsed_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::vspace) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::MarginTop, *parsed_value);
|
||||
style.set_property(CSS::PropertyID::MarginBottom, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginTop, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginBottom, *parsed_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::border) {
|
||||
if (auto parsed_value = parse_non_negative_integer(value); parsed_value.has_value()) {
|
||||
auto width_value = CSS::LengthStyleValue::create(CSS::Length::make_px(*parsed_value));
|
||||
style.set_property(CSS::PropertyID::BorderTopWidth, width_value);
|
||||
style.set_property(CSS::PropertyID::BorderRightWidth, width_value);
|
||||
style.set_property(CSS::PropertyID::BorderBottomWidth, width_value);
|
||||
style.set_property(CSS::PropertyID::BorderLeftWidth, width_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderTopWidth, width_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderRightWidth, width_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderBottomWidth, width_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderLeftWidth, width_value);
|
||||
|
||||
auto solid_value = CSS::CSSKeywordValue::create(CSS::Keyword::Solid);
|
||||
style.set_property(CSS::PropertyID::BorderTopStyle, solid_value);
|
||||
style.set_property(CSS::PropertyID::BorderRightStyle, solid_value);
|
||||
style.set_property(CSS::PropertyID::BorderBottomStyle, solid_value);
|
||||
style.set_property(CSS::PropertyID::BorderLeftStyle, solid_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderTopStyle, solid_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderRightStyle, solid_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderBottomStyle, solid_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderLeftStyle, solid_value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -121,7 +121,7 @@ private:
|
|||
|
||||
virtual void adopted_from(DOM::Document&) override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element:dimension-attributes
|
||||
virtual bool supports_dimension_attributes() const override { return true; }
|
||||
|
|
|
@ -1593,7 +1593,7 @@ void HTMLInputElement::form_associated_element_was_removed(DOM::Node*)
|
|||
set_shadow_root(nullptr);
|
||||
}
|
||||
|
||||
void HTMLInputElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLInputElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
if (type_state() != TypeAttributeState::ImageButton)
|
||||
return;
|
||||
|
@ -1601,42 +1601,42 @@ void HTMLInputElement::apply_presentational_hints(CSS::StyleProperties& style) c
|
|||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name == HTML::AttributeNames::align) {
|
||||
if (value.equals_ignoring_ascii_case("center"sv))
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center));
|
||||
else if (value.equals_ignoring_ascii_case("middle"sv))
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Middle));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Middle));
|
||||
} else if (name == HTML::AttributeNames::border) {
|
||||
if (auto parsed_value = parse_non_negative_integer(value); parsed_value.has_value()) {
|
||||
auto width_style_value = CSS::LengthStyleValue::create(CSS::Length::make_px(*parsed_value));
|
||||
style.set_property(CSS::PropertyID::BorderTopWidth, width_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderRightWidth, width_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderBottomWidth, width_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderLeftWidth, width_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderTopWidth, width_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderRightWidth, width_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderBottomWidth, width_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderLeftWidth, width_style_value);
|
||||
|
||||
auto border_style_value = CSS::CSSKeywordValue::create(CSS::Keyword::Solid);
|
||||
style.set_property(CSS::PropertyID::BorderTopStyle, border_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderRightStyle, border_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderBottomStyle, border_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderLeftStyle, border_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderTopStyle, border_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderRightStyle, border_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderBottomStyle, border_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderLeftStyle, border_style_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::height) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::Height, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, *parsed_value);
|
||||
}
|
||||
}
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images:maps-to-the-dimension-property
|
||||
else if (name == HTML::AttributeNames::hspace) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::MarginLeft, *parsed_value);
|
||||
style.set_property(CSS::PropertyID::MarginRight, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginLeft, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginRight, *parsed_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::vspace) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::MarginTop, *parsed_value);
|
||||
style.set_property(CSS::PropertyID::MarginBottom, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginTop, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginBottom, *parsed_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::width) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::Width, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, *parsed_value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -227,7 +227,7 @@ private:
|
|||
|
||||
void type_attribute_changed(TypeAttributeState old_state, TypeAttributeState new_state);
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
|
||||
// ^DOM::Node
|
||||
virtual bool is_html_input_element() const final { return true; }
|
||||
|
|
|
@ -30,33 +30,33 @@ void HTMLMarqueeElement::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLMarqueeElement);
|
||||
}
|
||||
|
||||
void HTMLMarqueeElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLMarqueeElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
HTMLElement::apply_presentational_hints(style);
|
||||
HTMLElement::apply_presentational_hints(cascaded_properties);
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name == HTML::AttributeNames::bgcolor) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#the-marquee-element-2:rules-for-parsing-a-legacy-colour-value
|
||||
auto color = parse_legacy_color_value(value);
|
||||
if (color.has_value())
|
||||
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
} else if (name == HTML::AttributeNames::height) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#the-marquee-element-2:maps-to-the-dimension-property
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::Height, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, *parsed_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::hspace) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::MarginLeft, *parsed_value);
|
||||
style.set_property(CSS::PropertyID::MarginRight, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginLeft, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginRight, *parsed_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::vspace) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::MarginTop, *parsed_value);
|
||||
style.set_property(CSS::PropertyID::MarginBottom, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginTop, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginBottom, *parsed_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::width) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::Width, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, *parsed_value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -30,7 +30,7 @@ private:
|
|||
HTMLMarqueeElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -100,49 +100,49 @@ void HTMLObjectElement::form_associated_element_was_removed(DOM::Node*)
|
|||
destroy_the_child_navigable();
|
||||
}
|
||||
|
||||
void HTMLObjectElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLObjectElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name == HTML::AttributeNames::align) {
|
||||
if (value.equals_ignoring_ascii_case("center"sv))
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center));
|
||||
else if (value.equals_ignoring_ascii_case("middle"sv))
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Middle));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Middle));
|
||||
} else if (name == HTML::AttributeNames::border) {
|
||||
if (auto parsed_value = parse_non_negative_integer(value); parsed_value.has_value()) {
|
||||
auto width_style_value = CSS::LengthStyleValue::create(CSS::Length::make_px(*parsed_value));
|
||||
style.set_property(CSS::PropertyID::BorderTopWidth, width_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderRightWidth, width_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderBottomWidth, width_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderLeftWidth, width_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderTopWidth, width_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderRightWidth, width_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderBottomWidth, width_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderLeftWidth, width_style_value);
|
||||
|
||||
auto border_style_value = CSS::CSSKeywordValue::create(CSS::Keyword::Solid);
|
||||
style.set_property(CSS::PropertyID::BorderTopStyle, border_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderRightStyle, border_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderBottomStyle, border_style_value);
|
||||
style.set_property(CSS::PropertyID::BorderLeftStyle, border_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderTopStyle, border_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderRightStyle, border_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderBottomStyle, border_style_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderLeftStyle, border_style_value);
|
||||
}
|
||||
}
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images:maps-to-the-dimension-property-3
|
||||
else if (name == HTML::AttributeNames::height) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::Height, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, *parsed_value);
|
||||
}
|
||||
}
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images:maps-to-the-dimension-property
|
||||
else if (name == HTML::AttributeNames::hspace) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::MarginLeft, *parsed_value);
|
||||
style.set_property(CSS::PropertyID::MarginRight, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginLeft, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginRight, *parsed_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::vspace) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::MarginTop, *parsed_value);
|
||||
style.set_property(CSS::PropertyID::MarginBottom, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginTop, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginBottom, *parsed_value);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::width) {
|
||||
if (auto parsed_value = parse_dimension_value(value)) {
|
||||
style.set_property(CSS::PropertyID::Width, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, *parsed_value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -54,7 +54,7 @@ private:
|
|||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
|
||||
virtual GC::Ptr<Layout::Node> create_layout_node(CSS::StyleProperties) override;
|
||||
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
||||
|
|
|
@ -28,19 +28,19 @@ void HTMLParagraphElement::initialize(JS::Realm& realm)
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2
|
||||
void HTMLParagraphElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLParagraphElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
HTMLElement::apply_presentational_hints(style);
|
||||
HTMLElement::apply_presentational_hints(cascaded_properties);
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name.equals_ignoring_ascii_case("align"sv)) {
|
||||
if (value == "left"sv)
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Left));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Left));
|
||||
else if (value == "right"sv)
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Right));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Right));
|
||||
else if (value == "center"sv)
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Center));
|
||||
else if (value == "justify"sv)
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Justify));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::Justify));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class HTMLParagraphElement final : public HTMLElement {
|
|||
public:
|
||||
virtual ~HTMLParagraphElement() override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
|
||||
// https://www.w3.org/TR/html-aria/#el-p
|
||||
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::paragraph; }
|
||||
|
|
|
@ -28,13 +28,13 @@ void HTMLPreElement::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLPreElement);
|
||||
}
|
||||
|
||||
void HTMLPreElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLPreElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
HTMLElement::apply_presentational_hints(style);
|
||||
HTMLElement::apply_presentational_hints(cascaded_properties);
|
||||
|
||||
for_each_attribute([&](auto const& name, auto const&) {
|
||||
if (name.equals_ignoring_ascii_case(HTML::AttributeNames::wrap))
|
||||
style.set_property(CSS::PropertyID::WhiteSpace, CSS::CSSKeywordValue::create(CSS::Keyword::PreWrap));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::WhiteSpace, CSS::CSSKeywordValue::create(CSS::Keyword::PreWrap));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ private:
|
|||
HTMLPreElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -28,13 +28,13 @@ void HTMLTableCaptionElement::initialize(JS::Realm& realm)
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2
|
||||
void HTMLTableCaptionElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLTableCaptionElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
HTMLElement::apply_presentational_hints(style);
|
||||
HTMLElement::apply_presentational_hints(cascaded_properties);
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name.equals_ignoring_ascii_case("align"sv)) {
|
||||
if (value == "bottom"sv)
|
||||
style.set_property(CSS::PropertyID::CaptionSide, CSS::CSSKeywordValue::create(CSS::Keyword::Bottom));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::CaptionSide, CSS::CSSKeywordValue::create(CSS::Keyword::Bottom));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class HTMLTableCaptionElement final : public HTMLElement {
|
|||
public:
|
||||
virtual ~HTMLTableCaptionElement() override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
|
||||
// https://www.w3.org/TR/html-aria/#el-caption
|
||||
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::caption; }
|
||||
|
|
|
@ -37,46 +37,46 @@ void HTMLTableCellElement::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTableCellElement);
|
||||
}
|
||||
|
||||
void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLTableCellElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name == HTML::AttributeNames::bgcolor) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
|
||||
auto color = parse_legacy_color_value(value);
|
||||
if (color.has_value())
|
||||
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
return;
|
||||
}
|
||||
if (name == HTML::AttributeNames::valign) {
|
||||
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::VerticalAlign))
|
||||
style.set_property(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull());
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull());
|
||||
return;
|
||||
}
|
||||
if (name == HTML::AttributeNames::align) {
|
||||
if (value.equals_ignoring_ascii_case("center"sv) || value.equals_ignoring_ascii_case("middle"sv)) {
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebCenter));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebCenter));
|
||||
} else if (value.equals_ignoring_ascii_case("left"sv)) {
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebLeft));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebLeft));
|
||||
} else if (value.equals_ignoring_ascii_case("right"sv)) {
|
||||
style.set_property(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebRight));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebRight));
|
||||
} else {
|
||||
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::TextAlign))
|
||||
style.set_property(CSS::PropertyID::TextAlign, parsed_value.release_nonnull());
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, parsed_value.release_nonnull());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (name == HTML::AttributeNames::width) {
|
||||
if (auto parsed_value = parse_nonzero_dimension_value(value))
|
||||
style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull());
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, parsed_value.release_nonnull());
|
||||
return;
|
||||
} 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());
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, parsed_value.release_nonnull());
|
||||
return;
|
||||
} else if (name == HTML::AttributeNames::background) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:encoding-parsing-and-serializing-a-url
|
||||
if (auto parsed_value = document().encoding_parse_url(value); parsed_value.is_valid())
|
||||
style.set_property(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
@ -86,10 +86,10 @@ void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& styl
|
|||
return;
|
||||
|
||||
if (auto padding = table_element->padding()) {
|
||||
style.set_property(CSS::PropertyID::PaddingTop, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
|
||||
style.set_property(CSS::PropertyID::PaddingBottom, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
|
||||
style.set_property(CSS::PropertyID::PaddingLeft, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
|
||||
style.set_property(CSS::PropertyID::PaddingRight, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::PaddingTop, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::PaddingBottom, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::PaddingLeft, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::PaddingRight, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
|
||||
}
|
||||
|
||||
auto border = table_element->border();
|
||||
|
@ -97,9 +97,9 @@ void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& styl
|
|||
if (!border)
|
||||
return;
|
||||
auto apply_border_style = [&](CSS::PropertyID style_property, CSS::PropertyID width_property, CSS::PropertyID color_property) {
|
||||
style.set_property(style_property, CSS::CSSKeywordValue::create(CSS::Keyword::Inset));
|
||||
style.set_property(width_property, CSS::LengthStyleValue::create(CSS::Length::make_px(1)));
|
||||
style.set_property(color_property, table_element->computed_css_values()->property(color_property));
|
||||
cascaded_properties->set_property_from_presentational_hint(style_property, CSS::CSSKeywordValue::create(CSS::Keyword::Inset));
|
||||
cascaded_properties->set_property_from_presentational_hint(width_property, CSS::LengthStyleValue::create(CSS::Length::make_px(1)));
|
||||
cascaded_properties->set_property_from_presentational_hint(color_property, table_element->computed_css_values()->property(color_property));
|
||||
};
|
||||
apply_border_style(CSS::PropertyID::BorderLeftStyle, CSS::PropertyID::BorderLeftWidth, CSS::PropertyID::BorderLeftColor);
|
||||
apply_border_style(CSS::PropertyID::BorderTopStyle, CSS::PropertyID::BorderTopWidth, CSS::PropertyID::BorderTopColor);
|
||||
|
|
|
@ -34,7 +34,7 @@ private:
|
|||
virtual bool is_html_table_cell_element() const override { return true; }
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -51,13 +51,13 @@ WebIDL::ExceptionOr<void> HTMLTableColElement::set_span(unsigned int value)
|
|||
return set_attribute(HTML::AttributeNames::span, String::number(value));
|
||||
}
|
||||
|
||||
void HTMLTableColElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLTableColElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
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)) {
|
||||
style.set_property(CSS::PropertyID::Width, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, *parsed_value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -26,7 +26,7 @@ private:
|
|||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -51,44 +51,44 @@ static unsigned parse_border(StringView value)
|
|||
return value.to_number<unsigned>().value_or(0);
|
||||
}
|
||||
|
||||
void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLTableElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name == HTML::AttributeNames::width) {
|
||||
if (auto parsed_value = parse_nonzero_dimension_value(value))
|
||||
style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull());
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, parsed_value.release_nonnull());
|
||||
return;
|
||||
}
|
||||
if (name == HTML::AttributeNames::height) {
|
||||
if (auto parsed_value = parse_dimension_value(value))
|
||||
style.set_property(CSS::PropertyID::Height, parsed_value.release_nonnull());
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, parsed_value.release_nonnull());
|
||||
return;
|
||||
}
|
||||
if (name == HTML::AttributeNames::align) {
|
||||
if (value.equals_ignoring_ascii_case("center"sv)) {
|
||||
style.set_property(CSS::PropertyID::MarginLeft, CSS::CSSKeywordValue::create(CSS::Keyword::Auto));
|
||||
style.set_property(CSS::PropertyID::MarginRight, CSS::CSSKeywordValue::create(CSS::Keyword::Auto));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginLeft, CSS::CSSKeywordValue::create(CSS::Keyword::Auto));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginRight, CSS::CSSKeywordValue::create(CSS::Keyword::Auto));
|
||||
} else if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::Float)) {
|
||||
style.set_property(CSS::PropertyID::Float, parsed_value.release_nonnull());
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Float, parsed_value.release_nonnull());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (name == HTML::AttributeNames::background) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:encoding-parsing-and-serializing-a-url
|
||||
if (auto parsed_value = document().encoding_parse_url(value); parsed_value.is_valid())
|
||||
style.set_property(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
|
||||
return;
|
||||
}
|
||||
if (name == HTML::AttributeNames::bgcolor) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
|
||||
auto color = parse_legacy_color_value(value);
|
||||
if (color.has_value())
|
||||
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
return;
|
||||
}
|
||||
if (name == HTML::AttributeNames::cellspacing) {
|
||||
if (auto parsed_value = parse_dimension_value(value))
|
||||
style.set_property(CSS::PropertyID::BorderSpacing, parsed_value.release_nonnull());
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderSpacing, parsed_value.release_nonnull());
|
||||
return;
|
||||
}
|
||||
if (name == HTML::AttributeNames::border) {
|
||||
|
@ -97,9 +97,9 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
|
|||
return;
|
||||
auto apply_border_style = [&](CSS::PropertyID style_property, CSS::PropertyID width_property, CSS::PropertyID color_property) {
|
||||
auto legacy_line_style = CSS::CSSKeywordValue::create(CSS::Keyword::Outset);
|
||||
style.set_property(style_property, legacy_line_style);
|
||||
style.set_property(width_property, CSS::LengthStyleValue::create(CSS::Length::make_px(border)));
|
||||
style.set_property(color_property, CSS::CSSColorValue::create_from_color(Color(128, 128, 128)));
|
||||
cascaded_properties->set_property_from_presentational_hint(style_property, legacy_line_style);
|
||||
cascaded_properties->set_property_from_presentational_hint(width_property, CSS::LengthStyleValue::create(CSS::Length::make_px(border)));
|
||||
cascaded_properties->set_property_from_presentational_hint(color_property, CSS::CSSColorValue::create_from_color(Color(128, 128, 128)));
|
||||
};
|
||||
apply_border_style(CSS::PropertyID::BorderLeftStyle, CSS::PropertyID::BorderLeftWidth, CSS::PropertyID::BorderLeftColor);
|
||||
apply_border_style(CSS::PropertyID::BorderTopStyle, CSS::PropertyID::BorderTopWidth, CSS::PropertyID::BorderTopColor);
|
||||
|
|
|
@ -58,7 +58,7 @@ private:
|
|||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
|
||||
|
||||
GC::Ptr<DOM::HTMLCollection> mutable m_rows;
|
||||
|
|
|
@ -39,25 +39,25 @@ void HTMLTableRowElement::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTableRowElement);
|
||||
}
|
||||
|
||||
void HTMLTableRowElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLTableRowElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
Base::apply_presentational_hints(style);
|
||||
Base::apply_presentational_hints(cascaded_properties);
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
if (name == HTML::AttributeNames::bgcolor) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
|
||||
auto color = parse_legacy_color_value(value);
|
||||
if (color.has_value())
|
||||
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
} else if (name == HTML::AttributeNames::background) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:encoding-parsing-and-serializing-a-url
|
||||
if (auto parsed_value = document().encoding_parse_url(value); parsed_value.is_valid())
|
||||
style.set_property(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
|
||||
} else if (name == HTML::AttributeNames::height) {
|
||||
if (auto parsed_value = parse_dimension_value(value))
|
||||
style.set_property(CSS::PropertyID::Height, *parsed_value);
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, *parsed_value);
|
||||
} else if (name == HTML::AttributeNames::valign) {
|
||||
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::VerticalAlign))
|
||||
style.set_property(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull());
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ private:
|
|||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
|
||||
GC::Ptr<DOM::HTMLCollection> mutable m_cells;
|
||||
};
|
||||
|
|
|
@ -100,18 +100,18 @@ WebIDL::ExceptionOr<void> HTMLTableSectionElement::delete_row(WebIDL::Long index
|
|||
return {};
|
||||
}
|
||||
|
||||
void HTMLTableSectionElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
void HTMLTableSectionElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
for_each_attribute([&](auto& name, auto& value) {
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:encoding-parsing-and-serializing-a-url
|
||||
if (name == HTML::AttributeNames::background) {
|
||||
if (auto parsed_value = document().encoding_parse_url(value); parsed_value.is_valid())
|
||||
style.set_property(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
|
||||
}
|
||||
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
|
||||
else if (name == HTML::AttributeNames::bgcolor) {
|
||||
if (auto color = parse_legacy_color_value(value); color.has_value())
|
||||
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ private:
|
|||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
||||
|
||||
GC::Ptr<DOM::HTMLCollection> mutable m_rows;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue