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

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

Issue 2719993003: Collapse whitespace away when creating whitespace layout objects.
Patch Set: skipping oof frames 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 | « no previous file | 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..e34a38417bc776002d59c866bc88a719fc19265f 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,9 +295,21 @@ bool Text::textLayoutObjectIsNeeded(const ComputedStyle& style,
const LayoutObject* prev =
LayoutTreeBuilderTraversal::previousSiblingLayoutObject(
*this, maxSiblingsToVisit);
+
+ while (prev && prev->isOutOfFlowPositioned() && --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())
rune 2017/02/28 09:59:46 prev cannot be out-of-flow at this point since pre
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698