Skip to content

Commit

Permalink
Table cell's anonymous wrappers are left in the tree, impacting our l…
Browse files Browse the repository at this point in the history
…ayout

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: svn://svn.chromium.org/blink/trunk@108098 bbb929c8-8fbe-4397-9dbb-9b2b20218538
  • Loading branch information
jchaffraix@webkit.org committed Feb 17, 2012
1 parent ba7bf10 commit f80fa07
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 1 deletion.
10 changes: 10 additions & 0 deletions third_party/WebKit/LayoutTests/ChangeLog
@@ -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>
Expand Down
@@ -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>
@@ -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>
31 changes: 31 additions & 0 deletions third_party/WebKit/Source/WebCore/ChangeLog
@@ -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>
Expand Down
2 changes: 1 addition & 1 deletion third_party/WebKit/Source/WebCore/dom/Node.cpp
Expand Up @@ -1340,7 +1340,7 @@ void Node::detach()
setFlag(InDetachFlag);

if (renderer())
renderer()->destroy();
renderer()->destroyAndCleanupAnonymousWrappers();
setRenderer(0);

Document* doc = document();
Expand Down
27 changes: 27 additions & 0 deletions third_party/WebKit/Source/WebCore/rendering/RenderObject.cpp
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions third_party/WebKit/Source/WebCore/rendering/RenderObject.h
Expand Up @@ -801,6 +801,7 @@ class RenderObject : public CachedImageClient {
// 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).
Expand Down

0 comments on commit f80fa07

Please sign in to comment.