Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibWeb/HTML: Skip layout for a an empty label that controls nothing #3079

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Libraries/LibWeb/HTML/HTMLLabelElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ void HTMLLabelElement::initialize(JS::Realm& realm)

GC::Ptr<Layout::Node> HTMLLabelElement::create_layout_node(GC::Ref<CSS::ComputedProperties> style)
{
bool const has_control = (control() != nullptr);
bool const is_child_text_empty = this->child_text_content().is_empty();

if (!has_control && is_child_text_empty) // Skip layout for an empty label that controls nothing.
return nullptr;

return heap().allocate<Layout::Label>(document(), this, move(style));
}

Expand Down
22 changes: 22 additions & 0 deletions Tests/LibWeb/Layout/expected/misc/label-empty-embedded-control.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 784x21 children: inline
frag 0 from Label start: 0, length: 0, rect: [8,8 200x21] baseline: 21
Label <label> at (8,8) content-size 200x21 inline-block [BFC] children: inline
frag 0 from BlockContainer start: 0, length: 0, rect: [9,9 198x19] baseline: 21
TextNode <#text>
BlockContainer <input#hello> at (9,9) content-size 198x19 inline-block [BFC] children: not-inline
Box <div> at (11,10) content-size 194x17 flex-container(row) [FFC] children: not-inline
BlockContainer <div> at (11,10) content-size 194x17 flex-item [BFC] children: inline
TextNode <#text>
TextNode <#text>
TextNode <#text>

ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
PaintableWithLines (BlockContainer<BODY>) [8,8 784x21]
PaintableWithLines (Label<LABEL>) [8,8 200x21]
PaintableWithLines (BlockContainer<INPUT>#hello) [8,8 200x21]
PaintableBox (Box<DIV>) [9,9 198x19]
PaintableWithLines (BlockContainer<DIV>) [11,10 194x17]

24 changes: 24 additions & 0 deletions Tests/LibWeb/Layout/expected/misc/label-empty-forcontrol.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 784x24 children: inline
frag 0 from Label start: 0, length: 0, rect: [8,29 0x0] baseline: 0
frag 1 from TextNode start: 0, length: 1, rect: [8,15 8x17] baseline: 13.296875
" "
frag 2 from BlockContainer start: 0, length: 0, rect: [17,9 198x19] baseline: 21
Label <label> at (8,29) content-size 0x0 inline-block [BFC] children: not-inline
TextNode <#text>
BlockContainer <input#hello> at (17,9) content-size 198x19 inline-block [BFC] children: not-inline
Box <div> at (19,10) content-size 194x17 flex-container(row) [FFC] children: not-inline
BlockContainer <div> at (19,10) content-size 194x17 flex-item [BFC] children: inline
TextNode <#text>
TextNode <#text>

ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
PaintableWithLines (BlockContainer<BODY>) [8,8 784x24]
PaintableWithLines (Label<LABEL>) [8,29 0x0]
TextPaintable (TextNode<#text>)
PaintableWithLines (BlockContainer<INPUT>#hello) [16,8 200x21]
PaintableBox (Box<DIV>) [17,9 198x19]
PaintableWithLines (BlockContainer<DIV>) [19,10 194x17]

19 changes: 19 additions & 0 deletions Tests/LibWeb/Layout/expected/misc/label-empty-nocontrol.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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 784x17 children: not-inline
BlockContainer <(anonymous)> at (8,8) content-size 784x0 children: inline
TextNode <#text>
BlockContainer <div> at (8,8) content-size 784x17 children: inline
frag 0 from TextNode start: 0, length: 5, rect: [8,8 36.84375x17] baseline: 13.296875
"hello"
TextNode <#text>
BlockContainer <(anonymous)> at (8,25) content-size 784x0 children: inline
TextNode <#text>

ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
PaintableWithLines (BlockContainer<BODY>) [8,8 784x17]
PaintableWithLines (BlockContainer(anonymous)) [8,8 784x0]
PaintableWithLines (BlockContainer<DIV>) [8,8 784x17]
TextPaintable (TextNode<#text>)
PaintableWithLines (BlockContainer(anonymous)) [8,25 784x0]
26 changes: 26 additions & 0 deletions Tests/LibWeb/Layout/expected/misc/label-notempty-nocontrol.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 784x34 children: not-inline
BlockContainer <(anonymous)> at (8,8) content-size 784x17 children: inline
frag 0 from Label start: 0, length: 0, rect: [8,8 45.90625x17] baseline: 13.296875
Label <label> at (8,8) content-size 45.90625x17 inline-block [BFC] children: inline
frag 0 from TextNode start: 0, length: 5, rect: [8,8 45.90625x17] baseline: 13.296875
"howdy"
TextNode <#text>
TextNode <#text>
BlockContainer <div> at (8,25) content-size 784x17 children: inline
frag 0 from TextNode start: 0, length: 5, rect: [8,25 36.84375x17] baseline: 13.296875
"hello"
TextNode <#text>
BlockContainer <(anonymous)> at (8,42) content-size 784x0 children: inline
TextNode <#text>

ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
PaintableWithLines (BlockContainer<BODY>) [8,8 784x34]
PaintableWithLines (BlockContainer(anonymous)) [8,8 784x17]
PaintableWithLines (Label<LABEL>) [8,8 45.90625x17]
TextPaintable (TextNode<#text>)
PaintableWithLines (BlockContainer<DIV>) [8,25 784x17]
TextPaintable (TextNode<#text>)
PaintableWithLines (BlockContainer(anonymous)) [8,42 784x0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<label>
<input id="hello" />
</label>
2 changes: 2 additions & 0 deletions Tests/LibWeb/Layout/input/misc/label-empty-forcontrol.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<label for="hello"></label>
<input id="hello" />
2 changes: 2 additions & 0 deletions Tests/LibWeb/Layout/input/misc/label-empty-nocontrol.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<label></label>
<div>hello</div>
2 changes: 2 additions & 0 deletions Tests/LibWeb/Layout/input/misc/label-notempty-nocontrol.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<label>howdy</label>
<div>hello</div>
Loading