Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(666)

Unified Diff: Source/core/dom/Text.cpp

Issue 684633006: Reattach whitespace siblings only when needed (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Text.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Text.cpp
diff --git a/Source/core/dom/Text.cpp b/Source/core/dom/Text.cpp
index 2426009c6edb92702b679096b4140bc7abb6aa20..eee103c9790e4b37044ef4c8f54f3eefa35dbdc7 100644
--- a/Source/core/dom/Text.cpp
+++ b/Source/core/dom/Text.cpp
@@ -276,7 +276,7 @@ bool Text::textRendererIsNeeded(const RenderStyle& style, const RenderObject& pa
RenderObject* first = parent.slowFirstChild();
while (first && first->isFloatingOrOutOfFlowPositioned() && maxSiblingsToVisit--)
first = first->nextSibling();
- if (!first || NodeRenderingTraversal::nextSiblingRenderer(this) == first)
+ if (!first || first == renderer() || NodeRenderingTraversal::nextSiblingRenderer(this) == first)
// Whitespace at the start of a block just goes away. Don't even
// make a render object for this text.
return false;
@@ -308,6 +308,32 @@ void Text::attach(const AttachContext& context)
CharacterData::attach(context);
}
+void Text::reattachIfNeeded(const AttachContext& context)
+{
+ bool rendererIsNeeded = false;
+ ContainerNode* renderingParent = NodeRenderingTraversal::parent(this);
+ if (renderingParent) {
+ if (RenderObject* parentRenderer = renderingParent->renderer()) {
+ if (textRendererIsNeeded(*parentRenderer->style(), *parentRenderer))
+ rendererIsNeeded = true;
+ }
+ }
+
+ if (rendererIsNeeded == !!renderer())
+ return;
+
+ // The following is almost the same as Node::reattach() except that we create renderer only if needed.
+ // Not calling reattach() to avoid repeated calls to Text::textRendererIsNeeded().
+ AttachContext reattachContext(context);
+ reattachContext.performingReattach = true;
+
+ if (styleChangeType() < NeedsReattachStyleChange)
+ detach(reattachContext);
+ if (rendererIsNeeded)
+ RenderTreeBuilderForText(this, renderingParent->renderer()).createRenderer();
+ CharacterData::attach(reattachContext);
+}
+
void Text::recalcTextStyle(StyleRecalcChange change, Text* nextTextSibling)
{
if (RenderText* renderer = this->renderer()) {
@@ -319,7 +345,7 @@ void Text::recalcTextStyle(StyleRecalcChange change, Text* nextTextSibling)
} else if (needsStyleRecalc() || needsWhitespaceRenderer()) {
reattach();
if (this->renderer())
- reattachWhitespaceSiblings(nextTextSibling);
+ reattachWhitespaceSiblingsIfNeeded(nextTextSibling);
}
}
« no previous file with comments | « Source/core/dom/Text.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698