Index: Source/core/dom/Node.cpp |
diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp |
index 650af854a80758d418cecf057cc2897e2bc8857b..2bc7123aa6726290d5c648d1121d86e115467482 100644 |
--- a/Source/core/dom/Node.cpp |
+++ b/Source/core/dom/Node.cpp |
@@ -987,6 +987,9 @@ inline void Node::detachNode(Node* root, const AttachContext& context) |
continue; |
} |
// Handle normal reattaches from style recalc (ex. display type changes) |
+ // or descendants of lazy attached nodes that got actually attached, for example, |
+ // by innerHTML or editing. |
+ // FIXME: innerHTML and editing should also lazyAttach. |
if (node->attached()) |
node->detach(context); |
node = NodeTraversal::nextSkippingChildren(node, root); |
@@ -995,6 +998,7 @@ inline void Node::detachNode(Node* root, const AttachContext& context) |
void Node::reattach(const AttachContext& context) |
{ |
+ ASSERT(document().inStyleRecalc()); |
AttachContext reattachContext(context); |
reattachContext.performingReattach = true; |
@@ -1004,10 +1008,30 @@ void Node::reattach(const AttachContext& context) |
void Node::attach(const AttachContext&) |
{ |
- ASSERT(document().inStyleRecalc()); |
ASSERT(!attached()); |
ASSERT(!renderer() || (renderer()->style() && (renderer()->parent() || renderer()->isRenderView()))); |
+ // If this node got a renderer it may be the previousRenderer() of sibling text nodes and thus affect the |
+ // result of Text::textRendererIsNeeded() for those nodes. |
+ // FIXME: This loop is no longer required once we lazy attach all the time. |
+ if (renderer() && !document().inStyleRecalc()) { |
+ for (Node* next = nextSibling(); next; next = next->nextSibling()) { |
+ if (next->renderer()) |
+ break; |
+ if (!next->attached()) |
+ break; // Assume this means none of the following siblings are attached. |
+ if (!next->isTextNode()) |
+ continue; |
+ ASSERT(!next->renderer()); |
+ toText(next)->reattach(); |
+ // If we again decided not to create a renderer for next, we can bail out the loop, |
+ // because it won't affect the result of Text::textRendererIsNeeded() for the rest |
+ // of sibling nodes. |
+ if (!next->renderer()) |
+ break; |
+ } |
+ } |
+ |
setAttached(); |
clearNeedsStyleRecalc(); |