| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 365 |
| 366 if (Cluster* cluster = maybeCreateCluster(block)) | 366 if (Cluster* cluster = maybeCreateCluster(block)) |
| 367 m_clusterStack.append(adoptPtr(cluster)); | 367 m_clusterStack.append(adoptPtr(cluster)); |
| 368 | 368 |
| 369 // Cells in auto-layout tables are handled separately by inflateAutoTable. | 369 // Cells in auto-layout tables are handled separately by inflateAutoTable. |
| 370 bool isAutoTableCell = block->isTableCell() && !toLayoutTableCell(block)->ta
ble()->style()->isFixedTableLayout(); | 370 bool isAutoTableCell = block->isTableCell() && !toLayoutTableCell(block)->ta
ble()->style()->isFixedTableLayout(); |
| 371 if (!isAutoTableCell && !m_clusterStack.isEmpty()) | 371 if (!isAutoTableCell && !m_clusterStack.isEmpty()) |
| 372 inflate(block); | 372 inflate(block); |
| 373 } | 373 } |
| 374 | 374 |
| 375 void TextAutosizer::inflateListItem(LayoutListItem* listItem, LayoutListMarker*
listItemMarker) | |
| 376 { | |
| 377 if (!shouldHandleLayout()) | |
| 378 return; | |
| 379 ASSERT(listItem && listItemMarker); | |
| 380 | |
| 381 if (prepareForLayout(listItem) == StopLayout) | |
| 382 return; | |
| 383 | |
| 384 // Force the LI to be inside the DBCAT when computing the multiplier. | |
| 385 // This guarantees that the DBCAT has entered layout, so we can ask for its
width. | |
| 386 // It also makes sense because the list marker is autosized like a text node
. | |
| 387 float multiplier = clusterMultiplier(currentCluster()); | |
| 388 | |
| 389 applyMultiplier(listItem, multiplier); | |
| 390 applyMultiplier(listItemMarker, multiplier); | |
| 391 } | |
| 392 | |
| 393 void TextAutosizer::inflateAutoTable(LayoutTable* table) | 375 void TextAutosizer::inflateAutoTable(LayoutTable* table) |
| 394 { | 376 { |
| 395 ASSERT(table); | 377 ASSERT(table); |
| 396 ASSERT(!table->style()->isFixedTableLayout()); | 378 ASSERT(!table->style()->isFixedTableLayout()); |
| 397 ASSERT(table->containingBlock()); | 379 ASSERT(table->containingBlock()); |
| 398 | 380 |
| 399 Cluster* cluster = currentCluster(); | 381 Cluster* cluster = currentCluster(); |
| 400 if (cluster->m_root != table) | 382 if (cluster->m_root != table) |
| 401 return; | 383 return; |
| 402 | 384 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 child = toLayoutInline(parent)->firstChild(); | 431 child = toLayoutInline(parent)->firstChild(); |
| 450 | 432 |
| 451 while (child) { | 433 while (child) { |
| 452 if (child->isText()) { | 434 if (child->isText()) { |
| 453 hasTextChild = true; | 435 hasTextChild = true; |
| 454 // We only calculate this multiplier on-demand to ensure the parent
block of this text | 436 // We only calculate this multiplier on-demand to ensure the parent
block of this text |
| 455 // has entered layout. | 437 // has entered layout. |
| 456 if (!multiplier) | 438 if (!multiplier) |
| 457 multiplier = cluster->m_flags & SUPPRESSING ? 1.0f : clusterMult
iplier(cluster); | 439 multiplier = cluster->m_flags & SUPPRESSING ? 1.0f : clusterMult
iplier(cluster); |
| 458 applyMultiplier(child, multiplier); | 440 applyMultiplier(child, multiplier); |
| 441 |
| 459 // FIXME: Investigate why MarkOnlyThis is sufficient. | 442 // FIXME: Investigate why MarkOnlyThis is sufficient. |
| 460 if (parent->isLayoutInline()) | 443 if (parent->isLayoutInline()) |
| 461 child->setPreferredLogicalWidthsDirty(MarkOnlyThis); | 444 child->setPreferredLogicalWidthsDirty(MarkOnlyThis); |
| 462 } else if (child->isLayoutInline()) { | 445 } else if (child->isLayoutInline()) { |
| 463 multiplier = inflate(child, behavior, multiplier); | 446 multiplier = inflate(child, behavior, multiplier); |
| 464 } else if (child->isLayoutBlock() && behavior == DescendToInnerBlocks | 447 } else if (child->isLayoutBlock() && behavior == DescendToInnerBlocks |
| 465 && !classifyBlock(child, INDEPENDENT | EXPLICIT_WIDTH | SUPPRESSING)
) { | 448 && !classifyBlock(child, INDEPENDENT | EXPLICIT_WIDTH | SUPPRESSING)
) { |
| 466 multiplier = inflate(child, behavior, multiplier); | 449 multiplier = inflate(child, behavior, multiplier); |
| 467 } | 450 } |
| 468 child = child->nextSibling(); | 451 child = child->nextSibling(); |
| 469 } | 452 } |
| 470 | 453 |
| 471 if (hasTextChild) { | 454 if (hasTextChild) { |
| 472 applyMultiplier(parent, multiplier); // Parent handles line spacing. | 455 applyMultiplier(parent, multiplier); // Parent handles line spacing. |
| 473 } else if (!parent->isListItem()) { | 456 } else if (!parent->isListItem()) { |
| 474 // For consistency, a block with no immediate text child should always h
ave a | 457 // For consistency, a block with no immediate text child should always h
ave a |
| 475 // multiplier of 1 (except for list items which are handled in inflateLi
stItem). | 458 // multiplier of 1. |
| 476 applyMultiplier(parent, 1); | 459 applyMultiplier(parent, 1); |
| 477 } | 460 } |
| 461 |
| 462 if (parent->isListItem()) { |
| 463 float multiplier = clusterMultiplier(cluster); |
| 464 applyMultiplier(parent, multiplier); |
| 465 |
| 466 // The list item has to be treated special because we can have a tree su
ch that you have |
| 467 // a list item for a form inside it. The list marker then ends up inside
the form and when |
| 468 // we try to get the clusterMultiplier we have the wrong cluster root to
work from and get |
| 469 // the wrong value. |
| 470 LayoutListItem* item = toLayoutListItem(parent); |
| 471 if (LayoutListMarker* marker = item->marker()) { |
| 472 applyMultiplier(marker, multiplier); |
| 473 marker->setPreferredLogicalWidthsDirty(MarkOnlyThis); |
| 474 } |
| 475 } |
| 476 |
| 478 return multiplier; | 477 return multiplier; |
| 479 } | 478 } |
| 480 | 479 |
| 481 bool TextAutosizer::shouldHandleLayout() const | 480 bool TextAutosizer::shouldHandleLayout() const |
| 482 { | 481 { |
| 483 return m_pageInfo.m_settingEnabled && m_pageInfo.m_pageNeedsAutosizing && !m
_updatePageInfoDeferred; | 482 return m_pageInfo.m_settingEnabled && m_pageInfo.m_pageNeedsAutosizing && !m
_updatePageInfoDeferred; |
| 484 } | 483 } |
| 485 | 484 |
| 486 void TextAutosizer::updatePageInfoInAllFrames() | 485 void TextAutosizer::updatePageInfoInAllFrames() |
| 487 { | 486 { |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 if (!containingBlock) | 932 if (!containingBlock) |
| 934 return root; | 933 return root; |
| 935 | 934 |
| 936 ASSERT(containingBlock->isDescendantOf(root)); | 935 ASSERT(containingBlock->isDescendantOf(root)); |
| 937 return containingBlock; | 936 return containingBlock; |
| 938 } | 937 } |
| 939 | 938 |
| 940 const LayoutObject* TextAutosizer::findTextLeaf(const LayoutObject* parent, size
_t& depth, TextLeafSearch firstOrLast) const | 939 const LayoutObject* TextAutosizer::findTextLeaf(const LayoutObject* parent, size
_t& depth, TextLeafSearch firstOrLast) const |
| 941 { | 940 { |
| 942 // List items are treated as text due to the marker. | 941 // List items are treated as text due to the marker. |
| 943 // The actual layoutObject for the marker (LayoutListMarker) may not be in t
he tree yet since it is added during layout. | |
| 944 if (parent->isListItem()) | 942 if (parent->isListItem()) |
| 945 return parent; | 943 return parent; |
| 946 | 944 |
| 947 if (parent->isText()) | 945 if (parent->isText()) |
| 948 return parent; | 946 return parent; |
| 949 | 947 |
| 950 ++depth; | 948 ++depth; |
| 951 const LayoutObject* child = (firstOrLast == First) ? parent->slowFirstChild(
) : parent->slowLastChild(); | 949 const LayoutObject* child = (firstOrLast == First) ? parent->slowFirstChild(
) : parent->slowLastChild(); |
| 952 while (child) { | 950 while (child) { |
| 953 // Note: At this point clusters may not have been created for these bloc
ks so we cannot rely | 951 // Note: At this point clusters may not have been created for these bloc
ks so we cannot rely |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 } | 1169 } |
| 1172 return computedSize; | 1170 return computedSize; |
| 1173 } | 1171 } |
| 1174 | 1172 |
| 1175 DEFINE_TRACE(TextAutosizer) | 1173 DEFINE_TRACE(TextAutosizer) |
| 1176 { | 1174 { |
| 1177 visitor->trace(m_document); | 1175 visitor->trace(m_document); |
| 1178 } | 1176 } |
| 1179 | 1177 |
| 1180 } // namespace blink | 1178 } // namespace blink |
| OLD | NEW |