diff --git a/Tests/LibWeb/Text/expected/HTML/form-image-submission.txt b/Tests/LibWeb/Text/expected/HTML/form-image-submission.txt index dc5af2eb605..5feee74756a 100644 --- a/Tests/LibWeb/Text/expected/HTML/form-image-submission.txt +++ b/Tests/LibWeb/Text/expected/HTML/form-image-submission.txt @@ -1 +1 @@ - 56,20 + 10,20 diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index c0288aa1bc2..4942f76400e 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2250,6 +2250,9 @@ RefPtr StyleComputer::compute_style_impl(DOM::Element& element, // 7. Resolve effective overflow values resolve_effective_overflow_values(style); + // 8. Let the element adjust computed style + element.adjust_computed_style(style); + return style; } diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index d1b62b50034..884e6c70019 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -212,6 +212,7 @@ public: JS::NonnullGCPtr get_client_rects() const; virtual JS::GCPtr create_layout_node(NonnullRefPtr); + virtual void adjust_computed_style(CSS::StyleProperties&) { } virtual void did_receive_focus() { } virtual void did_lose_focus() { } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index f2dd03203c5..be5db5361e5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -97,17 +97,23 @@ JS::GCPtr HTMLInputElement::create_layout_node(NonnullRefPtr(document(), *this, move(style)); + return Element::create_layout_node_for_display_type(document(), style->display(), style, this); +} + +void HTMLInputElement::adjust_computed_style(CSS::StyleProperties& style) +{ + if (type_state() == TypeAttributeState::Hidden || type_state() == TypeAttributeState::SubmitButton || type_state() == TypeAttributeState::Button || type_state() == TypeAttributeState::ResetButton || type_state() == TypeAttributeState::ImageButton || type_state() == TypeAttributeState::Checkbox || type_state() == TypeAttributeState::RadioButton) + return; + // AD-HOC: We rewrite `display: inline` to `display: inline-block`. // This is required for the internal shadow tree to work correctly in layout. - if (style->display().is_inline_outside() && style->display().is_flow_inside()) - style->set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock))); + if (style.display().is_inline_outside() && style.display().is_flow_inside()) + style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock))); if (type_state() != TypeAttributeState::FileUpload) { - if (style->property(CSS::PropertyID::Width)->has_auto()) - style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(size(), CSS::Length::Type::Ch))); + if (style.property(CSS::PropertyID::Width)->has_auto()) + style.set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(size(), CSS::Length::Type::Ch))); } - - return Element::create_layout_node_for_display_type(document(), style->display(), style, this); } void HTMLInputElement::set_checked(bool checked, ChangeSource change_source) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h index 0f87ecbfc94..c7bf365b3b0 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -58,6 +58,7 @@ public: virtual ~HTMLInputElement() override; virtual JS::GCPtr create_layout_node(NonnullRefPtr) override; + virtual void adjust_computed_style(CSS::StyleProperties&) override; enum class TypeAttributeState { #define __ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(_, state) state, diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index c64d5265c21..4bc8958cf21 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -48,14 +48,12 @@ void HTMLSelectElement::visit_edges(Cell::Visitor& visitor) visitor.visit(m_chevron_icon_element); } -JS::GCPtr HTMLSelectElement::create_layout_node(NonnullRefPtr style) +void HTMLSelectElement::adjust_computed_style(CSS::StyleProperties& style) { // AD-HOC: We rewrite `display: inline` to `display: inline-block`. // This is required for the internal shadow tree to work correctly in layout. - if (style->display().is_inline_outside() && style->display().is_flow_inside()) - style->set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock))); - - return Element::create_layout_node_for_display_type(document(), style->display(), style, this); + if (style.display().is_inline_outside() && style.display().is_flow_inside()) + style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock))); } // https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h index ecdbe9e37ff..b1e4805600f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -25,7 +25,7 @@ class HTMLSelectElement final public: virtual ~HTMLSelectElement() override; - virtual JS::GCPtr create_layout_node(NonnullRefPtr) override; + virtual void adjust_computed_style(CSS::StyleProperties&) override; JS::GCPtr const& options(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp index 4e15f7b2eb1..680073b435f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp @@ -31,19 +31,17 @@ HTMLTextAreaElement::HTMLTextAreaElement(DOM::Document& document, DOM::Qualified HTMLTextAreaElement::~HTMLTextAreaElement() = default; -JS::GCPtr HTMLTextAreaElement::create_layout_node(NonnullRefPtr style) +void HTMLTextAreaElement::adjust_computed_style(CSS::StyleProperties& style) { // AD-HOC: We rewrite `display: inline` to `display: inline-block`. // This is required for the internal shadow tree to work correctly in layout. - if (style->display().is_inline_outside() && style->display().is_flow_inside()) - style->set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock))); + if (style.display().is_inline_outside() && style.display().is_flow_inside()) + style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock))); - if (style->property(CSS::PropertyID::Width)->has_auto()) - style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(cols(), CSS::Length::Type::Ch))); - if (style->property(CSS::PropertyID::Height)->has_auto()) - style->set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length(rows(), CSS::Length::Type::Lh))); - - return Element::create_layout_node_for_display_type(document(), style->display(), style, this); + if (style.property(CSS::PropertyID::Width)->has_auto()) + style.set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(cols(), CSS::Length::Type::Ch))); + if (style.property(CSS::PropertyID::Height)->has_auto()) + style.set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length(rows(), CSS::Length::Type::Lh))); } void HTMLTextAreaElement::initialize(JS::Realm& realm) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h index c13475168c9..6fe152e2d2c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h @@ -28,7 +28,7 @@ class HTMLTextAreaElement final public: virtual ~HTMLTextAreaElement() override; - virtual JS::GCPtr create_layout_node(NonnullRefPtr) override; + virtual void adjust_computed_style(CSS::StyleProperties&) override; String const& type() const {