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

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

Issue 2719993003: Collapse whitespace away when creating whitespace layout objects.
Patch Set: g cl web Created 3 years, 10 months 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 | « third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-render-layer-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/Text.cpp
diff --git a/third_party/WebKit/Source/core/dom/Text.cpp b/third_party/WebKit/Source/core/dom/Text.cpp
index f69b8552c899c41d59a2d26db83f4be95856723f..959bd8a4547dd51f46c1ae874121527cf9940d08 100644
--- a/third_party/WebKit/Source/core/dom/Text.cpp
+++ b/third_party/WebKit/Source/core/dom/Text.cpp
@@ -252,6 +252,11 @@ static inline bool canHaveWhitespaceChildren(const LayoutObject& parent) {
return true;
}
+static inline bool emptyOrEndsWithWhitespace(const WTF::String& string) {
+ unsigned len = string.length();
+ return !len || isASCIISpace(string[len - 1]);
+}
+
bool Text::textLayoutObjectIsNeeded(const ComputedStyle& style,
const LayoutObject& parent) const {
DCHECK(!document().childNeedsDistributionRecalc());
@@ -290,12 +295,25 @@ bool Text::textLayoutObjectIsNeeded(const ComputedStyle& style,
const LayoutObject* prev =
LayoutTreeBuilderTraversal::previousSiblingLayoutObject(
*this, maxSiblingsToVisit);
+
+ while (prev && prev->isFloatingOrOutOfFlowPositioned() &&
+ --maxSiblingsToVisit)
+ prev = prev->previousSibling();
+
+ if (!maxSiblingsToVisit)
+ return true;
+
if (prev && prev->isBR()) // <span><br/> <br/></span>
return false;
+ // Collapse whitespace away.
+ if (prev && prev->isText() &&
+ emptyOrEndsWithWhitespace(toLayoutText(prev)->text()))
+ return false;
+
if (parent.isLayoutInline()) {
// <span><div/> <div/></span>
- if (prev && !prev->isInline() && !prev->isOutOfFlowPositioned())
+ if (prev && !prev->isInline())
return false;
} else {
if (parent.isLayoutBlock() && !parent.childrenInline() &&
« no previous file with comments | « third_party/WebKit/LayoutTests/virtual/gpu/fast/canvas/canvas-render-layer-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698