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

Side by Side Diff: Source/core/rendering/FastTextAutosizer.cpp

Issue 319013003: Set multiplier to 1 on blocks with no direct text children. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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
OLDNEW
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
365 ASSERT(shouldHandleLayout()); 365 ASSERT(shouldHandleLayout());
366 366
367 if (prepareForLayout(block) == StopLayout) 367 if (prepareForLayout(block) == StopLayout)
368 return; 368 return;
369 369
370 if (Cluster* cluster = maybeCreateCluster(block)) 370 if (Cluster* cluster = maybeCreateCluster(block))
371 m_clusterStack.append(adoptPtr(cluster)); 371 m_clusterStack.append(adoptPtr(cluster));
372 372
373 // Cells in auto-layout tables are handled separately by inflateAutoTable. 373 // Cells in auto-layout tables are handled separately by inflateAutoTable.
374 bool isAutoTableCell = block->isTableCell() && !toRenderTableCell(block)->ta ble()->style()->isFixedTableLayout(); 374 bool isAutoTableCell = block->isTableCell() && !toRenderTableCell(block)->ta ble()->style()->isFixedTableLayout();
375 if (block->childrenInline() && block->firstChild() && !isAutoTableCell) 375 if (!isAutoTableCell && !m_clusterStack.isEmpty())
376 inflate(block); 376 inflate(block);
377 } 377 }
378 378
379 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark er* listItemMarker) 379 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark er* listItemMarker)
380 { 380 {
381 if (!shouldHandleLayout()) 381 if (!shouldHandleLayout())
382 return; 382 return;
383 ASSERT(listItem && listItemMarker); 383 ASSERT(listItem && listItemMarker);
384 384
385 if (prepareForLayout(listItem) == StopLayout) 385 if (prepareForLayout(listItem) == StopLayout)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 #ifndef NDEBUG 434 #ifndef NDEBUG
435 m_blocksThatHaveBegunLayout.clear(); 435 m_blocksThatHaveBegunLayout.clear();
436 #endif 436 #endif
437 // Tables can create two layout scopes for the same block so the isEmpty 437 // Tables can create two layout scopes for the same block so the isEmpty
438 // check below is needed to guard against endLayout being called twice. 438 // check below is needed to guard against endLayout being called twice.
439 } else if (!m_clusterStack.isEmpty() && currentCluster()->m_root == block) { 439 } else if (!m_clusterStack.isEmpty() && currentCluster()->m_root == block) {
440 m_clusterStack.removeLast(); 440 m_clusterStack.removeLast();
441 } 441 }
442 } 442 }
443 443
444 void FastTextAutosizer::inflate(RenderBlock* block) 444 void FastTextAutosizer::inflate(RenderBlock* block)
pdr. 2014/06/05 20:13:49 I think this would be a little cleaner if this ret
skobes 2014/06/05 21:19:19 Done.
445 { 445 {
446 float multiplier = 0;
447 inflateRecursive(block, multiplier);
448 }
449
450 void FastTextAutosizer::inflateRecursive(RenderObject* parent, float& multiplier )
451 {
446 Cluster* cluster = currentCluster(); 452 Cluster* cluster = currentCluster();
447 float multiplier = 0; 453 bool hasTextChild = false;
448 RenderObject* descendant = block->firstChild(); 454
449 while (descendant) { 455 RenderObject* child = 0;
450 // Skip block descendants because they will be inflate()'d on their own. 456 if (parent->isRenderBlock() && parent->childrenInline())
pdr. 2014/06/05 20:13:49 The fast firstChild checks only remove a single vi
skobes 2014/06/05 21:19:20 We can't directly call parent->firstChild() becaus
451 if (descendant->isRenderBlock()) { 457 child = toRenderBlock(parent)->firstChild();
452 descendant = descendant->nextInPreOrderAfterChildren(block); 458 else if (parent->isRenderInline())
453 continue; 459 child = toRenderInline(parent)->firstChild();
454 } 460
455 if (descendant->isText()) { 461 while (child) {
462 if (child->isText()) {
463 hasTextChild = true;
456 // We only calculate this multiplier on-demand to ensure the parent block of this text 464 // We only calculate this multiplier on-demand to ensure the parent block of this text
457 // has entered layout. 465 // has entered layout.
458 if (!multiplier) 466 if (!multiplier)
459 multiplier = cluster->m_flags & SUPPRESSING ? 1.0f : clusterMult iplier(cluster); 467 multiplier = cluster->m_flags & SUPPRESSING ? 1.0f : clusterMult iplier(cluster);
460 applyMultiplier(descendant, multiplier); 468 applyMultiplier(child, multiplier);
461 applyMultiplier(descendant->parent(), multiplier); // Parent handles line spacing.
462 // FIXME: Investigate why MarkOnlyThis is sufficient. 469 // FIXME: Investigate why MarkOnlyThis is sufficient.
463 if (descendant->parent()->isRenderInline()) 470 if (parent->isRenderInline())
464 descendant->setPreferredLogicalWidthsDirty(MarkOnlyThis); 471 child->setPreferredLogicalWidthsDirty(MarkOnlyThis);
472 } else if (child->isRenderInline()) {
473 inflateRecursive(child, multiplier);
465 } 474 }
466 descendant = descendant->nextInPreOrder(block); 475 child = child->nextSibling();
476 }
477
478 if (hasTextChild) {
479 applyMultiplier(parent, multiplier); // Parent handles line spacing.
480 } else if (!parent->isListItem()) {
481 // For consistency, a block with no immediate text child should always h ave a
482 // multiplier of 1 (except for list items which are handled in inflateLi stItem).
483 applyMultiplier(parent, 1);
pdr. 2014/06/05 20:13:49 Should we only do this when textAutosizingMultipli
skobes 2014/06/05 21:19:19 applyMultiplier does this check.
467 } 484 }
468 } 485 }
469 486
470 bool FastTextAutosizer::shouldHandleLayout() const 487 bool FastTextAutosizer::shouldHandleLayout() const
471 { 488 {
472 return m_pageInfo.m_settingEnabled && m_pageInfo.m_pageNeedsAutosizing && !m _updatePageInfoDeferred; 489 return m_pageInfo.m_settingEnabled && m_pageInfo.m_pageNeedsAutosizing && !m _updatePageInfoDeferred;
473 } 490 }
474 491
475 void FastTextAutosizer::updatePageInfoInAllFrames() 492 void FastTextAutosizer::updatePageInfoInAllFrames()
476 { 493 {
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo() 1127 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo()
1111 { 1128 {
1112 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto sizer()) { 1129 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto sizer()) {
1113 ASSERT(textAutosizer->m_updatePageInfoDeferred); 1130 ASSERT(textAutosizer->m_updatePageInfoDeferred);
1114 textAutosizer->m_updatePageInfoDeferred = false; 1131 textAutosizer->m_updatePageInfoDeferred = false;
1115 textAutosizer->updatePageInfoInAllFrames(); 1132 textAutosizer->updatePageInfoInAllFrames();
1116 } 1133 }
1117 } 1134 }
1118 1135
1119 } // namespace WebCore 1136 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698