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

Side by Side 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, 9 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
5 * reserved. 5 * reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 245
246 if (parent.isTable() || parent.isTableRow() || parent.isTableSection() || 246 if (parent.isTable() || parent.isTableRow() || parent.isTableSection() ||
247 parent.isLayoutTableCol() || parent.isFrameSet() || 247 parent.isLayoutTableCol() || parent.isFrameSet() ||
248 parent.isFlexibleBox() || parent.isLayoutGrid() || parent.isSVGRoot() || 248 parent.isFlexibleBox() || parent.isLayoutGrid() || parent.isSVGRoot() ||
249 parent.isSVGContainer() || parent.isSVGImage() || parent.isSVGShape()) { 249 parent.isSVGContainer() || parent.isSVGImage() || parent.isSVGShape()) {
250 return false; 250 return false;
251 } 251 }
252 return true; 252 return true;
253 } 253 }
254 254
255 static inline bool emptyOrEndsWithWhitespace(const WTF::String& string) {
256 unsigned len = string.length();
257 return !len || isASCIISpace(string[len - 1]);
258 }
259
255 bool Text::textLayoutObjectIsNeeded(const ComputedStyle& style, 260 bool Text::textLayoutObjectIsNeeded(const ComputedStyle& style,
256 const LayoutObject& parent) const { 261 const LayoutObject& parent) const {
257 DCHECK(!document().childNeedsDistributionRecalc()); 262 DCHECK(!document().childNeedsDistributionRecalc());
258 263
259 if (!parent.canHaveChildren()) 264 if (!parent.canHaveChildren())
260 return false; 265 return false;
261 266
262 if (isEditingText()) 267 if (isEditingText())
263 return true; 268 return true;
264 269
(...skipping 18 matching lines...) Expand all
283 return true; 288 return true;
284 289
285 // Avoiding creation of a layoutObject for the text node is a non-essential 290 // Avoiding creation of a layoutObject for the text node is a non-essential
286 // memory optimization. So to avoid blowing up on very wide DOMs, we limit 291 // memory optimization. So to avoid blowing up on very wide DOMs, we limit
287 // the number of siblings to visit. 292 // the number of siblings to visit.
288 unsigned maxSiblingsToVisit = 50; 293 unsigned maxSiblingsToVisit = 50;
289 294
290 const LayoutObject* prev = 295 const LayoutObject* prev =
291 LayoutTreeBuilderTraversal::previousSiblingLayoutObject( 296 LayoutTreeBuilderTraversal::previousSiblingLayoutObject(
292 *this, maxSiblingsToVisit); 297 *this, maxSiblingsToVisit);
298
299 while (prev && prev->isFloatingOrOutOfFlowPositioned() &&
300 --maxSiblingsToVisit)
301 prev = prev->previousSibling();
302
303 if (!maxSiblingsToVisit)
304 return true;
305
293 if (prev && prev->isBR()) // <span><br/> <br/></span> 306 if (prev && prev->isBR()) // <span><br/> <br/></span>
294 return false; 307 return false;
295 308
309 // Collapse whitespace away.
310 if (prev && prev->isText() &&
311 emptyOrEndsWithWhitespace(toLayoutText(prev)->text()))
312 return false;
313
296 if (parent.isLayoutInline()) { 314 if (parent.isLayoutInline()) {
297 // <span><div/> <div/></span> 315 // <span><div/> <div/></span>
298 if (prev && !prev->isInline() && !prev->isOutOfFlowPositioned()) 316 if (prev && !prev->isInline())
299 return false; 317 return false;
300 } else { 318 } else {
301 if (parent.isLayoutBlock() && !parent.childrenInline() && 319 if (parent.isLayoutBlock() && !parent.childrenInline() &&
302 (!prev || !prev->isInline())) 320 (!prev || !prev->isInline()))
303 return false; 321 return false;
304 322
305 LayoutObject* first = parent.slowFirstChild(); 323 LayoutObject* first = parent.slowFirstChild();
306 for (; first && first->isFloatingOrOutOfFlowPositioned() && 324 for (; first && first->isFloatingOrOutOfFlowPositioned() &&
307 maxSiblingsToVisit; 325 maxSiblingsToVisit;
308 first = first->nextSibling(), --maxSiblingsToVisit) { 326 first = first->nextSibling(), --maxSiblingsToVisit) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 485
468 Text* Text::cloneWithData(const String& data) { 486 Text* Text::cloneWithData(const String& data) {
469 return create(document(), data); 487 return create(document(), data);
470 } 488 }
471 489
472 DEFINE_TRACE(Text) { 490 DEFINE_TRACE(Text) {
473 CharacterData::trace(visitor); 491 CharacterData::trace(visitor);
474 } 492 }
475 493
476 } // namespace blink 494 } // namespace blink
OLDNEW
« 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