Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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->isOutOfFlowPositioned() && --maxSiblingsToVisit) | |
| 300 prev = prev->previousSibling(); | |
| 301 | |
| 302 if (!maxSiblingsToVisit) | |
| 303 return true; | |
| 304 | |
| 293 if (prev && prev->isBR()) // <span><br/> <br/></span> | 305 if (prev && prev->isBR()) // <span><br/> <br/></span> |
| 294 return false; | 306 return false; |
| 295 | 307 |
| 308 // Collapse whitespace away. | |
| 309 if (prev && prev->isText() && | |
| 310 emptyOrEndsWithWhitespace(toLayoutText(prev)->text())) | |
| 311 return false; | |
| 312 | |
| 296 if (parent.isLayoutInline()) { | 313 if (parent.isLayoutInline()) { |
| 297 // <span><div/> <div/></span> | 314 // <span><div/> <div/></span> |
| 298 if (prev && !prev->isInline() && !prev->isOutOfFlowPositioned()) | 315 if (prev && !prev->isInline() && !prev->isOutOfFlowPositioned()) |
|
rune
2017/02/28 09:59:46
prev cannot be out-of-flow at this point since pre
| |
| 299 return false; | 316 return false; |
| 300 } else { | 317 } else { |
| 301 if (parent.isLayoutBlock() && !parent.childrenInline() && | 318 if (parent.isLayoutBlock() && !parent.childrenInline() && |
| 302 (!prev || !prev->isInline())) | 319 (!prev || !prev->isInline())) |
| 303 return false; | 320 return false; |
| 304 | 321 |
| 305 LayoutObject* first = parent.slowFirstChild(); | 322 LayoutObject* first = parent.slowFirstChild(); |
| 306 for (; first && first->isFloatingOrOutOfFlowPositioned() && | 323 for (; first && first->isFloatingOrOutOfFlowPositioned() && |
| 307 maxSiblingsToVisit; | 324 maxSiblingsToVisit; |
| 308 first = first->nextSibling(), --maxSiblingsToVisit) { | 325 first = first->nextSibling(), --maxSiblingsToVisit) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 | 484 |
| 468 Text* Text::cloneWithData(const String& data) { | 485 Text* Text::cloneWithData(const String& data) { |
| 469 return create(document(), data); | 486 return create(document(), data); |
| 470 } | 487 } |
| 471 | 488 |
| 472 DEFINE_TRACE(Text) { | 489 DEFINE_TRACE(Text) { |
| 473 CharacterData::trace(visitor); | 490 CharacterData::trace(visitor); |
| 474 } | 491 } |
| 475 | 492 |
| 476 } // namespace blink | 493 } // namespace blink |
| OLD | NEW |