Skip to content

Commit f547933

Browse files
lpasAtkinsSJ
authored andcommitted
LibWeb: Adjust buttons computed display style
1 parent 4bcb34d commit f547933

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

Libraries/LibWeb/CSS/StyleComputer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,7 @@ GC::Ptr<ComputedProperties> StyleComputer::compute_style_impl(DOM::AbstractEleme
23502350
for (auto const& property : inline_style->properties())
23512351
style->set_property(property.property_id, property.value);
23522352
}
2353+
abstract_element.element().adjust_computed_style(style);
23532354
return style;
23542355
}
23552356

@@ -2603,7 +2604,8 @@ GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::AbstractEleme
26032604
compute_text_align(computed_style, abstract_element);
26042605

26052606
// 8. Let the element adjust computed style
2606-
abstract_element.element().adjust_computed_style(computed_style);
2607+
if (!abstract_element.pseudo_element().has_value())
2608+
abstract_element.element().adjust_computed_style(computed_style);
26072609

26082610
// 9. Transition declarations [css-transitions-1]
26092611
// Theoretically this should be part of the cascade, but it works with computed values, which we don't have until now.

Libraries/LibWeb/HTML/HTMLButtonElement.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66

77
#include <LibWeb/Bindings/HTMLButtonElementPrototype.h>
8+
#include <LibWeb/CSS/ComputedProperties.h>
9+
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
810
#include <LibWeb/DOM/Document.h>
911
#include <LibWeb/DOM/Event.h>
1012
#include <LibWeb/HTML/CommandEvent.h>
@@ -29,6 +31,23 @@ void HTMLButtonElement::initialize(JS::Realm& realm)
2931
Base::initialize(realm);
3032
}
3133

34+
void HTMLButtonElement::adjust_computed_style(CSS::ComputedProperties& style)
35+
{
36+
// https://html.spec.whatwg.org/multipage/rendering.html#button-layout
37+
// If the computed value of 'display' is 'inline-grid', 'grid', 'inline-flex', 'flex', 'none', or 'contents', then behave as the computed value.
38+
auto display = style.display();
39+
if (display.is_flex_inside() || display.is_grid_inside() || display.is_none() || display.is_contents()) {
40+
// No-op
41+
} else if (display.is_inline_outside()) {
42+
// Otherwise, if the computed value of 'display' is a value such that the outer display type is 'inline', then behave as 'inline-block'.
43+
// AD-HOC https://github.com/whatwg/html/issues/11857
44+
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock)));
45+
} else {
46+
// Otherwise, behave as 'flow-root'.
47+
style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::FlowRoot)));
48+
}
49+
}
50+
3251
HTMLButtonElement::TypeAttributeState HTMLButtonElement::type_state() const
3352
{
3453
auto value = get_attribute_value(HTML::AttributeNames::type);

Libraries/LibWeb/HTML/HTMLButtonElement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class HTMLButtonElement final
3131
virtual ~HTMLButtonElement() override;
3232

3333
virtual void initialize(JS::Realm&) override;
34+
virtual void adjust_computed_style(CSS::ComputedProperties&) override;
3435

3536
enum class TypeAttributeState {
3637
#define __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(_, state) state,

Tests/LibWeb/Layout/expected/block-and-inline/button-width.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline
22
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 60 0+0+0] [BFC] children: not-inline
33
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 44 0+0+8] children: not-inline
4-
BlockContainer <button.btn.fixed-width> at [13,10] [0+1+4 190 4+1+584] [0+1+1 18 1+1+0] children: not-inline
4+
BlockContainer <button.btn.fixed-width> at [13,10] [0+1+4 190 4+1+584] [0+1+1 18 1+1+0] [BFC] children: not-inline
55
BlockContainer <(anonymous)> at [13,10] flex-container(column) [0+0+0 190 0+0+0] [0+0+0 18 0+0+0] [FFC] children: not-inline
66
BlockContainer <(anonymous)> at [13,10] flex-item [0+0+0 190 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
77
frag 0 from TextNode start: 0, length: 11, rect: [60.53125,10 94.921875x18] baseline: 13.796875
88
"200px width"
99
TextNode <#text> (not painted)
10-
BlockContainer <button.btn> at [13,32] [0+1+4 324.671875 4+1+0] [0+1+1 18 1+1+0] children: not-inline
10+
BlockContainer <button.btn> at [13,32] [0+1+4 324.671875 4+1+0] [0+1+1 18 1+1+0] [BFC] children: not-inline
1111
BlockContainer <(anonymous)> at [13,32] flex-container(column) [0+0+0 324.671875 0+0+0] [0+0+0 18 0+0+0] [FFC] children: not-inline
1212
BlockContainer <(anonymous)> at [13,32] flex-item [0+0+0 324.671875 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
1313
frag 0 from TextNode start: 0, length: 39, rect: [13,32 324.671875x18] baseline: 13.796875

Tests/LibWeb/Text/expected/wpt-import/html/rendering/widgets/button-layout/display-other.txt

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ Harness status: OK
22

33
Found 18 tests
44

5-
3 Pass
6-
15 Fail
7-
Fail display: block
5+
18 Pass
6+
Pass display: block
87
Pass display: run-in
98
Pass display: flow
10-
Fail display: flow-root
11-
Fail display: table
9+
Pass display: flow-root
10+
Pass display: table
1211
Pass display: list-item
13-
Fail display: table-row-group
14-
Fail display: table-header-group
15-
Fail display: table-footer-group
16-
Fail display: table-row
17-
Fail display: table-cell
18-
Fail display: table-column-group
19-
Fail display: table-column
20-
Fail display: table-caption
21-
Fail display: ruby-base
22-
Fail display: ruby-text
23-
Fail display: ruby-base-container
24-
Fail display: ruby-text-container
12+
Pass display: table-row-group
13+
Pass display: table-header-group
14+
Pass display: table-footer-group
15+
Pass display: table-row
16+
Pass display: table-cell
17+
Pass display: table-column-group
18+
Pass display: table-column
19+
Pass display: table-caption
20+
Pass display: ruby-base
21+
Pass display: ruby-text
22+
Pass display: ruby-base-container
23+
Pass display: ruby-text-container

0 commit comments

Comments
 (0)