1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibWeb: Use fit-content width if button's computed width is "auto"

Implements following line from the spec:
"If the computed value of 'inline-size' is 'auto', then the used value
is the fit-content inline size."
This commit is contained in:
Aliaksandr Kalenik 2023-09-09 17:13:41 +02:00 committed by Andreas Kling
parent 7eee3f6952
commit 63939445b1
Notes: sideshowbarker 2024-07-17 04:57:23 +09:00
5 changed files with 54 additions and 1 deletions

View file

@ -0,0 +1,29 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x58.9375 [BFC] children: not-inline
BlockContainer <body> at (8,8) content-size 784x42.9375 children: not-inline
BlockContainer <button.btn.fixed-width> at (13,10) content-size 190x17.46875 children: not-inline
BlockContainer <(anonymous)> at (13,10) content-size 190x17.46875 flex-container(column) [FFC] children: not-inline
BlockContainer <(anonymous)> at (13,10) content-size 190x17.46875 flex-item [BFC] children: inline
line 0 width: 94.921875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 11, rect: [61,10 94.921875x17.46875]
"200px width"
TextNode <#text>
BlockContainer <button.btn> at (13,31.46875) content-size 324.671875x17.46875 children: not-inline
BlockContainer <(anonymous)> at (13,31.46875) content-size 324.671875x17.46875 flex-container(column) [FFC] children: not-inline
BlockContainer <(anonymous)> at (13,31.46875) content-size 324.671875x17.46875 flex-item [BFC] children: inline
line 0 width: 324.671875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 39, rect: [13,31.46875 324.671875x17.46875]
"auto width should behave as fit-content"
TextNode <#text>
ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x58.9375]
PaintableWithLines (BlockContainer<BODY>) [8,8 784x42.9375]
PaintableWithLines (BlockContainer<BUTTON>.btn.fixed-width) [8,8 200x21.46875]
PaintableWithLines (BlockContainer(anonymous)) [13,10 190x17.46875]
PaintableWithLines (BlockContainer(anonymous)) [13,10 190x17.46875]
TextPaintable (TextNode<#text>)
PaintableWithLines (BlockContainer<BUTTON>.btn) [8,29.46875 334.671875x21.46875]
PaintableWithLines (BlockContainer(anonymous)) [13,31.46875 324.671875x17.46875]
PaintableWithLines (BlockContainer(anonymous)) [13,31.46875 324.671875x17.46875]
TextPaintable (TextNode<#text>)

View file

@ -0,0 +1,9 @@
<!DOCTYPE html><style>
.btn {
display: block;
}
.fixed-width {
width: 200px;
}
</style><button class="btn fixed-width">200px width</button><button class="btn">auto width should behave as fit-content</button>

View file

@ -100,6 +100,7 @@ public:
virtual bool is_html_table_row_element() const { return false; }
virtual bool is_html_table_cell_element() const { return false; }
virtual bool is_html_br_element() const { return false; }
virtual bool is_html_button_element() const { return false; }
virtual bool is_navigable_container() const { return false; }
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> pre_insert(JS::NonnullGCPtr<Node>, JS::GCPtr<Node>);

View file

@ -68,6 +68,8 @@ public:
virtual DeprecatedString value() const override;
private:
virtual bool is_html_button_element() const override { return true; }
HTMLButtonElement(DOM::Document&, DOM::QualifiedName);
// ^DOM::Element
@ -75,3 +77,8 @@ private:
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::HTMLButtonElement>() const { return is_html_button_element(); }
}

View file

@ -366,11 +366,18 @@ ErrorOr<void> TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::
}
}
// https://html.spec.whatwg.org/multipage/rendering.html#button-layout
// If the computed value of 'inline-size' is 'auto', then the used value is the fit-content inline size.
if (dom_node.is_html_button_element() && dom_node.layout_node()->computed_values().width().is_auto()) {
auto& computed_values = verify_cast<NodeWithStyle>(*dom_node.layout_node()).mutable_computed_values();
computed_values.set_width(CSS::Size::make_fit_content());
}
// https://html.spec.whatwg.org/multipage/rendering.html#button-layout
// If the element is an input element, or if it is a button element and its computed value for
// 'display' is not 'inline-grid', 'grid', 'inline-flex', or 'flex', then the element's box has
// a child anonymous button content box with the following behaviors:
if (is<HTML::HTMLButtonElement>(dom_node) && !display.is_grid_inside() && !display.is_flex_inside()) {
if (dom_node.is_html_button_element() && !display.is_grid_inside() && !display.is_flex_inside()) {
auto& parent = *dom_node.layout_node();
// If the box does not overflow in the vertical axis, then it is centered vertically.