Skip to content

Commit

Permalink
LibWeb/HTML: Skip layout for an empty label that controls nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-za committed Dec 29, 2024
1 parent f8dacda commit 3958d52
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
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
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]
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>

0 comments on commit 3958d52

Please sign in to comment.