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

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: Text::reattachIfNeeded() 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..92db5c2ab6d0bcc6ad625ade778ba9770d2b67f0 100644
--- a/Source/core/dom/Text.cpp
+++ b/Source/core/dom/Text.cpp
@@ -274,7 +274,7 @@ bool Text::textRendererIsNeeded(const RenderStyle& style, const RenderObject& pa
unsigned maxSiblingsToVisit = 50;
RenderObject* first = parent.slowFirstChild();
- while (first && first->isFloatingOrOutOfFlowPositioned() && maxSiblingsToVisit--)
+ while (first && (first == renderer() || first->isFloatingOrOutOfFlowPositioned()) && maxSiblingsToVisit--)
leviw_travelin_and_unemployed 2014/11/05 19:23:15 You still want to store renderer() in a local vari
Xianzhu 2014/11/05 20:15:33 Moved first==renderer() out of the loop into the f
first = first->nextSibling();
if (!first || NodeRenderingTraversal::nextSiblingRenderer(this) == first)
// Whitespace at the start of a block just goes away. Don't even
@@ -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();
leviw_travelin_and_unemployed 2014/11/05 19:23:15 You shouldn't need the !! when assigning into a bo
Xianzhu 2014/11/05 20:15:33 Done.
+ 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