Table cell's anonymous wrappers are left in the tree, impacting our layout
authorjchaffraix@webkit.org <jchaffraix@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2012 19:02:36 +0000 (19:02 +0000)
committerjchaffraix@webkit.org <jchaffraix@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2012 19:02:36 +0000 (19:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=7180

Reviewed by David Hyatt.

Source/WebCore:

Tests: fast/table/table-switch-cell-position-bad-layout-expected.html
       fast/table/table-switch-cell-position-bad-layout.html

This patch implements cell's anonymous wrapper removal at detach time.

Trimming the render tree when we remove objects from it would be more complex
to generalize as several objects override the behavior to do their own clean-ups.
This would also open more potential for programming errors.

This change is limited to table cells' as a simple step towards fixing bug 52123
and more generally eliminate some anonymous wrappers from the tree at detach time.

* dom/Node.cpp:
(WebCore::Node::detach):
Patched detach to call destroyAndCleanupAnonymousWrappers. The Document does not need
to clean up any anonymous wrappers on detach.

* rendering/RenderObject.cpp:
(WebCore::RenderObject::destroyAndCleanupAnonymousWrappers):
Added this method to wrap destroy() call and trim the render tree. To avoid slowing down
detach in some cases, added a fast path.

* rendering/RenderObject.h: Added destroyAndCleanupAnonymousWrappers.

LayoutTests:

* fast/table/table-switch-cell-position-bad-layout-expected.html: Added.
* fast/table/table-switch-cell-position-bad-layout.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@108098 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/table/table-switch-cell-position-bad-layout-expected.html [new file with mode: 0644]
LayoutTests/fast/table/table-switch-cell-position-bad-layout.html [new file with mode: 0755]
Source/WebCore/ChangeLog
Source/WebCore/dom/Node.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h

index 250e9ca..96f8c3b 100644 (file)
@@ -1,3 +1,13 @@
+2012-02-17  Julien Chaffraix  <jchaffraix@webkit.org>
+
+        Table cell's anonymous wrappers are left in the tree, impacting our layout
+        https://bugs.webkit.org/show_bug.cgi?id=7180
+
+        Reviewed by David Hyatt.
+
+        * fast/table/table-switch-cell-position-bad-layout-expected.html: Added.
+        * fast/table/table-switch-cell-position-bad-layout.html: Added.
+
 2012-02-17  Rob Buis  <rbuis@rim.com>
 
         ASSERT (and crash) with dynamically moved <font-face>
diff --git a/LayoutTests/fast/table/table-switch-cell-position-bad-layout-expected.html b/LayoutTests/fast/table/table-switch-cell-position-bad-layout-expected.html
new file mode 100644 (file)
index 0000000..84f5372
--- /dev/null
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>Bug <a href="https://bugs.webkit.org/show_bug.cgi?id=7180">7180</a>: Table cell's anonymous wrappers are left in the tree, impacting our layout.</p>
+<p>There should be no red in the output.</p>
+<div style="width: 200px; height: 200px; background-color: green"></div>
+</body>
+</html>
diff --git a/LayoutTests/fast/table/table-switch-cell-position-bad-layout.html b/LayoutTests/fast/table/table-switch-cell-position-bad-layout.html
new file mode 100755 (executable)
index 0000000..fe1e36f
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <style>
+    table {
+        background-color: red;
+        border-spacing: 0px;
+    }
+    td {
+        background-color: green;
+        height: 100px;
+        padding: 0px;
+        width: 200px;
+    }
+    </style>
+</head>
+<body>
+<p>Bug <a href="https://bugs.webkit.org/show_bug.cgi?id=7180">7180</a>: Table cell's anonymous wrappers are left in the tree, impacting our layout.</p>
+<p>There should be no red in the output.</p>
+<table>
+    <tr>
+        <td id="togglePosition"></td>
+    </tr>
+    <tr>
+        <td></td>
+    </tr>
+</table>
+<script>
+    var element = document.getElementById("togglePosition");
+    element.style.position = "absolute";
+
+    element.offsetWidth;
+
+    element.style.position = "static";
+</script>
+</body>
+</html>
index 46722cb..dfc29b7 100644 (file)
@@ -1,3 +1,34 @@
+2012-02-17  Julien Chaffraix  <jchaffraix@webkit.org>
+
+        Table cell's anonymous wrappers are left in the tree, impacting our layout
+        https://bugs.webkit.org/show_bug.cgi?id=7180
+
+        Reviewed by David Hyatt.
+
+        Tests: fast/table/table-switch-cell-position-bad-layout-expected.html
+               fast/table/table-switch-cell-position-bad-layout.html
+
+        This patch implements cell's anonymous wrapper removal at detach time.
+
+        Trimming the render tree when we remove objects from it would be more complex
+        to generalize as several objects override the behavior to do their own clean-ups.
+        This would also open more potential for programming errors.
+
+        This change is limited to table cells' as a simple step towards fixing bug 52123
+        and more generally eliminate some anonymous wrappers from the tree at detach time.
+
+        * dom/Node.cpp:
+        (WebCore::Node::detach):
+        Patched detach to call destroyAndCleanupAnonymousWrappers. The Document does not need
+        to clean up any anonymous wrappers on detach.
+
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::destroyAndCleanupAnonymousWrappers):
+        Added this method to wrap destroy() call and trim the render tree. To avoid slowing down
+        detach in some cases, added a fast path.
+
+        * rendering/RenderObject.h: Added destroyAndCleanupAnonymousWrappers.
+
 2012-02-17  Rob Buis  <rbuis@rim.com>
 
         ASSERT (and crash) with dynamically moved <font-face>
index 6d2e8f1..09b9155 100644 (file)
@@ -1340,7 +1340,7 @@ void Node::detach()
     setFlag(InDetachFlag);
 
     if (renderer())
-        renderer()->destroy();
+        renderer()->destroyAndCleanupAnonymousWrappers();
     setRenderer(0);
 
     Document* doc = document();
index 6ca7192..f3c0af4 100755 (executable)
@@ -2259,6 +2259,33 @@ void RenderObject::willBeDestroyed()
     }
 }
 
+void RenderObject::destroyAndCleanupAnonymousWrappers()
+{
+    RenderObject* parent = this->parent();
+
+    // If the tree is destroyed or our parent is not anonymous, there is no need for a clean-up phase.
+    if (documentBeingDestroyed() || !parent || !parent->isAnonymous()) {
+        destroy();
+        return;
+    }
+
+    bool parentIsLeftOverAnonymousWrapper = false;
+
+    // Currently we only remove anonymous cells' wrapper but we should remove all unneeded
+    // wrappers. See http://webkit.org/b/52123 as an example where this is needed.
+    if (parent->isTableCell())
+        parentIsLeftOverAnonymousWrapper = parent->firstChild() == this && parent->lastChild() == this;
+
+    destroy();
+
+    // WARNING: |this| is deleted here.
+
+    if (parentIsLeftOverAnonymousWrapper) {
+        ASSERT(!parent->firstChild());
+        parent->destroyAndCleanupAnonymousWrappers();
+    }
+}
+
 void RenderObject::destroy()
 {
     willBeDestroyed();
index 1bcda46..775a9b5 100644 (file)
@@ -801,6 +801,7 @@ public:
     // as a hook to detect the case of document destruction and don't waste time doing unnecessary work.
     bool documentBeingDestroyed() const;
 
+    void destroyAndCleanupAnonymousWrappers();
     virtual void destroy();
 
     // Virtual function helpers for the deprecated Flexible Box Layout (display: -webkit-box).