Skip to content

Commit 00c1da8

Browse files
implicitfieldawesomekling
authored andcommitted
LibWeb: Support cellpadding attribute on table elements
1 parent 3d1fbcb commit 00c1da8

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
2+
BlockContainer <html> at (0,0) content-size 800x220 [BFC] children: not-inline
3+
BlockContainer <body> at (8,8) content-size 784x204 children: not-inline
4+
TableWrapper <(anonymous)> at (8,8) content-size 498.1875x204 [BFC] children: not-inline
5+
Box <table> at (9,9) content-size 496.1875x202 table-box [TFC] children: not-inline
6+
Box <tbody> at (9,9) content-size 488.1875x198 table-row-group children: not-inline
7+
Box <tr> at (11,11) content-size 488.1875x198 table-row children: not-inline
8+
BlockContainer <td> at (71,71) content-size 26.640625x17.46875 table-cell [BFC] children: inline
9+
line 0 width: 26.640625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
10+
frag 0 from TextNode start: 0, length: 3, rect: [71,71 26.640625x17.46875]
11+
"top"
12+
TextNode <#text>
13+
BlockContainer <td> at (219.640625,101.265625) content-size 45.4375x17.46875 table-cell [BFC] children: inline
14+
line 0 width: 45.4375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
15+
frag 0 from TextNode start: 0, length: 6, rect: [219.640625,101.265625 45.4375x17.46875]
16+
"middle"
17+
TextNode <#text>
18+
BlockContainer <td> at (387.078125,131.53125) content-size 56.109375x17.46875 table-cell [BFC] children: inline
19+
line 0 width: 56.109375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
20+
frag 0 from TextNode start: 0, length: 6, rect: [387.078125,131.53125 56.109375x17.46875]
21+
"bottom"
22+
TextNode <#text>
23+
BlockContainer <(anonymous)> (not painted) children: inline
24+
TextNode <#text>
25+
26+
ViewportPaintable (Viewport<#document>) [0,0 800x600]
27+
PaintableWithLines (BlockContainer<HTML>) [0,0 800x220]
28+
PaintableWithLines (BlockContainer<BODY>) [8,8 784x204]
29+
PaintableWithLines (TableWrapper(anonymous)) [8,8 498.1875x204]
30+
PaintableBox (Box<TABLE>) [8,8 498.1875x204]
31+
PaintableBox (Box<TBODY>) [9,9 488.1875x198] overflow: [9,9 494.1875x200]
32+
PaintableBox (Box<TR>) [11,11 488.1875x198] overflow: [11,11 492.1875x198]
33+
PaintableWithLines (BlockContainer<TD>) [11,11 146.640625x198]
34+
TextPaintable (TextNode<#text>)
35+
PaintableWithLines (BlockContainer<TD>) [159.640625,11 165.4375x198]
36+
TextPaintable (TextNode<#text>)
37+
PaintableWithLines (BlockContainer<TD>) [327.078125,11 176.109375x198]
38+
TextPaintable (TextNode<#text>)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!doctype html><style>
2+
table {
3+
height: 200px;
4+
border: 1px solid black;
5+
}
6+
</style><table cellpadding="60"><td valign=top>top</td><td valign=middle>middle</td><td valign=bottom>bottom</td>

Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& styl
8585
}
8686
});
8787
auto const& table_element = table_containing_cell(*this);
88+
89+
if (auto padding = table_element.padding()) {
90+
style.set_property(CSS::PropertyID::PaddingTop, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
91+
style.set_property(CSS::PropertyID::PaddingBottom, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
92+
style.set_property(CSS::PropertyID::PaddingLeft, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
93+
style.set_property(CSS::PropertyID::PaddingRight, CSS::LengthStyleValue::create(CSS::Length::make_px(padding)));
94+
}
95+
8896
auto border = table_element.border();
97+
8998
if (!border)
9099
return;
91100
auto apply_border_style = [&](CSS::PropertyID style_property, CSS::PropertyID width_property, CSS::PropertyID color_property) {

Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <LibWeb/HTML/HTMLTableColElement.h>
1717
#include <LibWeb/HTML/HTMLTableElement.h>
1818
#include <LibWeb/HTML/HTMLTableRowElement.h>
19+
#include <LibWeb/HTML/Numbers.h>
1920
#include <LibWeb/HTML/Parser/HTMLParser.h>
2021
#include <LibWeb/Namespace.h>
2122

@@ -100,6 +101,19 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
100101
});
101102
}
102103

104+
void HTMLTableElement::attribute_changed(FlyString const& name, Optional<String> const& value)
105+
{
106+
Base::attribute_changed(name, value);
107+
if (name == HTML::AttributeNames::cellpadding) {
108+
if (value.has_value())
109+
m_padding = max(0, parse_integer(value.value()).value_or(0));
110+
else
111+
m_padding = 1;
112+
113+
return;
114+
}
115+
}
116+
103117
// https://html.spec.whatwg.org/multipage/tables.html#dom-table-caption
104118
JS::GCPtr<HTMLTableCaptionElement> HTMLTableElement::caption()
105119
{
@@ -424,4 +438,9 @@ unsigned int HTMLTableElement::border() const
424438
return parse_border(deprecated_attribute(HTML::AttributeNames::border));
425439
}
426440

441+
unsigned int HTMLTableElement::padding() const
442+
{
443+
return m_padding;
444+
}
445+
427446
}

Userland/Libraries/LibWeb/HTML/HTMLTableElement.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class HTMLTableElement final : public HTMLElement {
4747
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::table; }
4848

4949
unsigned border() const;
50+
unsigned padding() const;
5051

5152
private:
5253
HTMLTableElement(DOM::Document&, DOM::QualifiedName);
@@ -57,9 +58,11 @@ class HTMLTableElement final : public HTMLElement {
5758
virtual void visit_edges(Cell::Visitor&) override;
5859

5960
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
61+
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
6062

6163
JS::GCPtr<DOM::HTMLCollection> mutable m_rows;
6264
JS::GCPtr<DOM::HTMLCollection> mutable m_t_bodies;
65+
unsigned m_padding { 1 };
6366
};
6467

6568
}

0 commit comments

Comments
 (0)