Truly independent web browser
LibWeb: Rebuild an input's box when its type changes
Andreas Klinge7f624148eb5
diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.hindex 5e675a27f08..dfeb763c5df 100644--- a/Libraries/LibWeb/DOM/Node.h+++ b/Libraries/LibWeb/DOM/Node.h@@ -120,6 +120,7 @@ enum class SetNeedsLayoutReason {X(DetailsElementOpenedOrClosed) \X(HTMLImageElementUpdateTheImageData) \X(HTMLInputElementSrcAttribute) \+ X(HTMLInputElementTypeAttribute) \X(HTMLObjectElementUpdateLayoutAndChildObjects) \X(KeyframeEffect) \X(LanguageChangeUnderCasingTextTransform) \diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cppindex 8cc41559258..5d94a07c51f 100644--- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp@@ -1950,6 +1950,8 @@ void HTMLInputElement::type_attribute_changed(TypeAttributeState old_state, Type// 4. Update the element's rendering and behavior to the new state's.m_type = new_state;+ // NB: Which box the element gets depends on its state.+ set_needs_layout_tree_update(true, DOM::SetNeedsLayoutTreeUpdateReason::HTMLInputElementTypeAttribute);// Only the Image Button state maps align, border, width, height, hspace and vspace to hints,// so entering or leaving it changes the element's hints without any attribute changing.if ((old_state == TypeAttributeState::ImageButton) != (new_state == TypeAttributeState::ImageButton))diff --git a/Tests/LibWeb/Text/expected/HTML/input-type-change-rebuilds-box.txt b/Tests/LibWeb/Text/expected/HTML/input-type-change-rebuilds-box.txtnew file mode 100644index 00000000000..b910bba5506--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/input-type-change-rebuilds-box.txt@@ -0,0 +1,3 @@+checkbox: 13x13, the tree matches a full rebuild: true+radio: 12x12, the tree matches a full rebuild: true+back to a checkbox: 13x13, the tree matches a full rebuild: truediff --git a/Tests/LibWeb/Text/input/HTML/input-type-change-rebuilds-box.html b/Tests/LibWeb/Text/input/HTML/input-type-change-rebuilds-box.htmlnew file mode 100644index 00000000000..606bb15039d--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/input-type-change-rebuilds-box.html@@ -0,0 +1,17 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<body>+<input id="input" type="checkbox">+<script>+ test(() => {+ const report = label => {+ const { width, height } = input.getBoundingClientRect();+ println(`${label}: ${width}x${height}, the tree matches a full rebuild: ${internals.compareLayoutTreeWithFullRebuild().matches}`);+ };+ report("checkbox");+ input.type = "radio";+ report("radio");+ input.type = "checkbox";+ report("back to a checkbox");+ });+</script>