Skip to content

Truly independent web browser

LibWeb: Leave the box of a node whose contents are replaced in place

Andreas Klinga6e7b485e383
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp
index b17925353d1..ed399336c3a 100644
--- a/Libraries/LibWeb/DOM/Element.cpp
+++ b/Libraries/LibWeb/DOM/Element.cpp
@@ -2382,14 +2382,6 @@ WebIDL::ExceptionOr<void> Element::set_inner_html(Utf16View html, GC::Ptr<Truste
});
}
- // NOTE: We don't invalidate style & layout for <template> elements since they don't affect rendering.
- if (!template_element) {
- if (is_connected()) {
- // NOTE: Since the DOM has changed, we have to rebuild the layout tree.
- set_needs_layout_tree_update(true, DOM::SetNeedsLayoutTreeUpdateReason::ElementSetInnerHTML);
- }
- }
-
return {};
}
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index efc813ad95e..60bcf2a18a8 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -485,9 +485,9 @@ WebIDL::ExceptionOr<void> Node::set_text_content(Optional<Utf16String> const& ma
// Otherwise, do nothing.
- auto is_boxless_style_element = (is_html_style_element() || is_svg_style_element()) && !may_have_layout_box();
- if (is_connected() && !is_boxless_style_element)
- set_needs_layout_tree_update(true, SetNeedsLayoutTreeUpdateReason::NodeSetTextContent);
+ // NB: Each child that left or arrived with a box marked the layout tree build for it, and new data marked its text
+ // box. A mark on the node itself would have the build replace its box, which a box that lays out alone does not
+ // survive: the whole document would lay out again.
bump_dom_tree_version();
return {};
@@ -2548,10 +2548,7 @@ static bool is_structural_boundary_self_rebuild_reason(SetNeedsLayoutTreeUpdateR
switch (reason) {
case SetNeedsLayoutTreeUpdateReason::NodeInsertBefore:
case SetNeedsLayoutTreeUpdateReason::WhitespaceTextBoxChange:
- case SetNeedsLayoutTreeUpdateReason::NodeSetTextContent:
case SetNeedsLayoutTreeUpdateReason::CharacterDataReplaceData:
- case SetNeedsLayoutTreeUpdateReason::ElementSetInnerHTML:
- case SetNeedsLayoutTreeUpdateReason::ShadowRootSetInnerHTML:
case SetNeedsLayoutTreeUpdateReason::SlotAssignmentChange:
// The box of an element that entered the top layer leaves the parent's subtree,
// which is a child-list change.
diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h
index 1f0b98482a3..ad172791c7d 100644
--- a/Libraries/LibWeb/DOM/Node.h
+++ b/Libraries/LibWeb/DOM/Node.h
@@ -110,7 +110,6 @@ enum class SetNeedsLayoutReason {
#define ENUMERATE_SET_NEEDS_LAYOUT_TREE_UPDATE_REASONS(X) \
X(CharacterDataReplaceData) \
- X(ElementSetInnerHTML) \
X(ElementSetShadowRoot) \
X(DetailsElementOpenedOrClosed) \
X(HTMLImageElementUpdateTheImageData) \
@@ -125,9 +124,7 @@ enum class SetNeedsLayoutReason {
X(NodeInsertBeforeWithDisplayContents) \
X(NodeRemove) \
X(TableCellSpanAttribute) \
- X(NodeSetTextContent) \
X(None) \
- X(ShadowRootSetInnerHTML) \
X(SlotAssignmentChange) \
X(StyleChange) \
X(StyleRebuild) \
diff --git a/Libraries/LibWeb/DOM/ShadowRoot.cpp b/Libraries/LibWeb/DOM/ShadowRoot.cpp
index af807609e3d..ba37ce4ebae 100644
--- a/Libraries/LibWeb/DOM/ShadowRoot.cpp
+++ b/Libraries/LibWeb/DOM/ShadowRoot.cpp
@@ -176,14 +176,6 @@ WebIDL::ExceptionOr<void> ShadowRoot::set_inner_html(Utf16View html, GC::Ptr<Tru
// 4. Replace all with fragment within this.
this->replace_all(fragment);
- // NOTE: We don't invalidate style & layout for <template> elements since they don't affect rendering.
- if (!is<HTML::HTMLTemplateElement>(*this)) {
- if (this->is_connected()) {
- // NOTE: Since the DOM has changed, we have to rebuild this shadow root's layout subtree.
- this->set_needs_layout_tree_update(true, SetNeedsLayoutTreeUpdateReason::ShadowRootSetInnerHTML);
- }
- }
-
return {};
}
diff --git a/Tests/LibWeb/Text/expected/Layout/abspos-box-lays-out-alone-after-replacing-its-contents.txt b/Tests/LibWeb/Text/expected/Layout/abspos-box-lays-out-alone-after-replacing-its-contents.txt
index 5f28b618808..65a880cafe7 100644
--- a/Tests/LibWeb/Text/expected/Layout/abspos-box-lays-out-alone-after-replacing-its-contents.txt
+++ b/Tests/LibWeb/Text/expected/Layout/abspos-box-lays-out-alone-after-replacing-its-contents.txt
@@ -1,3 +1,3 @@
-textContent: layout FULL, the box grew: true
-innerHTML: layout FULL, the box grew: true
-shadow root innerHTML: layout FULL, the box grew: true
+textContent: layout PARTIAL, the box grew: true
+innerHTML: layout PARTIAL, the box grew: true
+shadow root innerHTML: layout PARTIAL, the box grew: true