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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 bool Text::textLayoutObjectIsNeeded(const ComputedStyle& style, | 255 bool Text::textLayoutObjectIsNeeded(const ComputedStyle& style, |
| 256 const LayoutObject& parent) const { | 256 const LayoutObject& parent) const { |
| 257 DCHECK(!document().childNeedsDistributionRecalc()); | |
| 258 | |
| 257 if (!parent.canHaveChildren()) | 259 if (!parent.canHaveChildren()) |
| 258 return false; | 260 return false; |
| 259 | 261 |
| 260 if (isEditingText()) | 262 if (isEditingText()) |
| 261 return true; | 263 return true; |
| 262 | 264 |
| 263 if (!length()) | 265 if (!length()) |
| 264 return false; | 266 return false; |
| 265 | 267 |
| 266 if (style.display() == EDisplay::None) | 268 if (style.display() == EDisplay::None) |
| 267 return false; | 269 return false; |
| 268 | 270 |
| 269 if (!containsOnlyWhitespace()) | 271 if (!containsOnlyWhitespace()) |
| 270 return true; | 272 return true; |
| 271 | 273 |
| 272 if (!canHaveWhitespaceChildren(parent)) | 274 if (!canHaveWhitespaceChildren(parent)) |
| 273 return false; | 275 return false; |
| 274 | 276 |
| 275 // pre-wrap in SVG never makes layoutObject. | 277 // pre-wrap in SVG never makes layoutObject. |
| 276 if (style.whiteSpace() == EWhiteSpace::kPreWrap && parent.isSVG()) | 278 if (style.whiteSpace() == EWhiteSpace::kPreWrap && parent.isSVG()) |
| 277 return false; | 279 return false; |
| 278 | 280 |
| 279 // pre/pre-wrap/pre-line always make layoutObjects. | 281 // pre/pre-wrap/pre-line always make layoutObjects. |
| 280 if (style.preserveNewline()) | 282 if (style.preserveNewline()) |
| 281 return true; | 283 return true; |
| 282 | 284 |
| 283 // childNeedsDistributionRecalc() here is rare, only happens JS calling | |
| 284 // surroundContents() etc. from DOMNodeInsertedIntoDocument etc. | |
| 285 if (document().childNeedsDistributionRecalc()) | |
| 286 return true; | |
| 287 | |
| 288 // Avoiding creation of a layoutObject for the text node is a non-essential | 285 // Avoiding creation of a layoutObject for the text node is a non-essential |
| 289 // memory optimization. So to avoid blowing up on very wide DOMs, we limit | 286 // memory optimization. So to avoid blowing up on very wide DOMs, we limit |
| 290 // the number of siblings to visit. | 287 // the number of siblings to visit. |
| 291 unsigned maxSiblingsToVisit = 50; | 288 unsigned maxSiblingsToVisit = 50; |
| 292 | 289 |
| 293 const LayoutObject* prev = | 290 const LayoutObject* prev = |
| 294 LayoutTreeBuilderTraversal::previousSiblingLayoutObject( | 291 LayoutTreeBuilderTraversal::previousSiblingLayoutObject( |
| 295 *this, maxSiblingsToVisit); | 292 *this, maxSiblingsToVisit); |
| 296 if (prev && prev->isBR()) // <span><br/> <br/></span> | 293 if (prev && prev->isBR()) // <span><br/> <br/></span> |
| 297 return false; | 294 return false; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 return false; | 413 return false; |
| 417 } | 414 } |
| 418 | 415 |
| 419 // Passing both |textNode| and its layout object because repeated calls to | 416 // Passing both |textNode| and its layout object because repeated calls to |
| 420 // |Node::layoutObject()| are discouraged. | 417 // |Node::layoutObject()| are discouraged. |
| 421 static bool shouldUpdateLayoutByReattaching(const Text& textNode, | 418 static bool shouldUpdateLayoutByReattaching(const Text& textNode, |
| 422 LayoutText* textLayoutObject) { | 419 LayoutText* textLayoutObject) { |
| 423 DCHECK_EQ(textNode.layoutObject(), textLayoutObject); | 420 DCHECK_EQ(textNode.layoutObject(), textLayoutObject); |
| 424 if (!textLayoutObject) | 421 if (!textLayoutObject) |
| 425 return true; | 422 return true; |
| 426 if (!textNode.textLayoutObjectIsNeeded(*textLayoutObject->style(), | 423 // In genenral we do not want to branch on lifecycle states such as |
| 427 *textLayoutObject->parent())) | 424 // |childNeedsDistributionRecalc|, but this code tries to figure out if we can |
| 425 // use an optimized code path that avoids reattach. | |
| 426 if (!textNode.document().childNeedsDistributionRecalc() && | |
| 427 !textNode.textLayoutObjectIsNeeded(*textLayoutObject->style(), | |
| 428 *textLayoutObject->parent())) { | |
|
rune
2017/02/09 09:16:48
genenral -> general
| |
| 428 return true; | 429 return true; |
| 430 } | |
| 429 if (textLayoutObject->isTextFragment()) { | 431 if (textLayoutObject->isTextFragment()) { |
| 430 // Changes of |textNode| may change first letter part, so we should | 432 // Changes of |textNode| may change first letter part, so we should |
| 431 // reattach. | 433 // reattach. |
| 432 return toLayoutTextFragment(textLayoutObject)->firstLetterPseudoElement(); | 434 return toLayoutTextFragment(textLayoutObject)->firstLetterPseudoElement(); |
| 433 } | 435 } |
| 434 return false; | 436 return false; |
| 435 } | 437 } |
| 436 | 438 |
| 437 void Text::updateTextLayoutObject(unsigned offsetOfReplacedData, | 439 void Text::updateTextLayoutObject(unsigned offsetOfReplacedData, |
| 438 unsigned lengthOfReplacedData) { | 440 unsigned lengthOfReplacedData) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 449 | 451 |
| 450 Text* Text::cloneWithData(const String& data) { | 452 Text* Text::cloneWithData(const String& data) { |
| 451 return create(document(), data); | 453 return create(document(), data); |
| 452 } | 454 } |
| 453 | 455 |
| 454 DEFINE_TRACE(Text) { | 456 DEFINE_TRACE(Text) { |
| 455 CharacterData::trace(visitor); | 457 CharacterData::trace(visitor); |
| 456 } | 458 } |
| 457 | 459 |
| 458 } // namespace blink | 460 } // namespace blink |
| OLD | NEW |