mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibWeb: Ensure normal line-height on HTMLInputElement
Previously, setting CSS `line-height: 0` on an `input` element would result in no text being displayed. Other browsers handle this by setting the minimum height to the "normal" value for single line inputs.
This commit is contained in:
parent
b36a78a798
commit
629068c2a7
Notes:
sideshowbarker
2024-07-17 11:06:06 +09:00
Author: https://github.com/rmg-x Commit: https://github.com/LadybirdBrowser/ladybird/commit/629068c2a7 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/496
3 changed files with 32 additions and 0 deletions
19
Tests/LibWeb/Layout/expected/css-line-height-zero.txt
Normal file
19
Tests/LibWeb/Layout/expected/css-line-height-zero.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
BlockContainer <html> at (0,0) content-size 800x37 [BFC] children: not-inline
|
||||
BlockContainer <body> at (8,8) content-size 784x21 children: inline
|
||||
frag 0 from BlockContainer start: 0, length: 0, rect: [9,9 191.875x19] baseline: 13.296875
|
||||
BlockContainer <input> at (9,9) content-size 191.875x19 inline-block [BFC] children: not-inline
|
||||
Box <div> at (11,10) content-size 187.875x17 flex-container(row) [FFC] children: not-inline
|
||||
BlockContainer <div> at (11,10) content-size 187.875x17 flex-item [BFC] children: inline
|
||||
frag 0 from TextNode start: 0, length: 11, rect: [11,10 91.953125x17] baseline: 13.296875
|
||||
"Hello World"
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
|
||||
ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x37]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x21]
|
||||
PaintableWithLines (BlockContainer<INPUT>) [8,8 193.875x21]
|
||||
PaintableBox (Box<DIV>) [9,9 191.875x19]
|
||||
PaintableWithLines (BlockContainer<DIV>) [11,10 187.875x17]
|
||||
TextPaintable (TextNode<#text>)
|
5
Tests/LibWeb/Layout/input/css-line-height-zero.html
Normal file
5
Tests/LibWeb/Layout/input/css-line-height-zero.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<!DOCTYPE html><html><head><style>
|
||||
input {
|
||||
line-height: 0;
|
||||
}
|
||||
</style></head><body><input type="text" value="Hello World">
|
|
@ -127,6 +127,14 @@ void HTMLInputElement::adjust_computed_style(CSS::StyleProperties& style)
|
|||
if (style.property(CSS::PropertyID::Width)->has_auto())
|
||||
style.set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(size(), CSS::Length::Type::Ch)));
|
||||
}
|
||||
|
||||
// NOTE: The following line-height check is done for web compatability and usability reasons.
|
||||
// FIXME: The "normal" line-height value should be calculated but assume 1.0 for now.
|
||||
double normal_line_height = 1.0;
|
||||
double current_line_height = style.line_height().to_double();
|
||||
|
||||
if (is_single_line() && current_line_height < normal_line_height)
|
||||
style.set_property(CSS::PropertyID::LineHeight, CSS::IdentifierStyleValue::create(CSS::ValueID::Normal));
|
||||
}
|
||||
|
||||
void HTMLInputElement::set_checked(bool checked, ChangeSource change_source)
|
||||
|
|
Loading…
Reference in a new issue