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

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: 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 ad796131d66ab9fb16c928cb0bfd4b6c74a6595b..c2069449277a875d96e31a372204cb5dd474c207 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)
Xianzhu 2014/11/05 20:15:33 '!first' is not strictly necessary because 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,26 @@ void Text::attach(const AttachContext& context)
CharacterData::attach(context);
}
+void Text::reattachIfNeeded(const AttachContext& context)
+{
+ RenderTreeBuilderForText treeBuilder(this);
+ bool hadRenderer = renderer();
+ bool rendererIsNeeded = treeBuilder.rendererIsNeeded();
+ if (rendererIsNeeded == hadRenderer)
+ return;
+
+ // The following is almost the same as Node::attach() 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)
+ treeBuilder.createRenderer();
+ CharacterData::attach(reattachContext);
+}
+
void Text::recalcTextStyle(StyleRecalcChange change, Text* nextTextSibling)
{
if (RenderText* renderer = this->renderer()) {
@@ -319,7 +339,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