From 6af7f7e0f5d768a44618aee7941274c48bda6fef Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 4 Apr 2024 12:27:22 -0400 Subject: [PATCH] LibWeb: Update placeholder visibility when the placeholder value changes Otherwise, setting a placeholder on an element that previously did not have a placeholder would have no visible effect. --- .../Layout/expected/input-placeholder.txt | 25 ++++++++++++++++--- .../Layout/input/input-placeholder.html | 7 ++++++ .../LibWeb/HTML/HTMLInputElement.cpp | 4 ++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Tests/LibWeb/Layout/expected/input-placeholder.txt b/Tests/LibWeb/Layout/expected/input-placeholder.txt index 486dff31309..a8e40b1649d 100644 --- a/Tests/LibWeb/Layout/expected/input-placeholder.txt +++ b/Tests/LibWeb/Layout/expected/input-placeholder.txt @@ -1,6 +1,6 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline - BlockContainer at (0,0) content-size 800x42 [BFC] children: not-inline - BlockContainer at (8,8) content-size 784x26 children: inline + BlockContainer at (0,0) content-size 800x68 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x52 children: inline frag 0 from BlockContainer start: 0, length: 0, rect: [9,9 200x24] baseline: 17 frag 1 from TextNode start: 0, length: 1, rect: [210,8 10x22] baseline: 17 " " @@ -8,6 +8,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline frag 3 from TextNode start: 0, length: 1, rect: [422,8 10x22] baseline: 17 " " frag 4 from BlockContainer start: 0, length: 0, rect: [433,9 200x24] baseline: 17 + frag 5 from BlockContainer start: 0, length: 0, rect: [9,35 200x24] baseline: 17 BlockContainer at (9,9) content-size 200x24 inline-block [BFC] children: not-inline Box
at (11,10) content-size 196x22 flex-container(row) [FFC] children: not-inline BlockContainer
at (11,10) content-size 196x22 flex-item [BFC] children: inline @@ -31,10 +32,22 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline "text" TextNode <#text> TextNode <#text> + BlockContainer at (9,35) content-size 200x24 inline-block [BFC] children: not-inline + Box
at (11,36) content-size 196x22 flex-container(row) [FFC] children: not-inline + BlockContainer
at (11,36) content-size 196x22 flex-item [BFC] children: inline + frag 0 from TextNode start: 0, length: 16, rect: [11,36 166.75x22] baseline: 17 + "This placeholder" + frag 1 from TextNode start: 17, length: 14, rect: [11,58 147.90625x22] baseline: 17 + "should also be" + frag 2 from TextNode start: 32, length: 8, rect: [11,80 73.046875x22] baseline: 17 + "visisble" + TextNode <#text> + TextNode <#text> + TextNode <#text> ViewportPaintable (Viewport<#document>) [0,0 800x600] - PaintableWithLines (BlockContainer) [0,0 800x42] - PaintableWithLines (BlockContainer) [8,8 784x26] + PaintableWithLines (BlockContainer) [0,0 800x68] + PaintableWithLines (BlockContainer) [8,8 784x52] PaintableWithLines (BlockContainer) [8,8 202x26] PaintableBox (Box
) [9,9 200x24] PaintableWithLines (BlockContainer
) [11,10 196x22] @@ -49,3 +62,7 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableBox (Box
) [433,9 200x24] PaintableWithLines (BlockContainer
) [435,10 196x22] TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer#placeholder) [8,34 202x26] overflow: [9,35 200x67] + PaintableBox (Box
) [9,35 200x24] overflow: [9,35 200x67] + PaintableWithLines (BlockContainer
) [11,36 196x22] overflow: [11,36 196x66] + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/input-placeholder.html b/Tests/LibWeb/Layout/input/input-placeholder.html index 73d57d7046a..8365429c789 100644 --- a/Tests/LibWeb/Layout/input/input-placeholder.html +++ b/Tests/LibWeb/Layout/input/input-placeholder.html @@ -8,3 +8,10 @@ input { + + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index f8ded54de26..67d89e63d3a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -1085,8 +1085,10 @@ void HTMLInputElement::form_associated_element_attribute_changed(FlyString const update_shadow_tree(); } } else if (name == HTML::AttributeNames::placeholder) { - if (m_placeholder_text_node) + if (m_placeholder_text_node) { m_placeholder_text_node->set_data(placeholder()); + update_placeholder_visibility(); + } } else if (name == HTML::AttributeNames::readonly) { handle_readonly_attribute(value); } else if (name == HTML::AttributeNames::src) {