mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 04:39:06 +00:00
LibWeb: Map dimension attributes for table elements
This commit is contained in:
parent
728236f4d2
commit
140dc95e67
Notes:
github-actions[bot]
2024-10-02 09:28:16 +00:00
Author: https://github.com/tcl3
Commit: 140dc95e67
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1591
9 changed files with 61 additions and 8 deletions
|
@ -1,8 +1,8 @@
|
|||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
|
||||
BlockContainer <body> at (8,8) content-size 784x2 children: not-inline
|
||||
TableWrapper <(anonymous)> at (8,8) content-size 6x2 [BFC] children: not-inline
|
||||
Box <table> at (8,8) content-size 6x2 table-box [TFC] children: not-inline
|
||||
TableWrapper <(anonymous)> at (8,8) content-size 46x2 [BFC] children: not-inline
|
||||
Box <table> at (8,8) content-size 46x2 table-box [TFC] children: not-inline
|
||||
BlockContainer <colgroup#my-group> (not painted) table-column-group children: not-inline
|
||||
BlockContainer <col> (not painted) children: not-inline
|
||||
BlockContainer <col> (not painted) children: not-inline
|
||||
|
@ -11,6 +11,6 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
|||
ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x2]
|
||||
PaintableWithLines (TableWrapper(anonymous)) [8,8 6x2]
|
||||
PaintableBox (Box<TABLE>) [8,8 6x2]
|
||||
PaintableWithLines (TableWrapper(anonymous)) [8,8 46x2]
|
||||
PaintableBox (Box<TABLE>) [8,8 46x2]
|
||||
PaintableBox (Box<TBODY>) [8,8 0x0]
|
||||
|
|
|
@ -55,3 +55,9 @@ Test embed.width = "120." maps to width: 120px
|
|||
Test embed.height = "100" maps to height: 100px
|
||||
Test embed.height = " 00110 " maps to height: 110px
|
||||
Test embed.height = "120." maps to height: 120px
|
||||
Test tr.height = "100" maps to height: 100px
|
||||
Test tr.height = " 00110 " maps to height: 110px
|
||||
Test tr.height = "120." maps to height: 120px
|
||||
Test col.width = "100" maps to width: 100px
|
||||
Test col.width = " 00110 " maps to width: 110px
|
||||
Test col.width = "120." maps to width: 120px
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
{ elementName: "embed", attribute: "vspace", mappedProperty: "marginBottom" },
|
||||
{ elementName: "embed", attribute: "width", mappedProperty: "width" },
|
||||
{ elementName: "embed", attribute: "height", mappedProperty: "height" },
|
||||
{ elementName: "tr", attribute: "height", mappedProperty: "height" },
|
||||
{ elementName: "col", attribute: "width", mappedProperty: "width" },
|
||||
];
|
||||
const values = ["100", " 00110 ", "120."];
|
||||
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
|
||||
#include <LibWeb/Bindings/HTMLTableColElementPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/StyleProperties.h>
|
||||
#include <LibWeb/HTML/HTMLTableColElement.h>
|
||||
#include <LibWeb/HTML/Numbers.h>
|
||||
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -42,4 +44,16 @@ WebIDL::ExceptionOr<void> HTMLTableColElement::set_span(unsigned int value)
|
|||
return set_attribute(HTML::AttributeNames::span, MUST(String::number(value)));
|
||||
}
|
||||
|
||||
void HTMLTableColElement::apply_presentational_hints(CSS::StyleProperties& style) 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ private:
|
|||
HTMLTableColElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <LibWeb/CSS/StyleProperties.h>
|
||||
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/HTMLCollection.h>
|
||||
|
@ -59,7 +60,7 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
|
|||
return;
|
||||
}
|
||||
if (name == HTML::AttributeNames::height) {
|
||||
if (auto parsed_value = parse_nonzero_dimension_value(value))
|
||||
if (auto parsed_value = parse_dimension_value(value))
|
||||
style.set_property(CSS::PropertyID::Height, parsed_value.release_nonnull());
|
||||
return;
|
||||
}
|
||||
|
@ -72,6 +73,11 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
|
|||
}
|
||||
return;
|
||||
}
|
||||
if (name == HTML::AttributeNames::background) {
|
||||
if (auto parsed_value = document().parse_url(value); parsed_value.is_valid())
|
||||
style.set_property(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);
|
||||
|
|
|
@ -48,15 +48,15 @@ void HTMLTableRowElement::apply_presentational_hints(CSS::StyleProperties& style
|
|||
auto color = parse_legacy_color_value(value);
|
||||
if (color.has_value())
|
||||
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
|
||||
return;
|
||||
} else if (name == HTML::AttributeNames::background) {
|
||||
if (auto parsed_value = document().parse_url(value); parsed_value.is_valid())
|
||||
style.set_property(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
|
||||
return;
|
||||
} else if (name == HTML::AttributeNames::height) {
|
||||
if (auto parsed_value = parse_dimension_value(value))
|
||||
style.set_property(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());
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -7,10 +7,15 @@
|
|||
|
||||
#include <LibWeb/Bindings/HTMLTableSectionElementPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/StyleProperties.h>
|
||||
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/HTMLCollection.h>
|
||||
#include <LibWeb/HTML/HTMLTableRowElement.h>
|
||||
#include <LibWeb/HTML/HTMLTableSectionElement.h>
|
||||
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -95,4 +100,20 @@ WebIDL::ExceptionOr<void> HTMLTableSectionElement::delete_row(WebIDL::Long index
|
|||
return {};
|
||||
}
|
||||
|
||||
void HTMLTableSectionElement::apply_presentational_hints(CSS::StyleProperties& style) 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().parse_url(value); parsed_value.is_valid())
|
||||
style.set_property(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()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ private:
|
|||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||
|
||||
JS::GCPtr<DOM::HTMLCollection> mutable m_rows;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue